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