annotate test/testemulation.py @ 354:5477e499b039

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