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
|
288
|
23 def do(self, filenames, imps=[]):
|
300
|
24 basedir = os.path.join('..', 'examples', 'c3')
|
288
|
25 arg_list = [os.path.join(basedir, fn) for fn in filenames]
|
|
26 for fn in imps:
|
|
27 arg_list.append('-i')
|
|
28 arg_list.append(os.path.join(basedir, fn))
|
292
|
29 arg_list.append('--target')
|
|
30 arg_list.append('arm')
|
288
|
31 args = zcc.parser.parse_args(arg_list)
|
286
|
32 self.assertEqual(0, zcc.main(args))
|
208
|
33
|
311
|
34 def testDumpIr(self):
|
|
35 basedir = os.path.join('..', 'examples', 'c3', 'comments.c3')
|
|
36 arg_list = [basedir]
|
|
37 arg_list.append('--target')
|
|
38 arg_list.append('arm')
|
|
39 args = zcc.parser.parse_args(arg_list)
|
|
40 self.assertEqual(0, zcc.main(args))
|
|
41
|
|
42 def testKernel(self):
|
|
43 # Build kernel using zcc:
|
|
44 kerneldir = os.path.normpath(os.path.join('..', 'kernel'))
|
313
|
45 sys.path.insert(0, kerneldir)
|
311
|
46 from make import make_kernel
|
|
47 os.chdir(kerneldir)
|
|
48 make_kernel()
|
|
49 sys.path.pop(-1)
|
313
|
50
|
311
|
51 def testUser(self):
|
|
52 # Build userspace using zcc:
|
|
53 userdir = os.path.normpath(os.path.join('..', 'user'))
|
313
|
54 sys.path.insert(0, userdir)
|
311
|
55 from makeuser import make_user
|
|
56 os.chdir(userdir)
|
|
57 make_user()
|
|
58 sys.path.pop(-1)
|
|
59
|
287
|
60 def testBurn2(self):
|
288
|
61 self.do(['burn2.c3'], ['stm32f4xx.c3'])
|
287
|
62
|
315
|
63 def testCommentsExample(self):
|
287
|
64 self.do(['comments.c3'])
|
|
65
|
|
66 def testCast(self):
|
|
67 self.do(['cast.c3'])
|
|
68
|
300
|
69 def testFunctions(self):
|
|
70 self.do(['functions.c3'])
|
|
71
|
250
|
72 def testSectionAddress(self):
|
301
|
73 src = """module tst;
|
287
|
74 function void t2() {var int t3; t3 = 2;}
|
|
75 """
|
|
76 f = io.StringIO(src)
|
250
|
77 outs = outstream.TextOutputStream()
|
322
|
78 tg = target.target_list.armtarget
|
329
|
79 tr = ppci.tasks.TaskRunner()
|
|
80 tr.add_task(ppci.buildtasks.Compile([f], [], tg, outs))
|
|
81 tr.run_tasks()
|
250
|
82 code = outs.getSection('code')
|
329
|
83 self.assertEqual(0x0, code.address)
|
250
|
84
|
|
85
|
208
|
86 if __name__ == '__main__':
|
313
|
87 unittest.main()
|