Mercurial > lcfOS
comparison test/testemulation.py @ 346:3bb7dcfe5529
expanded arm target
author | Windel Bouwman |
---|---|
date | Fri, 07 Mar 2014 17:05:32 +0100 |
parents | c7cc54c0dfdf |
children | 899ae3aea803 |
comparison
equal
deleted
inserted
replaced
345:b4882ff0ed06 | 346:3bb7dcfe5529 |
---|---|
12 | 12 |
13 | 13 |
14 class EmulationTestCase(ZccBaseTestCase): | 14 class EmulationTestCase(ZccBaseTestCase): |
15 """ Tests the compiler driver """ | 15 """ Tests the compiler driver """ |
16 def setUp(self): | 16 def setUp(self): |
17 os.chdir(testdir) | |
18 if 'TESTEMU' not in os.environ: | 17 if 'TESTEMU' not in os.environ: |
19 self.skipTest('Not running emulation tests') | 18 self.skipTest('Not running emulation tests') |
20 | 19 |
21 def tearDown(self): | 20 def runQemu(self, kernel, machine='lm3s811evb'): |
22 os.chdir(testdir) | 21 args = ['qemu-system-arm', '-M', machine, '-m', '16M', |
23 | |
24 def runQemu(self, kernel): | |
25 args = ['qemu-system-arm', '-M', 'lm3s811evb', '-m', '16M', | |
26 '-nographic', '-kernel', kernel, '-monitor', | 22 '-nographic', '-kernel', kernel, '-monitor', |
27 'unix:qemucontrol.sock,server', | 23 'unix:qemucontrol.sock,server', |
28 '-serial', 'unix:qemuserial.sock,server'] | 24 '-serial', 'unix:qemuserial.sock,server'] |
29 p = subprocess.Popen(args) | 25 p = subprocess.Popen(args) |
30 | 26 |
39 | 35 |
40 # Now connect to the serial output: | 36 # Now connect to the serial output: |
41 qemu_serial = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | 37 qemu_serial = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
42 qemu_serial.connect('qemuserial.sock') | 38 qemu_serial.connect('qemuserial.sock') |
43 | 39 |
40 time.sleep(0.5) | |
44 | 41 |
45 data = qemu_serial.recv(11).decode('ascii') | 42 qemu_serial.settimeout(0.2) |
46 print(data) | 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) | |
47 | 53 |
48 # Send quit command: | 54 # Send quit command: |
49 qemu_control.send("quit\n".encode('ascii')) | 55 qemu_control.send("quit\n".encode('ascii')) |
50 p.wait(timeout=3) | 56 p.wait(timeout=3) |
51 qemu_control.close() | 57 qemu_control.close() |
52 qemu_serial.close() | 58 qemu_serial.close() |
53 | 59 |
54 # Check that output was correct: | 60 # Check that output was correct: |
55 self.assertEqual('Hello worle', data) | 61 return data |
56 | 62 |
57 def testM3Bare(self): | 63 def testM3Bare(self): |
58 """ Build bare m3 binary and emulate it """ | 64 """ Build bare m3 binary and emulate it """ |
59 recipe = os.path.join(testdir, 'm3_bare', 'recipe.yaml') | 65 recipe = os.path.join(testdir, 'm3_bare', 'recipe.yaml') |
60 self.buildRecipe(recipe) | 66 self.buildRecipe(recipe) |
61 self.runQemu('m3_bare/bare.bin') | 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) | |
62 | 76 |
63 | 77 |
64 if __name__ == '__main__': | 78 if __name__ == '__main__': |
65 unittest.main() | 79 unittest.main() |