annotate test/testzcc.py @ 321:8c569fbe60e4

Load yacc and burg dynamic
author Windel Bouwman
date Sun, 19 Jan 2014 18:48:45 +0100
parents 084cccaa5deb
children 44f336460c2a
rev   line source
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
1 import unittest
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
2 import os
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
3 import sys
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
4
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
5 import zcc
250
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
6 import outstream
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
7 import ppci
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
8 import io
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 289
diff changeset
9 import target
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
10
286
d9df72971cbf Changed package to module
Windel Bouwman
parents: 284
diff changeset
11
321
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
12 # Store testdir for safe switch back to directory:
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
13 testdir = os.path.dirname(os.path.abspath(__file__))
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
14
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
15
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
16 class ZccTestCase(unittest.TestCase):
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
17 """ Tests the compiler driver """
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
18 def setUp(self):
321
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
19 os.chdir(testdir)
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
20
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
21 def tearDown(self):
8c569fbe60e4 Load yacc and burg dynamic
Windel Bouwman
parents: 315
diff changeset
22 os.chdir(testdir)
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
23
288
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
24 def do(self, filenames, imps=[]):
300
Windel Bouwman
parents: 292
diff changeset
25 basedir = os.path.join('..', 'examples', 'c3')
288
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
26 arg_list = [os.path.join(basedir, fn) for fn in filenames]
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
27 for fn in imps:
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
28 arg_list.append('-i')
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
29 arg_list.append(os.path.join(basedir, fn))
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 289
diff changeset
30 arg_list.append('--target')
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 289
diff changeset
31 arg_list.append('arm')
288
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
32 args = zcc.parser.parse_args(arg_list)
286
d9df72971cbf Changed package to module
Windel Bouwman
parents: 284
diff changeset
33 self.assertEqual(0, zcc.main(args))
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
34
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
35 def testDumpIr(self):
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
36 basedir = os.path.join('..', 'examples', 'c3', 'comments.c3')
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
37 arg_list = [basedir]
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
38 arg_list.append('--target')
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
39 arg_list.append('arm')
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
40 args = zcc.parser.parse_args(arg_list)
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
41 self.assertEqual(0, zcc.main(args))
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
42
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
43 def testKernel(self):
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
44 # Build kernel using zcc:
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
45 kerneldir = os.path.normpath(os.path.join('..', 'kernel'))
313
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
46 sys.path.insert(0, kerneldir)
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
47 from make import make_kernel
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
48 os.chdir(kerneldir)
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
49 make_kernel()
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
50 sys.path.pop(-1)
313
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
51
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
52 def testUser(self):
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
53 # Build userspace using zcc:
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
54 userdir = os.path.normpath(os.path.join('..', 'user'))
313
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
55 sys.path.insert(0, userdir)
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
56 from makeuser import make_user
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
57 os.chdir(userdir)
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
58 make_user()
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
59 sys.path.pop(-1)
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 301
diff changeset
60
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
61 def testBurn2(self):
288
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
62 self.do(['burn2.c3'], ['stm32f4xx.c3'])
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
63
315
084cccaa5deb Added console and screen
Windel Bouwman
parents: 313
diff changeset
64 def testCommentsExample(self):
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
65 self.do(['comments.c3'])
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
66
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
67 def testCast(self):
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
68 self.do(['cast.c3'])
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
69
300
Windel Bouwman
parents: 292
diff changeset
70 def testFunctions(self):
Windel Bouwman
parents: 292
diff changeset
71 self.do(['functions.c3'])
Windel Bouwman
parents: 292
diff changeset
72
250
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
73 def testSectionAddress(self):
301
6753763d3bec merge codegen into ppci package
Windel Bouwman
parents: 300
diff changeset
74 src = """module tst;
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
75 function void t2() {var int t3; t3 = 2;}
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
76 """
1c7c1e619be8 File movage
Windel Bouwman
parents: 286
diff changeset
77 f = io.StringIO(src)
250
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
78 diag = ppci.DiagnosticsManager()
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
79 outs = outstream.TextOutputStream()
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 289
diff changeset
80 tg = target.armtarget
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 289
diff changeset
81 self.assertTrue(zcc.zcc([f], [], tg, outs, diag))
250
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
82 code = outs.getSection('code')
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
83 self.assertEqual(0x08000000, code.address)
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
84 data = outs.getSection('data')
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
85 self.assertEqual(0x20000000, data.address)
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
86
f5fba5b554d7 Removal of obsolete editor
Windel Bouwman
parents: 237
diff changeset
87
208
4cb47d80fd1f Added zcc test
Windel Bouwman
parents:
diff changeset
88 if __name__ == '__main__':
313
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
89 unittest.main()