From 8da7de18c9b5a84bd594220121d9ab324427d057 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Fri, 17 Nov 2017 12:11:38 +0100 Subject: Refactor Qemu interaction into seperate functions. This should make it easy to make new test classes that launch independent qemu instances with different configurations. --- lib/oeqa/selftest/updater.py | 81 ++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index ad99964..408f2c3 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -118,49 +118,16 @@ class QemuTests(oeSelfTest): @classmethod def setUpClass(cls): - logger = logging.getLogger("selftest") - logger.info('Running bitbake to build core-image-minimal') - bitbake('core-image-minimal') - # Create empty object. - args = type('', (), {})() - args.imagename = 'core-image-minimal' - args.mac = None - # Could use DEPLOY_DIR_IMAGE here but it's already in the machine - # subdirectory. - args.dir = 'tmp/deploy/images' - args.efi = False - args.machine = None - args.kvm = None # Autodetect - args.no_gui = True - args.gdb = False - args.pcap = None - args.overlay = None - args.dry_run = False - - cls.qemu = QemuCommand(args) - cmdline = cls.qemu.command_line() - print('Booting image with run-qemu-ota...') - cls.s = subprocess.Popen(cmdline) - time.sleep(10) + cls.qemu, cls.s = qemu_launch() @classmethod def tearDownClass(cls): - try: - cls.s.terminate() - except KeyboardInterrupt: - pass - - def run_test_qemu(self, command): - command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + - str(self.qemu.ssh_port) + ' "' + command + '"'] - s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - value, err = s2.communicate() - return value, err + qemu_terminate(cls.s) def test_hostname(self): print('') print('Checking machine name (hostname) of device:') - value, err = self.run_test_qemu('hostname') + 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. @@ -172,8 +139,48 @@ class QemuTests(oeSelfTest): def test_var_sota(self): print('') print('Checking contents of /var/sota:') - value, err = self.run_test_qemu('ls /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') + # Create empty object. + args = type('', (), {})() + args.imagename = 'core-image-minimal' + args.mac = None + # Could use DEPLOY_DIR_IMAGE here but it's already in the machine + # subdirectory. + args.dir = 'tmp/deploy/images' + args.efi = False + args.machine = None + args.kvm = None # Autodetect + args.no_gui = True + args.gdb = False + args.pcap = None + args.overlay = None + args.dry_run = False + + qemu = QemuCommand(args) + cmdline = qemu.command_line() + print('Booting image with run-qemu-ota...') + s = subprocess.Popen(cmdline) + time.sleep(10) + return qemu, s + +def qemu_terminate(s): + try: + s.terminate() + except KeyboardInterrupt: + pass + +def qemu_send_command(port, command): + command = ['ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@localhost -p ' + + str(port) + ' "' + command + '"'] + s2 = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + value, err = s2.communicate() + return value, err + -- cgit v1.2.3-54-g00ecf From 495a4a4ec6d540e1045852bc92ef46aa6a6bd9d9 Mon Sep 17 00:00:00 2001 From: Patrick Vacek Date: Fri, 17 Nov 2017 14:11:10 +0100 Subject: Test booting with grub. --- lib/oeqa/selftest/updater.py | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/oeqa/selftest/updater.py b/lib/oeqa/selftest/updater.py index 408f2c3..e3d4fc3 100644 --- a/lib/oeqa/selftest/updater.py +++ b/lib/oeqa/selftest/updater.py @@ -118,7 +118,7 @@ class QemuTests(oeSelfTest): @classmethod def setUpClass(cls): - cls.qemu, cls.s = qemu_launch() + cls.qemu, cls.s = qemu_launch(machine='qemux86-64') @classmethod def tearDownClass(cls): @@ -143,8 +143,39 @@ class QemuTests(oeSelfTest): self.assertEqual(err, b'', 'Error: ' + err.decode()) print(value.decode()) +class GrubTests(oeSelfTest): + + def setUpLocal(self): + # This is a bit of a hack but I can't see a better option. + path = os.path.abspath(os.path.dirname(__file__)) + metadir = path + "/../../../../" + grub_config = 'OSTREE_BOOTLOADER = "grub"\nMACHINE = "intel-corei7-64"' + self.append_config(grub_config) + self.meta_intel = metadir + "meta-intel" + self.meta_minnow = metadir + "meta-updater-minnowboard" + runCmd('bitbake-layers add-layer "%s"' % self.meta_intel) + runCmd('bitbake-layers add-layer "%s"' % self.meta_minnow) + self.qemu, self.s = qemu_launch(efi=True, machine='intel-corei7-64') + + def tearDownLocal(self): + qemu_terminate(self.s) + runCmd('bitbake-layers remove-layer "%s"' % self.meta_intel, ignore_status=True) + runCmd('bitbake-layers remove-layer "%s"' % self.meta_minnow, ignore_status=True) + + def test_grub(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 qemu_launch(): +def qemu_launch(efi=False, machine=None): logger = logging.getLogger("selftest") logger.info('Running bitbake to build core-image-minimal') bitbake('core-image-minimal') @@ -155,8 +186,8 @@ def qemu_launch(): # Could use DEPLOY_DIR_IMAGE here but it's already in the machine # subdirectory. args.dir = 'tmp/deploy/images' - args.efi = False - args.machine = None + args.efi = efi + args.machine = machine args.kvm = None # Autodetect args.no_gui = True args.gdb = False -- cgit v1.2.3-54-g00ecf