view test/testzcc.py @ 290:7b38782ed496

File moves
author Windel Bouwman
date Sun, 24 Nov 2013 11:24:15 +0100
parents bd2593de3ff8
children 534b94b40aa8
line wrap: on
line source

import unittest
import glob
import zcc
import outstream
import ppci
import io
import os


class ZccTestCase(unittest.TestCase):
    """ Tests the compiler driver """

    def do(self, filenames, imps=[]):
        basedir = 'c3examples'
        arg_list = [os.path.join(basedir, fn) for fn in filenames]
        for fn in imps:
            arg_list.append('-i')
            arg_list.append(os.path.join(basedir, fn))
        args = zcc.parser.parse_args(arg_list)
        self.assertEqual(0, zcc.main(args))

    @unittest.skip('Not working yet')
    def testBurn(self):
        self.do(['burn.c3'], ['stm32f4xx.c3'])

    def testBurn2(self):
        self.do(['burn2.c3'], ['stm32f4xx.c3'])

    def testComments(self):
        self.do(['comments.c3'])

    def testCast(self):
        self.do(['cast.c3'])

    def testSectionAddress(self):
        src = """module tst; 
            function void t2() {var int t3; t3 = 2;}
        """
        f = io.StringIO(src)
        diag = ppci.DiagnosticsManager()
        outs = outstream.TextOutputStream()
        self.assertTrue(zcc.zcc([f], [], outs, diag))
        code = outs.getSection('code')
        self.assertEqual(0x08000000, code.address)
        data = outs.getSection('data')
        self.assertEqual(0x20000000, data.address)


if __name__ == '__main__':
    unittest.main()