blob: e32c4aff85d89d9376ec1c2ba1aef39d30502686 [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 Geissler1e34c2d2020-05-29 16:02:59 -0500263 qemu_distrofeatures = get_bb_var('DISTRO_FEATURES', 'qemu-system-native')
Patrick Williams92b42cb2022-09-03 06:53:57 -0500264 features = 'IMAGE_CLASSES += "testimage"\n'
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500265 if 'opengl' not in qemu_distrofeatures:
Patrick Williams213cb262021-08-07 19:21:33 -0500266 features += 'DISTRO_FEATURES:append = " opengl"\n'
Brad Bishop19323692019-04-05 15:28:33 -0400267 features += 'TEST_SUITES = "ping ssh virgl"\n'
Patrick Williams213cb262021-08-07 19:21:33 -0500268 features += 'IMAGE_FEATURES:append = " ssh-server-dropbear"\n'
269 features += 'IMAGE_INSTALL:append = " kmscube"\n'
Brad Bishop19323692019-04-05 15:28:33 -0400270 features += 'TEST_RUNQEMUPARAMS = "egl-headless"\n'
271 self.write_config(features)
272 bitbake('core-image-minimal')
273 bitbake('-c testimage core-image-minimal')
274
Patrick Williams45852732022-04-02 08:58:32 -0500275@OETestTag("runqemu")
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500276class Postinst(OESelftestTestCase):
Andrew Geissler82c905d2020-04-13 13:39:40 -0500277
278 def init_manager_loop(self, init_manager):
279 import oe.path
280
281 vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
282 rootfs = vars["IMAGE_ROOTFS"]
283 self.assertIsNotNone(rootfs)
284 sysconfdir = vars["sysconfdir"]
285 self.assertIsNotNone(sysconfdir)
286 # Need to use oe.path here as sysconfdir starts with /
287 hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
288 targettestdir = os.path.join(sysconfdir, "postinst-test")
289
290 for classes in ("package_rpm", "package_deb", "package_ipk"):
291 with self.subTest(init_manager=init_manager, package_class=classes):
292 features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-delayed-b"\n'
293 features += 'IMAGE_FEATURES += "package-management empty-root-password"\n'
294 features += 'PACKAGE_CLASSES = "%s"\n' % classes
295 if init_manager == "systemd":
Patrick Williams213cb262021-08-07 19:21:33 -0500296 features += 'DISTRO_FEATURES:append = " systemd"\n'
Andrew Geissler82c905d2020-04-13 13:39:40 -0500297 features += 'VIRTUAL-RUNTIME_init_manager = "systemd"\n'
298 features += 'DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"\n'
299 features += 'VIRTUAL-RUNTIME_initscripts = ""\n'
300 self.write_config(features)
301
302 bitbake('core-image-minimal')
303
304 self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs")),
305 "rootfs state file was not created")
306
307 with runqemu('core-image-minimal') as qemu:
308 # Make the test echo a string and search for that as
309 # run_serial()'s status code is useless.'
310 for filename in ("rootfs", "delayed-a", "delayed-b"):
311 status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename))
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600312 self.assertIn("found", output, "%s was not present on boot" % filename)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500313
314
315
Patrick Williams45852732022-04-02 08:58:32 -0500316 @skipIfNotQemu()
Andrew Geissler82c905d2020-04-13 13:39:40 -0500317 def test_postinst_rootfs_and_boot_sysvinit(self):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500318 """
319 Summary: The purpose of this test case is to verify Post-installation
320 scripts are called when rootfs is created and also test
321 that script can be delayed to run at first boot.
322 Dependencies: NA
323 Steps: 1. Add proper configuration to local.conf file
324 2. Build a "core-image-minimal" image
325 3. Verify that file created by postinst_rootfs recipe is
326 present on rootfs dir.
327 4. Boot the image created on qemu and verify that the file
328 created by postinst_boot recipe is present on image.
329 Expected: The files are successfully created during rootfs and boot
330 time for 3 different package managers: rpm,ipk,deb and
Andrew Geissler82c905d2020-04-13 13:39:40 -0500331 for initialization managers: sysvinit.
332
333 """
334 self.init_manager_loop("sysvinit")
335
336
Patrick Williams45852732022-04-02 08:58:32 -0500337 @skipIfNotQemu()
Andrew Geissler82c905d2020-04-13 13:39:40 -0500338 def test_postinst_rootfs_and_boot_systemd(self):
339 """
340 Summary: The purpose of this test case is to verify Post-installation
341 scripts are called when rootfs is created and also test
342 that script can be delayed to run at first boot.
343 Dependencies: NA
344 Steps: 1. Add proper configuration to local.conf file
345 2. Build a "core-image-minimal" image
346 3. Verify that file created by postinst_rootfs recipe is
347 present on rootfs dir.
348 4. Boot the image created on qemu and verify that the file
349 created by postinst_boot recipe is present on image.
350 Expected: The files are successfully created during rootfs and boot
351 time for 3 different package managers: rpm,ipk,deb and
352 for initialization managers: systemd.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500353
354 """
Brad Bishop316dfdd2018-06-25 12:45:53 -0400355
Andrew Geissler82c905d2020-04-13 13:39:40 -0500356 self.init_manager_loop("systemd")
Brad Bishop316dfdd2018-06-25 12:45:53 -0400357
358
359 def test_failing_postinst(self):
360 """
361 Summary: The purpose of this test case is to verify that post-installation
362 scripts that contain errors are properly reported.
363 Expected: The scriptlet failure is properly reported.
364 The file that is created after the error in the scriptlet is not present.
365 Product: oe-core
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800366 Author: Alexander Kanavin <alex.kanavin@gmail.com>
Brad Bishop316dfdd2018-06-25 12:45:53 -0400367 """
368
369 import oe.path
370
371 vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
372 rootfs = vars["IMAGE_ROOTFS"]
373 self.assertIsNotNone(rootfs)
374 sysconfdir = vars["sysconfdir"]
375 self.assertIsNotNone(sysconfdir)
376 # Need to use oe.path here as sysconfdir starts with /
377 hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
378
379 for classes in ("package_rpm", "package_deb", "package_ipk"):
380 with self.subTest(package_class=classes):
381 features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-rootfs-failing"\n'
382 features += 'PACKAGE_CLASSES = "%s"\n' % classes
383 self.write_config(features)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800384 bb_result = bitbake('core-image-minimal', ignore_status=True)
385 self.assertGreaterEqual(bb_result.output.find("Postinstall scriptlets of ['postinst-rootfs-failing'] have failed."), 0,
Brad Bishop316dfdd2018-06-25 12:45:53 -0400386 "Warning about a failed scriptlet not found in bitbake output: %s" %(bb_result.output))
387
388 self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs-before-failure")),
389 "rootfs-before-failure file was not created")
390 self.assertFalse(os.path.isfile(os.path.join(hosttestdir, "rootfs-after-failure")),
391 "rootfs-after-failure file was created")
392
Patrick Williams45852732022-04-02 08:58:32 -0500393@OETestTag("runqemu")
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500394class SystemTap(OESelftestTestCase):
395 """
396 Summary: The purpose of this test case is to verify native crosstap
397 works while talking to a target.
398 Expected: The script should successfully connect to the qemu machine
399 and run some systemtap examples on a qemu machine.
400 """
401
402 @classmethod
403 def setUpClass(cls):
404 super(SystemTap, cls).setUpClass()
405 cls.image = "core-image-minimal"
406
407 def default_config(self):
408 return """
409# These aren't the actual IP addresses but testexport class needs something defined
410TEST_SERVER_IP = "192.168.7.1"
411TEST_TARGET_IP = "192.168.7.2"
412
413EXTRA_IMAGE_FEATURES += "tools-profile dbg-pkgs"
Patrick Williams213cb262021-08-07 19:21:33 -0500414IMAGE_FEATURES:append = " ssh-server-dropbear"
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500415
416# enables kernel debug symbols
Patrick Williams213cb262021-08-07 19:21:33 -0500417KERNEL_EXTRA_FEATURES:append = " features/debug/debug-kernel.scc"
418KERNEL_EXTRA_FEATURES:append = " features/systemtap/systemtap.scc"
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500419
420# add systemtap run-time into target image if it is not there yet
Patrick Williams213cb262021-08-07 19:21:33 -0500421IMAGE_INSTALL:append = " systemtap-runtime"
Brad Bishop1d80a2e2019-11-15 16:35:03 -0500422"""
423
424 def test_crosstap_helloworld(self):
425 self.write_config(self.default_config())
426 bitbake('systemtap-native')
427 systemtap_examples = os.path.join(get_bb_var("WORKDIR","systemtap-native"), "usr/share/systemtap/examples")
428 bitbake(self.image)
429
430 with runqemu(self.image) as qemu:
431 cmd = "crosstap -r root@192.168.7.2 -s %s/general/helloworld.stp " % systemtap_examples
432 result = runCmd(cmd)
433 self.assertEqual(0, result.status, 'crosstap helloworld returned a non 0 status:%s' % result.output)
434
435 def test_crosstap_pstree(self):
436 self.write_config(self.default_config())
437
438 bitbake('systemtap-native')
439 systemtap_examples = os.path.join(get_bb_var("WORKDIR","systemtap-native"), "usr/share/systemtap/examples")
440 bitbake(self.image)
441
442 with runqemu(self.image) as qemu:
443 cmd = "crosstap -r root@192.168.7.2 -s %s/process/pstree.stp" % systemtap_examples
444 result = runCmd(cmd)
445 self.assertEqual(0, result.status, 'crosstap pstree returned a non 0 status:%s' % result.output)
446
447 def test_crosstap_syscalls_by_proc(self):
448 self.write_config(self.default_config())
449
450 bitbake('systemtap-native')
451 systemtap_examples = os.path.join(get_bb_var("WORKDIR","systemtap-native"), "usr/share/systemtap/examples")
452 bitbake(self.image)
453
454 with runqemu(self.image) as qemu:
455 cmd = "crosstap -r root@192.168.7.2 -s %s/process/ syscalls_by_proc.stp" % systemtap_examples
456 result = runCmd(cmd)
457 self.assertEqual(0, result.status, 'crosstap syscalls_by_proc returned a non 0 status:%s' % result.output)
458
459 def test_crosstap_syscalls_by_pid(self):
460 self.write_config(self.default_config())
461
462 bitbake('systemtap-native')
463 systemtap_examples = os.path.join(get_bb_var("WORKDIR","systemtap-native"), "usr/share/systemtap/examples")
464 bitbake(self.image)
465
466 with runqemu(self.image) as qemu:
467 cmd = "crosstap -r root@192.168.7.2 -s %s/process/ syscalls_by_pid.stp" % systemtap_examples
468 result = runCmd(cmd)
469 self.assertEqual(0, result.status, 'crosstap syscalls_by_pid returned a non 0 status:%s' % result.output)