Mercurial > lcfOS
changeset 338:8eb4a6fe8fc8
Added testcase with emulator
author | Windel Bouwman |
---|---|
date | Fri, 21 Feb 2014 13:31:29 +0100 |
parents | b00219172a42 |
children | 6ee17c4dd6b8 |
files | test/testemulation.py test/testzcc.py |
diffstat | 2 files changed, 80 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/testemulation.py Fri Feb 21 13:31:29 2014 +0100 @@ -0,0 +1,67 @@ +import unittest +import os +import sys +import subprocess +import socket +import time + +from testzcc import ZccBaseTestCase + +# Store testdir for safe switch back to directory: +testdir = os.path.dirname(os.path.abspath(__file__)) + + +class EmulationTestCase(ZccBaseTestCase): + """ Tests the compiler driver """ + def setUp(self): + os.chdir(testdir) + if 'TESTEMU' not in os.environ: + self.skipTest('Not running emulation tests') + + def tearDown(self): + os.chdir(testdir) + + def runQemu(self, kernel, timespan=2): + args = ['qemu-system-arm', '-M', 'lm3s811evb', '-m', '16M', + '-nographic', '-kernel', kernel, '-monitor', + 'unix:qemucontrol.sock,server', + '-serial', 'unix:qemuserial.sock,server'] + p = subprocess.Popen(args) + + # Give process some time to boot: + time.sleep(0.5) + + # Connect to the control socket: + qemu_control = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + qemu_control.connect('qemucontrol.sock') + + time.sleep(0.5) + + # Now connect to the serial output: + qemu_serial = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + qemu_serial.connect('qemuserial.sock') + + + data = qemu_serial.recv(11).decode('ascii') + print(data) + + # Send quit command: + qemu_control.send("quit\n".encode('ascii')) + + p.wait(timeout=timespan) + + qemu_control.close() + qemu_serial.close() + + # Check that output was correct: + self.assertEqual('Hello worle', data) + + def testM3Bare(self): + """ Build bare m3 binary and emulate it """ + recipe = os.path.join(testdir, 'm3_bare', 'recipe.yaml') + self.buildRecipe(recipe) + self.runQemu('m3_bare/bare.bin') + + +if __name__ == '__main__': + unittest.main()
--- a/test/testzcc.py Thu Feb 20 20:04:52 2014 +0100 +++ b/test/testzcc.py Fri Feb 21 13:31:29 2014 +0100 @@ -12,7 +12,19 @@ testdir = os.path.dirname(os.path.abspath(__file__)) -class ZccTestCase(unittest.TestCase): +class ZccBaseTestCase(unittest.TestCase): + def callZcc(self, arg_list): + parser = zcc.make_parser() + arg_list = ['--log', 'warn'] + arg_list + args = parser.parse_args(arg_list) + self.assertEqual(0, zcc.main(args)) + + def buildRecipe(self, recipe): + arg_list = ['recipe', recipe] + self.callZcc(arg_list) + + +class ZccTestCase(ZccBaseTestCase): """ Tests the compiler driver """ def setUp(self): os.chdir(testdir) @@ -32,15 +44,6 @@ arg_list += extra_args self.callZcc(arg_list) - def callZcc(self, arg_list): - parser = zcc.make_parser() - arg_list = ['--log', 'warn'] + arg_list - 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')