Mercurial > lcfOS
annotate test/testzcc.py @ 369:5333318ee33d
Python 3.2 compatible issues
author | Windel Bouwman |
---|---|
date | Fri, 21 Mar 2014 11:54:50 +0100 |
parents | 577ed7fb3fe4 |
children | 9667d78ba79e |
rev | line source |
---|---|
208 | 1 import unittest |
311 | 2 import os |
3 import sys | |
4 | |
208 | 5 import zcc |
335 | 6 from ppci.objectfile import ObjectFile |
250 | 7 import ppci |
287 | 8 import io |
342 | 9 from ppci.target import target_list |
208 | 10 |
321 | 11 # Store testdir for safe switch back to directory: |
12 testdir = os.path.dirname(os.path.abspath(__file__)) | |
13 | |
346 | 14 def relpath(*args): |
15 return os.path.join(testdir, *args) | |
321 | 16 |
338 | 17 class ZccBaseTestCase(unittest.TestCase): |
18 def callZcc(self, arg_list): | |
19 parser = zcc.make_parser() | |
20 arg_list = ['--log', 'warn'] + arg_list | |
21 args = parser.parse_args(arg_list) | |
22 self.assertEqual(0, zcc.main(args)) | |
23 | |
24 def buildRecipe(self, recipe): | |
25 arg_list = ['recipe', recipe] | |
26 self.callZcc(arg_list) | |
27 | |
28 | |
29 class ZccTestCase(ZccBaseTestCase): | |
208 | 30 """ Tests the compiler driver """ |
311 | 31 def setUp(self): |
321 | 32 os.chdir(testdir) |
33 | |
34 def tearDown(self): | |
35 os.chdir(testdir) | |
208 | 36 |
331 | 37 def do(self, filenames, imps=[], extra_args=[]): |
366 | 38 basedir = relpath('..', 'examples', 'c3') |
331 | 39 arg_list = ['compile'] |
40 arg_list += [os.path.join(basedir, fn) for fn in filenames] | |
288 | 41 for fn in imps: |
42 arg_list.append('-i') | |
43 arg_list.append(os.path.join(basedir, fn)) | |
292 | 44 arg_list.append('--target') |
341 | 45 arg_list.append('thumb') |
331 | 46 arg_list += extra_args |
47 self.callZcc(arg_list) | |
48 | |
49 | |
311 | 50 def testDumpIr(self): |
346 | 51 basedir = relpath('..', 'examples', 'c3', 'comments.c3') |
331 | 52 arg_list = ['compile', basedir] |
311 | 53 arg_list.append('--target') |
341 | 54 arg_list.append('thumb') |
331 | 55 self.callZcc(arg_list) |
311 | 56 |
367 | 57 @unittest.skip('Too hard') |
352 | 58 def testThumbKernel(self): |
331 | 59 """ Build kernel using zcc: """ |
352 | 60 recipe = relpath('..', 'kernel', 'thumb.yaml') |
61 self.buildRecipe(recipe) | |
62 | |
63 def testArmKernel(self): | |
64 """ Build kernel using zcc: """ | |
65 recipe = relpath('..', 'kernel', 'arm.yaml') | |
331 | 66 self.buildRecipe(recipe) |
313 | 67 |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
68 def testKernelBuildsEqualTwice(self): |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
69 """ Build kernel two times and check the output is equal """ |
366 | 70 recipe = relpath('..', 'kernel', 'arm.yaml') |
71 bin_filename = relpath('..', 'kernel', 'kernel_arm.bin') | |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
72 self.buildRecipe(recipe) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
73 with open(bin_filename, 'rb') as f: |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
74 a = f.read() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
75 self.buildRecipe(recipe) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
76 with open(bin_filename, 'rb') as f: |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
77 b = f.read() |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
78 self.assertSequenceEqual(a, b) |
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
79 |
311 | 80 def testUser(self): |
331 | 81 """ Build userspace using zcc: """ |
346 | 82 recipe = relpath('..', 'user', 'recipe.yaml') |
331 | 83 self.buildRecipe(recipe) |
311 | 84 |
287 | 85 def testBurn2(self): |
288 | 86 self.do(['burn2.c3'], ['stm32f4xx.c3']) |
287 | 87 |
334 | 88 def testBurn2_recipe(self): |
346 | 89 recipe = relpath('..', 'examples', 'c3', 'recipe.yaml') |
90 self.buildRecipe(recipe) | |
91 | |
92 def test_hello_A9_c3_recipe(self): | |
93 recipe = relpath('..', 'examples', 'qemu_a9_hello', 'recipe.yaml') | |
334 | 94 self.buildRecipe(recipe) |
95 | |
341 | 96 @unittest.skip('Skip because of logfile') |
331 | 97 def testBurn2WithLogging(self): |
98 self.do(['burn2.c3'], ['stm32f4xx.c3'], extra_args=['--report', 'x.rst']) | |
99 | |
315 | 100 def testCommentsExample(self): |
287 | 101 self.do(['comments.c3']) |
102 | |
103 def testCast(self): | |
104 self.do(['cast.c3']) | |
105 | |
300 | 106 def testFunctions(self): |
107 self.do(['functions.c3']) | |
108 | |
341 | 109 @unittest.skip('Revise this test') |
250 | 110 def testSectionAddress(self): |
301 | 111 src = """module tst; |
287 | 112 function void t2() {var int t3; t3 = 2;} |
113 """ | |
114 f = io.StringIO(src) | |
335 | 115 out = ObjectFile() |
342 | 116 tg = target_list.armtarget |
329 | 117 tr = ppci.tasks.TaskRunner() |
335 | 118 tr.add_task(ppci.buildtasks.Compile([f], [], tg, out)) |
329 | 119 tr.run_tasks() |
335 | 120 code = out.get_section('code') |
329 | 121 self.assertEqual(0x0, code.address) |
250 | 122 |
123 | |
208 | 124 if __name__ == '__main__': |
313 | 125 unittest.main() |