338
|
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
|
340
|
24 def runQemu(self, kernel):
|
338
|
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
|
340
|
38 time.sleep(0.5)
|
338
|
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'))
|
340
|
50 p.wait(timeout=3)
|
338
|
51 qemu_control.close()
|
|
52 qemu_serial.close()
|
|
53
|
|
54 # Check that output was correct:
|
|
55 self.assertEqual('Hello worle', data)
|
|
56
|
|
57 def testM3Bare(self):
|
|
58 """ Build bare m3 binary and emulate it """
|
|
59 recipe = os.path.join(testdir, 'm3_bare', 'recipe.yaml')
|
|
60 self.buildRecipe(recipe)
|
|
61 self.runQemu('m3_bare/bare.bin')
|
|
62
|
|
63
|
|
64 if __name__ == '__main__':
|
|
65 unittest.main()
|