blob: 4e35bb97e3a8899cc600e9c69b533aa258afd958 [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 = ''
Brad Bishopd7bf8c12018-02-25 22:55:05 -050017
18 def setUpLocal(self):
19 super(RunqemuTests, self).setUpLocal()
20 self.recipe = 'core-image-minimal'
21 self.machine = 'qemux86-64'
22 self.fstypes = "ext4 iso hddimg wic.vmdk wic.qcow2 wic.vdi"
23 self.cmd_common = "runqemu nographic"
24
25 self.write_config(
26"""
27MACHINE = "%s"
28IMAGE_FSTYPES = "%s"
29# 10 means 1 second
30SYSLINUX_TIMEOUT = "10"
31"""
32% (self.machine, self.fstypes)
33 )
34
35 if not RunqemuTests.image_is_ready:
36 RunqemuTests.deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
37 bitbake(self.recipe)
38 RunqemuTests.image_is_ready = True
39
40 @OETestID(2001)
41 def test_boot_machine(self):
42 """Test runqemu machine"""
43 cmd = "%s %s" % (self.cmd_common, self.machine)
44 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
Brad Bishopf86d0552018-12-04 14:18:15 -080045 with open(qemu.qemurunnerlog) as f:
46 self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read()))
Brad Bishopd7bf8c12018-02-25 22:55:05 -050047
48 @OETestID(2002)
49 def test_boot_machine_ext4(self):
50 """Test runqemu machine ext4"""
51 cmd = "%s %s ext4" % (self.cmd_common, self.machine)
52 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
53 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -080054 self.assertIn('rootfs.ext4', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050055
56 @OETestID(2003)
57 def test_boot_machine_iso(self):
58 """Test runqemu machine iso"""
59 cmd = "%s %s iso" % (self.cmd_common, self.machine)
60 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
61 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -080062 self.assertIn('media=cdrom', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050063
64 @OETestID(2004)
65 def test_boot_recipe_image(self):
66 """Test runqemu recipe-image"""
67 cmd = "%s %s" % (self.cmd_common, self.recipe)
68 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
Brad Bishopf86d0552018-12-04 14:18:15 -080069 with open(qemu.qemurunnerlog) as f:
70 self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read()))
71
Brad Bishopd7bf8c12018-02-25 22:55:05 -050072
73 @OETestID(2005)
74 def test_boot_recipe_image_vmdk(self):
75 """Test runqemu recipe-image vmdk"""
76 cmd = "%s %s wic.vmdk" % (self.cmd_common, self.recipe)
77 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
78 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -080079 self.assertIn('format=vmdk', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050080
81 @OETestID(2006)
82 def test_boot_recipe_image_vdi(self):
83 """Test runqemu recipe-image vdi"""
84 cmd = "%s %s wic.vdi" % (self.cmd_common, self.recipe)
85 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
86 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -080087 self.assertIn('format=vdi', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050088
89 @OETestID(2007)
90 def test_boot_deploy(self):
91 """Test runqemu deploy_dir_image"""
92 cmd = "%s %s" % (self.cmd_common, self.deploy_dir_image)
93 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
Brad Bishopf86d0552018-12-04 14:18:15 -080094 with open(qemu.qemurunnerlog) as f:
95 self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read()))
96
Brad Bishopd7bf8c12018-02-25 22:55:05 -050097
98 @OETestID(2008)
99 def test_boot_deploy_hddimg(self):
100 """Test runqemu deploy_dir_image hddimg"""
101 cmd = "%s %s hddimg" % (self.cmd_common, self.deploy_dir_image)
102 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
103 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -0800104 self.assertTrue(re.search('file=.*.hddimg', f.read()), "Failed: %s, %s" % (cmd, f.read()))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500105
106 @OETestID(2009)
107 def test_boot_machine_slirp(self):
108 """Test runqemu machine slirp"""
109 cmd = "%s slirp %s" % (self.cmd_common, self.machine)
110 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
111 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -0800112 self.assertIn(' -netdev user', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500113
114 @OETestID(2009)
115 def test_boot_machine_slirp_qcow2(self):
116 """Test runqemu machine slirp qcow2"""
117 cmd = "%s slirp wic.qcow2 %s" % (self.cmd_common, self.machine)
118 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
119 with open(qemu.qemurunnerlog) as f:
Brad Bishopf86d0552018-12-04 14:18:15 -0800120 self.assertIn('format=qcow2', f.read(), "Failed: %s" % cmd)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500121
122 @OETestID(2010)
123 def test_boot_qemu_boot(self):
124 """Test runqemu /path/to/image.qemuboot.conf"""
125 qemuboot_conf = "%s-%s.qemuboot.conf" % (self.recipe, self.machine)
126 qemuboot_conf = os.path.join(self.deploy_dir_image, qemuboot_conf)
127 if not os.path.exists(qemuboot_conf):
128 self.skipTest("%s not found" % qemuboot_conf)
129 cmd = "%s %s" % (self.cmd_common, qemuboot_conf)
130 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
Brad Bishopf86d0552018-12-04 14:18:15 -0800131 with open(qemu.qemurunnerlog) as f:
132 self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read()))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500133
134 @OETestID(2011)
135 def test_boot_rootfs(self):
136 """Test runqemu /path/to/rootfs.ext4"""
137 rootfs = "%s-%s.ext4" % (self.recipe, self.machine)
138 rootfs = os.path.join(self.deploy_dir_image, rootfs)
139 if not os.path.exists(rootfs):
140 self.skipTest("%s not found" % rootfs)
141 cmd = "%s %s" % (self.cmd_common, rootfs)
142 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
Brad Bishopf86d0552018-12-04 14:18:15 -0800143 with open(qemu.qemurunnerlog) as f:
144 self.assertTrue(qemu.runner.logged, "Failed: %s, %s" % (cmd, f.read()))
145
Brad Bishop316dfdd2018-06-25 12:45:53 -0400146
147# This test was designed as a separate class to test that shutdown
148# command will shutdown qemu as expected on each qemu architecture
149# based on the MACHINE configuration inside the config file
150# (eg. local.conf).
151#
152# This was different compared to RunqemuTests, where RunqemuTests was
153# dedicated for MACHINE=qemux86-64 where it test that qemux86-64 will
154# bootup various filesystem types, including live image(iso and hddimg)
155# where live image was not supported on all qemu architecture.
156class QemuTest(OESelftestTestCase):
157
158 @classmethod
159 def setUpClass(cls):
160 super(QemuTest, cls).setUpClass()
161 cls.recipe = 'core-image-minimal'
162 cls.machine = get_bb_var('MACHINE')
163 cls.deploy_dir_image = get_bb_var('DEPLOY_DIR_IMAGE')
164 cls.cmd_common = "runqemu nographic"
165 cls.qemuboot_conf = "%s-%s.qemuboot.conf" % (cls.recipe, cls.machine)
166 cls.qemuboot_conf = os.path.join(cls.deploy_dir_image, cls.qemuboot_conf)
167 bitbake(cls.recipe)
168
169 def _start_qemu_shutdown_check_if_shutdown_succeeded(self, qemu, timeout):
170 qemu.run_serial("shutdown -h now")
171 # Stop thread will stop the LoggingThread instance used for logging
172 # qemu through serial console, stop thread will prevent this code
173 # from facing exception (Console connection closed unexpectedly)
174 # when qemu was shutdown by the above shutdown command
175 qemu.runner.stop_thread()
176 time_track = 0
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800177 try:
178 while True:
179 is_alive = qemu.check()
180 if not is_alive:
181 return True
182 if time_track > timeout:
183 return False
184 time.sleep(1)
185 time_track += 1
186 except SystemExit:
187 return True
Brad Bishop316dfdd2018-06-25 12:45:53 -0400188
189 def test_qemu_can_shutdown(self):
190 self.assertExists(self.qemuboot_conf)
191 cmd = "%s %s" % (self.cmd_common, self.qemuboot_conf)
192 shutdown_timeout = 120
193 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
194 qemu_shutdown_succeeded = self._start_qemu_shutdown_check_if_shutdown_succeeded(qemu, shutdown_timeout)
195 self.assertTrue(qemu_shutdown_succeeded, 'Failed: %s does not shutdown within timeout(%s)' % (self.machine, shutdown_timeout))
196
197 # Need to have portmap/rpcbind running to allow this test to work and
198 # current autobuilder setup does not have this.
199 def disabled_test_qemu_can_boot_nfs_and_shutdown(self):
200 self.assertExists(self.qemuboot_conf)
201 bitbake('meta-ide-support')
202 rootfs_tar = "%s-%s.tar.bz2" % (self.recipe, self.machine)
203 rootfs_tar = os.path.join(self.deploy_dir_image, rootfs_tar)
204 self.assertExists(rootfs_tar)
205 tmpdir = tempfile.mkdtemp(prefix='qemu_nfs')
206 tmpdir_nfs = os.path.join(tmpdir, 'nfs')
207 cmd_extract_nfs = 'runqemu-extract-sdk %s %s' % (rootfs_tar, tmpdir_nfs)
208 result = runCmd(cmd_extract_nfs)
209 self.assertEqual(0, result.status, "runqemu-extract-sdk didn't run as expected. %s" % result.output)
210 cmd = "%s nfs %s %s" % (self.cmd_common, self.qemuboot_conf, tmpdir_nfs)
211 shutdown_timeout = 120
212 with runqemu(self.recipe, ssh=False, launch_cmd=cmd) as qemu:
213 qemu_shutdown_succeeded = self._start_qemu_shutdown_check_if_shutdown_succeeded(qemu, shutdown_timeout)
214 self.assertTrue(qemu_shutdown_succeeded, 'Failed: %s does not shutdown within timeout(%s)' % (self.machine, shutdown_timeout))
215 runCmd('rm -rf %s' % tmpdir)