Mercurial > lcfOS
annotate test/testzcc.py @ 346:3bb7dcfe5529
expanded arm target
author | Windel Bouwman |
---|---|
date | Fri, 07 Mar 2014 17:05:32 +0100 |
parents | 86b02c98a717 |
children | 899ae3aea803 |
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=[]): |
300 | 38 basedir = os.path.join('..', '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 |
57 def testKernel(self): | |
331 | 58 """ Build kernel using zcc: """ |
346 | 59 recipe = relpath('..', 'kernel', 'recipe.yaml') |
331 | 60 self.buildRecipe(recipe) |
313 | 61 |
337 | 62 @unittest.skip('Too difficult to fix') |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
63 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
|
64 """ Build kernel two times and check the output is equal """ |
346 | 65 recipe = relpath('..', 'kernel', 'recipe.yaml') |
66 bin_filename = relpath('..', 'kernel', 'kernel.bin') | |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 |
311 | 75 def testUser(self): |
331 | 76 """ Build userspace using zcc: """ |
346 | 77 recipe = relpath('..', 'user', 'recipe.yaml') |
331 | 78 self.buildRecipe(recipe) |
311 | 79 |
287 | 80 def testBurn2(self): |
288 | 81 self.do(['burn2.c3'], ['stm32f4xx.c3']) |
287 | 82 |
334 | 83 def testBurn2_recipe(self): |
346 | 84 recipe = relpath('..', 'examples', 'c3', 'recipe.yaml') |
85 self.buildRecipe(recipe) | |
86 | |
87 def test_hello_A9_c3_recipe(self): | |
88 recipe = relpath('..', 'examples', 'qemu_a9_hello', 'recipe.yaml') | |
334 | 89 self.buildRecipe(recipe) |
90 | |
341 | 91 @unittest.skip('Skip because of logfile') |
331 | 92 def testBurn2WithLogging(self): |
93 self.do(['burn2.c3'], ['stm32f4xx.c3'], extra_args=['--report', 'x.rst']) | |
94 | |
315 | 95 def testCommentsExample(self): |
287 | 96 self.do(['comments.c3']) |
97 | |
98 def testCast(self): | |
99 self.do(['cast.c3']) | |
100 | |
300 | 101 def testFunctions(self): |
102 self.do(['functions.c3']) | |
103 | |
341 | 104 @unittest.skip('Revise this test') |
250 | 105 def testSectionAddress(self): |
301 | 106 src = """module tst; |
287 | 107 function void t2() {var int t3; t3 = 2;} |
108 """ | |
109 f = io.StringIO(src) | |
335 | 110 out = ObjectFile() |
342 | 111 tg = target_list.armtarget |
329 | 112 tr = ppci.tasks.TaskRunner() |
335 | 113 tr.add_task(ppci.buildtasks.Compile([f], [], tg, out)) |
329 | 114 tr.run_tasks() |
335 | 115 code = out.get_section('code') |
329 | 116 self.assertEqual(0x0, code.address) |
250 | 117 |
118 | |
208 | 119 if __name__ == '__main__': |
313 | 120 unittest.main() |