comparison test/testemulation.py @ 338:8eb4a6fe8fc8

Added testcase with emulator
author Windel Bouwman
date Fri, 21 Feb 2014 13:31:29 +0100
parents
children 6ee17c4dd6b8
comparison
equal deleted inserted replaced
337:b00219172a42 338:8eb4a6fe8fc8
1 import unittest
2 import os
3 import sys
4 import subprocess
5 import socket
6 import time
7
8 from testzcc import ZccBaseTestCase
9
10 # Store testdir for safe switch back to directory:
11 testdir = os.path.dirname(os.path.abspath(__file__))
12
13
14 class EmulationTestCase(ZccBaseTestCase):
15 """ Tests the compiler driver """
16 def setUp(self):
17 os.chdir(testdir)
18 if 'TESTEMU' not in os.environ:
19 self.skipTest('Not running emulation tests')
20
21 def tearDown(self):
22 os.chdir(testdir)
23
24 def runQemu(self, kernel, timespan=2):
25 args = ['qemu-system-arm', '-M', 'lm3s811evb', '-m', '16M',
26 '-nographic', '-kernel', kernel, '-monitor',
27 'unix:qemucontrol.sock,server',
28 '-serial', 'unix:qemuserial.sock,server']
29 p = subprocess.Popen(args)
30
31 # Give process some time to boot:
32 time.sleep(0.5)
33
34 # Connect to the control socket:
35 qemu_control = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
36 qemu_control.connect('qemucontrol.sock')
37
38 time.sleep(0.5)
39
40 # Now connect to the serial output:
41 qemu_serial = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
42 qemu_serial.connect('qemuserial.sock')
43
44
45 data = qemu_serial.recv(11).decode('ascii')
46 print(data)
47
48 # Send quit command:
49 qemu_control.send("quit\n".encode('ascii'))
50
51 p.wait(timeout=timespan)
52
53 qemu_control.close()
54 qemu_serial.close()
55
56 # Check that output was correct:
57 self.assertEqual('Hello worle', data)
58
59 def testM3Bare(self):
60 """ Build bare m3 binary and emulate it """
61 recipe = os.path.join(testdir, 'm3_bare', 'recipe.yaml')
62 self.buildRecipe(recipe)
63 self.runQemu('m3_bare/bare.bin')
64
65
66 if __name__ == '__main__':
67 unittest.main()