view test/testzcc.py @ 327:61c9df5bffce

Changed emulated board to cortex a8 board
author Windel Bouwman
date Sat, 01 Feb 2014 17:21:21 +0100
parents 44f336460c2a
children 8f6f3ace4e78
line wrap: on
line source

import unittest
import os
import sys

import zcc
import outstream
import ppci
import io
import target


# Store testdir for safe switch back to directory:
testdir = os.path.dirname(os.path.abspath(__file__))


class ZccTestCase(unittest.TestCase):
    """ Tests the compiler driver """
    def setUp(self):
        os.chdir(testdir)

    def tearDown(self):
        os.chdir(testdir)

    def do(self, filenames, imps=[]):
        basedir = os.path.join('..', 'examples', 'c3')
        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))
        arg_list.append('--target')
        arg_list.append('arm')
        args = zcc.parser.parse_args(arg_list)
        self.assertEqual(0, zcc.main(args))

    def testDumpIr(self):
        basedir = os.path.join('..', 'examples', 'c3', 'comments.c3')
        arg_list = [basedir]
        arg_list.append('--target')
        arg_list.append('arm')
        args = zcc.parser.parse_args(arg_list)
        self.assertEqual(0, zcc.main(args))

    def testKernel(self):
        # Build kernel using zcc:
        kerneldir = os.path.normpath(os.path.join('..', 'kernel'))
        sys.path.insert(0, kerneldir)
        from make import make_kernel
        os.chdir(kerneldir)
        make_kernel()
        sys.path.pop(-1)

    def testUser(self):
        # Build userspace using zcc:
        userdir = os.path.normpath(os.path.join('..', 'user'))
        sys.path.insert(0, userdir)
        from makeuser import make_user
        os.chdir(userdir)
        make_user()
        sys.path.pop(-1)

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

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

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

    def testFunctions(self):
        self.do(['functions.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()
        tg = target.target_list.armtarget
        self.assertTrue(zcc.zcc([f], [], tg, 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()