Files
bfe-core1106-sdk/qemu/tests/console-shell-test.sh
T
BFE EngineeringandClaude Opus 5.5 37037926df
ci / quality (push) Successful in 2m25s
ci / badges (push) Skipped
ci / mcdc (push) Successful in 29s
ci / prune-artifacts (push) Skipped
ci / test (push) Successful in 13s
ci / bench (push) Successful in 10s
ci / patches-apply (push) Successful in 24s
ci / kernel-build (push) Skipped
ci / mcdc (pull_request) Successful in 21s
ci / bench (pull_request) Successful in 17s
ci / test (pull_request) Successful in 14s
ci / prune-artifacts (pull_request) Skipped
ci / kernel-build (pull_request) Skipped
ci / qemu-tools (push) Successful in 4m32s
ci / kernel-symbols (push) Successful in 4m28s
ci / patches-apply (pull_request) Successful in 57s
ci / qemu-tools (pull_request) Successful in 3m8s
ci / kernel-symbols (pull_request) Successful in 6m42s
ci / quality (pull_request) Successful in 2m19s
ci / badges (pull_request) Skipped
qemu: build the panel's own BusyBox for the rig (flare-edge#2210)
The rig runs busybox.net's 1.31.0 multiarch binary, not the image's 1.37.0
with its applet config, so a script calling an applet or option the panel
lacks (#1903 setpriv --reuid, #2002 stat, #1349 flock -w) passes in the rig
and breaks on a panel.

- qemu/busybox/panel.config: the image's config, rebuilt from Buildroot
  2025.02.8 busybox.config plus 0001-busybox-applets.patch, resolved for
  1.37.0 as Buildroot does. patches/: Buildroot's 11 busybox patches.
  rig.fragment: static link and BusyBox's own passwd readers only.
  applets.txt and help.txt: the bench a capture (image 417a66b).
- qemu/build-busybox.sh: pinned 1.37.0 source, fails on any Kconfig rewrite
  of the config, an applet list other than the panel's, or a dynamic binary.
- qemu/lib.sh: RIG_BUSYBOX=panel selects it (default stays multiarch);
  the bounded verified download is now qemu_fetch_verified.
- warden.shell uses warden_console_shell: cttyhack where it exists, else
  setsid -c on the console tty (the panel's BusyBox has no cttyhack).
- CI: offline tests in qemu-tools, a build there checked against every
  applet's --help from the panel through qemu-user, and a second boot smoke
  with the panel initramfs in kernel-build.

Refs flare-edge#2210

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KerYPVh72hhNgKi3wS5ijG
2026-10-29 07:36:25 -06:00

79 lines
2.9 KiB
Bash

#!/usr/bin/env bash
# Offline test for warden_console_shell (qemu/rootfs/etc/warden-lib.sh), the
# warden.shell debug shell: with cttyhack it runs `setsid cttyhack sh` as
# before; without it (the panel's BusyBox, RIG_BUSYBOX=panel) it opens the
# console's tty from sysfs and runs `setsid -c sh` on it; with no tty it says
# so and runs a plain sh (flare-edge#2210). Stub commands record each call.
#
# bash qemu/tests/console-shell-test.sh (WARDEN_TEST_SH="busybox sh" for the rig's shell)
set -uo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
LIB="$HERE/../rootfs/etc/warden-lib.sh"
SH="${WARDEN_TEST_SH:-sh}"
WORK="$(mktemp -d "${TMPDIR:-/tmp}/console-shell.XXXXXX")" || exit 1
trap 'rm -rf "$WORK"' EXIT
FAIL=0
pass() { printf '[PASS] %s\n' "$1"; }
fail() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
# Stubs: setsid and sh record their argv and where stdin points.
mkdir -p "$WORK/bin" "$WORK/bin-ctty"
for c in setsid sh; do
# The single-quoted text is the stub's own source.
# shellcheck disable=SC2016
printf '#!/bin/sh\necho "%s $*" >> "$CALLS"\nreadlink /proc/self/fd/0 >> "$CALLS"\n' "$c" > "$WORK/bin/$c"
chmod 0755 "$WORK/bin/$c"
done
cp "$WORK/bin/setsid" "$WORK/bin/sh" "$WORK/bin-ctty/"
printf '#!/bin/sh\nexit 0\n' > "$WORK/bin-ctty/cttyhack"
chmod 0755 "$WORK/bin-ctty/cttyhack"
# run_case <stub dir> <console active file>: the calls the helper made.
# The helper runs with only the stub dir and the host's basic tools on PATH,
# so a host cttyhack (none expected) cannot leak in.
run_case() {
local calls="$WORK/calls.$RANDOM"
: > "$calls"
# $SH may carry arguments ("busybox sh"): split on purpose.
# shellcheck disable=SC2086
CALLS="$calls" WARDEN_CONSOLE_ACTIVE="$2" WARDEN_DEV_DIR=/dev \
$SH -c ". '$LIB'; PATH='$1':/usr/bin:/bin; warden_console_shell" < /dev/zero > "$WORK/out" 2>&1
cat "$calls"
}
printf 'tty1 null\n' > "$WORK/active"
got="$(run_case "$WORK/bin-ctty" "$WORK/active")"
if [ "$(head -n 1 <<<"$got")" = "setsid cttyhack sh" ]; then
pass "with cttyhack: setsid cttyhack sh"
else
fail "with cttyhack the helper ran: $got"
fi
got="$(run_case "$WORK/bin" "$WORK/active")"
if [ "$got" = "$(printf 'setsid -c sh\n/dev/null')" ]; then
pass "without cttyhack: setsid -c sh on the last console tty (/dev/null stand-in)"
else
fail "without cttyhack the helper ran: $got"
fi
got="$(run_case "$WORK/bin" "$WORK/no-such-active")"
if [ "$(head -n 1 <<<"$got")" = "sh " ] && grep -q 'no console tty found' "$WORK/out"; then
pass "no console tty: says so and runs a plain sh"
else
fail "with no console tty the helper ran: $got ($(cat "$WORK/out"))"
fi
printf 'ttyNOPE\n' > "$WORK/active-bad"
got="$(run_case "$WORK/bin" "$WORK/active-bad")"
if [ "$(head -n 1 <<<"$got")" = "sh " ]; then
pass "a console name with no device node: plain sh, no setsid -c"
else
fail "a missing tty node ran: $got"
fi
if [ "$FAIL" -ne 0 ]; then
echo "console-shell: FAILED"
exit 1
fi
echo "console-shell: all checks passed"