xref: /OK3568_Linux_fs/yocto/poky/meta-selftest/recipes-test/postinst/postinst_1.0.bb (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593SmuzhiyunSUMMARY = "Packages to exercise postinstall functions"
2*4882a593SmuzhiyunLICENSE = "MIT"
3*4882a593Smuzhiyun
4*4882a593Smuzhiyuninherit allarch
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunPACKAGES = "${PN}-rootfs ${PN}-delayed-a ${PN}-delayed-b ${PN}-rootfs-failing"
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunALLOW_EMPTY:${PN}-rootfs = "1"
9*4882a593SmuzhiyunALLOW_EMPTY:${PN}-delayed-a = "1"
10*4882a593SmuzhiyunALLOW_EMPTY:${PN}-delayed-b = "1"
11*4882a593SmuzhiyunALLOW_EMPTY:${PN}-rootfs-failing = "1"
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunRDEPENDS:${PN}-delayed-a = "${PN}-rootfs"
14*4882a593SmuzhiyunRDEPENDS:${PN}-delayed-b = "${PN}-delayed-a"
15*4882a593Smuzhiyun
16*4882a593SmuzhiyunTESTDIR = "${sysconfdir}/postinst-test"
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun# At rootfs time touch $TESTDIR/rootfs.  Errors if the file already exists, or
19*4882a593Smuzhiyun# if the function runs on first boot.
20*4882a593Smuzhiyunpkg_postinst:${PN}-rootfs () {
21*4882a593Smuzhiyun    set -e
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun    if [ -z "$D" ]; then
24*4882a593Smuzhiyun        echo "${PN}-rootfs should have finished at rootfs time"
25*4882a593Smuzhiyun        exit 1
26*4882a593Smuzhiyun    fi
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun    if [ -e $D${TESTDIR}/rootfs ]; then
29*4882a593Smuzhiyun        echo "$D${TESTDIR}/rootfs exists, but should not"
30*4882a593Smuzhiyun        exit 1
31*4882a593Smuzhiyun    fi
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun    mkdir -p $D${TESTDIR}
34*4882a593Smuzhiyun    touch $D${TESTDIR}/rootfs
35*4882a593Smuzhiyun}
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun# Depends on rootfs, delays until first boot, verifies that the rootfs file was
38*4882a593Smuzhiyun# written.
39*4882a593Smuzhiyunpkg_postinst_ontarget:${PN}-delayed-a () {
40*4882a593Smuzhiyun    set -e
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun    if [ ! -e ${TESTDIR}/rootfs ]; then
43*4882a593Smuzhiyun        echo "${PN}-delayed-a: ${TESTDIR}/rootfs not found"
44*4882a593Smuzhiyun        exit 1
45*4882a593Smuzhiyun    fi
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun    touch ${TESTDIR}/delayed-a
48*4882a593Smuzhiyun}
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun# Depends on delayed-a, delays until first boot, verifies that the delayed-a file was
51*4882a593Smuzhiyun# written. This verifies the ordering between delayed postinsts.
52*4882a593Smuzhiyunpkg_postinst_ontarget:${PN}-delayed-b () {
53*4882a593Smuzhiyun    set -e
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun    if [ ! -e ${TESTDIR}/delayed-a ]; then
56*4882a593Smuzhiyun        echo "${PN}-delayed-b: ${TESTDIR}/delayed-a not found"
57*4882a593Smuzhiyun        exit 1
58*4882a593Smuzhiyun    fi
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun    touch ${TESTDIR}/delayed-b
61*4882a593Smuzhiyun}
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun# This scriptlet intentionally includes a bogus command in the middle to test
64*4882a593Smuzhiyun# that we catch and report such errors properly.
65*4882a593Smuzhiyunpkg_postinst:${PN}-rootfs-failing () {
66*4882a593Smuzhiyun    mkdir -p $D${TESTDIR}
67*4882a593Smuzhiyun    touch $D${TESTDIR}/rootfs-before-failure
68*4882a593Smuzhiyun    run_a_really_broken_command
69*4882a593Smuzhiyun    # Scriptlet execution should stop here; the following commands are NOT supposed to run.
70*4882a593Smuzhiyun    # (oe-selftest checks for it).
71*4882a593Smuzhiyun    touch $D${TESTDIR}/rootfs-after-failure
72*4882a593Smuzhiyun}
73