annotate test/testzcc.py @ 334:6f4753202b9a

Added more recipes
author Windel Bouwman
date Thu, 13 Feb 2014 22:02:08 +0100
parents a78b41ff6ad2
children 582a1aaa3983
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
250
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
6 import outstream
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
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 289
diff changeset
9 import target
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
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
14
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
15 class ZccTestCase(unittest.TestCase):
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
16 """ Tests the compiler driver """
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
17 def setUp(self):
321
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
18 os.chdir(testdir)
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
19
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
20 def tearDown(self):
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
21 os.chdir(testdir)
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
22
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
23 def do(self, filenames, imps=[], extra_args=[]):
300
Windel Bouwman
parents: 292
diff changeset
24 basedir = os.path.join('..', 'examples', 'c3')
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
25 arg_list = ['compile']
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
26 arg_list += [os.path.join(basedir, fn) for fn in filenames]
288
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
27 for fn in imps:
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
28 arg_list.append('-i')
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
29 arg_list.append(os.path.join(basedir, fn))
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 289
diff changeset
30 arg_list.append('--target')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 289
diff changeset
31 arg_list.append('arm')
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
32 arg_list += extra_args
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
33 self.callZcc(arg_list)
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
34
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
35 def callZcc(self, arg_list):
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
36 parser = zcc.make_parser()
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
37 args = parser.parse_args(arg_list)
286
d9df72971cbf Changed package to module
Windel Bouwman
parents: 284
diff changeset
38 self.assertEqual(0, zcc.main(args))
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
39
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
40 def buildRecipe(self, recipe):
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
41 arg_list = ['recipe', recipe]
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
42 self.callZcc(arg_list)
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
43
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
44 def testDumpIr(self):
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
45 basedir = os.path.join('..', 'examples', 'c3', 'comments.c3')
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
46 arg_list = ['compile', basedir]
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
47 arg_list.append('--target')
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
48 arg_list.append('arm')
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
49 self.callZcc(arg_list)
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
50
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
51 def testKernel(self):
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
52 """ Build kernel using zcc: """
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
53 recipe = os.path.join(testdir, '..', 'kernel', 'recipe.yaml')
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
54 self.buildRecipe(recipe)
313
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
55
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
56 def testUser(self):
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
57 """ Build userspace using zcc: """
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
58 recipe = os.path.join(testdir, '..', 'user', 'recipe.yaml')
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
59 self.buildRecipe(recipe)
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
60
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
61 def testBurn2(self):
288
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
62 self.do(['burn2.c3'], ['stm32f4xx.c3'])
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
63
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 331
diff changeset
64 def testBurn2_recipe(self):
6f4753202b9a Added more recipes
Windel Bouwman
parents: 331
diff changeset
65 recipe = os.path.join(testdir, '..', 'examples', 'c3', 'recipe.yaml')
6f4753202b9a Added more recipes
Windel Bouwman
parents: 331
diff changeset
66 self.buildRecipe(recipe)
6f4753202b9a Added more recipes
Windel Bouwman
parents: 331
diff changeset
67
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
68 #@unittest.skip('s')
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
69 def testBurn2WithLogging(self):
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
70 self.do(['burn2.c3'], ['stm32f4xx.c3'], extra_args=['--report', 'x.rst'])
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
71
315
084cccaa5deb Added console and screen
Windel Bouwman
parents: 313
diff changeset
72 def testCommentsExample(self):
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
73 self.do(['comments.c3'])
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
74
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
75 def testCast(self):
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
76 self.do(['cast.c3'])
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
77
300
Windel Bouwman
parents: 292
diff changeset
78 def testFunctions(self):
Windel Bouwman
parents: 292
diff changeset
79 self.do(['functions.c3'])
Windel Bouwman
parents: 292
diff changeset
80
250
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
81 def testSectionAddress(self):
301
6753763d3bec merge codegen into ppci package
Windel Bouwman
parents: 300
diff changeset
82 src = """module tst;
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
83 function void t2() {var int t3; t3 = 2;}
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
84 """
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
85 f = io.StringIO(src)
250
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
86 outs = outstream.TextOutputStream()
322
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents: 321
diff changeset
87 tg = target.target_list.armtarget
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents: 322
diff changeset
88 tr = ppci.tasks.TaskRunner()
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents: 322
diff changeset
89 tr.add_task(ppci.buildtasks.Compile([f], [], tg, outs))
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents: 322
diff changeset
90 tr.run_tasks()
250
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
91 code = outs.getSection('code')
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents: 322
diff changeset
92 self.assertEqual(0x0, code.address)
250
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
93
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
94
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
95 if __name__ == '__main__':
313
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
96 unittest.main()