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
|
286
|
11
|
208
|
12 class ZccTestCase(unittest.TestCase):
|
|
13 """ Tests the compiler driver """
|
311
|
14 def setUp(self):
|
|
15 os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
208
|
16
|
288
|
17 def do(self, filenames, imps=[]):
|
300
|
18 basedir = os.path.join('..', 'examples', 'c3')
|
288
|
19 arg_list = [os.path.join(basedir, fn) for fn in filenames]
|
|
20 for fn in imps:
|
|
21 arg_list.append('-i')
|
|
22 arg_list.append(os.path.join(basedir, fn))
|
292
|
23 arg_list.append('--target')
|
|
24 arg_list.append('arm')
|
288
|
25 args = zcc.parser.parse_args(arg_list)
|
286
|
26 self.assertEqual(0, zcc.main(args))
|
208
|
27
|
311
|
28 def testDumpIr(self):
|
|
29 basedir = os.path.join('..', 'examples', 'c3', 'comments.c3')
|
|
30 arg_list = [basedir]
|
|
31 arg_list.append('--target')
|
|
32 arg_list.append('arm')
|
|
33 args = zcc.parser.parse_args(arg_list)
|
|
34 self.assertEqual(0, zcc.main(args))
|
|
35
|
|
36 def testKernel(self):
|
|
37 # Build kernel using zcc:
|
|
38 kerneldir = os.path.normpath(os.path.join('..', 'kernel'))
|
313
|
39 sys.path.insert(0, kerneldir)
|
311
|
40 from make import make_kernel
|
|
41 os.chdir(kerneldir)
|
|
42 make_kernel()
|
|
43 sys.path.pop(-1)
|
313
|
44
|
311
|
45 def testUser(self):
|
|
46 # Build userspace using zcc:
|
|
47 userdir = os.path.normpath(os.path.join('..', 'user'))
|
313
|
48 sys.path.insert(0, userdir)
|
311
|
49 from makeuser import make_user
|
|
50 os.chdir(userdir)
|
|
51 make_user()
|
|
52 sys.path.pop(-1)
|
|
53
|
287
|
54 def testBurn2(self):
|
288
|
55 self.do(['burn2.c3'], ['stm32f4xx.c3'])
|
287
|
56
|
315
|
57 def testCommentsExample(self):
|
287
|
58 self.do(['comments.c3'])
|
|
59
|
|
60 def testCast(self):
|
|
61 self.do(['cast.c3'])
|
|
62
|
300
|
63 def testFunctions(self):
|
|
64 self.do(['functions.c3'])
|
|
65
|
250
|
66 def testSectionAddress(self):
|
301
|
67 src = """module tst;
|
287
|
68 function void t2() {var int t3; t3 = 2;}
|
|
69 """
|
|
70 f = io.StringIO(src)
|
250
|
71 diag = ppci.DiagnosticsManager()
|
|
72 outs = outstream.TextOutputStream()
|
292
|
73 tg = target.armtarget
|
|
74 self.assertTrue(zcc.zcc([f], [], tg, outs, diag))
|
250
|
75 code = outs.getSection('code')
|
|
76 self.assertEqual(0x08000000, code.address)
|
|
77 data = outs.getSection('data')
|
|
78 self.assertEqual(0x20000000, data.address)
|
|
79
|
|
80
|
208
|
81 if __name__ == '__main__':
|
313
|
82 unittest.main()
|