. "$BST_LIB" # The deb / run-postinsts first-boot deferral path. brintos-postinst-canary ships a # pkg_postinst_ontarget that do_rootfs must never execute (there is no wasm32 # qemu-user) and that run-postinsts -> `dpkg --configure -a` must execute once the # deferral runs. Rootfs-time behaviour is asserted in the build log, not here. # # The deferral is wired to /etc/inittab (::sysinit:/usr/sbin/run-postinsts), so it # fires only under a pid 1 that reads inittab. A guest booted straight to a shell # never reaches it -- which is what run-machine.mjs does by default, and therefore # what the local runner the nightly uses does. Read the boot mode first and report # it as its own case, then assert the deferral either way: where the boot ran it, # that is asserted directly; where it did not, drive it here, which still exercises # the whole path the canary exists to prove -- a wasm32 binary exec'd under # HardwareJS from a maintainer script, and `dpkg --configure -a` completing. # Without that split the runner's choice of pid 1 is reported as three package reds. # # BRINTOS-WORKAROUND: brintos/hardwarejs#19 revisit -- once run-machine.mjs boots the # image's own init, first-boot goes green on its own and the drive branch below # becomes dead code to drop. # # Numbered ahead of 80-dpkg.test deliberately: the runner globs tests/*.test in # sorted order, and that suite's install/remove/purge lifecycle rewrites the same # status DB no-unpacked reads. require dpkg run-postinsts/dpkg stamp=/var/lib/brintos-postinst-canary.stamp probe=/var/lib/.bst-run-postinsts-probe if ! dpkg -l brintos-postinst-canary >/dev/null 2>&1; then bst_skip run-postinsts/canary "brintos-postinst-canary not installed on this image" else # pid 1, not the stamp, is what says whether THIS boot could have run the # deferral: a stamp left by an earlier run on a reused rootfs would otherwise # read as a first boot that never happened. pid1=$(cat /proc/1/comm 2>/dev/null) || pid1=unknown case "$pid1" in init|busybox) bst_ok run-postinsts/first-boot ;; *) bst_skip run-postinsts/first-boot \ "pid 1 is '$pid1', which does not read /etc/inittab, so nothing ran the deferral at boot (brintos/hardwarejs#19)" ;; esac # Bring the deferral about if the boot did not, so the cases below assert the # mechanism rather than the runner. touch, not `:`, because a redirection # failure on a special builtin exits the shell under POSIX. if [ ! -s "$stamp" ]; then if touch "$probe" 2>/dev/null; then rm -f "$probe" /usr/sbin/run-postinsts >/dev/null 2>&1 else ro="no deferral ran at boot and /var/lib is read-only, so it cannot be driven here" bst_skip run-postinsts/stamp "$ro" bst_skip run-postinsts/no-unpacked "$ro" bst_skip run-postinsts/canary-installed "$ro" exit 0 fi fi # The deferred scriptlet ran and its exec produced output. A non-empty stamp is # the assertion rather than its text: uname's exact wording is the runtime's to # choose, but only a wasm32 binary that really executed can have written anything. check run-postinsts/stamp test -s "$stamp" # `dpkg --configure -a` went all the way through: no package is left half- # configured. grep -q exits 1 when it finds no match, which is the pass here. check_rc run-postinsts/no-unpacked 1 grep -q "^Status:.*unpacked" /var/lib/dpkg/status # The canary itself reached the configured state, not just the others. check_out run-postinsts/canary-installed "install ok installed" \ sh -c "dpkg -s brintos-postinst-canary 2>&1" fi