blob: f69d4706a50c627c20c0af0662ba931c63609d64 [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001#
2# Copyright (c) 2017 Wind River Systems, Inc.
3#
4
5import re
Brad Bishop316dfdd2018-06-25 12:45:53 -04006import tempfile
7import time
Brad Bishop977dc1a2019-02-06 16:01:43 -05008import oe.types
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009from oeqa.selftest.case import OESelftestTestCase
Brad Bishop316dfdd2018-06-25 12:45:53 -040010from oeqa.utils.commands import bitbake, runqemu, get_bb_var, runCmd
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011from oeqa.core.decorator.oeid import OETestID
12
13class RunqemuTests(OESelftestTestCase):
14 """Runqemu test class"""
15
16 image_is_ready = False
17 deploy_dir_image = ''
Brad Bishopd7bf8c12018-02-25 22:55:05 -050018
19 def setUpLocal(self):
20 super(RunqemuTests, self).setUpLocal()
21 self.recipe = 'core-image-minimal'
22 self.machine = 'qemux86-64'
23 self.fstypes = "ext4 iso hddimg wic.vmdk wic.qcow2 wic.vdi"
24 self.cmd_common = "runqemu nographic"
25
Brad Bishop977dc1a2019-02-06 16:01:43 -050026 kvm = oe.types.qemu_use_kvm(get_bb_var('QEMU_USE_KVM'), 'x86_64')
27 if kvm:
28 self.cmd_common += " kvm"
29
Brad Bishopd7bf8c12018-02-25 22:55:05 -050030 self.write_config(
31"""
32MACHINE = "%s"
33IMAGE_FSTYPES = "%s"
34# 10 means 1 second
35SYSLINUX_TIMEOUT = "10"
36"""
37% (self.machine, self.fstypes)
38 )
39
40 if not RunqemuTests.image_is_ready:
41 RunqemuTests.deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
42 bitbake(self.recipe)
43 RunqemuTests.image_is_ready = True
44
45 @OETestID(2001)
46 def test_boot_machine(self):
47 """Test runqemu machine"""
48 cmd = "%s %s" % (self.cmd_common, self.machine)
49 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
Brad Bishopf86d0552018-12-04 14:18:15 -080050 with open(qemu.qemurunnerlog) as f:
51 self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read()))
Brad Bishopd7bf8c12018-02-25 22:55:05 -050052
53 @OETestID(2002)
54 def test_boot_machine_ext4(self):
55 """Test runqemu machine ext4"""
56 cmd = "%s %s ext4" % (self.cmd_common, self.machine)
57 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
58 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -080059 self.assertIn('rootfs.ext4', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050060
61 @OETestID(2003)
62 def test_boot_machine_iso(self):
63 """Test runqemu machine iso"""
64 cmd = "%s %s iso" % (self.cmd_common, self.machine)
65 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
66 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -080067 self.assertIn('media=cdrom', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050068
69 @OETestID(2004)
70 def test_boot_recipe_image(self):
71 """Test runqemu recipe-image"""
72 cmd = "%s %s" % (self.cmd_common, self.recipe)
73 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
Brad Bishopf86d0552018-12-04 14:18:15 -080074 with open(qemu.qemurunnerlog) as f:
75 self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read()))
76
Brad Bishopd7bf8c12018-02-25 22:55:05 -050077
78 @OETestID(2005)
79 def test_boot_recipe_image_vmdk(self):
80 """Test runqemu recipe-image vmdk"""
81 cmd = "%s %s wic.vmdk" % (self.cmd_common, self.recipe)
82 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
83 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -080084 self.assertIn('format=vmdk', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050085
86 @OETestID(2006)
87 def test_boot_recipe_image_vdi(self):
88 """Test runqemu recipe-image vdi"""
89 cmd = "%s %s wic.vdi" % (self.cmd_common, self.recipe)
90 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
91 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -080092 self.assertIn('format=vdi', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050093
94 @OETestID(2007)
95 def test_boot_deploy(self):
96 """Test runqemu deploy_dir_image"""
97 cmd = "%s %s" % (self.cmd_common, self.deploy_dir_image)
98 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
Brad Bishopf86d0552018-12-04 14:18:15 -080099 with open(qemu.qemurunnerlog) as f:
100 self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read()))
101
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500102
103 @OETestID(2008)
104 def test_boot_deploy_hddimg(self):
105 """Test runqemu deploy_dir_image hddimg"""
106 cmd = "%s %s hddimg" % (self.cmd_common, self.deploy_dir_image)
107 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
108 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -0800109 self.assertTrue(re.search('file=.*.hddimg', f.read()), "Failed: %s, %s" % (cmd, f.read()))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500110
111 @OETestID(2009)
112 def test_boot_machine_slirp(self):
113 """Test runqemu machine slirp"""
114 cmd = "%s slirp %s" % (self.cmd_common, self.machine)
115 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
116 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -0800117 self.assertIn(' -netdev user', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500118
119 @OETestID(2009)
120 def test_boot_machine_slirp_qcow2(self):
121 """Test runqemu machine slirp qcow2"""
122 cmd = "%s slirp wic.qcow2 %s" % (self.cmd_common, self.machine)
123 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
124 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -0800125 self.assertIn('format=qcow2', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500126
127 @OETestID(2010)
128 def test_boot_qemu_boot(self):
129 """Test runqemu /path/to/image.qemuboot.conf"""
130 qemuboot_conf = "%s-%s.qemuboot.conf" % (self.recipe, self.machine)
131 qemuboot_conf = os.path.join(self.deploy_dir_image, qemuboot_conf)
132 if not os.path.exists(qemuboot_conf):
133 self.skipTest("%s not found" % qemuboot_conf)
134 cmd = "%s %s" % (self.cmd_common, qemuboot_conf)
135 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
Brad Bishopf86d0552018-12-04 14:18:15 -0800136 with open(qemu.qemurunnerlog) as f:
137 self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read()))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500138
139 @OETestID(2011)
140 def test_boot_rootfs(self):
141 """Test runqemu /path/to/rootfs.ext4"""
142 rootfs = "%s-%s.ext4" % (self.recipe, self.machine)
143 rootfs = os.path.join(self.deploy_dir_image, rootfs)
144 if not os.path.exists(rootfs):
145 self.skipTest("%s not found" % rootfs)
146 cmd = "%s %s" % (self.cmd_common, rootfs)
147 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
Brad Bishopf86d0552018-12-04 14:18:15 -0800148 with open(qemu.qemurunnerlog) as f:
149 self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read()))
150
Brad Bishop316dfdd2018-06-25 12:45:53 -0400151
152# This test was designed as a separate class to test that shutdown
153# command will shutdown qemu as expected on each qemu architecture
154# based on the MACHINE configuration inside the config file
155# (eg. local.conf).
156#
157# This was different compared to RunqemuTests, where RunqemuTests was
158# dedicated for MACHINE=qemux86-64 where it test that qemux86-64 will
159# bootup various filesystem types, including live image(iso and hddimg)
160# where live image was not supported on all qemu architecture.
161class QemuTest(OESelftestTestCase):
162
163 @classmethod
164 def setUpClass(cls):
165 super(QemuTest, cls).setUpClass()
166 cls.recipe = 'core-image-minimal'
167 cls.machine = get_bb_var('MACHINE')
168 cls.deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
169 cls.cmd_common = "runqemu nographic"
170 cls.qemuboot_conf = "%s-%s.qemuboot.conf" % (cls.recipe, cls.machine)
171 cls.qemuboot_conf = os.path.join(cls.deploy_dir_image, cls.qemuboot_conf)
172 bitbake(cls.recipe)
173
174 def _start_qemu_shutdown_check_if_shutdown_succeeded(self, qemu, timeout):
175 qemu.run_serial("shutdown -h now")
176 # Stop thread will stop the LoggingThread instance used for logging
177 # qemu through serial console, stop thread will prevent this code
178 # from facing exception (Console connection closed unexpectedly)
179 # when qemu was shutdown by the above shutdown command
180 qemu.runner.stop_thread()
181 time_track = 0
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800182 try:
183 while True:
184 is_alive = qemu.check()
185 if not is_alive:
186 return True
187 if time_track > timeout:
188 return False
189 time.sleep(1)
190 time_track += 1
191 except SystemExit:
192 return True
Brad Bishop316dfdd2018-06-25 12:45:53 -0400193
194 def test_qemu_can_shutdown(self):
195 self.assertExists(self.qemuboot_conf)
196 cmd = "%s %s" % (self.cmd_common, self.qemuboot_conf)
197 shutdown_timeout = 120
198 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
199 qemu_shutdown_succeeded = self._start_qemu_shutdown_check_if_shutdown_succeeded(qemu, shutdown_timeout)
200 self.assertTrue(qemu_shutdown_succeeded, 'Failed: %s does not shutdown within timeout(%s)' % (self.machine, shutdown_timeout))
201
202 # Need to have portmap/rpcbind running to allow this test to work and
203 # current autobuilder setup does not have this.
204 def disabled_test_qemu_can_boot_nfs_and_shutdown(self):
205 self.assertExists(self.qemuboot_conf)
206 bitbake('meta-ide-support')
207 rootfs_tar = "%s-%s.tar.bz2" % (self.recipe, self.machine)
208 rootfs_tar = os.path.join(self.deploy_dir_image, rootfs_tar)
209 self.assertExists(rootfs_tar)
210 tmpdir = tempfile.mkdtemp(prefix='qemu_nfs')
211 tmpdir_nfs = os.path.join(tmpdir, 'nfs')
212 cmd_extract_nfs = 'runqemu-extract-sdk %s %s' % (rootfs_tar, tmpdir_nfs)
213 result = runCmd(cmd_extract_nfs)
214 self.assertEqual(0, result.status, "runqemu-extract-sdk didn't run as expected. %s" % result.output)
215 cmd = "%s nfs %s %s" % (self.cmd_common, self.qemuboot_conf, tmpdir_nfs)
216 shutdown_timeout = 120
217 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
218 qemu_shutdown_succeeded = self._start_qemu_shutdown_check_if_shutdown_succeeded(qemu, shutdown_timeout)
219 self.assertTrue(qemu_shutdown_succeeded, 'Failed: %s does not shutdown within timeout(%s)' % (self.machine, shutdown_timeout))
220 runCmd('rm -rf %s' % tmpdir)