diff options
| -rw-r--r-- | meta/lib/oeqa/selftest/cases/runqemu.py | 70 |
1 files changed, 68 insertions, 2 deletions
diff --git a/meta/lib/oeqa/selftest/cases/runqemu.py b/meta/lib/oeqa/selftest/cases/runqemu.py index 47d41f5218..f3ff015cba 100644 --- a/meta/lib/oeqa/selftest/cases/runqemu.py +++ b/meta/lib/oeqa/selftest/cases/runqemu.py | |||
| @@ -3,9 +3,10 @@ | |||
| 3 | # | 3 | # |
| 4 | 4 | ||
| 5 | import re | 5 | import re |
| 6 | 6 | import tempfile | |
| 7 | import time | ||
| 7 | from oeqa.selftest.case import OESelftestTestCase | 8 | from oeqa.selftest.case import OESelftestTestCase |
| 8 | from oeqa.utils.commands import bitbake, runqemu, get_bb_var | 9 | from oeqa.utils.commands import bitbake, runqemu, get_bb_var, runCmd |
| 9 | from oeqa.core.decorator.oeid import OETestID | 10 | from oeqa.core.decorator.oeid import OETestID |
| 10 | 11 | ||
| 11 | class RunqemuTests(OESelftestTestCase): | 12 | class RunqemuTests(OESelftestTestCase): |
| @@ -136,3 +137,68 @@ SYSLINUX_TIMEOUT = "10" | |||
| 136 | cmd = "%s %s" % (self.cmd_common, rootfs) | 137 | cmd = "%s %s" % (self.cmd_common, rootfs) |
| 137 | with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: | 138 | with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: |
| 138 | self.assertTrue(qemu.runner.logged, "Failed: %s" % cmd) | 139 | self.assertTrue(qemu.runner.logged, "Failed: %s" % cmd) |
| 140 | |||
| 141 | # This test was designed as a separate class to test that shutdown | ||
| 142 | # command will shutdown qemu as expected on each qemu architecture | ||
| 143 | # based on the MACHINE configuration inside the config file | ||
| 144 | # (eg. local.conf). | ||
| 145 | # | ||
| 146 | # This was different compared to RunqemuTests, where RunqemuTests was | ||
| 147 | # dedicated for MACHINE=qemux86-64 where it test that qemux86-64 will | ||
| 148 | # bootup various filesystem types, including live image(iso and hddimg) | ||
| 149 | # where live image was not supported on all qemu architecture. | ||
| 150 | class QemuTest(OESelftestTestCase): | ||
| 151 | |||
| 152 | @classmethod | ||
| 153 | def setUpClass(cls): | ||
| 154 | super(QemuTest, cls).setUpClass() | ||
| 155 | cls.recipe = 'core-image-minimal' | ||
| 156 | cls.machine = get_bb_var('MACHINE') | ||
| 157 | cls.deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') | ||
| 158 | cls.cmd_common = "runqemu nographic" | ||
| 159 | cls.qemuboot_conf = "%s-%s.qemuboot.conf" % (cls.recipe, cls.machine) | ||
| 160 | cls.qemuboot_conf = os.path.join(cls.deploy_dir_image, cls.qemuboot_conf) | ||
| 161 | bitbake(cls.recipe) | ||
| 162 | |||
| 163 | def _start_qemu_shutdown_check_if_shutdown_succeeded(self, qemu, timeout): | ||
| 164 | qemu.run_serial("shutdown -h now") | ||
| 165 | # Stop thread will stop the LoggingThread instance used for logging | ||
| 166 | # qemu through serial console, stop thread will prevent this code | ||
| 167 | # from facing exception (Console connection closed unexpectedly) | ||
| 168 | # when qemu was shutdown by the above shutdown command | ||
| 169 | qemu.runner.stop_thread() | ||
| 170 | time_track = 0 | ||
| 171 | while True: | ||
| 172 | is_alive = qemu.check() | ||
| 173 | if not is_alive: | ||
| 174 | return True | ||
| 175 | if time_track > timeout: | ||
| 176 | return False | ||
| 177 | time.sleep(1) | ||
| 178 | time_track += 1 | ||
| 179 | |||
| 180 | def test_qemu_can_shutdown(self): | ||
| 181 | self.assertExists(self.qemuboot_conf) | ||
| 182 | cmd = "%s %s" % (self.cmd_common, self.qemuboot_conf) | ||
| 183 | shutdown_timeout = 120 | ||
| 184 | with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: | ||
| 185 | qemu_shutdown_succeeded = self._start_qemu_shutdown_check_if_shutdown_succeeded(qemu, shutdown_timeout) | ||
| 186 | self.assertTrue(qemu_shutdown_succeeded, 'Failed: %s does not shutdown within timeout(%s)' % (self.machine, shutdown_timeout)) | ||
| 187 | |||
| 188 | def test_qemu_can_boot_nfs_and_shutdown(self): | ||
| 189 | self.assertExists(self.qemuboot_conf) | ||
| 190 | bitbake('meta-ide-support') | ||
| 191 | rootfs_tar = "%s-%s.tar.bz2" % (self.recipe, self.machine) | ||
| 192 | rootfs_tar = os.path.join(self.deploy_dir_image, rootfs_tar) | ||
| 193 | self.assertExists(rootfs_tar) | ||
| 194 | tmpdir = tempfile.mkdtemp(prefix='qemu_nfs') | ||
| 195 | tmpdir_nfs = os.path.join(tmpdir, 'nfs') | ||
| 196 | cmd_extract_nfs = 'runqemu-extract-sdk %s %s' % (rootfs_tar, tmpdir_nfs) | ||
| 197 | result = runCmd(cmd_extract_nfs) | ||
| 198 | self.assertEqual(0, result.status, "runqemu-extract-sdk didn't run as expected. %s" % result.output) | ||
| 199 | cmd = "%s nfs %s %s" % (self.cmd_common, self.qemuboot_conf, tmpdir_nfs) | ||
| 200 | shutdown_timeout = 120 | ||
| 201 | with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: | ||
| 202 | qemu_shutdown_succeeded = self._start_qemu_shutdown_check_if_shutdown_succeeded(qemu, shutdown_timeout) | ||
| 203 | self.assertTrue(qemu_shutdown_succeeded, 'Failed: %s does not shutdown within timeout(%s)' % (self.machine, shutdown_timeout)) | ||
| 204 | runCmd('rm -rf %s' % tmpdir) | ||
