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 if 'TESTEMU' not in os.environ:
|
|
18 self.skipTest('Not running emulation tests')
|
|
19
|
346
|
20 def runQemu(self, kernel, machine='lm3s811evb'):
|
|
21 args = ['qemu-system-arm', '-M', machine, '-m', '16M',
|
338
|
22 '-nographic', '-kernel', kernel, '-monitor',
|
|
23 'unix:qemucontrol.sock,server',
|
|
24 '-serial', 'unix:qemuserial.sock,server']
|
|
25 p = subprocess.Popen(args)
|
|
26
|
|
27 # Give process some time to boot:
|
|
28 time.sleep(0.5)
|
|
29
|
|
30 # Connect to the control socket:
|
|
31 qemu_control = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
32 qemu_control.connect('qemucontrol.sock')
|
|
33
|
340
|
34 time.sleep(0.5)
|
338
|
35
|
|
36 # Now connect to the serial output:
|
|
37 qemu_serial = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
|
38 qemu_serial.connect('qemuserial.sock')
|
|
39
|
346
|
40 time.sleep(0.5)
|
338
|
41
|
346
|
42 qemu_serial.settimeout(0.2)
|
|
43
|
|
44 # Receive all data:
|
|
45 data = bytearray()
|
|
46 for i in range(40):
|
|
47 try:
|
|
48 data += qemu_serial.recv(1)
|
|
49 except socket.timeout as e:
|
|
50 break
|
|
51 data = data.decode('ascii')
|
|
52 # print(data)
|
338
|
53
|
|
54 # Send quit command:
|
|
55 qemu_control.send("quit\n".encode('ascii'))
|
340
|
56 p.wait(timeout=3)
|
338
|
57 qemu_control.close()
|
|
58 qemu_serial.close()
|
|
59
|
|
60 # Check that output was correct:
|
346
|
61 return data
|
338
|
62
|
|
63 def testM3Bare(self):
|
|
64 """ Build bare m3 binary and emulate it """
|
|
65 recipe = os.path.join(testdir, 'm3_bare', 'recipe.yaml')
|
|
66 self.buildRecipe(recipe)
|
346
|
67 data = self.runQemu('m3_bare/bare.bin')
|
|
68 self.assertEqual('Hello worle', data)
|
|
69
|
|
70 def testA9Bare(self):
|
|
71 """ Build vexpress cortex-A9 binary and emulate it """
|
|
72 recipe = os.path.join(testdir, '..', 'examples', 'qemu_a9_hello', 'recipe.yaml')
|
|
73 self.buildRecipe(recipe)
|
|
74 data = self.runQemu('../examples/qemu_a9_hello/hello.bin', machine='vexpress-a9')
|
|
75 self.assertEqual('Hello worle', data)
|
338
|
76
|
352
|
77 def testKernelVexpressA9(self):
|
|
78 """ Build vexpress cortex-A9 binary and emulate it """
|
|
79 recipe = os.path.join(testdir, '..', 'kernel', 'arm.yaml')
|
|
80 self.buildRecipe(recipe)
|
|
81 data = self.runQemu('../kernel/kernel_arm.bin', machine='vexpress-a9')
|
|
82 self.assertEqual('e', data[0])
|
|
83
|
338
|
84
|
|
85 if __name__ == '__main__':
|
|
86 unittest.main()
|