annotate test/testemulation.py @ 339:6ee17c4dd6b8

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