Mercurial > lcfOS
annotate test/testzcc.py @ 380:67a584582aee
Small change to hexfile
author | Windel Bouwman |
---|---|
date | Fri, 18 Apr 2014 13:08:45 +0200 |
parents | 9667d78ba79e |
children |
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 |
377 | 17 |
338 | 18 class ZccBaseTestCase(unittest.TestCase): |
19 def callZcc(self, arg_list): | |
20 parser = zcc.make_parser() | |
21 arg_list = ['--log', 'warn'] + arg_list | |
22 args = parser.parse_args(arg_list) | |
23 self.assertEqual(0, zcc.main(args)) | |
24 | |
377 | 25 def buildRecipe(self, recipe, targetlist=[]): |
26 arg_list = ['--buildfile', recipe] + targetlist | |
338 | 27 self.callZcc(arg_list) |
28 | |
29 | |
30 class ZccTestCase(ZccBaseTestCase): | |
208 | 31 """ Tests the compiler driver """ |
311 | 32 def setUp(self): |
321 | 33 os.chdir(testdir) |
34 | |
35 def tearDown(self): | |
36 os.chdir(testdir) | |
208 | 37 |
331 | 38 def do(self, filenames, imps=[], extra_args=[]): |
377 | 39 return |
366 | 40 basedir = relpath('..', 'examples', 'c3') |
331 | 41 arg_list = ['compile'] |
42 arg_list += [os.path.join(basedir, fn) for fn in filenames] | |
288 | 43 for fn in imps: |
44 arg_list.append('-i') | |
45 arg_list.append(os.path.join(basedir, fn)) | |
292 | 46 arg_list.append('--target') |
341 | 47 arg_list.append('thumb') |
331 | 48 arg_list += extra_args |
49 self.callZcc(arg_list) | |
50 | |
377 | 51 @unittest.skip('Api change') |
311 | 52 def testDumpIr(self): |
346 | 53 basedir = relpath('..', 'examples', 'c3', 'comments.c3') |
331 | 54 arg_list = ['compile', basedir] |
311 | 55 arg_list.append('--target') |
341 | 56 arg_list.append('thumb') |
331 | 57 self.callZcc(arg_list) |
311 | 58 |
367 | 59 @unittest.skip('Too hard') |
352 | 60 def testThumbKernel(self): |
331 | 61 """ Build kernel using zcc: """ |
352 | 62 recipe = relpath('..', 'kernel', 'thumb.yaml') |
63 self.buildRecipe(recipe) | |
64 | |
65 def testArmKernel(self): | |
66 """ Build kernel using zcc: """ | |
377 | 67 recipe = relpath('..', 'kernel', 'build.xml') |
331 | 68 self.buildRecipe(recipe) |
313 | 69 |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
70 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
|
71 """ Build kernel two times and check the output is equal """ |
377 | 72 recipe = relpath('..', 'kernel', 'build.xml') |
366 | 73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 |
311 | 82 def testUser(self): |
331 | 83 """ Build userspace using zcc: """ |
377 | 84 recipe = relpath('..', 'user', 'build.xml') |
331 | 85 self.buildRecipe(recipe) |
311 | 86 |
287 | 87 def testBurn2(self): |
377 | 88 recipe = relpath('..', 'examples', 'c3', 'build.xml') |
346 | 89 self.buildRecipe(recipe) |
90 | |
91 def test_hello_A9_c3_recipe(self): | |
377 | 92 recipe = relpath('..', 'examples', 'qemu_a9_hello', 'build.xml') |
334 | 93 self.buildRecipe(recipe) |
94 | |
341 | 95 @unittest.skip('Skip because of logfile') |
331 | 96 def testBurn2WithLogging(self): |
97 self.do(['burn2.c3'], ['stm32f4xx.c3'], extra_args=['--report', 'x.rst']) | |
98 | |
315 | 99 def testCommentsExample(self): |
287 | 100 self.do(['comments.c3']) |
101 | |
102 def testCast(self): | |
103 self.do(['cast.c3']) | |
104 | |
300 | 105 def testFunctions(self): |
106 self.do(['functions.c3']) | |
107 | |
250 | 108 |
208 | 109 if __name__ == '__main__': |
313 | 110 unittest.main() |