208
|
1 import unittest
|
|
2 import zcc
|
250
|
3 import outstream
|
|
4 import ppci
|
287
|
5 import io
|
|
6 import os
|
292
|
7 import target
|
208
|
8
|
286
|
9
|
208
|
10 class ZccTestCase(unittest.TestCase):
|
|
11 """ Tests the compiler driver """
|
|
12
|
288
|
13 def do(self, filenames, imps=[]):
|
300
|
14 basedir = os.path.join('..', 'examples', 'c3')
|
288
|
15 arg_list = [os.path.join(basedir, fn) for fn in filenames]
|
|
16 for fn in imps:
|
|
17 arg_list.append('-i')
|
|
18 arg_list.append(os.path.join(basedir, fn))
|
292
|
19 arg_list.append('--target')
|
|
20 arg_list.append('arm')
|
288
|
21 args = zcc.parser.parse_args(arg_list)
|
286
|
22 self.assertEqual(0, zcc.main(args))
|
208
|
23
|
287
|
24 def testBurn2(self):
|
288
|
25 self.do(['burn2.c3'], ['stm32f4xx.c3'])
|
287
|
26
|
|
27 def testComments(self):
|
|
28 self.do(['comments.c3'])
|
|
29
|
|
30 def testCast(self):
|
|
31 self.do(['cast.c3'])
|
|
32
|
300
|
33 def testFunctions(self):
|
|
34 self.do(['functions.c3'])
|
|
35
|
250
|
36 def testSectionAddress(self):
|
287
|
37 src = """module tst;
|
|
38 function void t2() {var int t3; t3 = 2;}
|
|
39 """
|
|
40 f = io.StringIO(src)
|
250
|
41 diag = ppci.DiagnosticsManager()
|
|
42 outs = outstream.TextOutputStream()
|
292
|
43 tg = target.armtarget
|
|
44 self.assertTrue(zcc.zcc([f], [], tg, outs, diag))
|
250
|
45 code = outs.getSection('code')
|
|
46 self.assertEqual(0x08000000, code.address)
|
|
47 data = outs.getSection('data')
|
|
48 self.assertEqual(0x20000000, data.address)
|
|
49
|
|
50
|
208
|
51 if __name__ == '__main__':
|
|
52 unittest.main()
|