ci / prune-artifacts (push) Skipped
ci / patches-apply (push) Successful in 24s
ci / bench (pull_request) Successful in 16s
ci / test (push) Successful in 24s
ci / mcdc (push) Successful in 29s
ci / kernel-build (push) Skipped
ci / test (pull_request) Successful in 10s
ci / quality (push) Successful in 39s
ci / badges (push) Skipped
ci / mcdc (pull_request) Successful in 30s
ci / bench (push) Successful in 10s
ci / qemu-tools (push) Successful in 3m16s
ci / qemu-tools (pull_request) Successful in 2m34s
ci / kernel-symbols (pull_request) Successful in 1m54s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / patches-apply (pull_request) Successful in 55s
ci / quality (pull_request) Successful in 1m36s
ci / badges (pull_request) Skipped
ci / kernel-symbols (push) Successful in 4m24s
The rig's stage-2 init starts /usr/bin/warden-ui directly as root, so it never ran S03warden-accounts, S99lvgl or warden-ui-run: no privilege drop, respawn loop or safe mode was exercised, and the BusyBox setpriv bug of flare-edge #1903 left every rebuild image without a UI while CI was green. - mkimage.sh: ROOTFS_OVERLAY lays a directory of panel files over the rootfs of both slots, modes kept. Only etc/ and usr/ at its top, no symlinks; a refused overlay writes no image. - sbin/init: with warden.initchain on the command line it runs /etc/init.d/S00-S09 before the bus and S10-S99 after the payload daemons, in place of the direct UI start (warden_init_chain in warden-lib.sh). The splash handover is marked done and warden-ui-run gets "-b fbdev". A chain boot without scripts prints WARDEN-QEMU-INITCHAIN-EMPTY and starts no UI. - warden_rig_bus_owners: when the accounts exist, cred/ui belongs to warden-ui and the cred directory to group warden-bus, as S10bus does. - Tests: init-chain-test.sh (19 checks, also under busybox sh) and rootfs-overlay.sh (17 scenarios, images read back with debugfs), both in CI. Refs flare-edge#2210 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
156 lines
6.4 KiB
Bash
Executable File
156 lines
6.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Regression test for mkimage.sh's ROOTFS_OVERLAY hook (see its Env note): a
|
|
# run lays the panel's own init scripts over the rig rootfs of both slots, so
|
|
# a warden.initchain boot starts the UI through S99lvgl and warden-ui-run
|
|
# (flare-edge #2210). Only etc/ and usr/ may appear at the overlay's top and
|
|
# no entry may be a symlink; a refused overlay writes no image.
|
|
#
|
|
# Works on a copy of qemu/ (no payload, no out/) so the default payload
|
|
# directory is the copy's own and nothing in the checkout is touched. Builds
|
|
# real disk images the same way mkimage.sh always does (unprivileged
|
|
# mkfs.ext4 -d), then reads rootfs_a and rootfs_b back with debugfs -R
|
|
# (read-only, no mount or loop device) to check what actually landed.
|
|
#
|
|
# bash rootfs-overlay.sh
|
|
set -uo pipefail
|
|
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # qemu/tests/
|
|
SRC_QEMU="$(cd "$HERE/.." && pwd)" # qemu/
|
|
FAIL=0
|
|
pass() { printf '[PASS] %s\n' "$1"; }
|
|
fail() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
|
|
|
|
# mkfs.ext4 and debugfs live in sbin, which user shells on Debian do not put
|
|
# on PATH; mkimage.sh applies the same fix.
|
|
PATH="$PATH:/usr/sbin:/sbin"
|
|
command -v debugfs >/dev/null || {
|
|
echo "FATAL: debugfs (e2fsprogs) not found: needed to read the rootfs partitions back" >&2
|
|
exit 1
|
|
}
|
|
|
|
SCRATCH="$(mktemp -d "${TMPDIR:-/tmp}/warden-qemu-rootfs-overlay.XXXXXX")"
|
|
trap 'rm -rf "$SCRATCH"' EXIT
|
|
|
|
# The copy: everything mkimage.sh reads, without the build outputs or any
|
|
# payload a developer dropped into the checkout.
|
|
QEMU_DIR="$SCRATCH/qemu"
|
|
mkdir -p "$QEMU_DIR/payload"
|
|
for entry in "$SRC_QEMU"/*; do
|
|
case "$(basename "$entry")" in out|payload) continue ;; esac
|
|
cp -a "$entry" "$QEMU_DIR/"
|
|
done
|
|
|
|
# shellcheck source=../lib.sh disable=SC1091
|
|
. "$QEMU_DIR/lib.sh"
|
|
# shellcheck source=../blkdevparts.conf disable=SC1091
|
|
. "$QEMU_DIR/blkdevparts.conf"
|
|
|
|
declare -A PART_OFF PART_SIZE
|
|
capture_part() { PART_OFF[$1]="$2"; PART_SIZE[$1]="$3"; return 0; }
|
|
qemu_each_partition capture_part
|
|
for name in rootfs_a rootfs_b; do
|
|
[ -n "${PART_OFF[$name]:-}" ] || { echo "FATAL: no '$name' entry in blkdevparts.conf" >&2; exit 1; }
|
|
done
|
|
|
|
# extract_part DISK NAME OUTFILE: one partition window, sparse.
|
|
extract_part() {
|
|
dd if="$1" of="$3" bs=4096 skip=$((PART_OFF[$2] / 4096)) \
|
|
count=$((PART_SIZE[$2] / 4096)) conv=sparse status=none
|
|
}
|
|
|
|
# Reuse an already-verified busybox wherever a prior build produced one; a
|
|
# checkout that never ran mkimage.sh fetches and verifies it once here.
|
|
BUSYBOX_BIN="$SRC_QEMU/out/busybox-armv7l"
|
|
if [ ! -f "$BUSYBOX_BIN" ]; then
|
|
OUT="$SCRATCH/bb" qemu_get_busybox
|
|
BUSYBOX_BIN="$BB"
|
|
fi
|
|
|
|
|
|
OV="$SCRATCH/overlay"
|
|
mkdir -p "$OV/etc/init.d" "$OV/usr/lib/warden"
|
|
printf '#!/bin/sh\necho lvgl\n' > "$OV/etc/init.d/S99lvgl"
|
|
chmod 0755 "$OV/etc/init.d/S99lvgl"
|
|
printf '#!/bin/sh\necho run\n' > "$OV/usr/lib/warden/warden-ui-run"
|
|
chmod 0750 "$OV/usr/lib/warden/warden-ui-run"
|
|
printf 'ui=1\n' > "$OV/etc/flare.conf"
|
|
chmod 0640 "$OV/etc/flare.conf"
|
|
|
|
mode_of() { # mode_of IMG PATH
|
|
debugfs -R "stat $2" "$1" 2>/dev/null | grep -oE 'Mode: *[0-7]+' | grep -oE '[0-7]+$'
|
|
}
|
|
|
|
# --- scenario 1: the overlay lands in both slots with its modes ---
|
|
OUT1="$SCRATCH/out1"
|
|
if OUT="$OUT1" BUSYBOX="$BUSYBOX_BIN" ROOTFS_OVERLAY="$OV" \
|
|
bash "$QEMU_DIR/mkimage.sh" > "$SCRATCH/mkimage1.log" 2>&1; then
|
|
for slot in rootfs_a rootfs_b; do
|
|
IMG="$SCRATCH/$slot.1.img"
|
|
extract_part "$OUT1/disk.img" "$slot" "$IMG"
|
|
got="$(debugfs -R "cat /etc/init.d/S99lvgl" "$IMG" 2>/dev/null | tail -n 1)"
|
|
if [ "$got" = "echo lvgl" ]; then pass "overlay: $slot carries etc/init.d/S99lvgl"
|
|
else fail "overlay: $slot S99lvgl = '$got'"; fi
|
|
m="$(mode_of "$IMG" /usr/lib/warden/warden-ui-run)"
|
|
if [ "$m" = "0750" ]; then pass "overlay: $slot keeps warden-ui-run's mode 0750"
|
|
else fail "overlay: $slot warden-ui-run mode '$m', want 0750"; fi
|
|
m="$(mode_of "$IMG" /etc/flare.conf)"
|
|
if [ "$m" = "0640" ]; then pass "overlay: $slot keeps a data file's mode 0640"
|
|
else fail "overlay: $slot flare.conf mode '$m', want 0640"; fi
|
|
if debugfs -R "stat /sbin/init" "$IMG" 2>&1 | grep -q 'File not found'; then
|
|
fail "overlay: $slot lost the rig's own /sbin/init"
|
|
else
|
|
pass "overlay: $slot still has the rig's /sbin/init"
|
|
fi
|
|
if debugfs -R "stat /etc/passwd" "$IMG" 2>&1 | grep -q 'File not found'; then
|
|
fail "overlay: $slot lost the skeleton's /etc/passwd"
|
|
else
|
|
pass "overlay: $slot keeps the skeleton's /etc/passwd beside the overlay's etc/"
|
|
fi
|
|
done
|
|
else
|
|
fail "overlay: mkimage.sh exited nonzero with a valid overlay (see $SCRATCH/mkimage1.log)"
|
|
fi
|
|
|
|
# --- scenario 2: no overlay leaves /etc/init.d out ---
|
|
OUT2="$SCRATCH/out2"
|
|
if OUT="$OUT2" BUSYBOX="$BUSYBOX_BIN" bash "$QEMU_DIR/mkimage.sh" > "$SCRATCH/mkimage2.log" 2>&1; then
|
|
IMG="$SCRATCH/rootfs_a.2.img"
|
|
extract_part "$OUT2/disk.img" rootfs_a "$IMG"
|
|
if debugfs -R "stat /etc/init.d" "$IMG" 2>&1 | grep -q 'File not found'; then
|
|
pass "no overlay: rootfs_a has no /etc/init.d (the rig's direct start)"
|
|
else
|
|
fail "no overlay: rootfs_a has an /etc/init.d"
|
|
fi
|
|
else
|
|
fail "no overlay: mkimage.sh exited nonzero (see $SCRATCH/mkimage2.log)"
|
|
fi
|
|
|
|
# --- scenario 3: refused overlays fail closed and write no image ---
|
|
refused() { # refused <label> <dir> <stderr text>
|
|
local out="$SCRATCH/out-$1" err rc
|
|
err="$(OUT="$out" BUSYBOX="$BUSYBOX_BIN" ROOTFS_OVERLAY="$2" bash "$QEMU_DIR/mkimage.sh" 2>&1 1>/dev/null)"
|
|
rc=$?
|
|
if [ "$rc" -ne 0 ] && printf '%s' "$err" | grep -qF "$3" && [ ! -e "$out/disk.img" ]; then
|
|
pass "overlay refused ($1): nonzero, '$3', no image"
|
|
else
|
|
fail "overlay $1: rc=$rc stderr='$err' image=$([ -e "$out/disk.img" ] && echo yes || echo no)"
|
|
fi
|
|
}
|
|
: > "$SCRATCH/notadir"
|
|
refused notadir "$SCRATCH/notadir" "is not a directory"
|
|
mkdir -p "$SCRATCH/sbin-ov/sbin"; printf 'x\n' > "$SCRATCH/sbin-ov/sbin/init"
|
|
refused sbin "$SCRATCH/sbin-ov" "not 'sbin'"
|
|
mkdir -p "$SCRATCH/init-ov"; printf 'x\n' > "$SCRATCH/init-ov/init"
|
|
refused init "$SCRATCH/init-ov" "not 'init'"
|
|
mkdir -p "$SCRATCH/link-ov/etc"; ln -s /etc/shadow "$SCRATCH/link-ov/etc/shadow"
|
|
refused link "$SCRATCH/link-ov" "holds symlinks"
|
|
mkdir -p "$SCRATCH/toplink-ov"; ln -s "$OV/etc" "$SCRATCH/toplink-ov/etc"
|
|
refused toplink "$SCRATCH/toplink-ov" "not 'etc'"
|
|
mkdir -p "$SCRATCH/dot-ov/etc"; printf 'x\n' > "$SCRATCH/dot-ov/.hidden"
|
|
refused dot "$SCRATCH/dot-ov" "not '.hidden'"
|
|
|
|
if [ "$FAIL" -ne 0 ]; then
|
|
echo "rootfs-overlay: FAILED"
|
|
exit 1
|
|
fi
|
|
echo "rootfs-overlay: all scenarios passed"
|