Mercurial > lcfOS
comparison test/testemulation.py @ 364:c49459768aaa
Work on globals
author | Windel Bouwman |
---|---|
date | Wed, 19 Mar 2014 20:24:03 +0100 |
parents | 614a7f6d4d4d |
children | 39bf68bf1891 |
comparison
equal
deleted
inserted
replaced
363:396e5cefba13 | 364:c49459768aaa |
---|---|
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'): | 13 def runQemu(kernel, machine='lm3s811evb'): |
14 """ Runs qemu on a given kernel file on some machine """ | 14 """ Runs qemu on a given kernel file """ |
15 try: | |
16 os.remove('qemucontrol.sock') | |
17 except FileNotFoundError: | |
18 pass | |
19 | |
20 try: | |
21 os.remove('qemuserial.sock') | |
22 except FileNotFoundError: | |
23 pass | |
24 | |
25 # Listen to the control socket: | |
26 qemu_control = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
27 qemu_control.bind('qemucontrol.sock') | |
28 qemu_control.listen(0) | |
29 | |
30 # Listen to the serial output: | |
31 qemu_serial = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
32 qemu_serial.bind('qemuserial.sock') | |
33 qemu_serial.listen(0) | |
34 | |
15 args = ['qemu-system-arm', '-M', machine, '-m', '16M', | 35 args = ['qemu-system-arm', '-M', machine, '-m', '16M', |
16 '-nographic', '-kernel', kernel, '-monitor', | 36 '-nographic', '-kernel', kernel, '-monitor', |
17 'unix:qemucontrol.sock,server', | 37 'unix:qemucontrol.sock', |
18 '-serial', 'unix:qemuserial.sock,server'] | 38 '-serial', 'unix:qemuserial.sock', '-S'] |
19 p = subprocess.Popen(args, stdout=subprocess.DEVNULL, | 39 p = subprocess.Popen(args) |
20 stderr=subprocess.DEVNULL) | 40 #stdout=subprocess.DEVNULL, |
41 #stderr=subprocess.DEVNULL) | |
21 | 42 |
22 # Give process some time to boot: | 43 # Give process some time to boot: |
23 time.sleep(0.5) | 44 qemu_serial, address_peer = qemu_serial.accept() |
24 | 45 qemu_control, address_peer = qemu_control.accept() |
25 # Connect to the control socket: | 46 qemu_control.send('cont\n'.encode('ascii')) |
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 | 47 |
37 qemu_serial.settimeout(0.2) | 48 qemu_serial.settimeout(0.2) |
38 | 49 |
39 # Receive all data: | 50 # Receive all data: |
40 data = bytearray() | 51 data = bytearray() |
41 for i in range(40): | 52 for i in range(400): |
42 try: | 53 try: |
43 data += qemu_serial.recv(1) | 54 data += qemu_serial.recv(1) |
44 except socket.timeout as e: | 55 except socket.timeout as e: |
45 break | 56 break |
46 data = data.decode('ascii') | 57 data = data.decode('ascii') |
47 # print(data) | 58 # print(data) |
48 | 59 |
49 # Send quit command: | 60 # Send quit command: |
50 qemu_control.send("quit\n".encode('ascii')) | 61 qemu_control.send("quit\n".encode('ascii')) |
51 p.wait(timeout=3) | 62 try: |
63 p.wait(timeout=3) | |
64 except subprocess.TimeoutExpired: | |
65 p.kill() | |
66 print(p.communicate()) | |
52 qemu_control.close() | 67 qemu_control.close() |
53 qemu_serial.close() | 68 qemu_serial.close() |
69 | |
70 try: | |
71 os.remove('qemucontrol.sock') | |
72 except FileNotFoundError: | |
73 pass | |
74 | |
75 try: | |
76 os.remove('qemuserial.sock') | |
77 except FileNotFoundError: | |
78 pass | |
54 | 79 |
55 # Check that output was correct: | 80 # Check that output was correct: |
56 return data | 81 return data |
57 | 82 |
58 | 83 |