annotate test/testzcc.py @ 389:2ec730e45ea1

Added check for recursive struct
author Windel Bouwman
date Fri, 16 May 2014 12:29:31 +0200
parents 9667d78ba79e
children
rev   line source
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
1 import unittest
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
2 import os
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
3 import sys
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
4
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
5 import zcc
335
582a1aaa3983 Added long branch format
Windel Bouwman
parents: 334
diff changeset
6 from ppci.objectfile import ObjectFile
250
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
7 import ppci
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
8 import io
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
9 from ppci.target import target_list
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
10
321
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
11 # Store testdir for safe switch back to directory:
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
12 testdir = os.path.dirname(os.path.abspath(__file__))
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
13
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 342
diff changeset
14 def relpath(*args):
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 342
diff changeset
15 return os.path.join(testdir, *args)
321
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
16
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
17
338
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents: 337
diff changeset
18 class ZccBaseTestCase(unittest.TestCase):
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents: 337
diff changeset
19 def callZcc(self, arg_list):
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents: 337
diff changeset
20 parser = zcc.make_parser()
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents: 337
diff changeset
21 arg_list = ['--log', 'warn'] + arg_list
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents: 337
diff changeset
22 args = parser.parse_args(arg_list)
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents: 337
diff changeset
23 self.assertEqual(0, zcc.main(args))
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents: 337
diff changeset
24
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
25 def buildRecipe(self, recipe, targetlist=[]):
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
26 arg_list = ['--buildfile', recipe] + targetlist
338
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents: 337
diff changeset
27 self.callZcc(arg_list)
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents: 337
diff changeset
28
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents: 337
diff changeset
29
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents: 337
diff changeset
30 class ZccTestCase(ZccBaseTestCase):
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
31 """ Tests the compiler driver """
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
32 def setUp(self):
321
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
33 os.chdir(testdir)
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
34
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
35 def tearDown(self):
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
36 os.chdir(testdir)
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
37
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
38 def do(self, filenames, imps=[], extra_args=[]):
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
39 return
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 353
diff changeset
40 basedir = relpath('..', 'examples', 'c3')
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
41 arg_list = ['compile']
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
42 arg_list += [os.path.join(basedir, fn) for fn in filenames]
288
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
43 for fn in imps:
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
44 arg_list.append('-i')
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
45 arg_list.append(os.path.join(basedir, fn))
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 289
diff changeset
46 arg_list.append('--target')
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 338
diff changeset
47 arg_list.append('thumb')
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
48 arg_list += extra_args
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
49 self.callZcc(arg_list)
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
50
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
51 @unittest.skip('Api change')
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
52 def testDumpIr(self):
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 342
diff changeset
53 basedir = relpath('..', 'examples', 'c3', 'comments.c3')
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
54 arg_list = ['compile', basedir]
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
55 arg_list.append('--target')
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 338
diff changeset
56 arg_list.append('thumb')
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
57 self.callZcc(arg_list)
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
58
367
577ed7fb3fe4 Try to make thumb work again
Windel Bouwman
parents: 366
diff changeset
59 @unittest.skip('Too hard')
352
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 346
diff changeset
60 def testThumbKernel(self):
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
61 """ Build kernel using zcc: """
352
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 346
diff changeset
62 recipe = relpath('..', 'kernel', 'thumb.yaml')
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 346
diff changeset
63 self.buildRecipe(recipe)
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 346
diff changeset
64
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 346
diff changeset
65 def testArmKernel(self):
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 346
diff changeset
66 """ Build kernel using zcc: """
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
67 recipe = relpath('..', 'kernel', 'build.xml')
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
68 self.buildRecipe(recipe)
313
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
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
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
72 recipe = relpath('..', 'kernel', 'build.xml')
366
39bf68bf1891 Fix sample tests and deterministic build
Windel Bouwman
parents: 353
diff changeset
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
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
82 def testUser(self):
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
83 """ Build userspace using zcc: """
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
84 recipe = relpath('..', 'user', 'build.xml')
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
85 self.buildRecipe(recipe)
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
86
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
87 def testBurn2(self):
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
88 recipe = relpath('..', 'examples', 'c3', 'build.xml')
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 342
diff changeset
89 self.buildRecipe(recipe)
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 342
diff changeset
90
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 342
diff changeset
91 def test_hello_A9_c3_recipe(self):
377
9667d78ba79e Switched to xml for project description
Windel Bouwman
parents: 367
diff changeset
92 recipe = relpath('..', 'examples', 'qemu_a9_hello', 'build.xml')
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 331
diff changeset
93 self.buildRecipe(recipe)
6f4753202b9a Added more recipes
Windel Bouwman
parents: 331
diff changeset
94
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 338
diff changeset
95 @unittest.skip('Skip because of logfile')
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
96 def testBurn2WithLogging(self):
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
97 self.do(['burn2.c3'], ['stm32f4xx.c3'], extra_args=['--report', 'x.rst'])
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
98
315
084cccaa5deb Added console and screen
Windel Bouwman
parents: 313
diff changeset
99 def testCommentsExample(self):
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
100 self.do(['comments.c3'])
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
101
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
102 def testCast(self):
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
103 self.do(['cast.c3'])
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
104
300
Windel Bouwman
parents: 292
diff changeset
105 def testFunctions(self):
Windel Bouwman
parents: 292
diff changeset
106 self.do(['functions.c3'])
Windel Bouwman
parents: 292
diff changeset
107
250
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
108
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
109 if __name__ == '__main__':
313
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
110 unittest.main()