comparison test/testemulation.py @ 355:c2ddc8a36f5e

Enabled optimization
author Windel Bouwman
date Fri, 14 Mar 2014 10:30:13 +0100
parents 5477e499b039
children 52492b304adf
comparison
equal deleted inserted replaced
354:5477e499b039 355:c2ddc8a36f5e
8 from testzcc import ZccBaseTestCase 8 from testzcc import ZccBaseTestCase
9 9
10 # Store testdir for safe switch back to directory: 10 # Store testdir for safe switch back to directory:
11 testdir = os.path.dirname(os.path.abspath(__file__)) 11 testdir = os.path.dirname(os.path.abspath(__file__))
12 12
13 def runQemu(kernel, machine='lm3s811evb'):
14 """ Runs qemu on a given kernel file on some machine """
15 args = ['qemu-system-arm', '-M', machine, '-m', '16M',
16 '-nographic', '-kernel', kernel, '-monitor',
17 'unix:qemucontrol.sock,server',
18 '-serial', 'unix:qemuserial.sock,server']
19 p = subprocess.Popen(args, stdout=subprocess.DEVNULL,
20 stderr=subprocess.DEVNULL)
21
22 # Give process some time to boot:
23 time.sleep(0.5)
24
25 # Connect to the control socket:
26 qemu_control = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
27 qemu_control.connect('qemucontrol.sock')
28
29 time.sleep(0.5)
30
31 # Now connect to the serial output:
32 qemu_serial = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
33 qemu_serial.connect('qemuserial.sock')
34
35 time.sleep(0.5)
36
37 qemu_serial.settimeout(0.2)
38
39 # Receive all data:
40 data = bytearray()
41 for i in range(40):
42 try:
43 data += qemu_serial.recv(1)
44 except socket.timeout as e:
45 break
46 data = data.decode('ascii')
47 # print(data)
48
49 # Send quit command:
50 qemu_control.send("quit\n".encode('ascii'))
51 p.wait(timeout=3)
52 qemu_control.close()
53 qemu_serial.close()
54
55 # Check that output was correct:
56 return data
57
13 58
14 class EmulationTestCase(ZccBaseTestCase): 59 class EmulationTestCase(ZccBaseTestCase):
15 """ Tests the compiler driver """ 60 """ Tests the compiler driver """
16 def setUp(self): 61 def setUp(self):
17 if 'TESTEMU' not in os.environ: 62 if 'TESTEMU' not in os.environ:
18 self.skipTest('Not running emulation tests') 63 self.skipTest('Not running emulation tests')
19 64
20 def runQemu(self, kernel, machine='lm3s811evb'):
21 args = ['qemu-system-arm', '-M', machine, '-m', '16M',
22 '-nographic', '-kernel', kernel, '-monitor',
23 'unix:qemucontrol.sock,server',
24 '-serial', 'unix:qemuserial.sock,server']
25 p = subprocess.Popen(args, stdout=subprocess.DEVNULL,
26 stderr=subprocess.DEVNULL)
27
28 # Give process some time to boot:
29 time.sleep(0.5)
30
31 # Connect to the control socket:
32 qemu_control = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
33 qemu_control.connect('qemucontrol.sock')
34
35 time.sleep(0.5)
36
37 # Now connect to the serial output:
38 qemu_serial = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
39 qemu_serial.connect('qemuserial.sock')
40
41 time.sleep(0.5)
42
43 qemu_serial.settimeout(0.2)
44
45 # Receive all data:
46 data = bytearray()
47 for i in range(40):
48 try:
49 data += qemu_serial.recv(1)
50 except socket.timeout as e:
51 break
52 data = data.decode('ascii')
53 # print(data)
54
55 # Send quit command:
56 qemu_control.send("quit\n".encode('ascii'))
57 p.wait(timeout=3)
58 qemu_control.close()
59 qemu_serial.close()
60
61 # Check that output was correct:
62 return data
63
64 def testM3Bare(self): 65 def testM3Bare(self):
65 """ Build bare m3 binary and emulate it """ 66 """ Build bare m3 binary and emulate it """
66 recipe = os.path.join(testdir, 'm3_bare', 'recipe.yaml') 67 recipe = os.path.join(testdir, 'm3_bare', 'recipe.yaml')
67 self.buildRecipe(recipe) 68 self.buildRecipe(recipe)
68 data = self.runQemu('m3_bare/bare.bin') 69 data = runQemu('m3_bare/bare.bin')
69 self.assertEqual('Hello worle', data) 70 self.assertEqual('Hello worle', data)
70 71
71 def testA9Bare(self): 72 def testA9Bare(self):
72 """ Build vexpress cortex-A9 binary and emulate it """ 73 """ Build vexpress cortex-A9 binary and emulate it """
73 recipe = os.path.join(testdir, '..', 'examples', 'qemu_a9_hello', 'recipe.yaml') 74 recipe = os.path.join(testdir, '..', 'examples', 'qemu_a9_hello', 'recipe.yaml')
74 self.buildRecipe(recipe) 75 self.buildRecipe(recipe)
75 data = self.runQemu('../examples/qemu_a9_hello/hello.bin', machine='vexpress-a9') 76 data = runQemu('../examples/qemu_a9_hello/hello.bin', machine='vexpress-a9')
76 self.assertEqual('Hello worle', data) 77 self.assertEqual('Hello worle', data)
77 78
78 def testKernelVexpressA9(self): 79 def testKernelVexpressA9(self):
79 """ Build vexpress cortex-A9 binary and emulate it """ 80 """ Build vexpress cortex-A9 binary and emulate it """
80 recipe = os.path.join(testdir, '..', 'kernel', 'arm.yaml') 81 recipe = os.path.join(testdir, '..', 'kernel', 'arm.yaml')
81 self.buildRecipe(recipe) 82 self.buildRecipe(recipe)
82 data = self.runQemu('../kernel/kernel_arm.bin', machine='vexpress-a9') 83 data = runQemu('../kernel/kernel_arm.bin', machine='vexpress-a9')
83 self.assertEqual('Welcome to lcfos!', data) 84 self.assertEqual('Welcome to lcfos!', data)
84 85
85 86
86 if __name__ == '__main__': 87 if __name__ == '__main__':
87 unittest.main() 88 unittest.main()