annotate test/testsamples.py @ 399:a7c444404df9

Fix hexwrite
author Windel Bouwman
date Fri, 20 Jun 2014 16:36:49 +0200
parents c0d9837acde8
children
rev   line source
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
1 import unittest
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
2 import os
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
3 import io
375
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 374
diff changeset
4 from testemulation import runQemu, has_qemu
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
5 from testzcc import relpath
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 375
diff changeset
6 from ppci.buildfunctions import assemble, c3compile, link
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
7
398
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
8 mod_io_src = """
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
9 module io;
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
10 import arch;
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
11
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
12 function void println(string txt)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
13 {
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
14 print(txt);
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
15 arch.putc(10); // Newline!
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
16 }
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
17
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
18 function void print(string txt)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
19 {
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
20 var int i;
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
21 i = 0;
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
22
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
23 while (i < txt->len)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
24 {
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
25 arch.putc(cast<int>(txt->txt[i]));
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
26 i = i + 1;
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
27 }
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
28 }
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
29
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
30 // Print integer in hexadecimal notation:
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
31 function void print_int(int i)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
32 {
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
33 print("0x");
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
34
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
35 // int txt[20];
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
36 var int b;
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
37 var int c;
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
38
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
39 for (b=28; b >= 0; b = b - 4)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
40 {
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
41 c = (i >> b) & 0xF;
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
42 if (c < 10)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
43 {
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
44 arch.putc( 48 + c );
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
45 }
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
46 else
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
47 {
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
48 arch.putc( 65 - 10 + c );
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
49 }
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
50 }
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
51
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
52 arch.putc(10); // Newline!
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
53 }
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
54
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
55 function void print2(string label, int value)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
56 {
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
57 print(label);
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
58 print_int(value);
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
59 }
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
60 """
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
61
383
173e20a47fda Added linker description loader
Windel Bouwman
parents: 381
diff changeset
62
358
5ef1cb1bb54f Fix nosetests
Windel Bouwman
parents: 355
diff changeset
63 class Samples:
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
64 def testPrint(self):
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
65 snippet = """
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
66 module sample;
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
67 import io;
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
68 function void start()
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
69 {
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
70 io.print("Hello world");
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
71 }
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
72 """
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
73 self.do(snippet, "Hello world")
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
74
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
75 def testForLoopPrint(self):
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
76 snippet = """
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
77 module sample;
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
78 import io;
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
79 function void start()
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
80 {
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
81 var int i;
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
82 for (i=0; i<10; i = i + 1)
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
83 {
362
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 358
diff changeset
84 io.print2("A = ", i);
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
85 }
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
86 }
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
87 """
362
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 358
diff changeset
88 res = "".join("A = 0x{0:08X}\n".format(a) for a in range(10))
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 358
diff changeset
89 self.do(snippet, res)
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
90
374
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
91 def testIfStatement(self):
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
92 snippet = """
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
93 module sample;
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
94 import io;
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
95 function void start()
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
96 {
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
97 var int i;
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
98 i = 13;
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
99 if (i*7 < 100)
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
100 {
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
101 io.print("Wow");
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
102 }
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
103 else
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
104 {
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
105 io.print("Outch");
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
106 }
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
107 }
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
108 """
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
109 res = "Wow"
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
110 self.do(snippet, res)
72a3b646d543 Added if statement sample
Windel Bouwman
parents: 372
diff changeset
111
372
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
112 def testParameterPassing4(self):
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
113 snippet = """
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
114 module sample;
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
115 import io;
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
116 function void dump(int a, int b, int c, int d)
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
117 {
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
118 io.print2("a=", a);
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
119 io.print2("b=", b);
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
120 io.print2("c=", c);
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
121 io.print2("d=", d);
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
122 }
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
123 function void start()
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
124 {
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
125 dump(4,55,66,0x1337);
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
126 }
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
127 """
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
128 res = "a=0x{0:08X}\n".format(4)
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
129 res += "b=0x{0:08X}\n".format(55)
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
130 res += "c=0x{0:08X}\n".format(66)
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
131 res += "d=0x{0:08X}\n".format(0x1337)
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
132 self.do(snippet, res)
68841f9ab96c Added yet another test snippet
Windel Bouwman
parents: 366
diff changeset
133
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
134 def testGlobalVariable(self):
364
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
135 snippet = """
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
136 module sample;
364
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
137 import io;
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
138 var int G;
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
139 function void do1()
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
140 {
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
141 G = G + 1;
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
142 io.print2("G=", G);
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
143 }
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
144 function void do5()
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
145 {
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
146 G = G + 5;
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
147 io.print2("G=", G);
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
148 }
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
149 function void start()
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
150 {
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
151 G = 0;
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
152 do1();
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
153 do1();
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
154 do5();
364
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
155 do1();
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
156 do5();
364
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
157 }
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
158 """
398
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
159 res = "".join("G=0x{0:08X}\n".format(a) for a in [1, 2, 7, 8, 13])
364
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
160 self.do(snippet, res)
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
161
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
162
358
5ef1cb1bb54f Fix nosetests
Windel Bouwman
parents: 355
diff changeset
163 class TestSamplesOnVexpress(unittest.TestCase, Samples):
375
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 374
diff changeset
164 def setUp(self):
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 374
diff changeset
165 if not has_qemu():
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 374
diff changeset
166 self.skipTest('Not running qemu tests')
19eacf4f7270 Started on memory manager
Windel Bouwman
parents: 374
diff changeset
167
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
168 def do(self, src, expected_output):
398
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
169 startercode = """
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
170 section reset
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
171 mov sp, 0x30000 ; setup stack pointer
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
172 BL sample_start ; Branch to sample start
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
173 local_loop:
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
174 B local_loop
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
175 """
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
176
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
177 modarchcode = """
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
178 module arch;
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
179
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
180 function void putc(int c)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
181 {
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
182 var int *UART0DR;
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
183 UART0DR = cast<int*>(0x10009000); // UART0 DR register
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
184 *UART0DR = c;
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
185 }
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
186
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
187 """
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
188
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
189 arch_mmap = """
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
190 MEMORY image LOCATION=0x10000 SIZE=0x10000 {
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
191 SECTION(reset)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
192 SECTION(code)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
193 }
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
194
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
195 MEMORY ram LOCATION=0x20000 SIZE=0x10000 {
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
196 SECTION(data)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
197 }
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
198 """
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
199 # Construct binary file from snippet:
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 375
diff changeset
200 o1 = assemble(io.StringIO(startercode), 'arm')
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 375
diff changeset
201 o2 = c3compile([
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
202 relpath('..', 'kernel', 'src', 'io.c3'),
381
6df89163e114 Fix section and ldr pseudo instruction
Windel Bouwman
parents: 377
diff changeset
203 io.StringIO(modarchcode),
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 375
diff changeset
204 io.StringIO(src)], [], 'arm')
385
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
205 o3 = link([o2, o1], io.StringIO(arch_mmap), 'arm')
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
206
385
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
207 img_data = o3.get_image('image')
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 375
diff changeset
208 sample_filename = 'testsample.bin'
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 375
diff changeset
209 with open(sample_filename, 'wb') as f:
385
d056b552d3f4 Made better use of layout
Windel Bouwman
parents: 383
diff changeset
210 f.write(img_data)
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 375
diff changeset
211
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
212 # Check bin file exists:
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
213 self.assertTrue(os.path.isfile(sample_filename))
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
214
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
215 # Run bin file in emulator:
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
216 res = runQemu(sample_filename, machine='vexpress-a9')
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 364
diff changeset
217 os.remove(sample_filename)
355
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
218 self.assertEqual(expected_output, res)
c2ddc8a36f5e Enabled optimization
Windel Bouwman
parents:
diff changeset
219
364
c49459768aaa Work on globals
Windel Bouwman
parents: 363
diff changeset
220
398
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
221 class TestSamplesOnX86(unittest.TestCase, Samples):
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
222 def setUp(self):
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
223 if not has_qemu():
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
224 self.skipTest('Not running qemu tests')
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
225 self.skipTest('No x86 target yet')
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
226
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
227 def do(self, src, expected_output):
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
228 # Construct binary file from snippet:
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
229 o1 = assemble(io.StringIO(startercode), 'x86')
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
230 o2 = c3compile([
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
231 relpath('..', 'kernel', 'src', 'io.c3'),
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
232 io.StringIO(modarchcode),
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
233 io.StringIO(src)], [], 'x86')
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
234 o3 = link([o2, o1], io.StringIO(arch_mmap), 'x86')
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
235
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
236 img_data = o3.get_image('image')
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
237 sample_filename = 'testsample.bin'
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
238 with open(sample_filename, 'wb') as f:
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
239 f.write(img_data)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
240
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
241 # Check bin file exists:
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
242 self.assertTrue(os.path.isfile(sample_filename))
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
243
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
244 # Run bin file in emulator:
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
245 res = runQemu(sample_filename, machine='vexpress-a9')
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
246 os.remove(sample_filename)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
247 self.assertEqual(expected_output, res)
c0d9837acde8 x86 target refactor
Windel Bouwman
parents: 385
diff changeset
248
383
173e20a47fda Added linker description loader
Windel Bouwman
parents: 381
diff changeset
249 # TODO: test samples on thumb target..
173e20a47fda Added linker description loader
Windel Bouwman
parents: 381
diff changeset
250
173e20a47fda Added linker description loader
Windel Bouwman
parents: 381
diff changeset
251
362
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 358
diff changeset
252 if __name__ == '__main__':
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 358
diff changeset
253 unittest.main()
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 375
diff changeset
254