diff options
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/runqemu.py')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/runqemu.py | 83 |
1 files changed, 44 insertions, 39 deletions
diff --git a/meta/lib/oeqa/selftest/cases/runqemu.py b/meta/lib/oeqa/selftest/cases/runqemu.py index 7e676bcb41..f01e1eec66 100644 --- a/meta/lib/oeqa/selftest/cases/runqemu.py +++ b/meta/lib/oeqa/selftest/cases/runqemu.py | |||
@@ -4,14 +4,17 @@ | |||
4 | # SPDX-License-Identifier: MIT | 4 | # SPDX-License-Identifier: MIT |
5 | # | 5 | # |
6 | 6 | ||
7 | import os | ||
7 | import re | 8 | import re |
8 | import tempfile | ||
9 | import time | 9 | import time |
10 | import oe.types | 10 | import oe.types |
11 | from oeqa.core.decorator import OETestTag | 11 | from oeqa.core.decorator import OETestTag |
12 | from oeqa.core.decorator.data import skipIfNotArch, skipIfNotMachine | ||
12 | from oeqa.selftest.case import OESelftestTestCase | 13 | from oeqa.selftest.case import OESelftestTestCase |
13 | from oeqa.utils.commands import bitbake, runqemu, get_bb_var, runCmd | 14 | from oeqa.utils.commands import bitbake, runqemu, get_bb_var |
14 | 15 | ||
16 | |||
17 | @OETestTag("runqemu") | ||
15 | class RunqemuTests(OESelftestTestCase): | 18 | class RunqemuTests(OESelftestTestCase): |
16 | """Runqemu test class""" | 19 | """Runqemu test class""" |
17 | 20 | ||
@@ -21,23 +24,26 @@ class RunqemuTests(OESelftestTestCase): | |||
21 | def setUpLocal(self): | 24 | def setUpLocal(self): |
22 | super(RunqemuTests, self).setUpLocal() | 25 | super(RunqemuTests, self).setUpLocal() |
23 | self.recipe = 'core-image-minimal' | 26 | self.recipe = 'core-image-minimal' |
24 | self.machine = 'qemux86-64' | 27 | self.machine = self.td['MACHINE'] |
25 | self.fstypes = "ext4 iso hddimg wic.vmdk wic.qcow2 wic.vdi" | 28 | self.image_link_name = get_bb_var('IMAGE_LINK_NAME', self.recipe) |
26 | self.cmd_common = "runqemu nographic" | ||
27 | 29 | ||
28 | kvm = oe.types.qemu_use_kvm(get_bb_var('QEMU_USE_KVM'), 'x86_64') | 30 | self.fstypes = "ext4" |
31 | if self.td["HOST_ARCH"] in ('i586', 'i686', 'x86_64'): | ||
32 | self.fstypes += " iso hddimg" | ||
33 | if self.machine == "qemux86-64": | ||
34 | self.fstypes += " wic.vmdk wic.qcow2 wic.vdi" | ||
35 | |||
36 | self.cmd_common = "runqemu nographic" | ||
37 | kvm = oe.types.qemu_use_kvm(get_bb_var('QEMU_USE_KVM'), self.td["TARGET_ARCH"]) | ||
29 | if kvm: | 38 | if kvm: |
30 | self.cmd_common += " kvm" | 39 | self.cmd_common += " kvm" |
31 | 40 | ||
32 | self.write_config( | 41 | self.write_config( |
33 | """ | 42 | """ |
34 | MACHINE = "%s" | ||
35 | IMAGE_FSTYPES = "%s" | 43 | IMAGE_FSTYPES = "%s" |
36 | # 10 means 1 second | 44 | # 10 means 1 second |
37 | SYSLINUX_TIMEOUT = "10" | 45 | SYSLINUX_TIMEOUT = "10" |
38 | """ | 46 | """ % self.fstypes) |
39 | % (self.machine, self.fstypes) | ||
40 | ) | ||
41 | 47 | ||
42 | if not RunqemuTests.image_is_ready: | 48 | if not RunqemuTests.image_is_ready: |
43 | RunqemuTests.deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') | 49 | RunqemuTests.deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') |
@@ -56,14 +62,17 @@ SYSLINUX_TIMEOUT = "10" | |||
56 | cmd = "%s %s ext4" % (self.cmd_common, self.machine) | 62 | cmd = "%s %s ext4" % (self.cmd_common, self.machine) |
57 | with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: | 63 | with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: |
58 | with open(qemu.qemurunnerlog) as f: | 64 | with open(qemu.qemurunnerlog) as f: |
59 | self.assertIn('rootfs.ext4', f.read(), "Failed: %s" % cmd) | 65 | regexp = r'\nROOTFS: .*\.ext4]\n' |
66 | self.assertRegex(f.read(), regexp, "Failed to find '%s' in '%s' after running '%s'" % (regexp, qemu.qemurunnerlog, cmd)) | ||
60 | 67 | ||
68 | @skipIfNotArch(['i586', 'i686', 'x86_64']) | ||
61 | def test_boot_machine_iso(self): | 69 | def test_boot_machine_iso(self): |
62 | """Test runqemu machine iso""" | 70 | """Test runqemu machine iso""" |
63 | cmd = "%s %s iso" % (self.cmd_common, self.machine) | 71 | cmd = "%s %s iso" % (self.cmd_common, self.machine) |
64 | with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: | 72 | with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: |
65 | with open(qemu.qemurunnerlog) as f: | 73 | with open(qemu.qemurunnerlog) as f: |
66 | self.assertIn('media=cdrom', f.read(), "Failed: %s" % cmd) | 74 | text_in = 'media=cdrom' |
75 | self.assertIn(text_in, f.read(), "Failed to find '%s' in '%s' after running '%s'" % (text_in, qemu.qemurunnerlog, cmd)) | ||
67 | 76 | ||
68 | def test_boot_recipe_image(self): | 77 | def test_boot_recipe_image(self): |
69 | """Test runqemu recipe-image""" | 78 | """Test runqemu recipe-image""" |
@@ -72,20 +81,24 @@ SYSLINUX_TIMEOUT = "10" | |||
72 | with open(qemu.qemurunnerlog) as f: | 81 | with open(qemu.qemurunnerlog) as f: |
73 | self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read())) | 82 | self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read())) |
74 | 83 | ||
75 | 84 | # https://bugzilla.yoctoproject.org/show_bug.cgi?id=14963 | |
85 | @skipIfNotMachine("qemux86-64", "tests are qemux86-64 specific currently") | ||
76 | def test_boot_recipe_image_vmdk(self): | 86 | def test_boot_recipe_image_vmdk(self): |
77 | """Test runqemu recipe-image vmdk""" | 87 | """Test runqemu recipe-image vmdk""" |
78 | cmd = "%s %s wic.vmdk" % (self.cmd_common, self.recipe) | 88 | cmd = "%s %s wic.vmdk" % (self.cmd_common, self.recipe) |
79 | with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: | 89 | with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: |
80 | with open(qemu.qemurunnerlog) as f: | 90 | with open(qemu.qemurunnerlog) as f: |
81 | self.assertIn('format=vmdk', f.read(), "Failed: %s" % cmd) | 91 | text_in = 'format=vmdk' |
92 | self.assertIn(text_in, f.read(), "Failed to find '%s' in '%s' after running '%s'" % (text_in, qemu.qemurunnerlog, cmd)) | ||
82 | 93 | ||
94 | @skipIfNotMachine("qemux86-64", "tests are qemux86-64 specific currently") | ||
83 | def test_boot_recipe_image_vdi(self): | 95 | def test_boot_recipe_image_vdi(self): |
84 | """Test runqemu recipe-image vdi""" | 96 | """Test runqemu recipe-image vdi""" |
85 | cmd = "%s %s wic.vdi" % (self.cmd_common, self.recipe) | 97 | cmd = "%s %s wic.vdi" % (self.cmd_common, self.recipe) |
86 | with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: | 98 | with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: |
87 | with open(qemu.qemurunnerlog) as f: | 99 | with open(qemu.qemurunnerlog) as f: |
88 | self.assertIn('format=vdi', f.read(), "Failed: %s" % cmd) | 100 | text_in = 'format=vdi' |
101 | self.assertIn(text_in, f.read(), "Failed to find '%s' in '%s' after running '%s'" % (text_in, qemu.qemurunnerlog, cmd)) | ||
89 | 102 | ||
90 | def test_boot_deploy(self): | 103 | def test_boot_deploy(self): |
91 | """Test runqemu deploy_dir_image""" | 104 | """Test runqemu deploy_dir_image""" |
@@ -94,7 +107,7 @@ SYSLINUX_TIMEOUT = "10" | |||
94 | with open(qemu.qemurunnerlog) as f: | 107 | with open(qemu.qemurunnerlog) as f: |
95 | self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read())) | 108 | self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read())) |
96 | 109 | ||
97 | 110 | @skipIfNotArch(['i586', 'i686', 'x86_64']) | |
98 | def test_boot_deploy_hddimg(self): | 111 | def test_boot_deploy_hddimg(self): |
99 | """Test runqemu deploy_dir_image hddimg""" | 112 | """Test runqemu deploy_dir_image hddimg""" |
100 | cmd = "%s %s hddimg" % (self.cmd_common, self.deploy_dir_image) | 113 | cmd = "%s %s hddimg" % (self.cmd_common, self.deploy_dir_image) |
@@ -109,6 +122,7 @@ SYSLINUX_TIMEOUT = "10" | |||
109 | with open(qemu.qemurunnerlog) as f: | 122 | with open(qemu.qemurunnerlog) as f: |
110 | self.assertIn(' -netdev user', f.read(), "Failed: %s" % cmd) | 123 | self.assertIn(' -netdev user', f.read(), "Failed: %s" % cmd) |
111 | 124 | ||
125 | @skipIfNotMachine("qemux86-64", "tests are qemux86-64 specific currently") | ||
112 | def test_boot_machine_slirp_qcow2(self): | 126 | def test_boot_machine_slirp_qcow2(self): |
113 | """Test runqemu machine slirp qcow2""" | 127 | """Test runqemu machine slirp qcow2""" |
114 | cmd = "%s slirp wic.qcow2 %s" % (self.cmd_common, self.machine) | 128 | cmd = "%s slirp wic.qcow2 %s" % (self.cmd_common, self.machine) |
@@ -118,7 +132,7 @@ SYSLINUX_TIMEOUT = "10" | |||
118 | 132 | ||
119 | def test_boot_qemu_boot(self): | 133 | def test_boot_qemu_boot(self): |
120 | """Test runqemu /path/to/image.qemuboot.conf""" | 134 | """Test runqemu /path/to/image.qemuboot.conf""" |
121 | qemuboot_conf = "%s-%s.qemuboot.conf" % (self.recipe, self.machine) | 135 | qemuboot_conf = "%s.qemuboot.conf" % (self.image_link_name) |
122 | qemuboot_conf = os.path.join(self.deploy_dir_image, qemuboot_conf) | 136 | qemuboot_conf = os.path.join(self.deploy_dir_image, qemuboot_conf) |
123 | if not os.path.exists(qemuboot_conf): | 137 | if not os.path.exists(qemuboot_conf): |
124 | self.skipTest("%s not found" % qemuboot_conf) | 138 | self.skipTest("%s not found" % qemuboot_conf) |
@@ -129,7 +143,7 @@ SYSLINUX_TIMEOUT = "10" | |||
129 | 143 | ||
130 | def test_boot_rootfs(self): | 144 | def test_boot_rootfs(self): |
131 | """Test runqemu /path/to/rootfs.ext4""" | 145 | """Test runqemu /path/to/rootfs.ext4""" |
132 | rootfs = "%s-%s.ext4" % (self.recipe, self.machine) | 146 | rootfs = "%s.ext4" % (self.image_link_name) |
133 | rootfs = os.path.join(self.deploy_dir_image, rootfs) | 147 | rootfs = os.path.join(self.deploy_dir_image, rootfs) |
134 | if not os.path.exists(rootfs): | 148 | if not os.path.exists(rootfs): |
135 | self.skipTest("%s not found" % rootfs) | 149 | self.skipTest("%s not found" % rootfs) |
@@ -149,26 +163,27 @@ SYSLINUX_TIMEOUT = "10" | |||
149 | # bootup various filesystem types, including live image(iso and hddimg) | 163 | # bootup various filesystem types, including live image(iso and hddimg) |
150 | # where live image was not supported on all qemu architecture. | 164 | # where live image was not supported on all qemu architecture. |
151 | @OETestTag("machine") | 165 | @OETestTag("machine") |
166 | @OETestTag("runqemu") | ||
152 | class QemuTest(OESelftestTestCase): | 167 | class QemuTest(OESelftestTestCase): |
153 | 168 | ||
154 | @classmethod | 169 | @classmethod |
155 | def setUpClass(cls): | 170 | def setUpClass(cls): |
156 | super(QemuTest, cls).setUpClass() | 171 | super(QemuTest, cls).setUpClass() |
157 | cls.recipe = 'core-image-minimal' | 172 | cls.recipe = 'core-image-minimal' |
158 | cls.machine = get_bb_var('MACHINE') | 173 | cls.machine = get_bb_var('MACHINE') |
159 | cls.deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') | 174 | cls.deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE') |
175 | cls.image_link_name = get_bb_var('IMAGE_LINK_NAME', cls.recipe) | ||
160 | cls.cmd_common = "runqemu nographic" | 176 | cls.cmd_common = "runqemu nographic" |
161 | cls.qemuboot_conf = "%s-%s.qemuboot.conf" % (cls.recipe, cls.machine) | 177 | cls.qemuboot_conf = "%s.qemuboot.conf" % (cls.image_link_name) |
162 | cls.qemuboot_conf = os.path.join(cls.deploy_dir_image, cls.qemuboot_conf) | 178 | cls.qemuboot_conf = os.path.join(cls.deploy_dir_image, cls.qemuboot_conf) |
163 | bitbake(cls.recipe) | 179 | bitbake(cls.recipe) |
164 | 180 | ||
165 | def _start_qemu_shutdown_check_if_shutdown_succeeded(self, qemu, timeout): | 181 | def _start_qemu_shutdown_check_if_shutdown_succeeded(self, qemu, timeout): |
182 | # Allow the runner's LoggingThread instance to exit without errors | ||
183 | # (such as the exception "Console connection closed unexpectedly") | ||
184 | # as qemu will disappear when we shut it down | ||
185 | qemu.runner.allowexit() | ||
166 | qemu.run_serial("shutdown -h now") | 186 | qemu.run_serial("shutdown -h now") |
167 | # Stop thread will stop the LoggingThread instance used for logging | ||
168 | # qemu through serial console, stop thread will prevent this code | ||
169 | # from facing exception (Console connection closed unexpectedly) | ||
170 | # when qemu was shutdown by the above shutdown command | ||
171 | qemu.runner.stop_thread() | ||
172 | time_track = 0 | 187 | time_track = 0 |
173 | try: | 188 | try: |
174 | while True: | 189 | while True: |
@@ -190,22 +205,12 @@ class QemuTest(OESelftestTestCase): | |||
190 | qemu_shutdown_succeeded = self._start_qemu_shutdown_check_if_shutdown_succeeded(qemu, shutdown_timeout) | 205 | qemu_shutdown_succeeded = self._start_qemu_shutdown_check_if_shutdown_succeeded(qemu, shutdown_timeout) |
191 | self.assertTrue(qemu_shutdown_succeeded, 'Failed: %s does not shutdown within timeout(%s)' % (self.machine, shutdown_timeout)) | 206 | self.assertTrue(qemu_shutdown_succeeded, 'Failed: %s does not shutdown within timeout(%s)' % (self.machine, shutdown_timeout)) |
192 | 207 | ||
193 | # Need to have portmap/rpcbind running to allow this test to work and | 208 | def test_qemu_can_boot_nfs_and_shutdown(self): |
194 | # current autobuilder setup does not have this. | 209 | rootfs_tar = "%s.tar.bz2" % (self.image_link_name) |
195 | def disabled_test_qemu_can_boot_nfs_and_shutdown(self): | ||
196 | self.assertExists(self.qemuboot_conf) | ||
197 | bitbake('meta-ide-support') | ||
198 | rootfs_tar = "%s-%s.tar.bz2" % (self.recipe, self.machine) | ||
199 | rootfs_tar = os.path.join(self.deploy_dir_image, rootfs_tar) | 210 | rootfs_tar = os.path.join(self.deploy_dir_image, rootfs_tar) |
200 | self.assertExists(rootfs_tar) | 211 | self.assertExists(rootfs_tar) |
201 | tmpdir = tempfile.mkdtemp(prefix='qemu_nfs') | 212 | cmd = "%s %s" % (self.cmd_common, rootfs_tar) |
202 | tmpdir_nfs = os.path.join(tmpdir, 'nfs') | ||
203 | cmd_extract_nfs = 'runqemu-extract-sdk %s %s' % (rootfs_tar, tmpdir_nfs) | ||
204 | result = runCmd(cmd_extract_nfs) | ||
205 | self.assertEqual(0, result.status, "runqemu-extract-sdk didn't run as expected. %s" % result.output) | ||
206 | cmd = "%s nfs %s %s" % (self.cmd_common, self.qemuboot_conf, tmpdir_nfs) | ||
207 | shutdown_timeout = 120 | 213 | shutdown_timeout = 120 |
208 | with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: | 214 | with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu: |
209 | qemu_shutdown_succeeded = self._start_qemu_shutdown_check_if_shutdown_succeeded(qemu, shutdown_timeout) | 215 | qemu_shutdown_succeeded = self._start_qemu_shutdown_check_if_shutdown_succeeded(qemu, shutdown_timeout) |
210 | self.assertTrue(qemu_shutdown_succeeded, 'Failed: %s does not shutdown within timeout(%s)' % (self.machine, shutdown_timeout)) | 216 | self.assertTrue(qemu_shutdown_succeeded, 'Failed: %s does not shutdown within timeout(%s)' % (self.machine, shutdown_timeout)) |
211 | runCmd('rm -rf %s' % tmpdir) | ||