view test/testzcc.py @ 331:a78b41ff6ad2

Added better recipe files
author Windel Bouwman
date Fri, 07 Feb 2014 12:39:59 +0100
parents 8f6f3ace4e78
children 6f4753202b9a
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=[], extra_args=[]):
        basedir = os.path.join('..', 'examples', 'c3')
        arg_list = ['compile']
        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')
        arg_list += extra_args
        self.callZcc(arg_list)

    def callZcc(self, arg_list):
        parser = zcc.make_parser()
        args = parser.parse_args(arg_list)
        self.assertEqual(0, zcc.main(args))

    def buildRecipe(self, recipe):
        arg_list = ['recipe', recipe]
        self.callZcc(arg_list)

    def testDumpIr(self):
        basedir = os.path.join('..', 'examples', 'c3', 'comments.c3')
        arg_list = ['compile', basedir]
        arg_list.append('--target')
        arg_list.append('arm')
        self.callZcc(arg_list)

    def testKernel(self):
        """ Build kernel using zcc: """
        recipe = os.path.join(testdir, '..', 'kernel', 'recipe.yaml')
        self.buildRecipe(recipe)

    def testUser(self):
        """ Build userspace using zcc: """
        recipe = os.path.join(testdir, '..', 'user', 'recipe.yaml')
        self.buildRecipe(recipe)

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

    #@unittest.skip('s')
    def testBurn2WithLogging(self):
        self.do(['burn2.c3'], ['stm32f4xx.c3'], extra_args=['--report', 'x.rst'])

    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)
        outs = outstream.TextOutputStream()
        tg = target.target_list.armtarget
        tr = ppci.tasks.TaskRunner()
        tr.add_task(ppci.buildtasks.Compile([f], [], tg, outs))
        tr.run_tasks()
        code = outs.getSection('code')
        self.assertEqual(0x0, code.address)


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