Mercurial > lcfOS
diff test/testsamples.py @ 366:39bf68bf1891
Fix sample tests and deterministic build
author | Windel Bouwman |
---|---|
date | Fri, 21 Mar 2014 09:43:01 +0100 |
parents | c49459768aaa |
children | 68841f9ab96c |
line wrap: on
line diff
--- a/test/testsamples.py Wed Mar 19 22:32:04 2014 +0100 +++ b/test/testsamples.py Fri Mar 21 09:43:01 2014 +0100 @@ -1,13 +1,23 @@ import unittest +import os +import io from testemulation import runQemu -from ppci.recipe import RecipeLoader +from testzcc import relpath from ppci.tasks import TaskRunner +from ppci.buildtasks import Assemble, Compile, Link +from ppci.objectfile import ObjectFile +startercode = """ +mov sp, 0x30000 ; setup stack pointer +BL sample_start ; Branch to sample start +local_loop: +B local_loop +""" class Samples: def testPrint(self): snippet = """ - module testsample; + module sample; import io; function void start() { @@ -18,12 +28,12 @@ def testForLoopPrint(self): snippet = """ - module testsample; + module sample; import io; function void start() { var int i; - for (i=0; i<10; i++) + for (i=0; i<10; i = i + 1) { io.print2("A = ", i); } @@ -32,9 +42,9 @@ res = "".join("A = 0x{0:08X}\n".format(a) for a in range(10)) self.do(snippet, res) - def testForLoopPrint(self): + def testGlobalVariable(self): snippet = """ - module testglobal; + module sample; import io; var int G; function void do1() @@ -52,9 +62,9 @@ G = 0; do1(); do1(); - do2(); + do5(); do1(); - do2(); + do5(); } """ res = "".join("G=0x{0:08X}\n".format(a) for a in [1,2,7,8,13]) @@ -63,25 +73,30 @@ class TestSamplesOnVexpress(unittest.TestCase, Samples): def do(self, src, expected_output): + # Construct binary file from snippet: + o1 = ObjectFile() + o2 = ObjectFile() + asmb = Assemble(io.StringIO(startercode), 'arm', o1) + comp = Compile([ + relpath('..', 'kernel', 'src', 'io.c3'), + relpath('..', 'kernel', 'arch', 'vexpressA9.c3'), + io.StringIO(src)], [], 'arm', o2) + sample_filename = 'testsample.bin' + layout = {'code': 0x10000, 'data':0x20000} + link = Link([o1, o2], layout, sample_filename) + + # Create task executor: runner = TaskRunner() - recipe_loader = RecipeLoader(runner) - # print(expected_output) - return - # TODO: improve recipe loading?? - recipe_loader.load_dict({ - 'link': { - 'inputs': [ - ], - 'layout': { - 'code': 0x60010000, - 'data': 0x60020000 - }, - 'output': 'tst.bin' - } - }) - runner.add_task(Compile()) + runner.add_task(asmb) + runner.add_task(comp) + runner.add_task(link) runner.run_tasks() - res = runQemu('tst.bin', machine='vexpress-a9') + # Check bin file exists: + self.assertTrue(os.path.isfile(sample_filename)) + + # Run bin file in emulator: + res = runQemu(sample_filename, machine='vexpress-a9') + os.remove(sample_filename) self.assertEqual(expected_output, res)