blob: 7d99c158e5d4a3e958a610bcbf3015bf08941380 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: MIT
5#
6
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007from oeqa.selftest.case import OESelftestTestCase
8from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars, runqemu
Patrick Williams45852732022-04-02 08:58:32 -05009from oeqa.core.decorator import OETestTag
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010import os
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011import tempfile
Brad Bishop19323692019-04-05 15:28:33 -040012import oe.lsb
Patrick Williams7784c422022-11-17 07:29:11 -060013from oeqa.core.decorator.data import skipIfNotQemu, skipIfNotMachine
Brad Bishopd7bf8c12018-02-25 22:55:05 -050014
15class TestExport(OESelftestTestCase):
16
Patrick Williams45852732022-04-02 08:58:32 -050017 @OETestTag("runqemu")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050018 def test_testexport_basic(self):
19 """
20 Summary: Check basic testexport functionality with only ping test enabled.
21 Expected: 1. testexport directory must be created.
22 2. runexported.py must run without any error/exception.
23 3. ping test must succeed.
24 Product: oe-core
25 Author: Mariano Lopez <mariano.lopez@intel.com>
26 """
27
Patrick Williams92b42cb2022-09-03 06:53:57 -050028 features = 'IMAGE_CLASSES += "testexport"\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050029 # These aren't the actual IP addresses but testexport class needs something defined
30 features += 'TEST_SERVER_IP = "192.168.7.1"\n'
31 features += 'TEST_TARGET_IP = "192.168.7.1"\n'
32 features += 'TEST_SUITES = "ping"\n'
33 self.write_config(features)
34
35 # Build tesexport for core-image-minimal
36 bitbake('core-image-minimal')
37 bitbake('-c testexport core-image-minimal')
38
39 testexport_dir = get_bb_var('TEST_EXPORT_DIR', 'core-image-minimal')
40
41 # Verify if TEST_EXPORT_DIR was created
42 isdir = os.path.isdir(testexport_dir)
43 self.assertEqual(True, isdir, 'Failed to create testexport dir: %s' % testexport_dir)
44
45 with runqemu('core-image-minimal') as qemu:
46 # Attempt to run runexported.py to perform ping test
47 test_path = os.path.join(testexport_dir, "oe-test")
48 data_file = os.path.join(testexport_dir, 'data', 'testdata.json')
49 manifest = os.path.join(testexport_dir, 'data', 'manifest')
50 cmd = ("%s runtime --test-data-file %s --packages-manifest %s "
51 "--target-ip %s --server-ip %s --quiet"
52 % (test_path, data_file, manifest, qemu.ip, qemu.server_ip))
53 result = runCmd(cmd)
54 # Verify ping test was succesful
55 self.assertEqual(0, result.status, 'oe-test runtime returned a non 0 status')
56
Brad Bishopd7bf8c12018-02-25 22:55:05 -050057 def test_testexport_sdk(self):
58 """
59 Summary: Check sdk functionality for testexport.
60 Expected: 1. testexport directory must be created.
61 2. SDK tarball must exists.
62 3. Uncompressing of tarball must succeed.
63 4. Check if the SDK directory is added to PATH.
64 5. Run tar from the SDK directory.
65 Product: oe-core
66 Author: Mariano Lopez <mariano.lopez@intel.com>
67 """
68
Patrick Williams92b42cb2022-09-03 06:53:57 -050069 features = 'IMAGE_CLASSES += "testexport"\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050070 # These aren't the actual IP addresses but testexport class needs something defined
71 features += 'TEST_SERVER_IP = "192.168.7.1"\n'
72 features += 'TEST_TARGET_IP = "192.168.7.1"\n'
73 features += 'TEST_SUITES = "ping"\n'
74 features += 'TEST_EXPORT_SDK_ENABLED = "1"\n'
75 features += 'TEST_EXPORT_SDK_PACKAGES = "nativesdk-tar"\n'
76 self.write_config(features)
77
78 # Build tesexport for core-image-minimal
79 bitbake('core-image-minimal')
80 bitbake('-c testexport core-image-minimal')
81
82 needed_vars = ['TEST_EXPORT_DIR', 'TEST_EXPORT_SDK_DIR', 'TEST_EXPORT_SDK_NAME']
83 bb_vars = get_bb_vars(needed_vars, 'core-image-minimal')
84 testexport_dir = bb_vars['TEST_EXPORT_DIR']
85 sdk_dir = bb_vars['TEST_EXPORT_SDK_DIR']
86 sdk_name = bb_vars['TEST_EXPORT_SDK_NAME']
87
88 # Check for SDK
89 tarball_name = "%s.sh" % sdk_name
90 tarball_path = os.path.join(testexport_dir, sdk_dir, tarball_name)
91 msg = "Couldn't find SDK tarball: %s" % tarball_path
92 self.assertEqual(os.path.isfile(tarball_path), True, msg)
93
Andrew Geissler09036742021-06-25 14:25:14 -050094 with tempfile.TemporaryDirectory() as tmpdirname:
95 # Extract SDK and run tar from SDK
96 result = runCmd("%s -y -d %s" % (tarball_path, tmpdirname))
97 self.assertEqual(0, result.status, "Couldn't extract SDK")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050098
Andrew Geissler09036742021-06-25 14:25:14 -050099 env_script = result.output.split()[-1]
100 result = runCmd(". %s; which tar" % env_script, shell=True)
101 self.assertEqual(0, result.status, "Couldn't setup SDK environment")
102 is_sdk_tar = True if tmpdirname in result.output else False
103 self.assertTrue(is_sdk_tar, "Couldn't setup SDK environment")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500104
Andrew Geissler09036742021-06-25 14:25:14 -0500105 tar_sdk = result.output
106 result = runCmd("%s --version" % tar_sdk)
107 self.assertEqual(0, result.status, "Couldn't run tar from SDK")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500108
109
Patrick Williams45852732022-04-02 08:58:32 -0500110@OETestTag("runqemu")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500111class TestImage(OESelftestTestCase):
112
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500113 def test_testimage_install(self):
114 """
115 Summary: Check install packages functionality for testimage/testexport.
116 Expected: 1. Import tests from a directory other than meta.
117 2. Check install/uninstall of socat.
118 Product: oe-core
119 Author: Mariano Lopez <mariano.lopez@intel.com>
120 """
121 if get_bb_var('DISTRO') == 'poky-tiny':
122 self.skipTest('core-image-full-cmdline not buildable for poky-tiny')
123
Patrick Williams92b42cb2022-09-03 06:53:57 -0500124 features = 'IMAGE_CLASSES += "testimage"\n'
Patrick Williams213cb262021-08-07 19:21:33 -0500125 features += 'IMAGE_INSTALL:append = " libssl"\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500126 features += 'TEST_SUITES = "ping ssh selftest"\n'
127 self.write_config(features)
128
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500129 bitbake('core-image-full-cmdline socat')
130 bitbake('-c testimage core-image-full-cmdline')
131
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500132 def test_testimage_dnf(self):
133 """
134 Summary: Check package feeds functionality for dnf
135 Expected: 1. Check that remote package feeds can be accessed
136 Product: oe-core
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800137 Author: Alexander Kanavin <alex.kanavin@gmail.com>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500138 """
139 if get_bb_var('DISTRO') == 'poky-tiny':
140 self.skipTest('core-image-full-cmdline not buildable for poky-tiny')
141
Patrick Williams92b42cb2022-09-03 06:53:57 -0500142 features = 'IMAGE_CLASSES += "testimage"\n'
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500143 features += 'TEST_SUITES = "ping ssh dnf_runtime dnf.DnfBasicTest.test_dnf_help"\n'
144 # We don't yet know what the server ip and port will be - they will be patched
145 # in at the start of the on-image test
146 features += 'PACKAGE_FEED_URIS = "http://bogus_ip:bogus_port"\n'
147 features += 'EXTRA_IMAGE_FEATURES += "package-management"\n'
148 features += 'PACKAGE_CLASSES = "package_rpm"\n'
149
Brad Bishop6f8dcde2018-10-16 10:47:12 +0800150 bitbake('gnupg-native -c addto_recipe_sysroot')
151
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500152 # Enable package feed signing
153 self.gpg_home = tempfile.mkdtemp(prefix="oeqa-feed-sign-")
Brad Bishop96ff1982019-08-19 13:50:42 -0400154 self.track_for_cleanup(self.gpg_home)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500155 signing_key_dir = os.path.join(self.testlayer_path, 'files', 'signing')
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500156 runCmd('gpgconf --list-dirs --homedir %s; gpg -v --batch --homedir %s --import %s' % (self.gpg_home, self.gpg_home, os.path.join(signing_key_dir, 'key.secret')), native_sysroot=get_bb_var("RECIPE_SYSROOT_NATIVE", "gnupg-native"), shell=True)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500157 features += 'INHERIT += "sign_package_feed"\n'
158 features += 'PACKAGE_FEED_GPG_NAME = "testuser"\n'
159 features += 'PACKAGE_FEED_GPG_PASSPHRASE_FILE = "%s"\n' % os.path.join(signing_key_dir, 'key.passphrase')
160 features += 'GPG_PATH = "%s"\n' % self.gpg_home
Andrew Geisslerf0343792020-11-18 10:42:21 -0600161 features += 'PSEUDO_IGNORE_PATHS .= ",%s"\n' % self.gpg_home
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500162 self.write_config(features)
163
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500164 bitbake('core-image-full-cmdline socat')
165 bitbake('-c testimage core-image-full-cmdline')
166
Patrick Williams03907ee2022-05-01 06:28:52 -0500167 def test_testimage_apt(self):
168 """
169 Summary: Check package feeds functionality for apt
170 Expected: 1. Check that remote package feeds can be accessed
171 Product: oe-core
172 Author: Ferry Toth <fntoth@gmail.com>
173 """
174 if get_bb_var('DISTRO') == 'poky-tiny':
175 self.skipTest('core-image-full-cmdline not buildable for poky-tiny')
176
Patrick Williams92b42cb2022-09-03 06:53:57 -0500177 features = 'IMAGE_CLASSES += "testimage"\n'
Patrick Williams03907ee2022-05-01 06:28:52 -0500178 features += 'TEST_SUITES = "ping ssh apt.AptRepoTest.test_apt_install_from_repo"\n'
179 # We don't yet know what the server ip and port will be - they will be patched
180 # in at the start of the on-image test
181 features += 'PACKAGE_FEED_URIS = "http://bogus_ip:bogus_port"\n'
182 features += 'EXTRA_IMAGE_FEATURES += "package-management"\n'
183 features += 'PACKAGE_CLASSES = "package_deb"\n'
184 # We need gnupg on the target to install keys
185 features += 'IMAGE_INSTALL:append:pn-core-image-full-cmdline = " gnupg"\n'
186
187 bitbake('gnupg-native -c addto_recipe_sysroot')
188
189 # Enable package feed signing
190 self.gpg_home = tempfile.mkdtemp(prefix="oeqa-feed-sign-")
191 self.track_for_cleanup(self.gpg_home)
192 signing_key_dir = os.path.join(self.testlayer_path, 'files', 'signing')
193 runCmd('gpgconf --list-dirs --homedir %s; gpg -v --batch --homedir %s --import %s' % (self.gpg_home, self.gpg_home, os.path.join(signing_key_dir, 'key.secret')), native_sysroot=get_bb_var("RECIPE_SYSROOT_NATIVE", "gnupg-native"), shell=True)
194 features += 'INHERIT += "sign_package_feed"\n'
195 features += 'PACKAGE_FEED_GPG_NAME = "testuser"\n'
196 features += 'PACKAGE_FEED_GPG_PASSPHRASE_FILE = "%s"\n' % os.path.join(signing_key_dir, 'key.passphrase')
197 features += 'GPG_PATH = "%s"\n' % self.gpg_home
198 features += 'PSEUDO_IGNORE_PATHS .= ",%s"\n' % self.gpg_home
199 self.write_config(features)
200
201 # Build core-image-sato and testimage
202 bitbake('core-image-full-cmdline socat')
203 bitbake('-c testimage core-image-full-cmdline')
204
Patrick Williams7784c422022-11-17 07:29:11 -0600205 # https://bugzilla.yoctoproject.org/show_bug.cgi?id=14966
206 @skipIfNotMachine("qemux86-64", "test needs qemux86-64")
Andrew Geissler82c905d2020-04-13 13:39:40 -0500207 def test_testimage_virgl_gtk_sdl(self):
Brad Bishop19323692019-04-05 15:28:33 -0400208 """
Andrew Geissler82c905d2020-04-13 13:39:40 -0500209 Summary: Check host-assisted accelerate OpenGL functionality in qemu with gtk and SDL frontends
Brad Bishop19323692019-04-05 15:28:33 -0400210 Expected: 1. Check that virgl kernel driver is loaded and 3d acceleration is enabled
211 2. Check that kmscube demo runs without crashing.
212 Product: oe-core
213 Author: Alexander Kanavin <alex.kanavin@gmail.com>
214 """
215 if "DISPLAY" not in os.environ:
216 self.skipTest("virgl gtk test must be run inside a X session")
217 distro = oe.lsb.distro_identifier()
218 if distro and distro == 'debian-8':
219 self.skipTest('virgl isn\'t working with Debian 8')
Andrew Geisslerc182c622020-05-15 14:13:32 -0500220 if distro and distro == 'debian-9':
221 self.skipTest('virgl isn\'t working with Debian 9')
Brad Bishop64c979e2019-11-04 13:55:29 -0500222 if distro and distro == 'centos-7':
223 self.skipTest('virgl isn\'t working with Centos 7')
Andrew Geissler82c905d2020-04-13 13:39:40 -0500224 if distro and distro == 'opensuseleap-15.0':
225 self.skipTest('virgl isn\'t working with Opensuse 15.0')
Brad Bishop19323692019-04-05 15:28:33 -0400226
227 qemu_packageconfig = get_bb_var('PACKAGECONFIG', 'qemu-system-native')
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500228 qemu_distrofeatures = get_bb_var('DISTRO_FEATURES', 'qemu-system-native')
Patrick Williams92b42cb2022-09-03 06:53:57 -0500229 features = 'IMAGE_CLASSES += "testimage"\n'
Brad Bishop19323692019-04-05 15:28:33 -0400230 if 'gtk+' not in qemu_packageconfig:
Patrick Williams213cb262021-08-07 19:21:33 -0500231 features += 'PACKAGECONFIG:append:pn-qemu-system-native = " gtk+"\n'
Andrew Geissler82c905d2020-04-13 13:39:40 -0500232 if 'sdl' not in qemu_packageconfig:
Patrick Williams213cb262021-08-07 19:21:33 -0500233 features += 'PACKAGECONFIG:append:pn-qemu-system-native = " sdl"\n'
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500234 if 'opengl' not in qemu_distrofeatures:
Patrick Williams213cb262021-08-07 19:21:33 -0500235 features += 'DISTRO_FEATURES:append = " opengl"\n'
Brad Bishop19323692019-04-05 15:28:33 -0400236 features += 'TEST_SUITES = "ping ssh virgl"\n'
Patrick Williams213cb262021-08-07 19:21:33 -0500237 features += 'IMAGE_FEATURES:append = " ssh-server-dropbear"\n'
238 features += 'IMAGE_INSTALL:append = " kmscube"\n'
Andrew Geissler82c905d2020-04-13 13:39:40 -0500239 features_gtk = features + 'TEST_RUNQEMUPARAMS = "gtk gl"\n'
240 self.write_config(features_gtk)
241 bitbake('core-image-minimal')
242 bitbake('-c testimage core-image-minimal')
243 features_sdl = features + 'TEST_RUNQEMUPARAMS = "sdl gl"\n'
244 self.write_config(features_sdl)
Brad Bishop19323692019-04-05 15:28:33 -0400245 bitbake('core-image-minimal')
246 bitbake('-c testimage core-image-minimal')
247
Patrick Williams7784c422022-11-17 07:29:11 -0600248 @skipIfNotMachine("qemux86-64", "test needs qemux86-64")
Brad Bishop19323692019-04-05 15:28:33 -0400249 def test_testimage_virgl_headless(self):
250 """
251 Summary: Check host-assisted accelerate OpenGL functionality in qemu with egl-headless frontend
252 Expected: 1. Check that virgl kernel driver is loaded and 3d acceleration is enabled
253 2. Check that kmscube demo runs without crashing.
254 Product: oe-core
255 Author: Alexander Kanavin <alex.kanavin@gmail.com>
256 """
257 import subprocess, os
Andrew Geisslerd159c7f2021-09-02 21:05:58 -0500258
Andrew Geisslereff27472021-10-29 15:35:00 -0500259 distro = oe.lsb.distro_identifier()
Andrew Geissler615f2f12022-07-15 14:00:58 -0500260 if distro and (distro in ['debian-9', 'debian-10', 'centos-7', 'centos-8', 'ubuntu-16.04', 'ubuntu-18.04'] or distro.startswith('almalinux')):
Andrew Geisslereff27472021-10-29 15:35:00 -0500261 self.skipTest('virgl headless cannot be tested with %s' %(distro))
262
Andrew Geissler9aee5002022-03-30 16:27:02 +0000263 render_hint = """If /dev/dri/renderD* is absent due to lack of suitable GPU, 'modprobe vgem' will create one suitable for mesa llvmpipe software renderer."""
Brad Bishop19323692019-04-05 15:28:33 -0400264 try:
265 content = os.listdir("/dev/dri")
266 if len([i for i in content if i.startswith('render')]) == 0:
Andrew Geisslereff27472021-10-29 15:35:00 -0500267 self.fail("No render nodes found in /dev/dri: %s. %s" %(content, render_hint))
Brad Bishop19323692019-04-05 15:28:33 -0400268 except FileNotFoundError:
Andrew Geisslereff27472021-10-29 15:35:00 -0500269 self.fail("/dev/dri directory does not exist; no render nodes available on this machine. %s" %(render_hint))
Brad Bishop19323692019-04-05 15:28:33 -0400270 try:
Andrew Geisslerc5535c92023-01-27 16:10:19 -0600271 dripath = subprocess.check_output("PATH=/bin:/usr/bin:$PATH pkg-config --variable=dridriverdir dri", shell=True)
Brad Bishop19323692019-04-05 15:28:33 -0400272 except subprocess.CalledProcessError as e:
Andrew Geisslereff27472021-10-29 15:35:00 -0500273 self.fail("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.")
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500274 qemu_distrofeatures = get_bb_var('DISTRO_FEATURES', 'qemu-system-native')
Patrick Williams92b42cb2022-09-03 06:53:57 -0500275 features = 'IMAGE_CLASSES += "testimage"\n'
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500276 if 'opengl' not in qemu_distrofeatures:
Patrick Williams213cb262021-08-07 19:21:33 -0500277 features += 'DISTRO_FEATURES:append = " opengl"\n'
Brad Bishop19323692019-04-05 15:28:33 -0400278 features += 'TEST_SUITES = "ping ssh virgl"\n'
Patrick Williams213cb262021-08-07 19:21:33 -0500279 features += 'IMAGE_FEATURES:append = " ssh-server-dropbear"\n'
280 features += 'IMAGE_INSTALL:append = " kmscube"\n'
Brad Bishop19323692019-04-05 15:28:33 -0400281 features += 'TEST_RUNQEMUPARAMS = "egl-headless"\n'
282 self.write_config(features)
283 bitbake('core-image-minimal')
284 bitbake('-c testimage core-image-minimal')
285
Patrick Williams45852732022-04-02 08:58:32 -0500286@OETestTag("runqemu")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500287class Postinst(OESelftestTestCase):
Andrew Geissler82c905d2020-04-13 13:39:40 -0500288
289 def init_manager_loop(self, init_manager):
290 import oe.path
291
292 vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
293 rootfs = vars["IMAGE_ROOTFS"]
294 self.assertIsNotNone(rootfs)
295 sysconfdir = vars["sysconfdir"]
296 self.assertIsNotNone(sysconfdir)
297 # Need to use oe.path here as sysconfdir starts with /
298 hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
299 targettestdir = os.path.join(sysconfdir, "postinst-test")
300
301 for classes in ("package_rpm", "package_deb", "package_ipk"):
302 with self.subTest(init_manager=init_manager, package_class=classes):
303 features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-delayed-b"\n'
304 features += 'IMAGE_FEATURES += "package-management empty-root-password"\n'
305 features += 'PACKAGE_CLASSES = "%s"\n' % classes
306 if init_manager == "systemd":
Patrick Williams213cb262021-08-07 19:21:33 -0500307 features += 'DISTRO_FEATURES:append = " systemd"\n'
Andrew Geissler82c905d2020-04-13 13:39:40 -0500308 features += 'VIRTUAL-RUNTIME_init_manager = "systemd"\n'
309 features += 'DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"\n'
310 features += 'VIRTUAL-RUNTIME_initscripts = ""\n'
311 self.write_config(features)
312
313 bitbake('core-image-minimal')
314
315 self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs")),
316 "rootfs state file was not created")
317
318 with runqemu('core-image-minimal') as qemu:
319 # Make the test echo a string and search for that as
320 # run_serial()'s status code is useless.'
321 for filename in ("rootfs", "delayed-a", "delayed-b"):
322 status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename))
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600323 self.assertIn("found", output, "%s was not present on boot" % filename)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500324
325
326
Patrick Williams45852732022-04-02 08:58:32 -0500327 @skipIfNotQemu()
Andrew Geissler82c905d2020-04-13 13:39:40 -0500328 def test_postinst_rootfs_and_boot_sysvinit(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500329 """
330 Summary: The purpose of this test case is to verify Post-installation
331 scripts are called when rootfs is created and also test
332 that script can be delayed to run at first boot.
333 Dependencies: NA
334 Steps: 1. Add proper configuration to local.conf file
335 2. Build a "core-image-minimal" image
336 3. Verify that file created by postinst_rootfs recipe is
337 present on rootfs dir.
338 4. Boot the image created on qemu and verify that the file
339 created by postinst_boot recipe is present on image.
340 Expected: The files are successfully created during rootfs and boot
341 time for 3 different package managers: rpm,ipk,deb and
Andrew Geissler82c905d2020-04-13 13:39:40 -0500342 for initialization managers: sysvinit.
343
344 """
345 self.init_manager_loop("sysvinit")
346
347
Patrick Williams45852732022-04-02 08:58:32 -0500348 @skipIfNotQemu()
Andrew Geissler82c905d2020-04-13 13:39:40 -0500349 def test_postinst_rootfs_and_boot_systemd(self):
350 """
351 Summary: The purpose of this test case is to verify Post-installation
352 scripts are called when rootfs is created and also test
353 that script can be delayed to run at first boot.
354 Dependencies: NA
355 Steps: 1. Add proper configuration to local.conf file
356 2. Build a "core-image-minimal" image
357 3. Verify that file created by postinst_rootfs recipe is
358 present on rootfs dir.
359 4. Boot the image created on qemu and verify that the file
360 created by postinst_boot recipe is present on image.
361 Expected: The files are successfully created during rootfs and boot
362 time for 3 different package managers: rpm,ipk,deb and
363 for initialization managers: systemd.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500364
365 """
Brad Bishop316dfdd2018-06-25 12:45:53 -0400366
Andrew Geissler82c905d2020-04-13 13:39:40 -0500367 self.init_manager_loop("systemd")
Brad Bishop316dfdd2018-06-25 12:45:53 -0400368
369
370 def test_failing_postinst(self):
371 """
372 Summary: The purpose of this test case is to verify that post-installation
373 scripts that contain errors are properly reported.
374 Expected: The scriptlet failure is properly reported.
375 The file that is created after the error in the scriptlet is not present.
376 Product: oe-core
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800377 Author: Alexander Kanavin <alex.kanavin@gmail.com>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400378 """
379
380 import oe.path
381
382 vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
383 rootfs = vars["IMAGE_ROOTFS"]
384 self.assertIsNotNone(rootfs)
385 sysconfdir = vars["sysconfdir"]
386 self.assertIsNotNone(sysconfdir)
387 # Need to use oe.path here as sysconfdir starts with /
388 hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
389
390 for classes in ("package_rpm", "package_deb", "package_ipk"):
391 with self.subTest(package_class=classes):
392 features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-rootfs-failing"\n'
393 features += 'PACKAGE_CLASSES = "%s"\n' % classes
394 self.write_config(features)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800395 bb_result = bitbake('core-image-minimal', ignore_status=True)
396 self.assertGreaterEqual(bb_result.output.find("Postinstall scriptlets of ['postinst-rootfs-failing'] have failed."), 0,
Brad Bishop316dfdd2018-06-25 12:45:53 -0400397 "Warning about a failed scriptlet not found in bitbake output: %s" %(bb_result.output))
398
399 self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs-before-failure")),
400 "rootfs-before-failure file was not created")
401 self.assertFalse(os.path.isfile(os.path.join(hosttestdir, "rootfs-after-failure")),
402 "rootfs-after-failure file was created")
403
Patrick Williams45852732022-04-02 08:58:32 -0500404@OETestTag("runqemu")
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500405class SystemTap(OESelftestTestCase):
406 """
407 Summary: The purpose of this test case is to verify native crosstap
408 works while talking to a target.
409 Expected: The script should successfully connect to the qemu machine
410 and run some systemtap examples on a qemu machine.
411 """
412
413 @classmethod
414 def setUpClass(cls):
415 super(SystemTap, cls).setUpClass()
416 cls.image = "core-image-minimal"
417
418 def default_config(self):
419 return """
420# These aren't the actual IP addresses but testexport class needs something defined
421TEST_SERVER_IP = "192.168.7.1"
422TEST_TARGET_IP = "192.168.7.2"
423
424EXTRA_IMAGE_FEATURES += "tools-profile dbg-pkgs"
Patrick Williams213cb262021-08-07 19:21:33 -0500425IMAGE_FEATURES:append = " ssh-server-dropbear"
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500426
427# enables kernel debug symbols
Patrick Williams213cb262021-08-07 19:21:33 -0500428KERNEL_EXTRA_FEATURES:append = " features/debug/debug-kernel.scc"
429KERNEL_EXTRA_FEATURES:append = " features/systemtap/systemtap.scc"
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500430
431# add systemtap run-time into target image if it is not there yet
Patrick Williams213cb262021-08-07 19:21:33 -0500432IMAGE_INSTALL:append = " systemtap-runtime"
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500433"""
434
435 def test_crosstap_helloworld(self):
436 self.write_config(self.default_config())
437 bitbake('systemtap-native')
438 systemtap_examples = os.path.join(get_bb_var("WORKDIR","systemtap-native"), "usr/share/systemtap/examples")
439 bitbake(self.image)
440
441 with runqemu(self.image) as qemu:
442 cmd = "crosstap -r root@192.168.7.2 -s %s/general/helloworld.stp " % systemtap_examples
443 result = runCmd(cmd)
444 self.assertEqual(0, result.status, 'crosstap helloworld returned a non 0 status:%s' % result.output)
445
446 def test_crosstap_pstree(self):
447 self.write_config(self.default_config())
448
449 bitbake('systemtap-native')
450 systemtap_examples = os.path.join(get_bb_var("WORKDIR","systemtap-native"), "usr/share/systemtap/examples")
451 bitbake(self.image)
452
453 with runqemu(self.image) as qemu:
454 cmd = "crosstap -r root@192.168.7.2 -s %s/process/pstree.stp" % systemtap_examples
455 result = runCmd(cmd)
456 self.assertEqual(0, result.status, 'crosstap pstree returned a non 0 status:%s' % result.output)
457
458 def test_crosstap_syscalls_by_proc(self):
459 self.write_config(self.default_config())
460
461 bitbake('systemtap-native')
462 systemtap_examples = os.path.join(get_bb_var("WORKDIR","systemtap-native"), "usr/share/systemtap/examples")
463 bitbake(self.image)
464
465 with runqemu(self.image) as qemu:
466 cmd = "crosstap -r root@192.168.7.2 -s %s/process/ syscalls_by_proc.stp" % systemtap_examples
467 result = runCmd(cmd)
468 self.assertEqual(0, result.status, 'crosstap syscalls_by_proc returned a non 0 status:%s' % result.output)
469
470 def test_crosstap_syscalls_by_pid(self):
471 self.write_config(self.default_config())
472
473 bitbake('systemtap-native')
474 systemtap_examples = os.path.join(get_bb_var("WORKDIR","systemtap-native"), "usr/share/systemtap/examples")
475 bitbake(self.image)
476
477 with runqemu(self.image) as qemu:
478 cmd = "crosstap -r root@192.168.7.2 -s %s/process/ syscalls_by_pid.stp" % systemtap_examples
479 result = runCmd(cmd)
480 self.assertEqual(0, result.status, 'crosstap syscalls_by_pid returned a non 0 status:%s' % result.output)