summaryrefslogtreecommitdiffstats
path: root/meta-selftest/recipes-test/postinst/postinst_1.0.bb
blob: 913bfabf89e3a22f59600fffab1bdccbab401e7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
SUMMARY = "Packages to exercise postinstall functions"
LICENSE = "MIT"

inherit allarch

PACKAGES = "${PN}-rootfs ${PN}-delayed-a ${PN}-delayed-b ${PN}-rootfs-failing"

ALLOW_EMPTY_${PN}-rootfs = "1"
ALLOW_EMPTY_${PN}-delayed-a = "1"
ALLOW_EMPTY_${PN}-delayed-b = "1"
ALLOW_EMPTY_${PN}-rootfs-failing = "1"

RDEPENDS_${PN}-delayed-a = "${PN}-rootfs"
RDEPENDS_${PN}-delayed-b = "${PN}-delayed-a"

TESTDIR = "${sysconfdir}/postinst-test"

# At rootfs time touch $TESTDIR/rootfs.  Errors if the file already exists, or
# if the function runs on first boot.
pkg_postinst_${PN}-rootfs () {
    set -e

    if [ -z "$D" ]; then
        echo "${PN}-rootfs should have finished at rootfs time"
        exit 1
    fi

    if [ -e $D${TESTDIR}/rootfs ]; then
        echo "$D${TESTDIR}/rootfs exists, but should not"
        exit 1
    fi

    mkdir -p $D${TESTDIR}
    touch $D${TESTDIR}/rootfs
}

# Depends on rootfs, delays until first boot, verifies that the rootfs file was
# written.
pkg_postinst_ontarget_${PN}-delayed-a () {
    set -e

    if [ ! -e ${TESTDIR}/rootfs ]; then
        echo "${PN}-delayed-a: ${TESTDIR}/rootfs not found"
        exit 1
    fi

    touch ${TESTDIR}/delayed-a
}

# Depends on delayed-a, delays until first boot, verifies that the delayed-a file was
# written. This verifies the ordering between delayed postinsts.
pkg_postinst_ontarget_${PN}-delayed-b () {
    set -e

    if [ ! -e ${TESTDIR}/delayed-a ]; then
        echo "${PN}-delayed-b: ${TESTDIR}/delayed-a not found"
        exit 1
    fi

    touch ${TESTDIR}/delayed-b
}

# This scriptlet intentionally includes a bogus command in the middle to test 
# that we catch and report such errors properly.
pkg_postinst_${PN}-rootfs-failing () {
    mkdir -p $D${TESTDIR}
    touch $D${TESTDIR}/rootfs-before-failure
    run_a_really_broken_command
    # Scriptlet execution should stop here; the following commands are NOT supposed to run.
    # (oe-selftest checks for it).
    touch $D${TESTDIR}/rootfs-after-failure
}