Refactor Qemu interaction into seperate functions.
This should make it easy to make new test classes that launch
independent qemu instances with different configurations.
@@ -118,6 +118,33 @@ class QemuTests(oeSelfTest):
@classmethod
def setUpClass(cls):
+ cls.qemu, cls.s = qemu_launch()
+
+ @classmethod
+ def tearDownClass(cls):
+ qemu_terminate(cls.s)
+
+ def test_hostname(self):
+ print('')
+ print('Checking machine name (hostname) of device:')
+ value, err = qemu_send_command(self.qemu.ssh_port, 'hostname')
+ machine = get_bb_var('MACHINE', 'core-image-minimal')
+ self.assertEqual(err, b'', 'Error: ' + err.decode())
+ # Strip off line ending.
+ value_str = value.decode()[:-1]
+ self.assertEqual(value_str, machine,
+ 'MACHINE does not match hostname: ' + machine + ', ' + value_str)
+ print(value_str)
+
+ def test_var_sota(self):
+ print('')
+ print('Checking contents of /var/sota:')
+ value, err = qemu_send_command(self.qemu.ssh_port, 'ls /var/sota')
+ self.assertEqual(err, b'', 'Error: ' + err.decode())
+ print(value.decode())
+
+
+def qemu_launch():
logger = logging.getLogger("selftest")
logger.info('Running bitbake to build core-image-minimal')
bitbake('core-image-minimal')
@@ -137,43 +164,23 @@ class QemuTests(oeSelfTest):
args.overlay = None
args.dry_run = False
- cls.qemu = QemuCommand(args)
- cmdline = cls.qemu.command_line()
+ qemu = QemuCommand(args)
+ cmdline = qemu.command_line()
print('Booting image with run-qemu-ota...')
- cls.s = subprocess.Popen(cmdline)
+ s = subprocess.Popen(cmdline)
time.sleep(10)
+ return qemu, s
- @classmethod
- def tearDownClass(cls):
+def qemu_terminate(s):
try:
- cls.s.terminate()
+ s.terminate()
except KeyboardInterrupt:
pass
- def run_test_qemu(self, command):
+def qemu_send_command(port, command):
command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' +
- str(self.qemu.ssh_port) + ' "' + command + '"']
+ str(port) + ' "' + command + '"']
s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
value, err = s2.communicate()
return value, err
- def test_hostname(self):
- print('')
- print('Checking machine name (hostname) of device:')
- value, err = self.run_test_qemu('hostname')
- machine = get_bb_var('MACHINE', 'core-image-minimal')
- self.assertEqual(err, b'', 'Error: ' + err.decode())
- # Strip off line ending.
- value_str = value.decode()[:-1]
- self.assertEqual(value_str, machine,
- 'MACHINE does not match hostname: ' + machine + ', ' + value_str)
- print(value_str)
-
- def test_var_sota(self):
- print('')
- print('Checking contents of /var/sota:')
- value, err = self.run_test_qemu('ls /var/sota')
- self.assertEqual(err, b'', 'Error: ' + err.decode())
- print(value.decode())
-
-
