annotate test/testemulation.py @ 340:c7cc54c0dfdf devel

Test featurebranch
author Windel Bouwman
date Sun, 23 Feb 2014 16:24:01 +0100
parents 6ee17c4dd6b8
children 3bb7dcfe5529
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
340
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 339
diff changeset
24 def runQemu(self, kernel):
338
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
340
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 339
diff changeset
38 time.sleep(0.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'))
340
c7cc54c0dfdf Test featurebranch
Windel Bouwman
parents: 339
diff changeset
50 p.wait(timeout=3)
338
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents:
diff changeset
51 qemu_control.close()
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents:
diff changeset
52 qemu_serial.close()
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents:
diff changeset
53
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents:
diff changeset
54 # Check that output was correct:
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents:
diff changeset
55 self.assertEqual('Hello worle', data)
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents:
diff changeset
56
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents:
diff changeset
57 def testM3Bare(self):
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents:
diff changeset
58 """ Build bare m3 binary and emulate it """
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents:
diff changeset
59 recipe = os.path.join(testdir, 'm3_bare', 'recipe.yaml')
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents:
diff changeset
60 self.buildRecipe(recipe)
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents:
diff changeset
61 self.runQemu('m3_bare/bare.bin')
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents:
diff changeset
62
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents:
diff changeset
63
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents:
diff changeset
64 if __name__ == '__main__':
8eb4a6fe8fc8 Added testcase with emulator
Windel Bouwman
parents:
diff changeset
65 unittest.main()