blob: a758aafbdde9274052deebc69810fcf3fdd451d5 [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 Bishopd7bf8c12018-02-25 22:55:05 -05008from oeqa.selftest.case import OESelftestTestCase
Brad Bishop316dfdd2018-06-25 12:45:53 -04009from oeqa.utils.commands import bitbake, runqemu, get_bb_var, runCmd
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010from oeqa.core.decorator.oeid import OETestID
11
12class RunqemuTests(OESelftestTestCase):
13 """Runqemu test class"""
14
15 image_is_ready = False
16 deploy_dir_image = ''
17 # We only want to print runqemu stdout/stderr if there is a test case failure
18 buffer = True
19
20 def setUpLocal(self):
21 super(RunqemuTests, self).setUpLocal()
22 self.recipe = 'core-image-minimal'
23 self.machine = 'qemux86-64'
24 self.fstypes = "ext4 iso hddimg wic.vmdk wic.qcow2 wic.vdi"
25 self.cmd_common = "runqemu nographic"
26
27 self.write_config(
28"""
29MACHINE = "%s"
30IMAGE_FSTYPES = "%s"
31# 10 means 1 second
32SYSLINUX_TIMEOUT = "10"
33"""
34% (self.machine, self.fstypes)
35 )
36
37 if not RunqemuTests.image_is_ready:
38 RunqemuTests.deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
39 bitbake(self.recipe)
40 RunqemuTests.image_is_ready = True
41
42 @OETestID(2001)
43 def test_boot_machine(self):
44 """Test runqemu machine"""
45 cmd = "%s %s" % (self.cmd_common, self.machine)
46 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
Brad Bishopf86d0552018-12-04 14:18:15 -080047 with open(qemu.qemurunnerlog) as f:
48 self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read()))
Brad Bishopd7bf8c12018-02-25 22:55:05 -050049
50 @OETestID(2002)
51 def test_boot_machine_ext4(self):
52 """Test runqemu machine ext4"""
53 cmd = "%s %s ext4" % (self.cmd_common, self.machine)
54 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
55 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -080056 self.assertIn('rootfs.ext4', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050057
58 @OETestID(2003)
59 def test_boot_machine_iso(self):
60 """Test runqemu machine iso"""
61 cmd = "%s %s iso" % (self.cmd_common, self.machine)
62 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
63 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -080064 self.assertIn('media=cdrom', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050065
66 @OETestID(2004)
67 def test_boot_recipe_image(self):
68 """Test runqemu recipe-image"""
69 cmd = "%s %s" % (self.cmd_common, self.recipe)
70 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
Brad Bishopf86d0552018-12-04 14:18:15 -080071 with open(qemu.qemurunnerlog) as f:
72 self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read()))
73
Brad Bishopd7bf8c12018-02-25 22:55:05 -050074
75 @OETestID(2005)
76 def test_boot_recipe_image_vmdk(self):
77 """Test runqemu recipe-image vmdk"""
78 cmd = "%s %s wic.vmdk" % (self.cmd_common, self.recipe)
79 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
80 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -080081 self.assertIn('format=vmdk', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050082
83 @OETestID(2006)
84 def test_boot_recipe_image_vdi(self):
85 """Test runqemu recipe-image vdi"""
86 cmd = "%s %s wic.vdi" % (self.cmd_common, self.recipe)
87 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
88 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -080089 self.assertIn('format=vdi', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050090
91 @OETestID(2007)
92 def test_boot_deploy(self):
93 """Test runqemu deploy_dir_image"""
94 cmd = "%s %s" % (self.cmd_common, self.deploy_dir_image)
95 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
Brad Bishopf86d0552018-12-04 14:18:15 -080096 with open(qemu.qemurunnerlog) as f:
97 self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read()))
98
Brad Bishopd7bf8c12018-02-25 22:55:05 -050099
100 @OETestID(2008)
101 def test_boot_deploy_hddimg(self):
102 """Test runqemu deploy_dir_image hddimg"""
103 cmd = "%s %s hddimg" % (self.cmd_common, self.deploy_dir_image)
104 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
105 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -0800106 self.assertTrue(re.search('file=.*.hddimg', f.read()), "Failed: %s, %s" % (cmd, f.read()))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500107
108 @OETestID(2009)
109 def test_boot_machine_slirp(self):
110 """Test runqemu machine slirp"""
111 cmd = "%s slirp %s" % (self.cmd_common, self.machine)
112 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
113 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -0800114 self.assertIn(' -netdev user', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500115
116 @OETestID(2009)
117 def test_boot_machine_slirp_qcow2(self):
118 """Test runqemu machine slirp qcow2"""
119 cmd = "%s slirp wic.qcow2 %s" % (self.cmd_common, self.machine)
120 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
121 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -0800122 self.assertIn('format=qcow2', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500123
124 @OETestID(2010)
125 def test_boot_qemu_boot(self):
126 """Test runqemu /path/to/image.qemuboot.conf"""
127 qemuboot_conf = "%s-%s.qemuboot.conf" % (self.recipe, self.machine)
128 qemuboot_conf = os.path.join(self.deploy_dir_image, qemuboot_conf)
129 if not os.path.exists(qemuboot_conf):
130 self.skipTest("%s not found" % qemuboot_conf)
131 cmd = "%s %s" % (self.cmd_common, qemuboot_conf)
132 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
Brad Bishopf86d0552018-12-04 14:18:15 -0800133 with open(qemu.qemurunnerlog) as f:
134 self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read()))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500135
136 @OETestID(2011)
137 def test_boot_rootfs(self):
138 """Test runqemu /path/to/rootfs.ext4"""
139 rootfs = "%s-%s.ext4" % (self.recipe, self.machine)
140 rootfs = os.path.join(self.deploy_dir_image, rootfs)
141 if not os.path.exists(rootfs):
142 self.skipTest("%s not found" % rootfs)
143 cmd = "%s %s" % (self.cmd_common, rootfs)
144 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
Brad Bishopf86d0552018-12-04 14:18:15 -0800145 with open(qemu.qemurunnerlog) as f:
146 self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read()))
147
Brad Bishop316dfdd2018-06-25 12:45:53 -0400148
149# This test was designed as a separate class to test that shutdown
150# command will shutdown qemu as expected on each qemu architecture
151# based on the MACHINE configuration inside the config file
152# (eg. local.conf).
153#
154# This was different compared to RunqemuTests, where RunqemuTests was
155# dedicated for MACHINE=qemux86-64 where it test that qemux86-64 will
156# bootup various filesystem types, including live image(iso and hddimg)
157# where live image was not supported on all qemu architecture.
158class QemuTest(OESelftestTestCase):
159
160 @classmethod
161 def setUpClass(cls):
162 super(QemuTest, cls).setUpClass()
163 cls.recipe = 'core-image-minimal'
164 cls.machine = get_bb_var('MACHINE')
165 cls.deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
166 cls.cmd_common = "runqemu nographic"
167 cls.qemuboot_conf = "%s-%s.qemuboot.conf" % (cls.recipe, cls.machine)
168 cls.qemuboot_conf = os.path.join(cls.deploy_dir_image, cls.qemuboot_conf)
169 bitbake(cls.recipe)
170
171 def _start_qemu_shutdown_check_if_shutdown_succeeded(self, qemu, timeout):
172 qemu.run_serial("shutdown -h now")
173 # Stop thread will stop the LoggingThread instance used for logging
174 # qemu through serial console, stop thread will prevent this code
175 # from facing exception (Console connection closed unexpectedly)
176 # when qemu was shutdown by the above shutdown command
177 qemu.runner.stop_thread()
178 time_track = 0
179 while True:
180 is_alive = qemu.check()
181 if not is_alive:
182 return True
183 if time_track > timeout:
184 return False
185 time.sleep(1)
186 time_track += 1
187
188 def test_qemu_can_shutdown(self):
189 self.assertExists(self.qemuboot_conf)
190 cmd = "%s %s" % (self.cmd_common, self.qemuboot_conf)
191 shutdown_timeout = 120
192 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
193 qemu_shutdown_succeeded = self._start_qemu_shutdown_check_if_shutdown_succeeded(qemu, shutdown_timeout)
194 self.assertTrue(qemu_shutdown_succeeded, 'Failed: %s does not shutdown within timeout(%s)' % (self.machine, shutdown_timeout))
195
196 # Need to have portmap/rpcbind running to allow this test to work and
197 # current autobuilder setup does not have this.
198 def disabled_test_qemu_can_boot_nfs_and_shutdown(self):
199 self.assertExists(self.qemuboot_conf)
200 bitbake('meta-ide-support')
201 rootfs_tar = "%s-%s.tar.bz2" % (self.recipe, self.machine)
202 rootfs_tar = os.path.join(self.deploy_dir_image, rootfs_tar)
203 self.assertExists(rootfs_tar)
204 tmpdir = tempfile.mkdtemp(prefix='qemu_nfs')
205 tmpdir_nfs = os.path.join(tmpdir, 'nfs')
206 cmd_extract_nfs = 'runqemu-extract-sdk %s %s' % (rootfs_tar, tmpdir_nfs)
207 result = runCmd(cmd_extract_nfs)
208 self.assertEqual(0, result.status, "runqemu-extract-sdk didn't run as expected. %s" % result.output)
209 cmd = "%s nfs %s %s" % (self.cmd_common, self.qemuboot_conf, tmpdir_nfs)
210 shutdown_timeout = 120
211 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
212 qemu_shutdown_succeeded = self._start_qemu_shutdown_check_if_shutdown_succeeded(qemu, shutdown_timeout)
213 self.assertTrue(qemu_shutdown_succeeded, 'Failed: %s does not shutdown within timeout(%s)' % (self.machine, shutdown_timeout))
214 runCmd('rm -rf %s' % tmpdir)