summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta-selftest/recipes-test/postinst/postinst_1.0.bb14
-rw-r--r--meta/lib/oeqa/selftest/cases/runtime_test.py37
2 files changed, 50 insertions, 1 deletions
diff --git a/meta-selftest/recipes-test/postinst/postinst_1.0.bb b/meta-selftest/recipes-test/postinst/postinst_1.0.bb
index d4bab6dcc2..913bfabf89 100644
--- a/meta-selftest/recipes-test/postinst/postinst_1.0.bb
+++ b/meta-selftest/recipes-test/postinst/postinst_1.0.bb
@@ -3,11 +3,12 @@ LICENSE = "MIT"
3 3
4inherit allarch 4inherit allarch
5 5
6PACKAGES = "${PN}-rootfs ${PN}-delayed-a ${PN}-delayed-b" 6PACKAGES = "${PN}-rootfs ${PN}-delayed-a ${PN}-delayed-b ${PN}-rootfs-failing"
7 7
8ALLOW_EMPTY_${PN}-rootfs = "1" 8ALLOW_EMPTY_${PN}-rootfs = "1"
9ALLOW_EMPTY_${PN}-delayed-a = "1" 9ALLOW_EMPTY_${PN}-delayed-a = "1"
10ALLOW_EMPTY_${PN}-delayed-b = "1" 10ALLOW_EMPTY_${PN}-delayed-b = "1"
11ALLOW_EMPTY_${PN}-rootfs-failing = "1"
11 12
12RDEPENDS_${PN}-delayed-a = "${PN}-rootfs" 13RDEPENDS_${PN}-delayed-a = "${PN}-rootfs"
13RDEPENDS_${PN}-delayed-b = "${PN}-delayed-a" 14RDEPENDS_${PN}-delayed-b = "${PN}-delayed-a"
@@ -58,3 +59,14 @@ pkg_postinst_ontarget_${PN}-delayed-b () {
58 59
59 touch ${TESTDIR}/delayed-b 60 touch ${TESTDIR}/delayed-b
60} 61}
62
63# This scriptlet intentionally includes a bogus command in the middle to test
64# that we catch and report such errors properly.
65pkg_postinst_${PN}-rootfs-failing () {
66 mkdir -p $D${TESTDIR}
67 touch $D${TESTDIR}/rootfs-before-failure
68 run_a_really_broken_command
69 # Scriptlet execution should stop here; the following commands are NOT supposed to run.
70 # (oe-selftest checks for it).
71 touch $D${TESTDIR}/rootfs-after-failure
72}
diff --git a/meta/lib/oeqa/selftest/cases/runtime_test.py b/meta/lib/oeqa/selftest/cases/runtime_test.py
index 1c69255b56..9c9b4b3411 100644
--- a/meta/lib/oeqa/selftest/cases/runtime_test.py
+++ b/meta/lib/oeqa/selftest/cases/runtime_test.py
@@ -221,3 +221,40 @@ class Postinst(OESelftestTestCase):
221 for filename in ("rootfs", "delayed-a", "delayed-b"): 221 for filename in ("rootfs", "delayed-a", "delayed-b"):
222 status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename)) 222 status, output = qemu.run_serial("test -f %s && echo found" % os.path.join(targettestdir, filename))
223 self.assertEqual(output, "found", "%s was not present on boot" % filename) 223 self.assertEqual(output, "found", "%s was not present on boot" % filename)
224
225
226
227 def test_failing_postinst(self):
228 """
229 Summary: The purpose of this test case is to verify that post-installation
230 scripts that contain errors are properly reported.
231 Expected: The scriptlet failure is properly reported.
232 The file that is created after the error in the scriptlet is not present.
233 Product: oe-core
234 Author: Alexander Kanavin <alexander.kanavin@intel.com>
235 """
236
237 import oe.path
238
239 vars = get_bb_vars(("IMAGE_ROOTFS", "sysconfdir"), "core-image-minimal")
240 rootfs = vars["IMAGE_ROOTFS"]
241 self.assertIsNotNone(rootfs)
242 sysconfdir = vars["sysconfdir"]
243 self.assertIsNotNone(sysconfdir)
244 # Need to use oe.path here as sysconfdir starts with /
245 hosttestdir = oe.path.join(rootfs, sysconfdir, "postinst-test")
246
247 for classes in ("package_rpm", "package_deb", "package_ipk"):
248 with self.subTest(package_class=classes):
249 features = 'CORE_IMAGE_EXTRA_INSTALL = "postinst-rootfs-failing"\n'
250 features += 'PACKAGE_CLASSES = "%s"\n' % classes
251 self.write_config(features)
252 bb_result = bitbake('core-image-minimal')
253 self.assertGreaterEqual(bb_result.output.find("Intentionally failing postinstall scriptlets of ['postinst-rootfs-failing'] to defer them to first boot is deprecated."), 0,
254 "Warning about a failed scriptlet not found in bitbake output: %s" %(bb_result.output))
255
256 self.assertTrue(os.path.isfile(os.path.join(hosttestdir, "rootfs-before-failure")),
257 "rootfs-before-failure file was not created")
258 self.assertFalse(os.path.isfile(os.path.join(hosttestdir, "rootfs-after-failure")),
259 "rootfs-after-failure file was created")
260