From 23d1c4ffb7791e2f75f0eaa84dd6b936d3b861f7 Mon Sep 17 00:00:00 2001 From: Francisco Pedraza Date: Thu, 24 Nov 2016 15:54:53 -0600 Subject: selftest: Test needed to verify postinst order It verifies the following: 1. Compile a minimal image. 2. The compiled image will add the layer with the recipe postinst, previously created at: "meta-selftest/recipes-test" 3. Run QEMU. 4. Validate the task execution order. [YOCTO #5319] (From OE-Core rev: a8ff789a3bfedcbc4358db7907a45270d8b1b76a) Signed-off-by: Francisco Pedraza Signed-off-by: Ross Burton Signed-off-by: Richard Purdie --- .../recipes-test/postinst/postinst_1.0.bb | 124 +++++++++++++++++++++ meta/lib/oeqa/selftest/runtime-test.py | 52 +++++++++ 2 files changed, 176 insertions(+) create mode 100644 meta-selftest/recipes-test/postinst/postinst_1.0.bb diff --git a/meta-selftest/recipes-test/postinst/postinst_1.0.bb b/meta-selftest/recipes-test/postinst/postinst_1.0.bb new file mode 100644 index 0000000000..97a1987305 --- /dev/null +++ b/meta-selftest/recipes-test/postinst/postinst_1.0.bb @@ -0,0 +1,124 @@ +LICENSE = "MIT" +ALLOW_EMPTY_${PN}-at-rootfs = "1" +ALLOW_EMPTY_${PN}-delayed-a = "1" +ALLOW_EMPTY_${PN}-delayed-b = "1" +ALLOW_EMPTY_${PN}-delayed-d = "1" +ALLOW_EMPTY_${PN}-delayed-p = "1" +ALLOW_EMPTY_${PN}-delayed-t = "1" + +PACKAGES += "${PN}-at-rootfs ${PN}-delayed-a ${PN}-delayed-b ${PN}-delayed-d ${PN}-delayed-p ${PN}-delayed-t" +PROVIDES += "${PN}-at-rootfs ${PN}-delayed-a ${PN}-delayed-b ${PN}-delayed-d ${PN}-delayed-p ${PN}-delayed-t" +FILES_${PN}-delayed-a = "" +FILES_${PN}-delayed-b = "" +FILES_${PN}-delayed-d = "" +FILES_${PN}-delayed-p = "" +FILES_${PN}-delayed-t = "" + +# Runtime dependencies +RDEPENDS_${PN}-delayed-a = "${PN}-at-rootfs" +RDEPENDS_${PN}-delayed-b = "${PN}-delayed-a" +RDEPENDS_${PN}-delayed-d = "${PN}-delayed-b" +RDEPENDS_${PN}-delayed-p = "${PN}-delayed-d" +RDEPENDS_${PN}-delayed-t = "${PN}-delayed-p" + +# Main recipe post-install +pkg_postinst_${PN}-at-rootfs () { + tfile="/etc/postinsta-test" + if test "x$D" != "x" then + # Need to run on first boot + exit 1 + else + echo "lets write postinst" > $tfile + fi +} + +# Dependency recipes post-installs +pkg_postinst_${PN}-delayed-a () { + efile="/etc/postinst-test" + tfile="/etc/postinsta-test" + rdeps="postinst" + + if test "x$D" != "x"; then + # Need to run on first boot + exit 1 + else + if test -e $efile ; then + echo 'success' > $tfile + else + echo 'fail to install $rdeps first!' >&2 + exit 1 + fi + fi +} + +pkg_postinst_${PN}-delayed-b () { + efile="/etc/postinsta-test" + tfile="/etc/postinstb-test" + rdeps="postinsta" + + if test "x$D" != "x"; then + # Need to run on first boot + exit 1 + else + if test -e $efile ; then + echo 'success' > $tfile + else + echo 'fail to install $rdeps first!' >&2 + exit 1 + fi + fi +} + +pkg_postinst_${PN}-delayed-d () { + efile="/etc/postinstb-test" + tfile="/etc/postinstd-test" + rdeps="postinstb" + + if test "x$D" != "x"; then + # Need to run on first boot + exit 1 + else + if test -e $efile ; then + echo 'success' > $tfile + else + echo 'fail to install $rdeps first!' >&2 + exit 1 + fi + fi +} + +pkg_postinst_${PN}-delayed-p () { + efile="/etc/postinstd-test" + tfile="/etc/postinstp-test" + rdeps="postinstd" + + if test "x$D" != "x"; then + # Need to run on first boot + exit 1 + else + if test -e $efile ; then + echo 'success' > $tfile + else + echo 'fail to install $rdeps first!' >&2 + exit 1 + fi + fi +} + +pkg_postinst_${PN}-delayed-t () { + efile="/etc/postinstp-test" + tfile="/etc/postinstt-test" + rdeps="postinstp" + + if test "x$D" != "x"; then + # Need to run on first boot + exit 1 + else + if test -e $efile ; then + echo 'success' > $tfile + else + echo 'fail to install $rdeps first!' >&2 + exit 1 + fi + fi +} diff --git a/meta/lib/oeqa/selftest/runtime-test.py b/meta/lib/oeqa/selftest/runtime-test.py index c2d5b45a4b..1dbfae1106 100644 --- a/meta/lib/oeqa/selftest/runtime-test.py +++ b/meta/lib/oeqa/selftest/runtime-test.py @@ -2,6 +2,7 @@ from oeqa.selftest.base import oeSelfTest from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu from oeqa.utils.decorators import testcase import os +import re class TestExport(oeSelfTest): @@ -103,3 +104,54 @@ class TestImage(oeSelfTest): # Build core-image-sato and testimage bitbake('core-image-full-cmdline socat') bitbake('-c testimage core-image-full-cmdline') + +class Postinst(oeSelfTest): + @testcase(1540) + def test_verify_postinst(self): + """ + Summary: The purpose of this test is to verify the execution order of postinst Bugzilla ID: [5319] + Expected : + 1. Compile a minimal image. + 2. The compiled image will add the created layer with the recipes postinst[ abdpt] + 3. Run qemux86 + 4. Validate the task execution order + Author: Francisco Pedraza + """ + features = 'INHERIT += "testimage"\n' + features += 'CORE_IMAGE_EXTRA_INSTALL += "postinst-at-rootfs \ +postinst-delayed-a \ +postinst-delayed-b \ +postinst-delayed-d \ +postinst-delayed-p \ +postinst-delayed-t \ +"\n' + self.write_config(features) + + bitbake('core-image-minimal -f ') + + postinst_list = ['100-postinst-at-rootfs', + '101-postinst-delayed-a', + '102-postinst-delayed-b', + '103-postinst-delayed-d', + '104-postinst-delayed-p', + '105-postinst-delayed-t'] + path_workdir = get_bb_var('WORKDIR','core-image-minimal') + workspacedir = 'testimage/qemu_boot_log' + workspacedir = os.path.join(path_workdir, workspacedir) + rexp = re.compile("^Running postinst .*/(?P.*)\.\.\.$") + with runqemu('core-image-minimal') as qemu: + with open(workspacedir) as f: + found = False + idx = 0 + for line in f.readlines(): + line = line.strip().replace("^M","") + if not line: # To avoid empty lines + continue + m = rexp.search(line) + if m: + self.assertEqual(postinst_list[idx], m.group('postinst'), "Fail") + idx = idx+1 + found = True + elif found: + self.assertEqual(idx, len(postinst_list), "Not found all postinsts") + break -- cgit 1.2.3-korg