blob: 20969d2c48a1331664208ee15f07b0f429d71d9d [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005from oeqa.selftest.case import OESelftestTestCase
6from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars, runqemu
7from oeqa.utils.sshcontrol import SSHControl
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008import os
9import re
10import tempfile
11import shutil
Brad Bishop19323692019-04-05 15:28:33 -040012import oe.lsb
Brad Bishopd7bf8c12018-02-25 22:55:05 -050013
14class TestExport(OESelftestTestCase):
15
16 @classmethod
17 def tearDownClass(cls):
18 runCmd("rm -rf /tmp/sdk")
19 super(TestExport, cls).tearDownClass()
20
Brad Bishopd7bf8c12018-02-25 22:55:05 -050021 def test_testexport_basic(self):
22 """
23 Summary: Check basic testexport functionality with only ping test enabled.
24 Expected: 1. testexport directory must be created.
25 2. runexported.py must run without any error/exception.
26 3. ping test must succeed.
27 Product: oe-core
28 Author: Mariano Lopez <mariano.lopez@intel.com>
29 """
30
31 features = 'INHERIT += "testexport"\n'
32 # These aren't the actual IP addresses but testexport class needs something defined
33 features += 'TEST_SERVER_IP = "192.168.7.1"\n'
34 features += 'TEST_TARGET_IP = "192.168.7.1"\n'
35 features += 'TEST_SUITES = "ping"\n'
36 self.write_config(features)
37
38 # Build tesexport for core-image-minimal
39 bitbake('core-image-minimal')
40 bitbake('-c testexport core-image-minimal')
41
42 testexport_dir = get_bb_var('TEST_EXPORT_DIR', 'core-image-minimal')
43
44 # Verify if TEST_EXPORT_DIR was created
45 isdir = os.path.isdir(testexport_dir)
46 self.assertEqual(True, isdir, 'Failed to create testexport dir: %s' % testexport_dir)
47
48 with runqemu('core-image-minimal') as qemu:
49 # Attempt to run runexported.py to perform ping test
50 test_path = os.path.join(testexport_dir, "oe-test")
51 data_file = os.path.join(testexport_dir, 'data', 'testdata.json')
52 manifest = os.path.join(testexport_dir, 'data', 'manifest')
53 cmd = ("%s runtime --test-data-file %s --packages-manifest %s "
54 "--target-ip %s --server-ip %s --quiet"
55 % (test_path, data_file, manifest, qemu.ip, qemu.server_ip))
56 result = runCmd(cmd)
57 # Verify ping test was succesful
58 self.assertEqual(0, result.status, 'oe-test runtime returned a non 0 status')
59
Brad Bishopd7bf8c12018-02-25 22:55:05 -050060 def test_testexport_sdk(self):
61 """
62 Summary: Check sdk functionality for testexport.
63 Expected: 1. testexport directory must be created.
64 2. SDK tarball must exists.
65 3. Uncompressing of tarball must succeed.
66 4. Check if the SDK directory is added to PATH.
67 5. Run tar from the SDK directory.
68 Product: oe-core
69 Author: Mariano Lopez <mariano.lopez@intel.com>
70 """
71
72 features = 'INHERIT += "testexport"\n'
73 # These aren't the actual IP addresses but testexport class needs something defined
74 features += 'TEST_SERVER_IP = "192.168.7.1"\n'
75 features += 'TEST_TARGET_IP = "192.168.7.1"\n'
76 features += 'TEST_SUITES = "ping"\n'
77 features += 'TEST_EXPORT_SDK_ENABLED = "1"\n'
78 features += 'TEST_EXPORT_SDK_PACKAGES = "nativesdk-tar"\n'
79 self.write_config(features)
80
81 # Build tesexport for core-image-minimal
82 bitbake('core-image-minimal')
83 bitbake('-c testexport core-image-minimal')
84
85 needed_vars = ['TEST_EXPORT_DIR', 'TEST_EXPORT_SDK_DIR', 'TEST_EXPORT_SDK_NAME']
86 bb_vars = get_bb_vars(needed_vars, 'core-image-minimal')
87 testexport_dir = bb_vars['TEST_EXPORT_DIR']
88 sdk_dir = bb_vars['TEST_EXPORT_SDK_DIR']
89 sdk_name = bb_vars['TEST_EXPORT_SDK_NAME']
90
91 # Check for SDK
92 tarball_name = "%s.sh" % sdk_name
93 tarball_path = os.path.join(testexport_dir, sdk_dir, tarball_name)
94 msg = "Couldn't find SDK tarball: %s" % tarball_path
95 self.assertEqual(os.path.isfile(tarball_path), True, msg)
96
97 # Extract SDK and run tar from SDK
98 result = runCmd("%s -y -d /tmp/sdk" % tarball_path)
99 self.assertEqual(0, result.status, "Couldn't extract SDK")
100
101 env_script = result.output.split()[-1]
102 result = runCmd(". %s; which tar" % env_script, shell=True)
103 self.assertEqual(0, result.status, "Couldn't setup SDK environment")
104 is_sdk_tar = True if "/tmp/sdk" in result.output else False
105 self.assertTrue(is_sdk_tar, "Couldn't setup SDK environment")
106
107 tar_sdk = result.output
108 result = runCmd("%s --version" % tar_sdk)
109 self.assertEqual(0, result.status, "Couldn't run tar from SDK")
110
111
112class TestImage(OESelftestTestCase):
113
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500114 def test_testimage_install(self):
115 """
116 Summary: Check install packages functionality for testimage/testexport.
117 Expected: 1. Import tests from a directory other than meta.
118 2. Check install/uninstall of socat.
119 Product: oe-core
120 Author: Mariano Lopez <mariano.lopez@intel.com>
121 """
122 if get_bb_var('DISTRO') == 'poky-tiny':
123 self.skipTest('core-image-full-cmdline not buildable for poky-tiny')
124
125 features = 'INHERIT += "testimage"\n'
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800126 features += 'IMAGE_INSTALL_append = " libssl"\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500127 features += 'TEST_SUITES = "ping ssh selftest"\n'
128 self.write_config(features)
129
130 # Build core-image-sato and testimage
131 bitbake('core-image-full-cmdline socat')
132 bitbake('-c testimage core-image-full-cmdline')
133
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500134 def test_testimage_dnf(self):
135 """
136 Summary: Check package feeds functionality for dnf
137 Expected: 1. Check that remote package feeds can be accessed
138 Product: oe-core
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800139 Author: Alexander Kanavin <alex.kanavin@gmail.com>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500140 """
141 if get_bb_var('DISTRO') == 'poky-tiny':
142 self.skipTest('core-image-full-cmdline not buildable for poky-tiny')
143
144 features = 'INHERIT += "testimage"\n'
145 features += 'TEST_SUITES = "ping ssh dnf_runtime dnf.DnfBasicTest.test_dnf_help"\n'
146 # We don't yet know what the server ip and port will be - they will be patched
147 # in at the start of the on-image test
148 features += 'PACKAGE_FEED_URIS = "http://bogus_ip:bogus_port"\n'
149 features += 'EXTRA_IMAGE_FEATURES += "package-management"\n'
150 features += 'PACKAGE_CLASSES = "package_rpm"\n'
151
Brad Bishop6f8dcde2018-10-16 10:47:12 +0800152 bitbake('gnupg-native -c addto_recipe_sysroot')
153
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500154 # Enable package feed signing
155 self.gpg_home = tempfile.mkdtemp(prefix="oeqa-feed-sign-")
Brad Bishop96ff1982019-08-19 13:50:42 -0400156 self.track_for_cleanup(self.gpg_home)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500157 signing_key_dir = os.path.join(self.testlayer_path, 'files', 'signing')
Brad Bishop6f8dcde2018-10-16 10:47:12 +0800158 runCmd('gpg --batch --homedir %s --import %s' % (self.gpg_home, os.path.join(signing_key_dir, 'key.secret')), native_sysroot=get_bb_var("RECIPE_SYSROOT_NATIVE", "gnupg-native"))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500159 features += 'INHERIT += "sign_package_feed"\n'
160 features += 'PACKAGE_FEED_GPG_NAME = "testuser"\n'
161 features += 'PACKAGE_FEED_GPG_PASSPHRASE_FILE = "%s"\n' % os.path.join(signing_key_dir, 'key.passphrase')
162 features += 'GPG_PATH = "%s"\n' % self.gpg_home
163 self.write_config(features)
164
165 # Build core-image-sato and testimage
166 bitbake('core-image-full-cmdline socat')
167 bitbake('-c testimage core-image-full-cmdline')
168
Brad Bishop19323692019-04-05 15:28:33 -0400169 def test_testimage_virgl_gtk(self):
170 """
171 Summary: Check host-assisted accelerate OpenGL functionality in qemu with gtk frontend
172 Expected: 1. Check that virgl kernel driver is loaded and 3d acceleration is enabled
173 2. Check that kmscube demo runs without crashing.
174 Product: oe-core
175 Author: Alexander Kanavin <alex.kanavin@gmail.com>
176 """
177 if "DISPLAY" not in os.environ:
178 self.skipTest("virgl gtk test must be run inside a X session")
179 distro = oe.lsb.distro_identifier()
180 if distro and distro == 'debian-8':
181 self.skipTest('virgl isn\'t working with Debian 8')
182
183 qemu_packageconfig = get_bb_var('PACKAGECONFIG', 'qemu-system-native')
184 features = 'INHERIT += "testimage"\n'
185 if 'gtk+' not in qemu_packageconfig:
186 features += 'PACKAGECONFIG_append_pn-qemu-system-native = " gtk+"\n'
187 if 'virglrenderer' not in qemu_packageconfig:
188 features += 'PACKAGECONFIG_append_pn-qemu-system-native = " virglrenderer"\n'
189 if 'glx' not in qemu_packageconfig:
190 features += 'PACKAGECONFIG_append_pn-qemu-system-native = " glx"\n'
191 features += 'TEST_SUITES = "ping ssh virgl"\n'
192 features += 'IMAGE_FEATURES_append = " ssh-server-dropbear"\n'
193 features += 'IMAGE_INSTALL_append = " kmscube"\n'
194 features += 'TEST_RUNQEMUPARAMS = "gtk-gl"\n'
195 self.write_config(features)
196 bitbake('core-image-minimal')
197 bitbake('-c testimage core-image-minimal')
198
Brad Bishop19323692019-04-05 15:28:33 -0400199 def test_testimage_virgl_headless(self):
200 """
201 Summary: Check host-assisted accelerate OpenGL functionality in qemu with egl-headless frontend
202 Expected: 1. Check that virgl kernel driver is loaded and 3d acceleration is enabled
203 2. Check that kmscube demo runs without crashing.
204 Product: oe-core
205 Author: Alexander Kanavin <alex.kanavin@gmail.com>
206 """
207 import subprocess, os
208 try:
209 content = os.listdir("/dev/dri")
210 if len([i for i in content if i.startswith('render')]) == 0:
211 self.skipTest("No render nodes found in /dev/dri: %s" %(content))
212 except FileNotFoundError:
213 self.skipTest("/dev/dri directory does not exist; no render nodes available on this machine.")
214 try:
215 dripath = subprocess.check_output("pkg-config --variable=dridriverdir dri", shell=True)
216 except subprocess.CalledProcessError as e:
217 self.skipTest("Could not determine the path to dri drivers on the host via pkg-config.\nPlease install Mesa development files (particularly, dri.pc) on the host machine.")
218 qemu_packageconfig = get_bb_var('PACKAGECONFIG', 'qemu-system-native')
219 features = 'INHERIT += "testimage"\n'
220 if 'virglrenderer' not in qemu_packageconfig:
221 features += 'PACKAGECONFIG_append_pn-qemu-system-native = " virglrenderer"\n'
222 if 'glx' not in qemu_packageconfig:
223 features += 'PACKAGECONFIG_append_pn-qemu-system-native = " glx"\n'
224 features += 'TEST_SUITES = "ping ssh virgl"\n'
225 features += 'IMAGE_FEATURES_append = " ssh-server-dropbear"\n'
226 features += 'IMAGE_INSTALL_append = " kmscube"\n'
227 features += 'TEST_RUNQEMUPARAMS = "egl-headless"\n'
228 self.write_config(features)
229 bitbake('core-image-minimal')
230 bitbake('-c testimage core-image-minimal')
231
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500232class Postinst(OESelftestTestCase):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500233 def test_postinst_rootfs_and_boot(self):
234 """
235 Summary: The purpose of this test case is to verify Post-installation
236 scripts are called when rootfs is created and also test
237 that script can be delayed to run at first boot.
238 Dependencies: NA
239 Steps: 1. Add proper configuration to local.conf file
240 2. Build a "core-image-minimal" image
241 3. Verify that file created by postinst_rootfs recipe is
242 present on rootfs dir.
243 4. Boot the image created on qemu and verify that the file
244 created by postinst_boot recipe is present on image.
245 Expected: The files are successfully created during rootfs and boot
246 time for 3 different package managers: rpm,ipk,deb and
247 for initialization managers: sysvinit and systemd.
248
249 """
Brad Bishop316dfdd2018-06-25 12:45:53 -0400250
251 import oe.path
252
253 vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
254 rootfs = vars["IMAGE_ROOTFS"]
255 self.assertIsNotNone(rootfs)
256 sysconfdir = vars["sysconfdir"]
257 self.assertIsNotNone(sysconfdir)
258 # Need to use oe.path here as sysconfdir starts with /
259 hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
260 targettestdir = os.path.join(sysconfdir, "postinst-test")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500261
262 for init_manager in ("sysvinit", "systemd"):
263 for classes in ("package_rpm", "package_deb", "package_ipk"):
264 with self.subTest(init_manager=init_manager, package_class=classes):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400265 features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-delayed-b"\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500266 features += 'IMAGE_FEATURES += "package-management empty-root-password"\n'
267 features += 'PACKAGE_CLASSES = "%s"\n' % classes
268 if init_manager == "systemd":
269 features += 'DISTRO_FEATURES_append = " systemd"\n'
270 features += 'VIRTUAL-RUNTIME_init_manager = "systemd"\n'
271 features += 'DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"\n'
272 features += 'VIRTUAL-RUNTIME_initscripts = ""\n'
273 self.write_config(features)
274
275 bitbake('core-image-minimal')
276
Brad Bishop316dfdd2018-06-25 12:45:53 -0400277 self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs")),
278 "rootfs state file was not created")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500279
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500280 with runqemu('core-image-minimal') as qemu:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400281 # Make the test echo a string and search for that as
282 # run_serial()'s status code is useless.'
283 for filename in ("rootfs", "delayed-a", "delayed-b"):
284 status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename))
285 self.assertEqual(output, "found", "%s was not present on boot" % filename)
286
287
288
289 def test_failing_postinst(self):
290 """
291 Summary: The purpose of this test case is to verify that post-installation
292 scripts that contain errors are properly reported.
293 Expected: The scriptlet failure is properly reported.
294 The file that is created after the error in the scriptlet is not present.
295 Product: oe-core
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800296 Author: Alexander Kanavin <alex.kanavin@gmail.com>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400297 """
298
299 import oe.path
300
301 vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
302 rootfs = vars["IMAGE_ROOTFS"]
303 self.assertIsNotNone(rootfs)
304 sysconfdir = vars["sysconfdir"]
305 self.assertIsNotNone(sysconfdir)
306 # Need to use oe.path here as sysconfdir starts with /
307 hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
308
309 for classes in ("package_rpm", "package_deb", "package_ipk"):
310 with self.subTest(package_class=classes):
311 features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-rootfs-failing"\n'
312 features += 'PACKAGE_CLASSES = "%s"\n' % classes
313 self.write_config(features)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800314 bb_result = bitbake('core-image-minimal', ignore_status=True)
315 self.assertGreaterEqual(bb_result.output.find("Postinstall scriptlets of ['postinst-rootfs-failing'] have failed."), 0,
Brad Bishop316dfdd2018-06-25 12:45:53 -0400316 "Warning about a failed scriptlet not found in bitbake output: %s" %(bb_result.output))
317
318 self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs-before-failure")),
319 "rootfs-before-failure file was not created")
320 self.assertFalse(os.path.isfile(os.path.join(hosttestdir, "rootfs-after-failure")),
321 "rootfs-after-failure file was created")
322