208
|
1 import unittest
|
311
|
2 import os
|
|
3 import sys
|
|
4
|
208
|
5 import zcc
|
250
|
6 import outstream
|
|
7 import ppci
|
287
|
8 import io
|
292
|
9 import target
|
208
|
10
|
321
|
11 # Store testdir for safe switch back to directory:
|
|
12 testdir = os.path.dirname(os.path.abspath(__file__))
|
|
13
|
|
14
|
208
|
15 class ZccTestCase(unittest.TestCase):
|
|
16 """ Tests the compiler driver """
|
311
|
17 def setUp(self):
|
321
|
18 os.chdir(testdir)
|
|
19
|
|
20 def tearDown(self):
|
|
21 os.chdir(testdir)
|
208
|
22
|
331
|
23 def do(self, filenames, imps=[], extra_args=[]):
|
300
|
24 basedir = os.path.join('..', 'examples', 'c3')
|
331
|
25 arg_list = ['compile']
|
|
26 arg_list += [os.path.join(basedir, fn) for fn in filenames]
|
288
|
27 for fn in imps:
|
|
28 arg_list.append('-i')
|
|
29 arg_list.append(os.path.join(basedir, fn))
|
292
|
30 arg_list.append('--target')
|
|
31 arg_list.append('arm')
|
331
|
32 arg_list += extra_args
|
|
33 self.callZcc(arg_list)
|
|
34
|
|
35 def callZcc(self, arg_list):
|
|
36 parser = zcc.make_parser()
|
|
37 args = parser.parse_args(arg_list)
|
286
|
38 self.assertEqual(0, zcc.main(args))
|
208
|
39
|
331
|
40 def buildRecipe(self, recipe):
|
|
41 arg_list = ['recipe', recipe]
|
|
42 self.callZcc(arg_list)
|
|
43
|
311
|
44 def testDumpIr(self):
|
|
45 basedir = os.path.join('..', 'examples', 'c3', 'comments.c3')
|
331
|
46 arg_list = ['compile', basedir]
|
311
|
47 arg_list.append('--target')
|
|
48 arg_list.append('arm')
|
331
|
49 self.callZcc(arg_list)
|
311
|
50
|
|
51 def testKernel(self):
|
331
|
52 """ Build kernel using zcc: """
|
|
53 recipe = os.path.join(testdir, '..', 'kernel', 'recipe.yaml')
|
|
54 self.buildRecipe(recipe)
|
313
|
55
|
311
|
56 def testUser(self):
|
331
|
57 """ Build userspace using zcc: """
|
|
58 recipe = os.path.join(testdir, '..', 'user', 'recipe.yaml')
|
|
59 self.buildRecipe(recipe)
|
311
|
60
|
287
|
61 def testBurn2(self):
|
288
|
62 self.do(['burn2.c3'], ['stm32f4xx.c3'])
|
287
|
63
|
334
|
64 def testBurn2_recipe(self):
|
|
65 recipe = os.path.join(testdir, '..', 'examples', 'c3', 'recipe.yaml')
|
|
66 self.buildRecipe(recipe)
|
|
67
|
331
|
68 #@unittest.skip('s')
|
|
69 def testBurn2WithLogging(self):
|
|
70 self.do(['burn2.c3'], ['stm32f4xx.c3'], extra_args=['--report', 'x.rst'])
|
|
71
|
315
|
72 def testCommentsExample(self):
|
287
|
73 self.do(['comments.c3'])
|
|
74
|
|
75 def testCast(self):
|
|
76 self.do(['cast.c3'])
|
|
77
|
300
|
78 def testFunctions(self):
|
|
79 self.do(['functions.c3'])
|
|
80
|
250
|
81 def testSectionAddress(self):
|
301
|
82 src = """module tst;
|
287
|
83 function void t2() {var int t3; t3 = 2;}
|
|
84 """
|
|
85 f = io.StringIO(src)
|
250
|
86 outs = outstream.TextOutputStream()
|
322
|
87 tg = target.target_list.armtarget
|
329
|
88 tr = ppci.tasks.TaskRunner()
|
|
89 tr.add_task(ppci.buildtasks.Compile([f], [], tg, outs))
|
|
90 tr.run_tasks()
|
250
|
91 code = outs.getSection('code')
|
329
|
92 self.assertEqual(0x0, code.address)
|
250
|
93
|
|
94
|
208
|
95 if __name__ == '__main__':
|
313
|
96 unittest.main()
|