oe-selftest: runqemu: add tests for qemu boot and shutdown
PATCH 1/1 oe-selftest: runqemu: add tests for qemu boot and shutdown
QA team were testing qemu boot image and shutdown on each qemu architecture manually. Add automated test to test qemu boot on ext4 and nfs, finally check that it can shutdown properly.
--- meta/lib/oeqa/selftest/cases/runqemu.py | 70 ++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 2 deletions(-)
meta/lib/oeqa/selftest/cases/runqemu.py +68 -2
@@ -3,9 +3,10 @@ # import re - +import tempfile +import time from oeqa.selftest.case import OESelftestTestCase -from oeqa.utils.commands import bitbake, runqemu, get_bb_var +from oeqa.utils.commands import bitbake, runqemu, get_bb_var, runCmd from oeqa.core.decorator.oeid import OETestID class RunqemuTests(OESelftestTestCase):
@@ -136,3 +137,68 @@ SYSLINUX_TIMEOUT = "10" cmd = "%s %s" % (self.cmd_common, rootfs) with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: self.assertTrue(qemu.runner.logged, "Failed: %s" % cmd) + +# This test was designed as a separate class to test that shutdown +# command will shutdown qemu as expected on each qemu architecture +# based on the MACHINE configuration inside the config file +# (eg. local.conf). +# +# This was different compared to RunqemuTests, where RunqemuTests was +# dedicated for MACHINE=qemux86-64 where it test that qemux86-64 will +# bootup various filesystem types, including live image(iso and hddimg) +# where live image was not supported on all qemu architecture. +class QemuTest(OESelftestTestCase): + + @classmethod + def setUpClass(cls): + super(QemuTest, cls).setUpClass() + cls.recipe = 'core-image-minimal' + cls.machine = get_bb_var('MACHINE') + cls.deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') + cls.cmd_common = "runqemu nographic" + cls.qemuboot_conf = "%s-%s.qemuboot.conf" % (cls.recipe, cls.machine) + cls.qemuboot_conf = os.path.join(cls.deploy_dir_image, cls.qemuboot_conf) + bitbake(cls.recipe) + + def _start_qemu_shutdown_check_if_shutdown_succeeded(self, qemu, timeout): + qemu.run_serial("shutdown -h now") + # Stop thread will stop the LoggingThread instance used for logging + # qemu through serial console, stop thread will prevent this code + # from facing exception (Console connection closed unexpectedly) + # when qemu was shutdown by the above shutdown command + qemu.runner.stop_thread() + time_track = 0 + while True: + is_alive = qemu.check() + if not is_alive: + return True + if time_track > timeout: + return False + time.sleep(1) + time_track += 1 + + def test_qemu_can_shutdown(self): + self.assertExists(self.qemuboot_conf) + cmd = "%s %s" % (self.cmd_common, self.qemuboot_conf) + shutdown_timeout = 120 + with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: + qemu_shutdown_succeeded = self._start_qemu_shutdown_check_if_shutdown_succeeded(qemu, shutdown_timeout) + self.assertTrue(qemu_shutdown_succeeded, 'Failed: %s does not shutdown within timeout(%s)' % (self.machine, shutdown_timeout)) + + def test_qemu_can_boot_nfs_and_shutdown(self): + self.assertExists(self.qemuboot_conf) + bitbake('meta-ide-support') + rootfs_tar = "%s-%s.tar.bz2" % (self.recipe, self.machine) + rootfs_tar = os.path.join(self.deploy_dir_image, rootfs_tar) + self.assertExists(rootfs_tar) + tmpdir = tempfile.mkdtemp(prefix='qemu_nfs') + tmpdir_nfs = os.path.join(tmpdir, 'nfs') + cmd_extract_nfs = 'runqemu-extract-sdk %s %s' % (rootfs_tar, tmpdir_nfs) + result = runCmd(cmd_extract_nfs) + self.assertEqual(0, result.status, "runqemu-extract-sdk didn't run as expected. %s" % result.output) + cmd = "%s nfs %s %s" % (self.cmd_common, self.qemuboot_conf, tmpdir_nfs) + shutdown_timeout = 120 + with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: + qemu_shutdown_succeeded = self._start_qemu_shutdown_check_if_shutdown_succeeded(qemu, shutdown_timeout) + self.assertTrue(qemu_shutdown_succeeded, 'Failed: %s does not shutdown within timeout(%s)' % (self.machine, shutdown_timeout)) + runCmd('rm -rf %s' % tmpdir)
Signature · 1 line
2.7.4
Quoted 9 lines · Yeoh Ee Peng
QA team were testing qemu boot image and shutdown on each qemu architecture manually. Add automated test to test qemu boot on ext4 and nfs, finally check that it can shutdown properly.
Signed-off-by Yeoh Ee Peng <[email protected]>---
meta/lib/oeqa/selftest/cases/runqemu.py | 70
++++++++++++++++++++++++++++++++-1 file changed, 68 insertions(+), 2 deletions(-)
The test is good however it fails on our infrastructure since portmap/rpcbind aren't running. This is a new dependency for the test infrastructure we'd have to document so I don't want to merge this for 2.5.
Since the code itself is fine, instead I've merged the test but disabled the NFS test by default and we'll need to revisit this in 2.6 to enable it.
Cheers,
Richard
Richard,
Noted, thank you very much!
It was fine, QA team shall be able to manually trigger this selftest, at least it was more efficient than manually executing the testcase.
Cheers,
Yeoh Ee Peng
-----Original Message-----
From: Richard Purdie [mailto:[email protected]]
Sent: Friday, April 20, 2018 3:15 PM
To: Yeoh, Ee Peng <[email protected]>; [email protected]
Subject: Re: [OE-core] [PATCH] oe-selftest: runqemu: add tests for qemu boot and shutdown
Quoted 9 lines · Yeoh Ee Peng
QA team were testing qemu boot image and shutdown on each qemu architecture manually. Add automated test to test qemu boot on ext4 and nfs, finally check that it can shutdown properly.
Signed-off-by Yeoh Ee Peng <[email protected]>---
meta/lib/oeqa/selftest/cases/runqemu.py | 70
++++++++++++++++++++++++++++++++-1 file changed, 68 insertions(+), 2 deletions(-)
The test is good however it fails on our infrastructure since portmap/rpcbind aren't running. This is a new dependency for the test infrastructure we'd have to document so I don't want to merge this for 2.5.
Since the code itself is fine, instead I've merged the test but disabled the NFS test by default and we'll need to revisit this in 2.6 to enable it.
Cheers,
Richard