208
|
1 import unittest
|
237
|
2 import glob
|
208
|
3 import zcc
|
250
|
4 import outstream
|
|
5 import ppci
|
287
|
6 import io
|
|
7 import os
|
208
|
8
|
286
|
9
|
208
|
10 class ZccTestCase(unittest.TestCase):
|
|
11 """ Tests the compiler driver """
|
|
12
|
287
|
13 def do(self, filenames):
|
|
14 basedir = 'c3examples'
|
|
15 filenames = [os.path.join(basedir, fn) for fn in filenames]
|
|
16 args = zcc.parser.parse_args(filenames + [])
|
286
|
17 self.assertEqual(0, zcc.main(args))
|
208
|
18
|
287
|
19 def t2estExamples(self):
|
237
|
20 """ Test all examples in the c3/examples directory """
|
284
|
21 example_filenames = glob.glob('./c3examples/*.c3')
|
237
|
22 for filename in example_filenames:
|
|
23 self.do(filename)
|
|
24
|
287
|
25 def testBurn(self):
|
|
26 self.do(['stm32f4xx.c3', 'burn.c3'])
|
|
27
|
|
28 def testBurn2(self):
|
|
29 self.do(['stm32f4xx.c3','burn2.c3'])
|
|
30
|
|
31 def testComments(self):
|
|
32 self.do(['comments.c3'])
|
|
33
|
|
34 def testCast(self):
|
|
35 self.do(['cast.c3'])
|
|
36
|
250
|
37 def testSectionAddress(self):
|
287
|
38 src = """module tst;
|
|
39 function void t2() {var int t3; t3 = 2;}
|
|
40 """
|
|
41 f = io.StringIO(src)
|
250
|
42 diag = ppci.DiagnosticsManager()
|
|
43 outs = outstream.TextOutputStream()
|
287
|
44 self.assertTrue(zcc.zcc([f], 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()
|
|
53
|