Mercurial > lcfOS
diff test/testemulation.py @ 355:c2ddc8a36f5e
Enabled optimization
author | Windel Bouwman |
---|---|
date | Fri, 14 Mar 2014 10:30:13 +0100 |
parents | 5477e499b039 |
children | 52492b304adf |
line wrap: on
line diff
--- a/test/testemulation.py Thu Mar 13 18:59:06 2014 +0100 +++ b/test/testemulation.py Fri Mar 14 10:30:13 2014 +0100 @@ -10,6 +10,51 @@ # Store testdir for safe switch back to directory: testdir = os.path.dirname(os.path.abspath(__file__)) +def runQemu(kernel, machine='lm3s811evb'): + """ Runs qemu on a given kernel file on some machine """ + args = ['qemu-system-arm', '-M', machine, '-m', '16M', + '-nographic', '-kernel', kernel, '-monitor', + 'unix:qemucontrol.sock,server', + '-serial', 'unix:qemuserial.sock,server'] + p = subprocess.Popen(args, stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) + + # Give process some time to boot: + time.sleep(0.5) + + # Connect to the control socket: + qemu_control = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + qemu_control.connect('qemucontrol.sock') + + time.sleep(0.5) + + # Now connect to the serial output: + qemu_serial = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + qemu_serial.connect('qemuserial.sock') + + time.sleep(0.5) + + qemu_serial.settimeout(0.2) + + # Receive all data: + data = bytearray() + for i in range(40): + try: + data += qemu_serial.recv(1) + except socket.timeout as e: + break + data = data.decode('ascii') + # print(data) + + # Send quit command: + qemu_control.send("quit\n".encode('ascii')) + p.wait(timeout=3) + qemu_control.close() + qemu_serial.close() + + # Check that output was correct: + return data + class EmulationTestCase(ZccBaseTestCase): """ Tests the compiler driver """ @@ -17,69 +62,25 @@ if 'TESTEMU' not in os.environ: self.skipTest('Not running emulation tests') - def runQemu(self, kernel, machine='lm3s811evb'): - args = ['qemu-system-arm', '-M', machine, '-m', '16M', - '-nographic', '-kernel', kernel, '-monitor', - 'unix:qemucontrol.sock,server', - '-serial', 'unix:qemuserial.sock,server'] - p = subprocess.Popen(args, stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL) - - # Give process some time to boot: - time.sleep(0.5) - - # Connect to the control socket: - qemu_control = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - qemu_control.connect('qemucontrol.sock') - - time.sleep(0.5) - - # Now connect to the serial output: - qemu_serial = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - qemu_serial.connect('qemuserial.sock') - - time.sleep(0.5) - - qemu_serial.settimeout(0.2) - - # Receive all data: - data = bytearray() - for i in range(40): - try: - data += qemu_serial.recv(1) - except socket.timeout as e: - break - data = data.decode('ascii') - # print(data) - - # Send quit command: - qemu_control.send("quit\n".encode('ascii')) - p.wait(timeout=3) - qemu_control.close() - qemu_serial.close() - - # Check that output was correct: - return data - def testM3Bare(self): """ Build bare m3 binary and emulate it """ recipe = os.path.join(testdir, 'm3_bare', 'recipe.yaml') self.buildRecipe(recipe) - data = self.runQemu('m3_bare/bare.bin') + data = runQemu('m3_bare/bare.bin') self.assertEqual('Hello worle', data) def testA9Bare(self): """ Build vexpress cortex-A9 binary and emulate it """ recipe = os.path.join(testdir, '..', 'examples', 'qemu_a9_hello', 'recipe.yaml') self.buildRecipe(recipe) - data = self.runQemu('../examples/qemu_a9_hello/hello.bin', machine='vexpress-a9') + data = runQemu('../examples/qemu_a9_hello/hello.bin', machine='vexpress-a9') self.assertEqual('Hello worle', data) def testKernelVexpressA9(self): """ Build vexpress cortex-A9 binary and emulate it """ recipe = os.path.join(testdir, '..', 'kernel', 'arm.yaml') self.buildRecipe(recipe) - data = self.runQemu('../kernel/kernel_arm.bin', machine='vexpress-a9') + data = runQemu('../kernel/kernel_arm.bin', machine='vexpress-a9') self.assertEqual('Welcome to lcfos!', data)