Compare commits
72
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1bb3b4436 | ||
|
|
9705273f92 | ||
|
|
81d609fed3 | ||
|
|
fc62400157 | ||
|
|
1e182a44e4 | ||
|
|
bbc91618f8 | ||
|
|
579ac260ca | ||
|
|
0232823855 | ||
|
|
61ecfac844 | ||
|
|
ff3d1de088 | ||
|
|
8fc32976a5 | ||
|
|
0c98a6018f | ||
|
|
820af4baaa | ||
|
|
37037926df | ||
|
|
4d30c3083b | ||
|
|
b4596ed737 | ||
|
|
4ff7c19537 | ||
|
|
a9f2b9b26a | ||
|
|
6e51f1a0e5 | ||
|
|
333c237949 | ||
|
|
f46a3519aa | ||
|
|
f04a31dc06 | ||
|
|
a4bbfbd83b | ||
|
|
7d5686e287 | ||
|
|
de1b973aa4 | ||
|
|
bd4eb5c201 | ||
|
|
eebfd23a96 | ||
|
|
06b86e68b4 | ||
|
|
9998182ef5 | ||
|
|
dd15eac1a8 | ||
|
|
eeb779b41b | ||
|
|
5494b87dc3 | ||
|
|
13cd0c63be | ||
|
|
d279bc4c9f | ||
|
|
44b96074ed | ||
|
|
b7be6f7fbe | ||
|
|
7d18896a0d | ||
|
|
b94fd156b4 | ||
|
|
f435a7d665 | ||
|
|
be4ad86230 | ||
|
|
aadf0e7f07 | ||
|
|
6f931bf3ad | ||
|
|
5507842878 | ||
|
|
35dc64714e | ||
|
|
cf72a6dcbc | ||
|
|
0589829619 | ||
|
|
8615f7c13a | ||
|
|
469f31c278 | ||
|
|
aa6956f595 | ||
|
|
445b2082f5 | ||
|
|
0360b8dc46 | ||
|
|
d22c900fb6 | ||
|
|
b7125fc4a7 | ||
|
|
35f3ca10eb | ||
|
|
8212bf5feb | ||
|
|
8c4870c6fb | ||
|
|
92d601f585 | ||
|
|
65a6800228 | ||
|
|
d01add5646 | ||
|
|
a828667b0f | ||
|
|
45569611da | ||
|
|
b18ed3888b | ||
|
|
d746ceba6d | ||
|
|
5f3db8453b | ||
|
|
85dc1ee04d | ||
|
|
6576a4a506 | ||
|
|
9b0659d30c | ||
|
|
317ae087fd | ||
|
|
07db1b9ec0 | ||
|
|
67da1141a0 | ||
|
|
5f36beb44a | ||
|
|
eb0691d84f |
+169
-1
@@ -111,7 +111,10 @@ jobs:
|
||||
shellcheck -x qemu/*.sh qemu/tests/*.sh build/*.sh \
|
||||
qemu/rootfs/etc/warden-lib.sh qemu/rootfs/etc/rc \
|
||||
qemu/rootfs/sbin/init qemu/rootfs/init tests/mk-bootimg/*.sh \
|
||||
tests/fetch-vendor/*.sh tests/fetch-buildroot-tarball/*.sh
|
||||
tests/fetch-vendor/*.sh tests/fetch-buildroot-tarball/*.sh \
|
||||
tests/fetch-kernel-tarball/*.sh tests/unpack-buildroot/*.sh
|
||||
- name: qemu init shellcheck regression test
|
||||
run: bash tests/qemu-init/run-init-shellcheck-tests.sh
|
||||
- name: cache apt archives (python3-pil)
|
||||
# Same cost class as the busybox binary cached below: a system package
|
||||
# plus its libjpeg/libpng transitive deps, downloaded fresh on every
|
||||
@@ -148,11 +151,72 @@ jobs:
|
||||
# on the debug channel. All offline (a stub qemu-system-arm on
|
||||
# PATH), so it runs on every push/PR, not only a real boot.
|
||||
run: bash qemu/tests/run-sh-args-test.sh
|
||||
- name: rig init honours reboot/poweroff/halt (#5)
|
||||
run: bash qemu/tests/init-power-signals-test.sh
|
||||
- name: rig init daemon order matches the panel (flare-edge#348)
|
||||
run: bash qemu/tests/init-daemon-order-test.sh
|
||||
- name: rig bus starts when the payload carries a broker (flare-edge#1754)
|
||||
# A stub broker stands in for mosquitto (the runner has none), and
|
||||
# once more under busybox sh, the rig's own shell.
|
||||
run: |
|
||||
bash qemu/tests/init-rig-bus-test.sh
|
||||
if command -v busybox >/dev/null; then
|
||||
WARDEN_TEST_SH="busybox sh" bash qemu/tests/init-rig-bus-test.sh
|
||||
fi
|
||||
- name: rig control bridge waits out a slow UI and reaches the test hook (flare-edge#1448, #2054)
|
||||
# Once more under busybox sh, the rig's own shell.
|
||||
run: |
|
||||
bash qemu/tests/ctl-bridge-test.sh
|
||||
if command -v busybox >/dev/null; then
|
||||
WARDEN_TEST_SH="busybox sh" bash qemu/tests/ctl-bridge-test.sh
|
||||
fi
|
||||
- name: rig agent runs framed scripts under a deadline (flare-edge M9 soak-lite)
|
||||
# warden_agent against request lines on stdin; once more under
|
||||
# busybox sh, the rig's own shell.
|
||||
run: |
|
||||
bash qemu/tests/agent-test.sh
|
||||
if command -v busybox >/dev/null; then
|
||||
WARDEN_TEST_SH="busybox sh" bash qemu/tests/agent-test.sh
|
||||
fi
|
||||
- name: rig init boots through the shipped init chain (flare-edge#2210)
|
||||
# warden_init_chain against stub scripts and the warden.initchain
|
||||
# wiring in sbin/init; once more under busybox sh, the rig's own shell.
|
||||
run: |
|
||||
bash qemu/tests/init-chain-test.sh
|
||||
if command -v busybox >/dev/null; then
|
||||
WARDEN_TEST_SH="busybox sh" bash qemu/tests/init-chain-test.sh
|
||||
fi
|
||||
- name: rig debug shell works without cttyhack (flare-edge#2210)
|
||||
# The panel's BusyBox has no cttyhack; warden.shell then opens the
|
||||
# console tty itself. Once more under busybox sh, the rig's own shell.
|
||||
run: |
|
||||
bash qemu/tests/console-shell-test.sh
|
||||
if command -v busybox >/dev/null; then
|
||||
WARDEN_TEST_SH="busybox sh" bash qemu/tests/console-shell-test.sh
|
||||
fi
|
||||
- name: panel BusyBox config and build helpers (flare-edge#2210)
|
||||
# panel.config carries the image's applet patch, the rig fragment only
|
||||
# changes linking, Kconfig rewrites and applet drift are caught: offline.
|
||||
run: bash qemu/tests/busybox-panel-test.sh
|
||||
- name: ui-drive.sh / ui-shot.sh UI start wait regression test (flare-edge#2295)
|
||||
# The console line that means "UI started" differs between a direct
|
||||
# start and a shipped init chain boot; every marker is checked
|
||||
# against sbin/init, and a chain failure fails at once.
|
||||
run: bash qemu/tests/ui-start-test.sh
|
||||
- name: mkimage.sh ROOTFS_OVERLAY regression test (flare-edge#2210)
|
||||
# The panel's scripts land in both slots with their modes; an overlay
|
||||
# reaching outside etc/ and usr/, or holding a symlink, writes no image.
|
||||
run: bash qemu/tests/rootfs-overlay.sh
|
||||
- name: mkimage.sh SEED_DIR regression test
|
||||
# Only ui-drive.sh --seed (a real VM boot) exercises this hook
|
||||
# otherwise; this builds the same unprivileged mkfs.ext4 image and
|
||||
# reads it back with debugfs, no VM needed.
|
||||
run: bash qemu/tests/seed-dir.sh
|
||||
- name: mkimage.sh PAYLOAD_DIR regression test (flare-edge#2054)
|
||||
# A run's own payload set (the hook set) lands in both slots, the
|
||||
# default still reads qemu/payload, and ui-drive.sh checks the same
|
||||
# directory; images read back with debugfs, no VM.
|
||||
run: bash qemu/tests/payload-dir.sh
|
||||
- name: qemu_stage_rootfs permission regression test
|
||||
# Git tracks only the executable bit, so a fresh checkout can land
|
||||
# the source etc/shadow world-readable under a permissive umask;
|
||||
@@ -166,6 +230,21 @@ jobs:
|
||||
# Retry-on-mismatch, cleanup, and the already-verified
|
||||
# short-circuit, against a fake curl on PATH: no network.
|
||||
run: bash tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh
|
||||
- name: fetch-kernel-tarball regression tests
|
||||
# Bounded curl and no partial tarball after a failed fetch (#1588),
|
||||
# against a fake curl on PATH: no network.
|
||||
run: bash tests/fetch-kernel-tarball/run-fetch-kernel-tarball-tests.sh
|
||||
- name: QEMU busybox fetch regression tests
|
||||
# Retry on a bad sha256, the cached copy, and a server that answers
|
||||
# and then stalls (#1588), against local listeners: no network.
|
||||
run: |
|
||||
bash qemu/tests/busybox-fetch.sh
|
||||
bash qemu/tests/busybox-source-mirror.sh
|
||||
- name: unpack-buildroot regression tests
|
||||
# Fresh unpack, leave-existing-tree-alone, and every refusal path
|
||||
# (unpatched selectors, bad tarball, half-present tree, failed
|
||||
# fetch), against a stub fetch script: no network (issue #4).
|
||||
run: bash tests/unpack-buildroot/run-unpack-buildroot-tests.sh
|
||||
- name: mk-bootimg boot.img validation regression tests
|
||||
# Guards issue #22 (a missing/erroring fdtget silently skipping the
|
||||
# data-position check) plus the FIT metadata and per-image
|
||||
@@ -190,6 +269,83 @@ jobs:
|
||||
run: bash qemu/mkinitramfs.sh
|
||||
- name: build A/B disk image
|
||||
run: bash qemu/mkimage.sh
|
||||
- name: cache panel BusyBox source
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: qemu/out/busybox-1.37.0.tar.bz2
|
||||
key: busybox-src-1.37.0
|
||||
- name: build the panel BusyBox and check it against the bench capture (flare-edge#2210)
|
||||
# The image's BusyBox version, applet config and Buildroot patches,
|
||||
# linked static (qemu/build-busybox.sh). Its applet list and every
|
||||
# applet's --help must equal the panel's own binary's (captured on
|
||||
# bench a), run here through qemu-user. Then an initramfs with it.
|
||||
run: |
|
||||
sudo apt-get install -y -qq gcc-arm-linux-gnueabihf qemu-user
|
||||
bash qemu/build-busybox.sh
|
||||
QEMU_USER="qemu-arm" bash qemu/tests/busybox-panel-help.sh
|
||||
RIG_BUSYBOX=panel bash qemu/mkinitramfs.sh
|
||||
# A job without the cross compiler takes the binary as BUSYBOX,
|
||||
# checked by its .inputs (flare-edge flow jobs).
|
||||
RIG_BUSYBOX=panel BUSYBOX=qemu/out/busybox-armv7l-panel bash qemu/mkinitramfs.sh
|
||||
|
||||
kernel-symbols:
|
||||
# The symbol gate (rebuild M0, kernel_symbols_exist): expand the real
|
||||
# configuration (pristine tarball + patch series + warden_defconfig) and
|
||||
# assert build/required-symbols.txt and probe-symbols.txt against the final
|
||||
# .config, without compiling. olddefconfig drops a symbol that does not exist
|
||||
# or whose dependencies are unmet without a word; this is what turns that
|
||||
# into a red check on every push, in seconds rather than the ~9 minutes of a
|
||||
# kernel build. The generic arm cross toolchain is enough: only the compiler
|
||||
# version text of the configuration depends on it.
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: offline symbol-list tests
|
||||
run: bash tests/required-symbols/run-required-symbols-tests.sh
|
||||
- name: install cross toolchain + kernel config deps
|
||||
run: |
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -y -qq gcc-arm-linux-gnueabihf bc bison flex libssl-dev
|
||||
- name: provision `python` (SDK quirk, the build calls bare python)
|
||||
run: |
|
||||
mkdir -p "$RUNNER_TEMP/bin"
|
||||
ln -sf "$(command -v python3)" "$RUNNER_TEMP/bin/python"
|
||||
echo "$RUNNER_TEMP/bin" >> "$GITHUB_PATH"
|
||||
- name: cache pristine kernel tarball
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/linux-6.18.46.tar.xz
|
||||
key: linux-6.18.46-tarball
|
||||
- name: expand the configuration and assert the symbols
|
||||
env:
|
||||
# WORK must be OUTSIDE the repo checkout (git apply, issue #1).
|
||||
WORK: ${{ runner.temp }}/kcfg-work
|
||||
CONFIG_OUT: ${{ runner.temp }}/final.config
|
||||
CROSS_COMPILE: arm-linux-gnueabihf-
|
||||
WARDEN_CONFIG_ONLY: "1"
|
||||
run: |
|
||||
export KERNEL_TARBALL="$HOME/linux-6.18.46.tar.xz"
|
||||
bash build/build-kernel.sh
|
||||
test -s "$CONFIG_OUT" && test -s "$CONFIG_OUT.sha256"
|
||||
# the sidecar is the sha256 of the file it sits beside
|
||||
test "$(sha256sum "$CONFIG_OUT" | cut -d' ' -f1)" = "$(cat "$CONFIG_OUT.sha256")"
|
||||
- name: the expansion is deterministic (same inputs, same digest)
|
||||
env:
|
||||
WORK: ${{ runner.temp }}/kcfg-work-2
|
||||
CONFIG_OUT: ${{ runner.temp }}/final-2.config
|
||||
CROSS_COMPILE: arm-linux-gnueabihf-
|
||||
WARDEN_CONFIG_ONLY: "1"
|
||||
run: |
|
||||
export KERNEL_TARBALL="$HOME/linux-6.18.46.tar.xz"
|
||||
bash build/build-kernel.sh
|
||||
cmp "${{ runner.temp }}/final.config" "$CONFIG_OUT"
|
||||
- name: the digest does not depend on the host python (issue #19)
|
||||
env:
|
||||
CROSS_COMPILE: arm-linux-gnueabihf-
|
||||
run: |
|
||||
export KERNEL_TARBALL="$HOME/linux-6.18.46.tar.xz"
|
||||
bash tests/required-symbols/run-config-determinism-tests.sh
|
||||
|
||||
patches-apply:
|
||||
# The RV1106 series must apply cleanly onto pristine linux-6.18.46.
|
||||
@@ -212,6 +368,13 @@ jobs:
|
||||
&& echo "applied $p" || { echo "FAILED to apply $p"; exit 1; }
|
||||
done
|
||||
echo "full series applied cleanly onto pristine 6.18.46"
|
||||
- name: arm32 vDSO stays off the virtual counter (bfe-core1106-sdk#35)
|
||||
# The kernel times on the physical counter and the firmware leaves
|
||||
# CNTVOFF non-zero, so the vDSO clock must stay off: the DT property and
|
||||
# the arm_arch_timer.c fallback both have to survive in the patched tree.
|
||||
run: |
|
||||
bash tests/arch-timer/run-check-vdso-counter-tests.sh
|
||||
python3 tests/arch-timer/check-vdso-counter.py /tmp/linux-6.18.46
|
||||
|
||||
# Automatic artifact GC (mirrors flare-edge). An exceeded account-wide Actions
|
||||
# storage quota blocks ALL new runs (startup_failure), not just uploads, so
|
||||
@@ -310,6 +473,11 @@ jobs:
|
||||
bash qemu/mkinitramfs.sh
|
||||
bash qemu/tests/boot-smoke.sh \
|
||||
"$RUNNER_TEMP/kbuild-out/linux-6.18.46/arch/arm/boot/zImage"
|
||||
# Once more with the panel's BusyBox (RIG_BUSYBOX=panel, flare-edge#2210).
|
||||
OUT="$RUNNER_TEMP/panel-rig" RIG_BUSYBOX=panel bash qemu/mkinitramfs.sh
|
||||
bash qemu/tests/boot-smoke.sh \
|
||||
"$RUNNER_TEMP/kbuild-out/linux-6.18.46/arch/arm/boot/zImage" \
|
||||
"$RUNNER_TEMP/panel-rig/initramfs.cpio.gz"
|
||||
# Best-effort: the build IS the gate. Uploading the zImage/dtb to GitHub
|
||||
# artifact storage can fail on an account-wide storage-quota hit (recalculated
|
||||
# every 6-12h) that has nothing to do with this build. Don't red-X a good
|
||||
|
||||
@@ -47,6 +47,13 @@ Add `WARDEN_KCONFIG_FRAGMENT=qemu/configs/virt.fragment` to step 1 for the
|
||||
kernel variant with the simulator's extra devices; `qemu/README.md` has the
|
||||
scenario tests (portal, OTA apply, display + touch, watchdog).
|
||||
|
||||
Every kernel symbol the platform needs is listed in `build/required-symbols.txt`
|
||||
(and `build/probe-symbols.txt` for a symbol under test). `build-kernel.sh` asserts
|
||||
both against the final `.config`, because `olddefconfig` drops an unknown or
|
||||
unsatisfied symbol without a word. `WARDEN_CONFIG_ONLY=1 CONFIG_OUT=<file>` stops
|
||||
after that assertion, so the gate takes seconds; `<file>.sha256` holds the digest
|
||||
of the final `.config` that firmware images record as `KCONFIG_SHA256`.
|
||||
|
||||
## Layout
|
||||
|
||||
| Directory | Contents |
|
||||
|
||||
@@ -19,6 +19,15 @@
|
||||
# (qemu/configs/virt.fragment builds the QEMU -M virt variant);
|
||||
# every fragment option is verified to have taken effect
|
||||
# WARDEN_CCACHE=1 compile through ccache (CI caches ~/.ccache)
|
||||
# WARDEN_CONFIG_ONLY=1
|
||||
# stop after the configuration and the symbol assertions
|
||||
# (no compile): a seconds-long symbol gate for CI and the
|
||||
# pre-build identity of /etc/warden-release. Needs CONFIG_OUT
|
||||
# or an explicit WORK, because a scratch WORK is removed.
|
||||
# CONFIG_OUT where the final .config is copied (default
|
||||
# $WORK/final.config); ${CONFIG_OUT}.sha256 gets its sha256
|
||||
# (hex only). Written by both modes: the config-only value
|
||||
# must equal the full build's, and the build checks it.
|
||||
# WARDEN_MODULES_COLLECT
|
||||
# space-separated in-tree dirs whose .ko files are wanted
|
||||
# (e.g. "drivers/net/wireless/aic8800"). Runs a full
|
||||
@@ -32,6 +41,10 @@ set -euo pipefail
|
||||
|
||||
KVER=6.18.46
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # build/
|
||||
# shellcheck source=build/lib-required-symbols.sh
|
||||
. "$HERE/lib-required-symbols.sh"
|
||||
REQ_SYMBOLS="$HERE/required-symbols.txt"
|
||||
PROBE_SYMBOLS="$HERE/probe-symbols.txt"
|
||||
REPO="$(cd "$HERE/.." && pwd)"
|
||||
PATCHES="$REPO/patches"
|
||||
JOBS="${JOBS:-$(nproc)}"
|
||||
@@ -48,6 +61,16 @@ else
|
||||
WORK_OWNED=1
|
||||
fi
|
||||
trap '[ "${WORK_OWNED:-0}" = 1 ] && rm -rf "$WORK"' EXIT
|
||||
CONFIG_ONLY="${WARDEN_CONFIG_ONLY:-0}"
|
||||
case "$CONFIG_ONLY" in
|
||||
0|1) ;;
|
||||
*) echo "FATAL: WARDEN_CONFIG_ONLY must be 0 or 1, got '$CONFIG_ONLY'" >&2; exit 1 ;;
|
||||
esac
|
||||
if [ "$CONFIG_ONLY" = 1 ] && [ "$WORK_OWNED" = 1 ] && [ -z "${CONFIG_OUT:-}" ]; then
|
||||
echo "FATAL: WARDEN_CONFIG_ONLY=1 needs CONFIG_OUT (or an explicit WORK): a scratch WORK is removed on exit" >&2
|
||||
exit 1
|
||||
fi
|
||||
CONFIG_OUT="${CONFIG_OUT:-$WORK/final.config}"
|
||||
|
||||
log() { printf '\033[36m== %s\033[0m\n' "$*"; }
|
||||
|
||||
@@ -121,6 +144,18 @@ command -v "${CROSS_COMPILE}gcc" >/dev/null \
|
||||
|| { echo "cross toolchain ${CROSS_COMPILE}gcc not on PATH (set SDK_TC, or CROSS_COMPILE to one that is)" >&2; exit 1; }
|
||||
make -C "$SRC" ARCH=arm CROSS_COMPILE="$CROSS_COMPILE" olddefconfig >/dev/null
|
||||
|
||||
# Took-effect assertion for every symbol the platform needs. olddefconfig drops
|
||||
# a defconfig line whose dependencies are unmet, or whose symbol does not exist,
|
||||
# without a word: flare-edge#533 shipped a firewall that quietly stopped
|
||||
# covering IPv6 that way. build/required-symbols.txt (and build/probe-symbols.txt
|
||||
# for a probe kernel) is the one list; every symbol in it is built in (=y, the
|
||||
# panel has no /lib/modules) or explicitly unset.
|
||||
# The probe list may be empty (every probe has passed); the required list may not.
|
||||
PROBE_LISTS=()
|
||||
[ -n "$(req_assertions "$PROBE_SYMBOLS")" ] && PROBE_LISTS=("$PROBE_SYMBOLS")
|
||||
req_assert_config "$SRC/.config" "$REQ_SYMBOLS" ${PROBE_LISTS[@]+"${PROBE_LISTS[@]}"} || exit 1
|
||||
log "required symbols verified in final .config ($(req_assertions "$REQ_SYMBOLS" | wc -l) required, $(req_assertions "$PROBE_SYMBOLS" | wc -l) probe)"
|
||||
|
||||
# Fragment took-effect assertion: merge_config -m only pastes text, and
|
||||
# olddefconfig silently resolves any symbol whose dependencies are unmet:
|
||||
# a fragment option could be dropped without a word. Verify every explicit
|
||||
@@ -151,6 +186,21 @@ if [ -n "${WARDEN_KCONFIG_FRAGMENT:-}" ]; then
|
||||
log "fragment options verified in final .config"
|
||||
fi
|
||||
|
||||
# The final .config, and its identity. KCONFIG_SHA256 in /etc/warden-release is
|
||||
# this digest (the whole file, compiler version text included): CONFIG_IKCONFIG_PROC
|
||||
# embeds a byte copy, so /proc/config.gz hashes to the same value.
|
||||
emit_config_identity() {
|
||||
mkdir -p "$(dirname "$CONFIG_OUT")"
|
||||
cp "$SRC/.config" "$CONFIG_OUT"
|
||||
sha256sum "$CONFIG_OUT" | awk '{print $1}' > "$CONFIG_OUT.sha256"
|
||||
echo "final.config sha256: $(cat "$CONFIG_OUT.sha256")"
|
||||
}
|
||||
if [ "$CONFIG_ONLY" = 1 ]; then
|
||||
emit_config_identity
|
||||
log "config-only: symbols verified, stopping before the compile"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Optional ccache (CI: cache ~/.ccache across dispatches; harmless if unset).
|
||||
KCC="${CROSS_COMPILE}gcc"
|
||||
if [ "${WARDEN_CCACHE:-0}" = 1 ]; then
|
||||
@@ -185,6 +235,9 @@ if [ -n "${WARDEN_MODULES_COLLECT:-}" ]; then
|
||||
ls -la "$MODOUT"
|
||||
fi
|
||||
|
||||
# Identity of the .config the compile actually used, not the one before it.
|
||||
emit_config_identity
|
||||
|
||||
Z="$SRC/arch/arm/boot/zImage"
|
||||
D="$SRC/arch/arm/boot/dts/rockchip/rv1106-warden.dtb"
|
||||
log "build OK"
|
||||
|
||||
@@ -12,13 +12,9 @@
|
||||
# Same shape as fetch-kernel-tarball.sh, deliberately: a version bump edits this
|
||||
# file and the pin beside it, nothing else. FAILS CLOSED on a missing pin.
|
||||
#
|
||||
# Not wired into build-firmware.sh or CI yet -- tools/build-firmware.sh stages
|
||||
# sdk-patches/buildroot/ onto whatever buildroot tree the vendor SDK already
|
||||
# has, it does not yet extract this pinned tarball over it. Exercised today by
|
||||
# tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh and by
|
||||
# running the script by hand; wiring it into the real build path is a separate
|
||||
# change (it has to reconcile the pristine tree with the existing SDK buildroot
|
||||
# checkout first).
|
||||
# Called by build/unpack-buildroot.sh, which flare-edge's
|
||||
# tools/build-firmware.sh runs after applying luckfox-sdk-patches/ (issue #4).
|
||||
# Tested by tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh.
|
||||
#
|
||||
# Usage: fetch-buildroot-tarball.sh <destination-path>
|
||||
set -euo pipefail
|
||||
|
||||
@@ -22,7 +22,16 @@ TB="${1:?usage: fetch-kernel-tarball.sh <destination-path>}"
|
||||
}
|
||||
if [ ! -f "$TB" ]; then
|
||||
echo "== downloading $URL"
|
||||
curl --retry 3 --retry-delay 5 --retry-connrefused -fSL "$URL" -o "$TB"
|
||||
# Bounded (#1588): a connection that opens and then stalls gives up after
|
||||
# 30 s below 10 KiB/s and is retried, instead of holding the job until its
|
||||
# own timeout. The download lands beside $TB and is renamed only when curl
|
||||
# succeeds, so a failed fetch never leaves a partial tarball that the next
|
||||
# run would take as present and then reject on its sha256.
|
||||
tmp="$TB.download.$$"
|
||||
trap 'rm -f "$tmp"' EXIT
|
||||
curl --retry 2 --retry-delay 5 --retry-connrefused --connect-timeout 20 \
|
||||
--speed-limit 10240 --speed-time 30 --max-time 600 -fSL "$URL" -o "$tmp"
|
||||
mv -f "$tmp" "$TB"
|
||||
fi
|
||||
want="$(cat "$SHA_FILE")"
|
||||
got="$(sha256sum "$TB" | awk '{print $1}')"
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# shellcheck shell=bash
|
||||
# Shared by build-kernel.sh and the symbol tests (tests/required-symbols/).
|
||||
#
|
||||
# build/required-symbols.txt is the source of record for every kernel symbol
|
||||
# the platform needs (rebuild M0, names.md 21.1). Format, one item per line:
|
||||
#
|
||||
# CONFIG_X=y assert the symbol is =y in the final .config
|
||||
# # CONFIG_X is not set assert the symbol is NOT set (an explicit unset)
|
||||
# ## tier R section header (R required, C recommended,
|
||||
# A assertion only / derived, never in a defconfig)
|
||||
# # any other text comment
|
||||
# (blank lines ignored)
|
||||
#
|
||||
# build/probe-symbols.txt has the same format for tier P: symbols built into
|
||||
# the test kernel to run a probe. They are asserted like the others, and join
|
||||
# required-symbols.txt only when the probe passes.
|
||||
|
||||
# req_assertions FILE: print the assertion lines of FILE.
|
||||
req_assertions() {
|
||||
grep -E '^(CONFIG_[A-Za-z0-9_]+=[ymn]|# CONFIG_[A-Za-z0-9_]+ is not set)$' "$1" || true
|
||||
}
|
||||
|
||||
# req_assert_config CONFIG LIST...: check each assertion of each LIST against
|
||||
# CONFIG (a final .config). Prints one FATAL line per failure and returns 1 if
|
||||
# any failed. A missing or empty LIST is itself a failure (fail closed).
|
||||
req_assert_config() {
|
||||
local cfg="$1" list line opt n bad=0
|
||||
shift
|
||||
[ -s "$cfg" ] || { echo "FATAL: config '$cfg' is missing or empty" >&2; return 1; }
|
||||
for list in "$@"; do
|
||||
[ -f "$list" ] || { echo "FATAL: symbol list '$list' is missing" >&2; return 1; }
|
||||
n=0
|
||||
while IFS= read -r line; do
|
||||
n=$((n + 1))
|
||||
case "$line" in
|
||||
CONFIG_*=*)
|
||||
grep -qxF "$line" "$cfg" || {
|
||||
echo "FATAL: required option $line is not in the final .config (unmet Kconfig dependency, or the symbol does not exist?)" >&2
|
||||
bad=1
|
||||
} ;;
|
||||
"# CONFIG_"*" is not set")
|
||||
# An unset holds if the symbol is absent or shown as "is not set";
|
||||
# only a live =value fails (a dependency may hide the symbol).
|
||||
opt="${line#\# }"; opt="${opt% is not set}"
|
||||
grep -qE "^$opt=" "$cfg" && {
|
||||
echo "FATAL: option $opt must not be set but is in the final .config" >&2
|
||||
bad=1
|
||||
} ;;
|
||||
esac
|
||||
done < <(req_assertions "$list")
|
||||
[ "$n" -gt 0 ] || { echo "FATAL: symbol list '$list' holds no assertions" >&2; return 1; }
|
||||
done
|
||||
return "$bad"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
## Tier P: symbols built into a test kernel to run a probe (rebuild M0).
|
||||
## Asserted like required-symbols.txt. A symbol moves to required-symbols.txt when its probe
|
||||
## passes on the panel, and leaves this file and the defconfig when it fails.
|
||||
##
|
||||
## Empty on purpose: probe V3 (hardware RNG, N-36, d06 O14, d09 T14) passed on 2026-10-09, so
|
||||
## CONFIG_HW_RANDOM and CONFIG_HW_RANDOM_ROCKCHIP moved to required-symbols.txt. An empty list
|
||||
## is valid for this file (build-kernel.sh skips it); required-symbols.txt may never be empty.
|
||||
@@ -0,0 +1,83 @@
|
||||
## Kernel symbols the platform needs. Source of record (rebuild M0, names.md
|
||||
## 21.1): build-kernel.sh asserts every line against the final .config, the
|
||||
## tests/required-symbols guards read this file, and the FE kernel_symbols_exist
|
||||
## gate checks every CONFIG_ name in the specs against it and the Kconfig tree.
|
||||
## Format: see build/lib-required-symbols.sh. Tier P lives in probe-symbols.txt.
|
||||
##
|
||||
## tier R already shipped (flare-edge#533)
|
||||
CONFIG_NF_DEFRAG_IPV6=y
|
||||
CONFIG_IP6_NF_IPTABLES=y
|
||||
CONFIG_IP6_NF_IPTABLES_LEGACY=y
|
||||
CONFIG_IP6_NF_FILTER=y
|
||||
##
|
||||
## tier R cgroup v2 controllers (W-D7)
|
||||
CONFIG_MEMCG=y
|
||||
CONFIG_CGROUP_PIDS=y
|
||||
CONFIG_CGROUP_SCHED=y
|
||||
CONFIG_FAIR_GROUP_SCHED=y
|
||||
CONFIG_CFS_BANDWIDTH=y
|
||||
##
|
||||
## tier R byte metering (D50 D51 D52)
|
||||
CONFIG_NETFILTER_XT_MATCH_CGROUP=y
|
||||
CONFIG_NETFILTER_XT_CONNMARK=y
|
||||
CONFIG_NETFILTER_XT_MARK=y
|
||||
CONFIG_IP6_NF_MANGLE=y
|
||||
##
|
||||
## tier R /proc/config.gz (D51)
|
||||
CONFIG_IKCONFIG=y
|
||||
CONFIG_IKCONFIG_PROC=y
|
||||
##
|
||||
## tier R uid fallback and NOTRACK (SCH-04, flare-edge#537)
|
||||
CONFIG_NETFILTER_XT_MATCH_OWNER=y
|
||||
CONFIG_IP_NF_RAW=y
|
||||
CONFIG_IP6_NF_RAW=y
|
||||
CONFIG_NETFILTER_XT_TARGET_CT=y
|
||||
##
|
||||
## tier R namespaces and PSI (SCH-04, NN-11)
|
||||
CONFIG_NAMESPACES=y
|
||||
CONFIG_UTS_NS=y
|
||||
CONFIG_IPC_NS=y
|
||||
CONFIG_PID_NS=y
|
||||
CONFIG_NET_NS=y
|
||||
CONFIG_USER_NS=y
|
||||
CONFIG_PSI=y
|
||||
##
|
||||
## tier R nftables (N-40)
|
||||
CONFIG_NF_TABLES=y
|
||||
CONFIG_NF_TABLES_IPV4=y
|
||||
CONFIG_NF_TABLES_IPV6=y
|
||||
CONFIG_NFT_CT=y
|
||||
CONFIG_NFT_MASQ=y
|
||||
CONFIG_NFT_NAT=y
|
||||
CONFIG_NFT_LIMIT=y
|
||||
CONFIG_NFT_SOCKET=y
|
||||
CONFIG_NFT_REJECT=y
|
||||
##
|
||||
## tier R hardware RNG (N-36, d06 O14). Probe V3 passed on the bench panel on 2026-10-09
|
||||
## (/dev/hwrng from rockchip-rng, 2.6 MB read in 2.4 s, 1 FIPS 140-2 failure in 1000 blocks), so
|
||||
## the two symbols moved here from probe-symbols.txt.
|
||||
CONFIG_HW_RANDOM=y
|
||||
CONFIG_HW_RANDOM_ROCKCHIP=y
|
||||
##
|
||||
## tier A power: no suspend (Noah 2026-10-09). The two lines below are derived
|
||||
## off with it; assert them so a Kconfig change cannot bring them back.
|
||||
# CONFIG_SUSPEND is not set
|
||||
# CONFIG_PM_SLEEP is not set
|
||||
##
|
||||
## tier C recommended
|
||||
CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=y
|
||||
CONFIG_NF_CONNTRACK_PROCFS=y
|
||||
##
|
||||
## tier A assertion only (a defconfig line is optional)
|
||||
CONFIG_SECCOMP=y
|
||||
CONFIG_SECCOMP_FILTER=y
|
||||
CONFIG_MULTIUSER=y
|
||||
CONFIG_SYSVIPC=y
|
||||
# CONFIG_RT_GROUP_SCHED is not set
|
||||
# CONFIG_TIME_NS is not set
|
||||
##
|
||||
## tier A derived (selected or defaulted by other symbols; never in a defconfig)
|
||||
CONFIG_NF_CONNTRACK_MARK=y
|
||||
CONFIG_SOCK_CGROUP_DATA=y
|
||||
CONFIG_NFT_REJECT_IPV4=y
|
||||
CONFIG_NFT_REJECT_IPV6=y
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env bash
|
||||
# Unpack the pinned Buildroot tree where the vendor SDK builds it.
|
||||
#
|
||||
# The vendor SDK ships buildroot-2023.02.6. WardenOS builds against
|
||||
# buildroot-2025.02.8, which is not in the vendor checkout, so a clean checkout
|
||||
# plus luckfox-sdk-patches/ had nothing to build (blueflare/bfe-core1106-sdk#4).
|
||||
# This script closes that gap: it fetches the tarball with
|
||||
# fetch-buildroot-tarball.sh (sha256-pinned, fails closed) and unpacks it to
|
||||
# sysdrv/source/buildroot/buildroot-<ver>, the path the patched project/build.sh
|
||||
# and sysdrv/Makefile select.
|
||||
#
|
||||
# Idempotent. An SDK that already has the tree is left alone, so the
|
||||
# persistent CI SDK and the workstation SDK are untouched. A partial unpack
|
||||
# never lands at the final path: the tarball is unpacked into a scratch
|
||||
# directory beside it and moved into place only when complete.
|
||||
#
|
||||
# Our own Buildroot delta (defconfigs, package patches, the busybox applet
|
||||
# patch) is NOT applied here. flare-edge's tools/build-firmware.sh stages it
|
||||
# after this script runs, the same way it applies the rest of the series.
|
||||
#
|
||||
# Usage: unpack-buildroot.sh <vendor-sdk-dir>
|
||||
#
|
||||
# The tarball is cached at sysdrv/source/buildroot/buildroot-<ver>.tar.xz
|
||||
# (inside a directory the vendor .gitignore already ignores); set
|
||||
# WARDEN_BUILDROOT_TARBALL to use another path.
|
||||
set -euo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # build/
|
||||
FETCH="$HERE/fetch-buildroot-tarball.sh"
|
||||
SDK="${1:?usage: unpack-buildroot.sh <vendor-sdk-dir>}"
|
||||
|
||||
die() { echo "unpack-buildroot: FATAL: $*" >&2; exit 1; }
|
||||
|
||||
[ -f "$FETCH" ] || die "missing $FETCH"
|
||||
BRVER="$(sed -n 's/^BRVER=//p' "$FETCH" | head -1)"
|
||||
case "$BRVER" in
|
||||
''|*[!0-9.]*) die "cannot read BRVER from $FETCH" ;;
|
||||
esac
|
||||
|
||||
# The SDK must already select this version. Both selectors come from
|
||||
# luckfox-sdk-patches/board/ (0006 for project/build.sh, 0009 for
|
||||
# sysdrv/Makefile); if either still names another tree the series has not
|
||||
# been applied, and unpacking would only hide that.
|
||||
BUILD_SH="$SDK/project/build.sh"
|
||||
MAKEFILE="$SDK/sysdrv/Makefile"
|
||||
[ -f "$BUILD_SH" ] || die "no vendor SDK at $SDK (missing project/build.sh)"
|
||||
[ -f "$MAKEFILE" ] || die "no vendor SDK at $SDK (missing sysdrv/Makefile)"
|
||||
# shellcheck disable=SC2016 # the literal ${SDK_SYSDRV_DIR} text in build.sh
|
||||
sel_build="$(sed -n 's|^BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/||p' "$BUILD_SH" | head -1)"
|
||||
sel_make="$(sed -n 's/^BUILDROOT_VER[[:space:]]*?=[[:space:]]*//p' "$MAKEFILE" | head -1)"
|
||||
[ "$sel_build" = "buildroot-$BRVER" ] ||
|
||||
die "project/build.sh selects '${sel_build:-nothing}', not buildroot-$BRVER (apply luckfox-sdk-patches/board first)"
|
||||
[ "$sel_make" = "buildroot-$BRVER" ] ||
|
||||
die "sysdrv/Makefile selects '${sel_make:-nothing}', not buildroot-$BRVER (apply luckfox-sdk-patches/board first)"
|
||||
|
||||
PARENT="$SDK/sysdrv/source/buildroot"
|
||||
TREE="$PARENT/buildroot-$BRVER"
|
||||
TB="${WARDEN_BUILDROOT_TARBALL:-$PARENT/buildroot-$BRVER.tar.xz}"
|
||||
|
||||
if [ -f "$TREE/Makefile" ] && [ -d "$TREE/configs" ] && [ -d "$TREE/package" ]; then
|
||||
echo "buildroot-$BRVER: tree already present at ${TREE#"$SDK"/}"
|
||||
exit 0
|
||||
fi
|
||||
# Something is at the path but it is not a Buildroot tree. Deleting it here
|
||||
# could destroy build output in a shared SDK, so say so and stop.
|
||||
[ ! -e "$TREE" ] || die "$TREE exists but is not a complete Buildroot tree; remove it and rerun"
|
||||
|
||||
mkdir -p "$PARENT"
|
||||
bash "$FETCH" "$TB"
|
||||
|
||||
SCRATCH="$(mktemp -d "$PARENT/.unpack-buildroot.XXXXXX")"
|
||||
[ -d "$SCRATCH" ] || die "mktemp failed under $PARENT"
|
||||
cleanup() { rm -rf "$SCRATCH"; }
|
||||
trap cleanup EXIT
|
||||
|
||||
echo "== unpacking buildroot-$BRVER into ${TREE#"$SDK"/}"
|
||||
tar -xJf "$TB" -C "$SCRATCH"
|
||||
[ -f "$SCRATCH/buildroot-$BRVER/Makefile" ] ||
|
||||
die "tarball did not contain buildroot-$BRVER/Makefile"
|
||||
mv "$SCRATCH/buildroot-$BRVER" "$TREE"
|
||||
echo "buildroot-$BRVER: unpacked"
|
||||
@@ -17,7 +17,8 @@
|
||||
# release tarball has no commit to name:
|
||||
#
|
||||
# linux-6.18.46 build/fetch-kernel-tarball.sh
|
||||
# buildroot-2025.02.8 build/fetch-buildroot-tarball.sh
|
||||
# buildroot-2025.02.8 build/fetch-buildroot-tarball.sh (unpacked into the
|
||||
# vendor SDK by build/unpack-buildroot.sh)
|
||||
#
|
||||
# The buildroot one matters more than it looks. The firmware builds against
|
||||
# sysdrv/source/buildroot/buildroot-2025.02.8 inside the vendor SDK, and the
|
||||
|
||||
@@ -1372,3 +1372,124 @@ CONFIG_IP_NF_FILTER=y
|
||||
CONFIG_IP_NF_TARGET_REJECT=y
|
||||
CONFIG_IP_NF_NAT=y
|
||||
CONFIG_IP_NF_MANGLE=y
|
||||
#
|
||||
# IPv6 netfilter (flare-edge#533). Without it ip6tables has no filter table
|
||||
# ("Table does not exist"), so the IPv4 default-drop INPUT policy in
|
||||
# S35iptables never applied to IPv6 and every listener bound to :: (dropbear,
|
||||
# telnetd, the web UI) was reachable over IPv6. Four symbols, all built in
|
||||
# because the panel has no /lib/modules:
|
||||
# IP6_NF_IPTABLES + IP6_NF_IPTABLES_LEGACY the ip6tables core, legacy
|
||||
# flavour (the userland is legacy)
|
||||
# IP6_NF_FILTER the filter table; it defaults to
|
||||
# =m under legacy, so =y is explicit
|
||||
# NF_DEFRAG_IPV6 IPv6 reassembly for conntrack, so
|
||||
# the state/conntrack matches work
|
||||
# (NF_CONNTRACK selects it when
|
||||
# IPV6 is on; listed so the set is
|
||||
# visible and guarded)
|
||||
# No new match symbols: the icmp6 match is part of the ip6_tables core
|
||||
# (IP6_NF_IPTABLES); tcp/udp matches are in xt_tcpudp, always built with
|
||||
# XTABLES; state, limit and conntrack are the family-agnostic matches enabled
|
||||
# above.
|
||||
CONFIG_NF_DEFRAG_IPV6=y
|
||||
CONFIG_IP6_NF_IPTABLES=y
|
||||
CONFIG_IP6_NF_IPTABLES_LEGACY=y
|
||||
CONFIG_IP6_NF_FILTER=y
|
||||
#
|
||||
# Cgroup v2 controllers, byte metering, raw table, namespaces and PSI
|
||||
# (rebuild M0; D50 D51 D52 W-D7 SCH-04 N-40 NN-11). The single kernel flash:
|
||||
# every option later work needs, so no second t2 update reaches a panel.
|
||||
# build/required-symbols.txt is the source of record and build-kernel.sh
|
||||
# asserts every line of it against the final .config. All built in: the panel
|
||||
# has no /lib/modules.
|
||||
#
|
||||
# Per-app limits (W-D7): memory.max / memory.events / memory.oom.group,
|
||||
# pids.max, cpu.weight and the cpu.max hard cap.
|
||||
CONFIG_MEMCG=y
|
||||
CONFIG_CGROUP_PIDS=y
|
||||
CONFIG_CGROUP_SCHED=y
|
||||
CONFIG_FAIR_GROUP_SCHED=y
|
||||
CONFIG_CFS_BANDWIDTH=y
|
||||
# RT group scheduling would block the v2 cpu controller; it must stay off.
|
||||
# CONFIG_RT_GROUP_SCHED is not set
|
||||
#
|
||||
# Byte metering by cgroup (D50 D51 D52): the cgroup match, CONNMARK so inbound
|
||||
# replies inherit the service, the mark match, and the ip6tables mangle table
|
||||
# (it defaults to =m under legacy). The meter itself is nftables since N-40.
|
||||
CONFIG_NETFILTER_XT_MATCH_CGROUP=y
|
||||
CONFIG_NETFILTER_XT_CONNMARK=y
|
||||
CONFIG_NETFILTER_XT_MARK=y
|
||||
CONFIG_IP6_NF_MANGLE=y
|
||||
#
|
||||
# /proc/config.gz (D51). IKCONFIG is a tristate: it must be =y, no module tree.
|
||||
# The whole .config digest (KCONFIG_SHA256 in /etc/warden-release) equals the
|
||||
# sha256 of the decompressed embed.
|
||||
CONFIG_IKCONFIG=y
|
||||
CONFIG_IKCONFIG_PROC=y
|
||||
#
|
||||
# Uid fallback metering (SCH-04), and the raw table with the CT target for the
|
||||
# NOTRACK of the discovery sweep (flare-edge#537). The legacy tables stay for
|
||||
# that interim and for any legacy tool in the image.
|
||||
CONFIG_NETFILTER_XT_MATCH_OWNER=y
|
||||
CONFIG_IP_NF_RAW=y
|
||||
CONFIG_IP6_NF_RAW=y
|
||||
CONFIG_NETFILTER_XT_TARGET_CT=y
|
||||
#
|
||||
# Cheap rule helpers. CONNTRACK_PROCFS keeps /proc/net/nf_conntrack so the
|
||||
# cause of #537 and its fix can be proven (C14).
|
||||
CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=y
|
||||
CONFIG_NF_CONNTRACK_PROCFS=y
|
||||
#
|
||||
# Namespaces for future app sandboxing (SCH-04, NN-11): NAMESPACES is a prompt
|
||||
# only under EXPERT and defaults off there, so it needs this line. All five
|
||||
# sub-options are set; USER_NS stays closed at runtime by
|
||||
# user.max_user_namespaces=0 (S02warden-sysctl) until the app sandbox needs it.
|
||||
# TIME_NS defaults on, so it is unset explicitly.
|
||||
CONFIG_NAMESPACES=y
|
||||
CONFIG_UTS_NS=y
|
||||
CONFIG_IPC_NS=y
|
||||
CONFIG_PID_NS=y
|
||||
CONFIG_NET_NS=y
|
||||
CONFIG_USER_NS=y
|
||||
# CONFIG_TIME_NS is not set
|
||||
#
|
||||
# Pressure stall information (SCH-04): /proc/pressure/* and per-cgroup
|
||||
# cpu.pressure and memory.pressure. On at boot (PSI_DEFAULT_DISABLED stays off).
|
||||
CONFIG_PSI=y
|
||||
#
|
||||
# nftables (N-40): the applier and the meter target nft in the families ip and
|
||||
# ip6. Counters, meta, payload, sets and jump are nf_tables core; there is no
|
||||
# NFT_COUNTER symbol. NFT_REJECT_IPV4 and NFT_REJECT_IPV6 have no prompt and
|
||||
# derive from NFT_REJECT, so they are asserted in required-symbols.txt and
|
||||
# never set here (a line for a promptless symbol is dropped).
|
||||
CONFIG_NF_TABLES=y
|
||||
CONFIG_NF_TABLES_IPV4=y
|
||||
CONFIG_NF_TABLES_IPV6=y
|
||||
CONFIG_NFT_CT=y
|
||||
CONFIG_NFT_MASQ=y
|
||||
CONFIG_NFT_NAT=y
|
||||
CONFIG_NFT_LIMIT=y
|
||||
CONFIG_NFT_SOCKET=y
|
||||
CONFIG_NFT_REJECT=y
|
||||
#
|
||||
# No suspend (rebuild M0, Noah 2026-10-09): the panel is wall powered and never
|
||||
# sleeps the SoC, and nothing in the product wakes it. Turning SUSPEND off lets
|
||||
# Kconfig drop everything that existed only for it: PM_SLEEP and PM_SLEEP_SMP,
|
||||
# SUSPEND_FREEZER and FREEZER, PM_GENERIC_DOMAINS_SLEEP, FW_CACHE (firmware
|
||||
# cached across a suspend) and VT_CONSOLE_SLEEP. PM_SLEEP_SMP was also the only
|
||||
# thing selecting HOTPLUG_CPU on this one-core SoC, and an SMP ARM kernel offers
|
||||
# KEXEC and CRASH_DUMP only with it, so those go too (nothing uses them: the
|
||||
# kexec flash path was a 5.10 experiment). PM, PM_CLK, runtime PM and
|
||||
# ARM_CPU_SUSPEND (kept by ARM_PSCI_FW) stay, because the USB, DRM and Wi-Fi
|
||||
# drivers use runtime PM. Hibernation was already off. The AIC8800 driver must
|
||||
# keep building and loading; the SDK build and the slot test prove it.
|
||||
# CONFIG_SUSPEND is not set
|
||||
# PM_SLEEP has no prompt and follows SUSPEND; the line records the expected result, and
|
||||
# required-symbols.txt asserts it against the final .config.
|
||||
# CONFIG_PM_SLEEP is not set
|
||||
#
|
||||
# Probe tier (N-36, d06 O14, probe V3): the Rockchip hardware RNG, built into
|
||||
# the test kernel. build/probe-symbols.txt lists it; it moves to
|
||||
# required-symbols.txt only if V3 passes on the panel, and comes out of this
|
||||
# file if it fails.
|
||||
CONFIG_HW_RANDOM_ROCKCHIP=y
|
||||
|
||||
@@ -82,7 +82,7 @@ tiered:
|
||||
behind a small injectable seam, mock its world, build
|
||||
`-fcondition-coverage`, enforce via the shared `drivers/enforce-mcdc.sh`
|
||||
(gcc-14 `gcov --conditions`) in the CI `mcdc` job (the proven flare-edge
|
||||
`tests/uboot-ab` method). **Done:** `relays.c` (40/40 conditions) and
|
||||
`tests/uboot-ab` method). **Done:** `relays.c` (50/50 conditions) and
|
||||
`freshness.c` (66/66). **Next in:** the modbus master and the RGA
|
||||
dispatch, with the ADR-0005 unification (`drivers/README.md`).
|
||||
- **Tier 2, near-mainline small drivers -> branch coverage + fault
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ execute code on private infrastructure (ADR-0007).
|
||||
| `mcdc` | ubuntu-latest | 100% MC/DC enforced on every `drivers/*/test` (gcc-14 `-fcondition-coverage`). |
|
||||
| `bench` | ubuntu-latest | Smoke-runs the sim + rs485-bridge micro-benchmarks; emits ns/op trend JSON. |
|
||||
| `patches-apply` | ubuntu-latest | Fetches pristine linux-6.18.46 (cached, sha256-verified) and applies `patches/*` in order. |
|
||||
| `qemu-tools` | ubuntu-latest | shellcheck on `qemu/**.sh`, `tests/mk-bootimg/*.sh`, `tests/fetch-vendor/*.sh`, `tests/fetch-buildroot-tarball/*.sh`; runs the offline regression tests for the mk-bootimg probe, boot.img validation, run.sh argv ordering, mkimage's SEED_DIR hook, staged rootfs permissions, fetch-vendor, fetch-buildroot-tarball, and its own CI wiring; builds the initramfs (pinned busybox) and the A/B disk image. |
|
||||
| `qemu-tools` | ubuntu-latest | shellcheck on `qemu/**.sh`, `tests/mk-bootimg/*.sh`, `tests/fetch-vendor/*.sh`, `tests/fetch-buildroot-tarball/*.sh`, `tests/unpack-buildroot/*.sh`; runs the offline regression tests for the mk-bootimg probe, boot.img validation, run.sh argv ordering, mkimage's SEED_DIR hook, staged rootfs permissions, fetch-vendor, fetch-buildroot-tarball, unpack-buildroot, and its own CI wiring; builds the initramfs (pinned busybox) and the A/B disk image. |
|
||||
| `quality` | ubuntu-latest | Codacy-style grade computed in-pipeline: clippy, cppcheck, shellcheck, ruff, lizard, jscpd, cargo-audit feed `tools/quality/score.py` (SQALE debt ratio + a separate worst-of security axis; SonarQube's published thresholds). Uploads `quality.json`; fails if the security grade is worse than C. |
|
||||
| `kernel-build` | ubuntu-latest, **dispatch-only** | apt-installs the cross toolchain + qemu, `build/build-kernel.sh` -> `zImage` + `rv1106-warden.dtb`, QEMU `-M virt` boot smoke (fail-closed), artifact upload (best-effort). Trigger: `gh workflow run ci.yml`. |
|
||||
| `prune-artifacts` | ubuntu-latest, dispatch-only | Deletes `kernel-rv1106` artifacts beyond the newest 3. |
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
|
||||
> **Outcome tested:** A relay is exported transparently and driven without disturbing a held contact.
|
||||
|
||||
**Coverage**: relays.c: 40/40 conditions, 100% MC/DC (CI-enforced)
|
||||
**Coverage**: relays.c: 50/50 conditions, 100% MC/DC (CI-enforced)
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
A[warden_relay_set idx,on] --> B{idx < COUNT?}
|
||||
B -- no --> Z[no-op]
|
||||
B -- yes --> C{exported?}
|
||||
B -- yes --> P{all sysfs paths fit PATH_MAX?}
|
||||
P -- no --> Z3[log to stderr, no-op]
|
||||
P -- yes --> C{exported?}
|
||||
C -- no --> D[write export] --> E{exported now?}
|
||||
E -- no --> Z2[give up]
|
||||
E -- yes --> F
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ Self-contained logic with a clean seam, measured to **100% MC/DC** (gcc-14
|
||||
|
||||
| Driver | Seam | MC/DC |
|
||||
|---|---|---|
|
||||
| `relays/` | `relay_io` vtable (sysfs backend + in-memory fake) | 40/40 conditions, 100% |
|
||||
| `relays/` | `relay_io` vtable (sysfs backend + in-memory fake) | 50/50 conditions, 100% |
|
||||
| `freshness/` | produce/render callbacks (the "no stale numbers" guard) | 66/66 conditions, 100% |
|
||||
|
||||
**Adding a Tier-1 driver:** copy `<name>.{c,h}` here, put the hardware/OS calls behind
|
||||
|
||||
+60
-28
@@ -1,5 +1,6 @@
|
||||
#include "relays.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -8,6 +9,8 @@
|
||||
/* GPIO1_A0 and GPIO1_A1; gpiochip1 base is 32. See relays.h. */
|
||||
static const int s_gpio[WARDEN_RELAY_COUNT] = { 32, 33 };
|
||||
static const char * const s_name[WARDEN_RELAY_COUNT] = { "Relay 1", "Relay 2" };
|
||||
/* The same numbers as the strings written to `export`, so no runtime formatting. */
|
||||
static const char * const s_gpio_str[WARDEN_RELAY_COUNT] = { "32", "33" };
|
||||
|
||||
/* ---- default sysfs backend (Tier-2 plumbing; covered by integration tests) ---- */
|
||||
|
||||
@@ -64,11 +67,46 @@ const char * warden_relay_name(uint32_t idx)
|
||||
return idx < WARDEN_RELAY_COUNT ? s_name[idx] : "-";
|
||||
}
|
||||
|
||||
static bool exported(int gpio)
|
||||
/**
|
||||
* Every sysfs path one relay operation can touch. Each holds PATH_MAX bytes, so
|
||||
* any root the kernel would accept fits.
|
||||
*/
|
||||
struct relay_paths {
|
||||
char gpio[PATH_MAX]; /* <root>/gpioN */
|
||||
char export_[PATH_MAX]; /* <root>/export */
|
||||
char direction[PATH_MAX]; /* <root>/gpioN/direction */
|
||||
char value[PATH_MAX]; /* <root>/gpioN/value */
|
||||
};
|
||||
|
||||
/**
|
||||
* Format the paths for relay @p idx up front. A `$WARDEN_GPIO_ROOT` too long for
|
||||
* any of them is refused with a log line, never truncated: a cut-short path
|
||||
* would silently report both relays unavailable, or name a different node.
|
||||
*/
|
||||
static bool relay_paths(uint32_t idx, struct relay_paths * rp)
|
||||
{
|
||||
char p[80];
|
||||
snprintf(p, sizeof(p), "%s/gpio%d", gpio_root(), gpio);
|
||||
return s_io->exists(p);
|
||||
const char * root = gpio_root();
|
||||
int gpio = s_gpio[idx];
|
||||
const int n[] = {
|
||||
snprintf(rp->gpio, sizeof(rp->gpio), "%s/gpio%d", root, gpio),
|
||||
snprintf(rp->export_, sizeof(rp->export_), "%s/export", root),
|
||||
snprintf(rp->direction, sizeof(rp->direction), "%s/gpio%d/direction", root, gpio),
|
||||
snprintf(rp->value, sizeof(rp->value), "%s/gpio%d/value", root, gpio),
|
||||
};
|
||||
for(size_t i = 0; i < sizeof(n) / sizeof(n[0]); i++) {
|
||||
/* The unsigned cast also maps an encoding error (n < 0) to "does not fit". */
|
||||
if((unsigned)n[i] >= PATH_MAX) {
|
||||
fprintf(stderr, "relays: WARDEN_GPIO_ROOT is too long (%zu bytes): sysfs paths "
|
||||
"under it exceed PATH_MAX (%d), refusing it\n", strlen(root), PATH_MAX);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool exported(const struct relay_paths * rp)
|
||||
{
|
||||
return s_io->exists(rp->gpio);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,28 +115,21 @@ static bool exported(int gpio)
|
||||
* relay the first time this page is opened; reading the current level first and
|
||||
* writing it straight back makes the export transparent.
|
||||
*/
|
||||
static bool ensure_ready(int gpio)
|
||||
static bool ensure_ready(uint32_t idx, const struct relay_paths * rp)
|
||||
{
|
||||
if(!exported(gpio)) {
|
||||
char ex[80], n[16];
|
||||
snprintf(ex, sizeof(ex), "%s/export", gpio_root());
|
||||
snprintf(n, sizeof(n), "%d", gpio);
|
||||
s_io->write(ex, n);
|
||||
if(!exported(gpio)) return false;
|
||||
if(!exported(rp)) {
|
||||
s_io->write(rp->export_, s_gpio_str[idx]);
|
||||
if(!exported(rp)) return false;
|
||||
}
|
||||
|
||||
char p[96];
|
||||
snprintf(p, sizeof(p), "%s/gpio%d/direction", gpio_root(), gpio);
|
||||
char dir[16] = "";
|
||||
if(!s_io->read_line(p, dir, sizeof(dir))) return false;
|
||||
if(!s_io->read_line(rp->direction, dir, sizeof(dir))) return false;
|
||||
|
||||
if(strncmp(dir, "out", 3) != 0) {
|
||||
/* Preserve the level across the switch to output. */
|
||||
char vp[96];
|
||||
int cur;
|
||||
snprintf(vp, sizeof(vp), "%s/gpio%d/value", gpio_root(), gpio);
|
||||
if(!s_io->read_int(vp, &cur)) cur = 0;
|
||||
s_io->write(p, cur ? "high" : "low");
|
||||
if(!s_io->read_int(rp->value, &cur)) cur = 0;
|
||||
s_io->write(rp->direction, cur ? "high" : "low");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -106,27 +137,28 @@ static bool ensure_ready(int gpio)
|
||||
bool warden_relay_available(uint32_t idx)
|
||||
{
|
||||
if(idx >= WARDEN_RELAY_COUNT) return false;
|
||||
return ensure_ready(s_gpio[idx]);
|
||||
struct relay_paths rp;
|
||||
if(!relay_paths(idx, &rp)) return false;
|
||||
return ensure_ready(idx, &rp);
|
||||
}
|
||||
|
||||
bool warden_relay_get(uint32_t idx)
|
||||
{
|
||||
if(idx >= WARDEN_RELAY_COUNT) return false;
|
||||
if(!exported(s_gpio[idx])) return false;
|
||||
struct relay_paths rp;
|
||||
if(!relay_paths(idx, &rp)) return false;
|
||||
if(!exported(&rp)) return false;
|
||||
|
||||
char p[96];
|
||||
int v;
|
||||
snprintf(p, sizeof(p), "%s/gpio%d/value", gpio_root(), s_gpio[idx]);
|
||||
if(!s_io->read_int(p, &v)) v = 0;
|
||||
if(!s_io->read_int(rp.value, &v)) v = 0;
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
void warden_relay_set(uint32_t idx, bool on)
|
||||
{
|
||||
if(idx >= WARDEN_RELAY_COUNT) return;
|
||||
if(!ensure_ready(s_gpio[idx])) return;
|
||||
|
||||
char p[96];
|
||||
snprintf(p, sizeof(p), "%s/gpio%d/value", gpio_root(), s_gpio[idx]);
|
||||
s_io->write(p, on ? "1" : "0");
|
||||
struct relay_paths rp;
|
||||
if(!relay_paths(idx, &rp)) return;
|
||||
if(!ensure_ready(idx, &rp)) return;
|
||||
s_io->write(rp.value, on ? "1" : "0");
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
* the decision logic runs and is measured to 100% MC/DC on the host, and the
|
||||
* gpio root is `$WARDEN_GPIO_ROOT`-overridable so the real backend can run
|
||||
* against a scratch tree in an integration test.
|
||||
*
|
||||
* Paths are built in PATH_MAX buffers. A root too long for its longest path
|
||||
* ("<root>/gpioNN/direction" within PATH_MAX) is refused with a stderr line, and
|
||||
* every call then reports unavailable / off / no-op; it is never truncated.
|
||||
*/
|
||||
#ifndef WARDEN_RELAYS_H
|
||||
#define WARDEN_RELAYS_H
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include "../relays.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -30,11 +32,12 @@ static struct {
|
||||
const char *read_line_val;
|
||||
bool read_int_ok;
|
||||
int read_int_val;
|
||||
char last_write_path[160];
|
||||
char last_write_path[PATH_MAX];
|
||||
char last_write_val[32];
|
||||
int exists_calls;
|
||||
} fk;
|
||||
|
||||
static bool fk_exists(const char *p) { (void)p; return fk.exists_ret; }
|
||||
static bool fk_exists(const char *p) { (void)p; fk.exists_calls++; return fk.exists_ret; }
|
||||
static void fk_write(const char *p, const char *v) {
|
||||
snprintf(fk.last_write_path, sizeof fk.last_write_path, "%s", p);
|
||||
snprintf(fk.last_write_val, sizeof fk.last_write_val, "%s", v);
|
||||
@@ -56,6 +59,104 @@ static const struct relay_io FAKE = { fk_exists, fk_write, fk_read_line, fk_read
|
||||
|
||||
static void fk_reset(void) { memset(&fk, 0, sizeof fk); }
|
||||
|
||||
/* ---- stderr capture: proves a refusal is logged, not silent ---- */
|
||||
|
||||
static char g_err[1024];
|
||||
static int g_saved_stderr = -1;
|
||||
static char g_err_path[] = "/tmp/warden-relays-stderr-XXXXXX";
|
||||
|
||||
static void err_begin(void)
|
||||
{
|
||||
int fd = mkstemp(g_err_path);
|
||||
assert(fd >= 0);
|
||||
fflush(stderr);
|
||||
g_saved_stderr = dup(2);
|
||||
dup2(fd, 2);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static void err_end(void)
|
||||
{
|
||||
fflush(stderr);
|
||||
dup2(g_saved_stderr, 2);
|
||||
close(g_saved_stderr);
|
||||
FILE *f = fopen(g_err_path, "r");
|
||||
size_t n = f ? fread(g_err, 1, sizeof g_err - 1, f) : 0;
|
||||
g_err[n] = '\0';
|
||||
if(f) fclose(f);
|
||||
unlink(g_err_path);
|
||||
memcpy(g_err_path + strlen(g_err_path) - 6, "XXXXXX", 6);
|
||||
}
|
||||
|
||||
/* A root of exactly @p len bytes ("/" then 'a's); it need not exist for fake io. */
|
||||
static char g_long[PATH_MAX + 64];
|
||||
static const char *long_root(size_t len)
|
||||
{
|
||||
assert(len >= 1 && len < sizeof g_long);
|
||||
g_long[0] = '/';
|
||||
memset(g_long + 1, 'a', len - 1);
|
||||
g_long[len] = '\0';
|
||||
return g_long;
|
||||
}
|
||||
|
||||
/* Root-length bounds (issue #10). The longest path is "<root>/gpio32/direction",
|
||||
* so a root of PATH_MAX - 1 - strlen("/gpio32/direction") bytes is the longest
|
||||
* that fits. One byte more must be refused loudly, never truncated. */
|
||||
static void long_root_unit_tests(void)
|
||||
{
|
||||
const size_t max_root = PATH_MAX - 1 - strlen("/gpio32/direction");
|
||||
|
||||
/* Well past the old 80/96-byte buffers but inside PATH_MAX: works, and the
|
||||
* io sees the full, untruncated path. */
|
||||
fk_reset(); fk.exists_ret = true; fk.read_line_ok = true; fk.read_line_val = "out\n";
|
||||
setenv("WARDEN_GPIO_ROOT", long_root(200), 1);
|
||||
warden_relay_set(0, true);
|
||||
EXPECT(strcmp(fk.last_write_val, "1") == 0);
|
||||
EXPECT(strlen(fk.last_write_path) == 200 + strlen("/gpio32/value"));
|
||||
EXPECT(strncmp(fk.last_write_path, g_long, 200) == 0);
|
||||
EXPECT(strcmp(fk.last_write_path + 200, "/gpio32/value") == 0);
|
||||
|
||||
/* Exactly at the bound: still accepted. */
|
||||
fk_reset(); fk.exists_ret = true; fk.read_line_ok = true; fk.read_line_val = "out\n";
|
||||
setenv("WARDEN_GPIO_ROOT", long_root(max_root), 1);
|
||||
EXPECT(warden_relay_available(0) == true);
|
||||
|
||||
/* One byte over: "<root>/gpio32" still fits, the direction path does not.
|
||||
* Every entry point refuses, logs, and never touches the io. */
|
||||
setenv("WARDEN_GPIO_ROOT", long_root(max_root + 1), 1);
|
||||
fk_reset(); fk.exists_ret = true; fk.read_line_ok = true; fk.read_line_val = "out\n";
|
||||
fk.read_int_ok = true; fk.read_int_val = 1;
|
||||
err_begin();
|
||||
EXPECT(warden_relay_available(0) == false);
|
||||
err_end();
|
||||
EXPECT(strstr(g_err, "WARDEN_GPIO_ROOT is too long") != NULL);
|
||||
EXPECT(fk.exists_calls == 0);
|
||||
|
||||
err_begin();
|
||||
EXPECT(warden_relay_get(0) == false);
|
||||
err_end();
|
||||
EXPECT(strstr(g_err, "WARDEN_GPIO_ROOT is too long") != NULL);
|
||||
EXPECT(fk.exists_calls == 0);
|
||||
|
||||
err_begin();
|
||||
warden_relay_set(1, true);
|
||||
err_end();
|
||||
EXPECT(strstr(g_err, "WARDEN_GPIO_ROOT is too long") != NULL);
|
||||
EXPECT(fk.last_write_path[0] == '\0');
|
||||
EXPECT(fk.exists_calls == 0);
|
||||
|
||||
/* A root longer than PATH_MAX itself: refused the same way. */
|
||||
setenv("WARDEN_GPIO_ROOT", long_root(PATH_MAX + 10), 1);
|
||||
fk_reset(); fk.exists_ret = true;
|
||||
err_begin();
|
||||
EXPECT(warden_relay_available(1) == false);
|
||||
err_end();
|
||||
EXPECT(strstr(g_err, "WARDEN_GPIO_ROOT is too long") != NULL);
|
||||
EXPECT(fk.exists_calls == 0);
|
||||
|
||||
unsetenv("WARDEN_GPIO_ROOT");
|
||||
}
|
||||
|
||||
static void unit_tests(void)
|
||||
{
|
||||
warden_relay__set_io(&FAKE);
|
||||
@@ -142,18 +243,20 @@ static void unit_tests(void)
|
||||
fk_reset(); fk.exists_ret = true; fk.read_line_ok = true; fk.read_line_val = "out\n";
|
||||
warden_relay_set(0, false);
|
||||
EXPECT(strcmp(fk.last_write_val, "0") == 0);
|
||||
|
||||
long_root_unit_tests();
|
||||
}
|
||||
|
||||
/* ---------------- layer 2: real sysfs backend over a scratch tree ---------------- */
|
||||
|
||||
static char g_root[128];
|
||||
static char g_root[PATH_MAX];
|
||||
|
||||
static void wr(const char *rel, const char *content) {
|
||||
char p[256]; snprintf(p, sizeof p, "%s/%s", g_root, rel);
|
||||
char p[PATH_MAX + 64]; snprintf(p, sizeof p, "%s/%s", g_root, rel);
|
||||
FILE *f = fopen(p, "w"); if(f) { fputs(content, f); fclose(f); }
|
||||
}
|
||||
static void mkgpio(int n) {
|
||||
char p[256]; snprintf(p, sizeof p, "%s/gpio%d", g_root, n); mkdir(p, 0777);
|
||||
char p[PATH_MAX + 64]; snprintf(p, sizeof p, "%s/gpio%d", g_root, n); mkdir(p, 0777);
|
||||
}
|
||||
|
||||
static void integration_tests(void)
|
||||
@@ -207,6 +310,24 @@ static void integration_tests(void)
|
||||
wr("gpio33/direction", "in\n");
|
||||
wr("gpio33/value", "1\n");
|
||||
EXPECT(warden_relay_available(1) == true); /* reads value=1, writes direction "high" */
|
||||
|
||||
/* Issue #10: a real scratch tree under a root far longer than the old 80/96-byte
|
||||
* buffers (the simulator's case). Both relays must be available and switchable. */
|
||||
for(int i = 0; i < 5; i++) {
|
||||
size_t l = strlen(g_root);
|
||||
snprintf(g_root + l, sizeof g_root - l, "/%s", "long-scratch-directory-component-for-issue-10");
|
||||
EXPECT(mkdir(g_root, 0777) == 0);
|
||||
}
|
||||
EXPECT(strlen(g_root) > 200);
|
||||
setenv("WARDEN_GPIO_ROOT", g_root, 1);
|
||||
mkgpio(32); mkgpio(33);
|
||||
wr("gpio32/direction", "out\n"); wr("gpio32/value", "0\n");
|
||||
wr("gpio33/direction", "out\n"); wr("gpio33/value", "0\n");
|
||||
EXPECT(warden_relay_available(0) == true);
|
||||
EXPECT(warden_relay_available(1) == true);
|
||||
warden_relay_set(1, true);
|
||||
EXPECT(warden_relay_get(1) == true);
|
||||
EXPECT(warden_relay_get(0) == false);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
||||
@@ -337,12 +337,21 @@ static struct rockchip_clk_branch rv1106_clk_branches[] __initdata = {
|
||||
/* PD_CORE */
|
||||
GATE(CLK_PVTM_CORE, "clk_pvtm_core", "xin24m", 0,
|
||||
RV1106_CORECLKGATE_CON(0), 14, GFLAGS),
|
||||
GATE(CLK_CORE_MCU_RTC, "clk_core_mcu_rtc", "xin24m", 0,
|
||||
/* clk_core_mcu_rtc is the 24 MHz mtime of the HPMCU, kept up for the
|
||||
* mtime safety tick. Nothing in Linux claims it, so clk_disable_unused()
|
||||
* would gate it after boot; IGNORE_UNUSED keeps it running, like
|
||||
* clk_core_mcu below (rebuild M0, SCH-01). */
|
||||
GATE(CLK_CORE_MCU_RTC, "clk_core_mcu_rtc", "xin24m", CLK_IGNORE_UNUSED,
|
||||
RV1106_CORECLKGATE_CON(1), 6, GFLAGS),
|
||||
COMPOSITE(HCLK_CPU, "hclk_cpu", mux_gpll_24m_p, CLK_IS_CRITICAL,
|
||||
RV1106_CORECLKSEL_CON(2), 5, 1, MFLAGS, 0, 5, DFLAGS,
|
||||
RV1106_CORECLKGATE_CON(0), 12, GFLAGS),
|
||||
COMPOSITE(CLK_CORE_MCU, "clk_core_mcu", mux_gpll_24m_p, 0,
|
||||
/* The HPMCU (RISC-V SCR1 coprocessor) runs on clk_core_mcu, but nothing in
|
||||
* Linux claims it, so clk_disable_unused() switches it off at boot and any
|
||||
* firmware loaded into the coprocessor never executes. Mark it
|
||||
* IGNORE_UNUSED so the coprocessor clock stays up (5.10 left it running;
|
||||
* our 6.18 disabled it). A future remoteproc/coproc driver could claim it. */
|
||||
COMPOSITE(CLK_CORE_MCU, "clk_core_mcu", mux_gpll_24m_p, CLK_IGNORE_UNUSED,
|
||||
RV1106_CORECLKSEL_CON(3), 11, 1, MFLAGS, 6, 5, DFLAGS,
|
||||
RV1106_CORECLKGATE_CON(1), 1, GFLAGS),
|
||||
COMPOSITE_NOMUX(0, "pclk_dbg", "armclk", CLK_IS_CRITICAL,
|
||||
|
||||
@@ -57,7 +57,9 @@ luckfox-sdk-patches/uboot/include/ new source files
|
||||
luckfox-sdk-patches/kernel/patches/ diffs against sysdrv/source/kernel/
|
||||
luckfox-sdk-patches/kernel/configs/ new kernel config fragments
|
||||
luckfox-sdk-patches/wifi/patches/ diffs against sysdrv/drv_ko/wifi/ (out-of-tree modules)
|
||||
luckfox-sdk-patches/board/patches/ diffs against project/ (board .mk + the build driver)
|
||||
luckfox-sdk-patches/board/patches/ diffs against project/ and sysdrv/ build files (board .mk,
|
||||
build drivers, Makefiles, init overlays); may delete files
|
||||
luckfox-sdk-patches/buildroot/ our delta on the Buildroot tree (see "Buildroot" below)
|
||||
```
|
||||
|
||||
Paths inside each patch are relative to the vendor SDK root, so apply with
|
||||
@@ -87,6 +89,29 @@ skipped; else if `git apply --check` succeeds it is applied; else it is a hand-
|
||||
patched SDK carrying an equivalent (or a genuine conflict) and the script warns
|
||||
and continues rather than aborting the build.
|
||||
|
||||
## Buildroot
|
||||
|
||||
The vendor checkout ships buildroot-2023.02.6; WardenOS builds against
|
||||
buildroot-2025.02.8, which is not in the vendor checkout.
|
||||
`board/patches/0006-buildroot-2025.patch` (project/build.sh) and
|
||||
`board/patches/0009-sysdrv-buildroot-2025.patch` (sysdrv/Makefile) select it,
|
||||
and `../build/unpack-buildroot.sh` puts the pristine tree at
|
||||
`sysdrv/source/buildroot/buildroot-2025.02.8`: it fetches the tarball with
|
||||
`../build/fetch-buildroot-tarball.sh` (sha256-pinned) and leaves an existing
|
||||
tree alone. flare-edge's `tools/build-firmware.sh` runs it right after
|
||||
applying the patches, then stages `buildroot/files/` and applies
|
||||
`buildroot/patches/` onto the tree (issue #4).
|
||||
|
||||
## Completeness check
|
||||
|
||||
flare-edge's `tools/verify-sdk-patches.sh` replays this series onto the vendor
|
||||
base and compares the result with an SDK checkout. It also fails when the SDK
|
||||
has a tracked change (edit or deletion) that no patch, no fragment and no
|
||||
entry in flare-edge's `tools/sdk-delta-allowlist.txt` accounts for, and when
|
||||
the 86Panel board config names a kernel or U-Boot config fragment that
|
||||
neither the vendor base nor this directory provides. Before that check, five
|
||||
real deltas lived only in copies of one SDK tree (issue #4).
|
||||
|
||||
## What each patch does
|
||||
|
||||
### `uboot/patches/0001-display-and-boot-timing.patch`
|
||||
@@ -269,6 +294,29 @@ had masked it (the reproducibility gap `tools/build-firmware.sh` exists to close
|
||||
`sysdrv/source/uboot/u-boot/configs/` (it is a whole new file, not a diff);
|
||||
the board `.mk` patch is what references it by name.
|
||||
|
||||
### `board/patches/0009` to `0013` (issue #4)
|
||||
|
||||
Deltas that lived only in the workstation SDK until issue #4. Each patch
|
||||
header explains its change.
|
||||
|
||||
| patch | file | what it does |
|
||||
|---|---|---|
|
||||
| `0009-sysdrv-buildroot-2025.patch` | `sysdrv/Makefile` | `BUILDROOT_VER` to 2025.02.8 (the tree the `buildroot` target builds); relaxes the vendor unpack fallback's `cp` lines |
|
||||
| `0010-drop-2023-buildroot-package-patches.patch` | `sysdrv/tools/board/buildroot/{busybox,hcitool}_patch/` | deletes five 2023-era package patches the fallback would copy into Buildroot |
|
||||
| `0011-oem-flare-minimize.patch` | `project/cfg/BoardConfig_IPC/luckfox-buildroot-oem-pre.sh` | `flare_minimize`: strips camera/ISP files and modules from /oem |
|
||||
| `0012-drop-s50sshd.patch` | `overlay-luckfox-buildroot-init/etc/init.d/S50sshd` | deletes the generic sshd starter; dropbear provides SSH |
|
||||
| `0013-e2fsprogs-build-cflags.patch` | `sysdrv/tools/board/e2fsprogs/Makefile` | `BUILD_CFLAGS` so the host helpers build with gcc 14 |
|
||||
|
||||
### `board/patches/0014-s50usbdevice-unset-role-is-client.patch`
|
||||
|
||||
0004's S50usbdevice gate read an unset role as router, so a fresh `/userdata`
|
||||
never composed the USB gadget and the panel had no `usb0` until its second
|
||||
boot (flare-edge#278). 0014 makes unset mean client (0), like every other
|
||||
role reader; flare-edge's `tests/guards/run-role-default-tests.sh` pins the
|
||||
gate to them. It is a separate patch, not an edit to 0004, because
|
||||
`build-firmware.sh` would skip an edited 0004 as inconclusive on an SDK that
|
||||
already carries 0004 and 0008.
|
||||
|
||||
## Config fragments
|
||||
|
||||
| fragment | why |
|
||||
@@ -278,6 +326,8 @@ had masked it (the reproducibility gap `tools/build-firmware.sh` exists to close
|
||||
| `uboot/flare-bootcount.config` | boot-failure fallback to `altbootcmd=download` -> MaskRom |
|
||||
| `uboot/flare-spl-brom.config` | builds `spl_bootrom.o`; does *not* set `SPL_ROCKCHIP_BACK_TO_BROM`, which would flip `SPL_MMC_SUPPORT` off |
|
||||
| `kernel/flare-backlight.config` | `CONFIG_BACKLIGHT_PWM=y`. As `=m` the backlight class device does not exist until userspace `insmod`s it at ~3.3-3.7 s, which is when the logo is being replaced anyway |
|
||||
| `kernel/flare-wireguard.config` | `CONFIG_WIREGUARD=y` for the vendor 5.10 kernel, which builds the recovery image. Named by the 86Panel board `.mk`; untracked in the workstation SDK until issue #4 |
|
||||
| `kernel/rv1106-usb-host-ethernet.config` | USB-Ethernet class drivers (with the `USB_NET_DRIVERS` menu gate) for the vendor 5.10 kernel. Same history as `flare-wireguard.config` |
|
||||
| `kernel/flare-fbcon.config` | `# CONFIG_LOGO is not set` (the SDK ships the LuckFox fox-head over our logo) plus `FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=y` (fbcon seizing the fb destroyed the `drm_logo` image U-Boot handed over) |
|
||||
|
||||
## Measured boot timeline
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
Build buildroot-2025.02.8 from sysdrv/Makefile too.
|
||||
|
||||
0006-buildroot-2025.patch points project/build.sh at buildroot-2025.02.8, but
|
||||
sysdrv/Makefile has its own default, BUILDROOT_VER, and that is the one the
|
||||
`buildroot` target actually builds. Left at the vendor's 2023.02.6, a clean
|
||||
checkout configures and builds the old tree.
|
||||
|
||||
The same Makefile carries the vendor's fallback that unpacks
|
||||
tools/board/buildroot/$(BUILDROOT_VER).tar.gz when the tree is missing and
|
||||
copies the vendor defconfigs and package patches into it. Two relaxations
|
||||
keep that fallback usable with 2025.02.8:
|
||||
|
||||
- `*_defconfig` instead of only luckfox_pico_w_defconfig, so any defconfig
|
||||
staged beside the vendor ones is copied too.
|
||||
- `|| true` on the busybox and hcitool patch copies, because
|
||||
0010-drop-2023-buildroot-package-patches.patch empties those directories.
|
||||
|
||||
The WardenOS build does not use the fallback: flare-edge's
|
||||
tools/build-firmware.sh unpacks the pinned, sha256-verified tarball with
|
||||
build/unpack-buildroot.sh before the SDK build runs, so the Makefile's
|
||||
`test -d` finds the tree and skips its own unpack and copies.
|
||||
|
||||
diff --git a/sysdrv/Makefile b/sysdrv/Makefile
|
||||
index 5edb8f875..c173c219e 100644
|
||||
--- a/sysdrv/Makefile
|
||||
+++ b/sysdrv/Makefile
|
||||
@@ -281,7 +281,7 @@ BUSYBOX_DIR := $(SYSDRV_DIR)/source/busybox
|
||||
SYSDRV_BUSYBOX_OBJS_OUTPUT_DIR ?= $(BUSYBOX_DIR)/objs_$(BUSYBOX_CFG)
|
||||
|
||||
BUILDROOT_CFG ?= config_normal
|
||||
-BUILDROOT_VER ?= buildroot-2023.02.6
|
||||
+BUILDROOT_VER ?= buildroot-2025.02.8
|
||||
BUILDROOT_DIR := $(SYSDRV_DIR)/source/buildroot
|
||||
|
||||
CUSTOM_VER ?= custom
|
||||
@@ -599,11 +599,11 @@ buildroot_create:
|
||||
mkdir -p $(BUILDROOT_DIR)
|
||||
tar xzf $(SYSDRV_DIR)/tools/board/buildroot/$(BUILDROOT_VER).tar.gz -C $(BUILDROOT_DIR)
|
||||
cp $(SYSDRV_DIR)/tools/board/buildroot/luckfox_pico_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/
|
||||
- cp $(SYSDRV_DIR)/tools/board/buildroot/luckfox_pico_w_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/
|
||||
+ cp $(SYSDRV_DIR)/tools/board/buildroot/*_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/
|
||||
cp $(SYSDRV_DIR)/tools/board/buildroot/busybox.config $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/
|
||||
- cp ${HCITOOL_TOOL_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/bluez5_utils/
|
||||
+ cp ${HCITOOL_TOOL_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/bluez5_utils/ || true
|
||||
cp ${MPV_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/mpv/
|
||||
- cp ${BUSYBOX_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/
|
||||
+ cp ${BUSYBOX_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/ || true
|
||||
|
||||
buildroot: prepare
|
||||
@echo -e "$(C_GREEN) ==sysdrv== build buildroot $(C_NORMAL)"
|
||||
@@ -611,11 +611,11 @@ buildroot: prepare
|
||||
mkdir -p $(BUILDROOT_DIR) ;\
|
||||
tar xzf $(SYSDRV_DIR)/tools/board/buildroot/$(BUILDROOT_VER).tar.gz -C $(BUILDROOT_DIR) ;\
|
||||
cp $(SYSDRV_DIR)/tools/board/buildroot/luckfox_pico_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/ ;\
|
||||
- cp $(SYSDRV_DIR)/tools/board/buildroot/luckfox_pico_w_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/ ;\
|
||||
+ cp $(SYSDRV_DIR)/tools/board/buildroot/*_defconfig $(BUILDROOT_DIR)/$(BUILDROOT_VER)/configs/ ;\
|
||||
cp $(SYSDRV_DIR)/tools/board/buildroot/busybox.config $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/ ;\
|
||||
- cp ${HCITOOL_TOOL_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/bluez5_utils/ ;\
|
||||
+ cp ${HCITOOL_TOOL_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/bluez5_utils/ || true ;\
|
||||
cp ${MPV_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/mpv/ ;\
|
||||
- cp ${BUSYBOX_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/ ;\
|
||||
+ cp ${BUSYBOX_PATCH_PATH}/*.patch $(BUILDROOT_DIR)/$(BUILDROOT_VER)/package/busybox/ || true ;\
|
||||
);
|
||||
|
||||
$(MAKE) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) $(BUILDROOT_DEFCONFIG) -C $(BUILDROOT_DIR)/$(BUILDROOT_VER)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,55 @@
|
||||
Strip camera and ISP payload from /oem.
|
||||
|
||||
luckfox-buildroot-oem-pre.sh runs over the OEM staging tree before it is
|
||||
packed. flare_minimize() removes what WardenOS never uses because no image
|
||||
sensor is fitted: the ISP tuning files (about 32 MB), the rkaiq 3A library
|
||||
and servers, the camera capture kernel modules, and the camera and MPI
|
||||
sample binaries.
|
||||
|
||||
NPU, video codec, RGA and rockit are kept on purpose. WiFi/BT, touch and the
|
||||
insmod scripts are not touched.
|
||||
|
||||
diff --git a/project/cfg/BoardConfig_IPC/luckfox-buildroot-oem-pre.sh b/project/cfg/BoardConfig_IPC/luckfox-buildroot-oem-pre.sh
|
||||
index 4187457d4..de2bf74e6 100755
|
||||
--- a/project/cfg/BoardConfig_IPC/luckfox-buildroot-oem-pre.sh
|
||||
+++ b/project/cfg/BoardConfig_IPC/luckfox-buildroot-oem-pre.sh
|
||||
@@ -46,4 +46,37 @@ function remove_data()
|
||||
#=========================
|
||||
# run
|
||||
#=========================
|
||||
-remove_data
|
||||
\ No newline at end of file
|
||||
+remove_data
|
||||
+#=========================
|
||||
+# flare-edge: drop camera / ISP from /oem
|
||||
+#
|
||||
+# Camera is out of scope for the Warden gateway role (no sensor attached).
|
||||
+# NPU, video codec, RGA and rockit are KEPT deliberately - they are onboard
|
||||
+# hardware we chose to retain. WiFi/BT (aic8800*), touch (goodix) and the
|
||||
+# insmod scripts are never touched here.
|
||||
+#=========================
|
||||
+function flare_minimize()
|
||||
+{
|
||||
+ KO=$RK_PROJECT_PACKAGE_OEM_DIR/usr/ko
|
||||
+
|
||||
+ # ISP tuning data - by far the biggest item in /oem (~32MB)
|
||||
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/share/iqfiles
|
||||
+
|
||||
+ # ISP 3A library and its servers
|
||||
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/lib/librkaiq*
|
||||
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/bin/rkaiq_3A_server
|
||||
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/bin/rkaiq_tool_server
|
||||
+
|
||||
+ # camera capture path: ISP, CIF, MIPI CSI-2 D-PHY, and the sensor drivers
|
||||
+ lf_rm $KO/video_rkisp.ko $KO/video_rkcif.ko
|
||||
+ lf_rm $KO/phy-rockchip-csi2-dphy.ko $KO/phy-rockchip-csi2-dphy-hw.ko
|
||||
+ lf_rm $KO/sc3336.ko $KO/mis5001.ko $KO/gspca_main.ko
|
||||
+
|
||||
+ # camera/ISP demo + sample binaries (keep luckfox_*_test and modetest:
|
||||
+ # those are the GPIO/UART/I2C/SPI/PWM/display bring-up tools we want)
|
||||
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/bin/sample_*
|
||||
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/bin/rk_mpi_*
|
||||
+ lf_rm $RK_PROJECT_PACKAGE_OEM_DIR/usr/bin/simple_*
|
||||
+}
|
||||
+
|
||||
+flare_minimize
|
||||
@@ -0,0 +1,65 @@
|
||||
Remove the generic S50sshd init script.
|
||||
|
||||
overlay-luckfox-buildroot-init is in the 86Panel board's RK_POST_OVERLAY.
|
||||
Its S50sshd runs `ssh-keygen -A` inline. With no hardware RNG and no saved
|
||||
seed on a freshly written rootfs, getrandom() blocks, and rcS is sequential,
|
||||
so every init script sorting after it (S50usbdevice among them) never ran
|
||||
and the board came up with no reachable interface.
|
||||
|
||||
WardenOS gets its SSH server from Buildroot's dropbear package, selected by
|
||||
flare_warden_defconfig, which installs its own init script.
|
||||
|
||||
diff --git a/project/cfg/BoardConfig_IPC/overlay/overlay-luckfox-buildroot-init/etc/init.d/S50sshd b/project/cfg/BoardConfig_IPC/overlay/overlay-luckfox-buildroot-init/etc/init.d/S50sshd
|
||||
deleted file mode 100755
|
||||
index e5b9c4451..000000000
|
||||
--- a/project/cfg/BoardConfig_IPC/overlay/overlay-luckfox-buildroot-init/etc/init.d/S50sshd
|
||||
+++ /dev/null
|
||||
@@ -1,48 +0,0 @@
|
||||
-#!/bin/sh
|
||||
-#
|
||||
-# sshd Starts sshd.
|
||||
-#
|
||||
-
|
||||
-# Make sure the ssh-keygen progam exists
|
||||
-[ -f /usr/bin/ssh-keygen ] || exit 0
|
||||
-
|
||||
-umask 077
|
||||
-
|
||||
-start() {
|
||||
- chown root:root /var/empty/
|
||||
- # Create any missing keys
|
||||
- /usr/bin/ssh-keygen -A
|
||||
-
|
||||
- printf "Starting sshd: "
|
||||
- /usr/sbin/sshd
|
||||
- touch /var/lock/sshd
|
||||
- echo "OK"
|
||||
-}
|
||||
-stop() {
|
||||
- printf "Stopping sshd: "
|
||||
- killall sshd
|
||||
- rm -f /var/lock/sshd
|
||||
- echo "OK"
|
||||
-}
|
||||
-restart() {
|
||||
- stop
|
||||
- start
|
||||
-}
|
||||
-
|
||||
-case "$1" in
|
||||
- start)
|
||||
- start
|
||||
- ;;
|
||||
- stop)
|
||||
- stop
|
||||
- ;;
|
||||
- restart|reload)
|
||||
- restart
|
||||
- ;;
|
||||
- *)
|
||||
- echo "Usage: $0 {start|stop|restart}"
|
||||
- exit 1
|
||||
-esac
|
||||
-
|
||||
-exit $?
|
||||
-
|
||||
@@ -0,0 +1,21 @@
|
||||
Build e2fsprogs host helpers with gcc 14.
|
||||
|
||||
The vendor's e2fsprogs 1.43.9 compiles a few helper programs for the build
|
||||
host (BUILD_CC) while cross-building the target tools. That source relies on
|
||||
implicit function declarations and implicit int, which gcc 14 turns into
|
||||
errors, so the host helper build fails. BUILD_CFLAGS demotes those two back
|
||||
to warnings for the host helpers only; the target CFLAGS are unchanged.
|
||||
|
||||
diff --git a/sysdrv/tools/board/e2fsprogs/Makefile b/sysdrv/tools/board/e2fsprogs/Makefile
|
||||
index 14ab9e503..baa541093 100644
|
||||
--- a/sysdrv/tools/board/e2fsprogs/Makefile
|
||||
+++ b/sysdrv/tools/board/e2fsprogs/Makefile
|
||||
@@ -20,7 +20,7 @@ all:
|
||||
mkdir -p $(CURRENT_DIR)/$(PKG_BIN)/usr/; \
|
||||
pushd $(CURRENT_DIR)/$(PKG_NAME)/; \
|
||||
./configure --host=$(SYSDRV_CROSS) --target=$(SYSDRV_CROSS) CFLAGS="$(SYSDRV_CROSS_CFLAGS)" \
|
||||
- LDFLAGS="$(SYSDRV_CROSS_CFLAGS)" --prefix=$(CURRENT_DIR)/$(PKG_BIN) \
|
||||
+ LDFLAGS="$(SYSDRV_CROSS_CFLAGS)" BUILD_CFLAGS="-Wno-implicit-function-declaration -Wno-implicit-int" --prefix=$(CURRENT_DIR)/$(PKG_BIN) \
|
||||
--disable-nls \
|
||||
--disable-debugfs --disable-imager --disable-defrag --enable-fsck --enable-resizer \
|
||||
--disable-testio-debug --disable-rpath --enable-symlink-install --disable-fuse2fs; \
|
||||
@@ -0,0 +1,45 @@
|
||||
Treat an unset USB role as client in S50usbdevice.
|
||||
|
||||
0004 gated the gadget build on `role || echo 1`, so a fresh /userdata (no
|
||||
role file) read as router and S50usbdevice exited before composing the
|
||||
gadget. Every other reader (flare-edge S26usbhost, S35iptables,
|
||||
usb-nic-hotplug.sh, wifi-link-watchdog.sh, flared's schema) defaults an
|
||||
unset role to client (0), so S26usbhost put the port in device role with no
|
||||
gadget to bind: a freshly provisioned or factory-reset panel had no usb0
|
||||
recovery link until its second boot (flare-edge#278).
|
||||
|
||||
A separate patch rather than an edit to 0004: tools/build-firmware.sh
|
||||
applies the series idempotently, and on an SDK that already carries 0004
|
||||
and 0008 an edited 0004 neither applies nor reverse-applies, so it would be
|
||||
skipped as inconclusive and the old gate would keep shipping. This one
|
||||
applies on top of either a pristine replay or an already-patched tree.
|
||||
|
||||
diff --git a/sysdrv/tools/board/android-tools/S50usbdevice b/sysdrv/tools/board/android-tools/S50usbdevice
|
||||
index b521af4..fd8b693 100755
|
||||
--- a/sysdrv/tools/board/android-tools/S50usbdevice
|
||||
+++ b/sysdrv/tools/board/android-tools/S50usbdevice
|
||||
@@ -6,12 +6,19 @@
|
||||
# Load default env variables from profiles
|
||||
. /etc/profile
|
||||
|
||||
-# flare-edge: the OTG port is a USB HOST in router (and the unset-role default),
|
||||
-# so building a gadget here is pointless AND harmful — the dwc3 "failed to add
|
||||
+# flare-edge: only build the gadget in client role. A router's OTG port is a
|
||||
+# USB HOST, where a gadget is pointless AND harmful: the dwc3 "failed to add
|
||||
# gadget" + the usb2-phy "illegal mode" it triggers race with the USB-Ethernet
|
||||
-# host enumeration and intermittently kill eth1 at boot. Only run in client role;
|
||||
-# S26usbhost re-invokes this explicitly when switching to client. (unset -> router)
|
||||
-[ "$(cat /userdata/warden/role 2>/dev/null || echo 1)" = "1" ] && exit 0
|
||||
+# host enumeration and intermittently kill eth1 at boot. S26usbhost re-invokes
|
||||
+# this explicitly when switching to client.
|
||||
+#
|
||||
+# An UNSET role is client (0), the fresh-install default every other reader
|
||||
+# uses (S26usbhost, S35iptables, usb-nic-hotplug.sh, wifi-link-watchdog.sh,
|
||||
+# flared's schema). This gate used to read unset as router, so a fresh store
|
||||
+# set the port to device role with no gadget to bind and came up with no usb0
|
||||
+# until a second boot (flare-edge#278). flare-edge's
|
||||
+# tests/guards/run-role-default-tests.sh pins this line to the other readers.
|
||||
+[ "$(cat /userdata/warden/role 2>/dev/null || echo 0)" = "1" ] && exit 0
|
||||
|
||||
UMS_EN=off
|
||||
ADB_EN=on
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
From: BlueFlare Warden <noah@wildrosemining.com>
|
||||
Subject: [PATCH] datatype: take the cgroupv2 id from the directory's file handle
|
||||
|
||||
"socket cgroupv2 level N <path>" compares the 64-bit kernfs id of the cgroup.
|
||||
nft built it from st_ino, which equals the id only on 64-bit kernels. On a
|
||||
32-bit kernel (armv7) the id is (generation << 32) | ino and st_ino carries the
|
||||
low half, so every rule built from a path compared against the wrong value and
|
||||
never matched: nothing was counted per service.
|
||||
|
||||
The directory's file handle holds the whole id on both. It is read with the raw
|
||||
name_to_handle_at syscall because uClibc has no wrapper. The listing path (id
|
||||
back to a name) uses the same helper.
|
||||
|
||||
Found on the WardenOS panel kernel (6.18.46, armv7) with nftables 1.1.0.
|
||||
|
||||
diff --git a/src/datatype.c b/src/datatype.c
|
||||
index d398a9c..289f930 100644
|
||||
--- a/src/datatype.c
|
||||
+++ b/src/datatype.c
|
||||
@@ -19,7 +19,10 @@
|
||||
#include <linux/netfilter.h>
|
||||
#include <linux/icmpv6.h>
|
||||
#include <dirent.h>
|
||||
+#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
+#include <sys/syscall.h>
|
||||
+#include <unistd.h>
|
||||
|
||||
#include <nftables.h>
|
||||
#include <datatype.h>
|
||||
@@ -1605,12 +1608,47 @@ const struct datatype policy_type = {
|
||||
|
||||
#define SYSFS_CGROUPSV2_PATH "/sys/fs/cgroup"
|
||||
|
||||
+/* The id the kernel compares in "socket cgroupv2" is the 64-bit kernfs id of
|
||||
+ * the cgroup directory. On 64-bit kernels that is st_ino, but on 32-bit kernels
|
||||
+ * it is (generation << 32) | ino and st_ino carries only the low half, so a
|
||||
+ * rule built from st_ino never matches. The file handle of the directory holds
|
||||
+ * the full id on both. The handle is read with the raw syscall: uClibc has no
|
||||
+ * name_to_handle_at() or struct file_handle. Fall back to st_ino where the
|
||||
+ * syscall is missing. */
|
||||
+static bool cgroupv2_path_id(const char *path, uint64_t *id)
|
||||
+{
|
||||
+#ifdef __NR_name_to_handle_at
|
||||
+ struct {
|
||||
+ unsigned int handle_bytes;
|
||||
+ int handle_type;
|
||||
+ unsigned char f_handle[sizeof(uint64_t)];
|
||||
+ } h;
|
||||
+ int mount_id;
|
||||
+
|
||||
+ h.handle_bytes = sizeof(h.f_handle);
|
||||
+ if (syscall(__NR_name_to_handle_at, AT_FDCWD, path, &h, &mount_id, 0) == 0 &&
|
||||
+ h.handle_bytes == sizeof(*id)) {
|
||||
+ memcpy(id, h.f_handle, sizeof(*id));
|
||||
+ return true;
|
||||
+ }
|
||||
+#endif
|
||||
+ {
|
||||
+ struct stat st;
|
||||
+
|
||||
+ if (stat(path, &st) < 0)
|
||||
+ return false;
|
||||
+ *id = st.st_ino;
|
||||
+ return true;
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
static char *cgroupv2_get_path(const char *path, uint64_t id)
|
||||
{
|
||||
char dent_name[PATH_MAX + 1];
|
||||
char *cgroup_path = NULL;
|
||||
struct dirent *dent;
|
||||
struct stat st;
|
||||
+ uint64_t dent_id;
|
||||
DIR *d;
|
||||
|
||||
d = opendir(path);
|
||||
@@ -1626,7 +1664,7 @@ static char *cgroupv2_get_path(const char *path, uint64_t id)
|
||||
path, dent->d_name);
|
||||
dent_name[sizeof(dent_name) - 1] = '\0';
|
||||
|
||||
- if (dent->d_ino == id) {
|
||||
+ if (cgroupv2_path_id(dent_name, &dent_id) && dent_id == id) {
|
||||
cgroup_path = xstrdup(dent_name);
|
||||
break;
|
||||
}
|
||||
@@ -1674,7 +1712,9 @@ static struct error_record *cgroupv2_type_parse(struct parse_ctx *ctx,
|
||||
return error(&sym->location, "cgroupv2 path fails: %s",
|
||||
strerror(errno));
|
||||
|
||||
- ino = st.st_ino;
|
||||
+ if (!cgroupv2_path_id(cgroupv2_path, &ino))
|
||||
+ return error(&sym->location, "cgroupv2 path fails: %s",
|
||||
+ strerror(errno));
|
||||
*res = constant_expr_alloc(&sym->location, &cgroupv2_type,
|
||||
BYTEORDER_HOST_ENDIAN,
|
||||
sizeof(ino) * BITS_PER_BYTE, &ino);
|
||||
@@ -0,0 +1,10 @@
|
||||
# WireGuard, built in rather than as a module.
|
||||
#
|
||||
# =y not =m deliberately: modules live on the oem partition and must be
|
||||
# reflashed in lockstep with the kernel, and this one is ~40KB. Paying that in
|
||||
# boot.img is cheaper than another matched-pair failure mode.
|
||||
#
|
||||
# Everything WireGuard needs it "select"s for itself (NET_UDP_TUNNEL,
|
||||
# DST_CACHE, CRYPTO_LIB_CURVE25519, CRYPTO_LIB_CHACHA20POLY1305), so unlike the
|
||||
# USB-Ethernet fragment there is no menu gate to open first. Verify anyway.
|
||||
CONFIG_WIREGUARD=y
|
||||
@@ -0,0 +1,20 @@
|
||||
# USB host + USB-Ethernet class drivers (flare-edge).
|
||||
#
|
||||
# The first symbol is the MENU GATE. Every driver below lives inside the
|
||||
# USB_NET_DRIVERS menuconfig, so without it kconfig discards the lot in
|
||||
# silence -- no warning, and not even the usual "not in final .config" from
|
||||
# merge_config.sh.
|
||||
#
|
||||
# Do not begin a comment line here with a hash followed by CONFIG_. That is
|
||||
# exactly the "is not set" syntax, so merge_config.sh parses the prose as a
|
||||
# directive and reports it as a redefinition of the symbol it names.
|
||||
CONFIG_USB_NET_DRIVERS=y
|
||||
CONFIG_USB_USBNET=y
|
||||
CONFIG_USB_NET_CDCETHER=y
|
||||
CONFIG_USB_NET_CDC_NCM=y
|
||||
CONFIG_USB_NET_CDC_EEM=y
|
||||
CONFIG_USB_RTL8152=y
|
||||
CONFIG_USB_NET_AX8817X=y
|
||||
CONFIG_USB_NET_AX88179_178A=y
|
||||
CONFIG_USB_NET_SMSC95XX=y
|
||||
CONFIG_USB_NET_MCS7830=y
|
||||
@@ -372,7 +372,7 @@ index a99846f4e..4fc64f33d 100644
|
||||
+ * by this point, so nothing puts it back underneath us.
|
||||
+ */
|
||||
+ if ((priv->cpll_hz % rate) && (priv->gpll_hz % rate)) {
|
||||
+ ulong want = rate * 32;
|
||||
+ ulong want = 900 * MHz;
|
||||
+
|
||||
+ if (want >= 300 * MHz && want <= 1200 * MHz &&
|
||||
+ !rockchip_pll_set_rate(&rv1106_pll_clks[CPLL],
|
||||
|
||||
@@ -142,10 +142,10 @@ index 52cd612d1..a81071566 100644
|
||||
obj-$(CONFIG_AUTOBOOT) += autoboot.o
|
||||
diff --git a/sysdrv/source/uboot/u-boot/common/flare_ab.c b/sysdrv/source/uboot/u-boot/common/flare_ab.c
|
||||
new file mode 100644
|
||||
index 000000000..6a5a07e37
|
||||
index 000000000..ec685444d
|
||||
--- /dev/null
|
||||
+++ b/sysdrv/source/uboot/u-boot/common/flare_ab.c
|
||||
@@ -0,0 +1,642 @@
|
||||
@@ -0,0 +1,709 @@
|
||||
+// SPDX-License-Identifier: GPL-2.0+
|
||||
+/*
|
||||
+ * flare-edge A/B slot boot for U-Boot proper.
|
||||
@@ -175,6 +175,9 @@ index 000000000..6a5a07e37
|
||||
+#include <part.h>
|
||||
+#include <flare_ab.h>
|
||||
+#include <android_avb/avb_ab_flow.h>
|
||||
+#if defined(CONFIG_DRM_ROCKCHIP)
|
||||
+#include <video_rockchip.h>
|
||||
+#endif
|
||||
+
|
||||
+/*
|
||||
+ * Per-power-session boot-attempt escalation (warehouse deployment).
|
||||
@@ -215,6 +218,8 @@ index 000000000..6a5a07e37
|
||||
+ */
|
||||
+#define FLARE_AB_GLB_RST_ST 0xff3b0c04u /* CRU reset-status: 0 on POR */
|
||||
+#define FLARE_AB_SESSION_REG 0xff020210u /* PMU GRF OS_REG4: attempt count */
|
||||
+#define FLARE_AB_GLB_SRST_FST 0xff3b0c08u /* CRU glb_srst_fst: global reset */
|
||||
+#define FLARE_AB_GLB_SRST_KEY 0xfdb9u /* poke value that starts the reset */
|
||||
+/*
|
||||
+ * Attempts on the selected committed slot before failing over to the other
|
||||
+ * committed slot; the other slot then gets the same budget before recovery.
|
||||
@@ -551,7 +556,12 @@ index 000000000..6a5a07e37
|
||||
+ return other;
|
||||
+ }
|
||||
+
|
||||
+ printf("FLARE-AB: both committed slots failed this power session, recovery\n");
|
||||
+ if (slot_is_bootable(&ab_data.slots[other]) &&
|
||||
+ ab_data.slots[other].successful_boot)
|
||||
+ printf("FLARE-AB: both committed slots failed this power session, recovery\n");
|
||||
+ else
|
||||
+ printf("FLARE-AB: slot %s failed %d attempts this session, no committed alternative, recovery\n",
|
||||
+ pref ? "_b" : "_a", FLARE_AB_SLOT_TRIES);
|
||||
+ flare_ab_force_recovery = 1;
|
||||
+ return pref;
|
||||
+}
|
||||
@@ -707,6 +717,58 @@ index 000000000..6a5a07e37
|
||||
+ ab_data_write(dev_desc, &ab_data);
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * Escalating reset after a failed storage boot.
|
||||
+ *
|
||||
+ * Do not call do_reset() here. On this SoC the U-Boot WARM request
|
||||
+ * (sysreset_rockchip, ARM32 path) writes CRU glb_srst_snd (0xeca8), which
|
||||
+ * does not reset the chip (flare-edge#4554). The p54 splash stall cause is
|
||||
+ * not established (flare-edge#4569). The reset that works is the CRU
|
||||
+ * glb_srst_fst poke that the Linux restart path and the bench scenarios use
|
||||
+ * (docs/boot-flow.md, "Watchdog / reset facts"). It is a warm reset, so
|
||||
+ * glb_rst_st stays nonzero and OS_REG4 carries the attempt count.
|
||||
+ */
|
||||
+static void flare_ab_global_reset(void)
|
||||
+{
|
||||
+ flare_ab_reg_write(FLARE_AB_GLB_SRST_FST, FLARE_AB_GLB_SRST_KEY);
|
||||
+ /*
|
||||
+ * A taken reset never returns. Reaching the next statement means the
|
||||
+ * chip did not reset, so give the reset time to land before the caller
|
||||
+ * falls through to the USB download screens.
|
||||
+ */
|
||||
+ udelay(100000);
|
||||
+}
|
||||
+
|
||||
+/*
|
||||
+ * USB download: the terminal state of every failed boot with no slot or
|
||||
+ * recovery FIT left (decision 2026-11-06, flare-edge#3118 cause 3).
|
||||
+ *
|
||||
+ * The sad-face screen is logo_recovery.bmp. rockchip_show_bmp() can fail
|
||||
+ * (-ENOMEM when the heap cannot hold the decode scratch after the failed FIT
|
||||
+ * loads), and do_download() ignores that return, so the splash would stay up
|
||||
+ * with no serial line saying why. The draw is made here and its result is
|
||||
+ * logged. do_download() paints the same image again as its first step.
|
||||
+ *
|
||||
+ * `download` serves rockusb and is not expected to return. If it does (the
|
||||
+ * USB session ended), the screen is painted again and download is re-entered
|
||||
+ * after a pause, so the unit stays USB-flashable and never stops silently at
|
||||
+ * the splash. This function does not return.
|
||||
+ */
|
||||
+static void flare_ab_usb_download(void)
|
||||
+{
|
||||
+ int rc;
|
||||
+
|
||||
+ for (;;) {
|
||||
+#if defined(CONFIG_DRM_ROCKCHIP)
|
||||
+ rc = rockchip_show_bmp("logo_recovery.bmp");
|
||||
+ printf("FLARE-AB: logo_recovery.bmp shown=%d\n", rc);
|
||||
+#endif
|
||||
+ rc = run_command("download", 0);
|
||||
+ printf("FLARE-AB: download returned %d, re-entering\n", rc);
|
||||
+ udelay(1000000);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void flare_ab_boot_failed(void)
|
||||
+{
|
||||
+ if (!flare_ab_enabled())
|
||||
@@ -723,8 +785,7 @@ index 000000000..6a5a07e37
|
||||
+ * it over the existing USB port.
|
||||
+ */
|
||||
+ printf("FLARE-AB: recovery FIT unbootable, entering USB download\n");
|
||||
+ run_command("download", 0);
|
||||
+ hang();
|
||||
+ flare_ab_usb_download();
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
@@ -740,8 +801,14 @@ index 000000000..6a5a07e37
|
||||
+ * written to flash for a committed slot.
|
||||
+ */
|
||||
+ printf("FLARE-AB: slot boot failed, resetting\n");
|
||||
+ do_reset(NULL, 0, 0, NULL);
|
||||
+ hang();
|
||||
+ flare_ab_global_reset();
|
||||
+ /*
|
||||
+ * The reset did not take. Do not spin silently at the splash: enter the
|
||||
+ * same USB download screens as the recovery branch above (sad face and
|
||||
+ * USB plug, logo_recovery.bmp), where a host can reflash the unit.
|
||||
+ */
|
||||
+ printf("FLARE-AB: reset did not take, entering USB download\n");
|
||||
+ flare_ab_usb_download();
|
||||
+}
|
||||
+
|
||||
+void flare_ab_update_root_partition(void)
|
||||
@@ -841,7 +908,7 @@ index 182c03771..ad73662eb 100644
|
||||
return -1;
|
||||
diff --git a/sysdrv/source/uboot/u-boot/include/flare_ab.h b/sysdrv/source/uboot/u-boot/include/flare_ab.h
|
||||
new file mode 100644
|
||||
index 000000000..d009525e0
|
||||
index 000000000..6e51b405e
|
||||
--- /dev/null
|
||||
+++ b/sysdrv/source/uboot/u-boot/include/flare_ab.h
|
||||
@@ -0,0 +1,73 @@
|
||||
@@ -857,7 +924,7 @@ index 000000000..d009525e0
|
||||
+ * per-attempt tries decrement, and fallback to the recovery FIT when
|
||||
+ * both slots are exhausted.
|
||||
+ *
|
||||
+ * Linux-side counterpart: flared's slotctl module — the ONLY writer of
|
||||
+ * Linux-side counterpart: flared's slotctl module, the ONLY writer of
|
||||
+ * this metadata from userspace (CI-enforced).
|
||||
+ */
|
||||
+
|
||||
@@ -891,7 +958,7 @@ index 000000000..d009525e0
|
||||
+/*
|
||||
+ * One boot attempt against the selected slot: decrement tries_remaining
|
||||
+ * iff the slot is not yet successful (single-sector write, and no write
|
||||
+ * at all in the successful steady state — spec fault 14 by construction).
|
||||
+ * at all in the successful steady state, spec fault 14 by construction).
|
||||
+ * No-op in recovery fallback mode or on a non-A/B layout.
|
||||
+ */
|
||||
+void flare_ab_boot_attempt(void);
|
||||
|
||||
@@ -33,7 +33,7 @@ new file mode 100644
|
||||
index 000000000..b44eeeadd
|
||||
--- /dev/null
|
||||
+++ b/drivers/clk/rockchip/clk-rv1106.c
|
||||
@@ -0,0 +1,1299 @@
|
||||
@@ -0,0 +1,1303 @@
|
||||
+// SPDX-License-Identifier: GPL-2.0
|
||||
+/*
|
||||
+ * Copyright (c) 2022 Rockchip Electronics Co. Ltd.
|
||||
@@ -373,7 +373,11 @@ index 000000000..b44eeeadd
|
||||
+ /* PD_CORE */
|
||||
+ GATE(CLK_PVTM_CORE, "clk_pvtm_core", "xin24m", 0,
|
||||
+ RV1106_CORECLKGATE_CON(0), 14, GFLAGS),
|
||||
+ GATE(CLK_CORE_MCU_RTC, "clk_core_mcu_rtc", "xin24m", 0,
|
||||
+ /* clk_core_mcu_rtc is the 24 MHz mtime of the HPMCU, kept up for the
|
||||
+ * mtime safety tick. Nothing in Linux claims it, so clk_disable_unused()
|
||||
+ * would gate it after boot; IGNORE_UNUSED keeps it running, like
|
||||
+ * clk_core_mcu below (rebuild M0, SCH-01). */
|
||||
+ GATE(CLK_CORE_MCU_RTC, "clk_core_mcu_rtc", "xin24m", CLK_IGNORE_UNUSED,
|
||||
+ RV1106_CORECLKGATE_CON(1), 6, GFLAGS),
|
||||
+ COMPOSITE(HCLK_CPU, "hclk_cpu", mux_gpll_24m_p, CLK_IS_CRITICAL,
|
||||
+ RV1106_CORECLKSEL_CON(2), 5, 1, MFLAGS, 0, 5, DFLAGS,
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
diff --git a/arch/arm/boot/dts/rockchip/rv1106-warden-m2.dts b/arch/arm/boot/dts/rockchip/rv1106-warden-m2.dts
|
||||
--- a/arch/arm/boot/dts/rockchip/rv1106-warden-m2.dts
|
||||
+++ b/arch/arm/boot/dts/rockchip/rv1106-warden-m2.dts
|
||||
@@ -74,6 +74,15 @@
|
||||
interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>,
|
||||
<GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>;
|
||||
clock-frequency = <24000000>;
|
||||
+ /*
|
||||
+ * The boot firmware does not enter the kernel in HYP mode and leaves
|
||||
+ * CNTVOFF non-zero (bfe-core1106-sdk#35): the virtual counter the
|
||||
+ * arm32 vDSO reads runs a fixed offset away from the physical one
|
||||
+ * the kernel keeps time on. This keeps the kernel on the physical
|
||||
+ * timer and drops the vDSO clock calls, so clock_gettime() uses the
|
||||
+ * syscall and agrees with every kernel deadline.
|
||||
+ */
|
||||
+ arm,cpu-registers-not-fw-configured;
|
||||
};
|
||||
|
||||
gic: interrupt-controller@ff1f0000 {
|
||||
diff --git a/arch/arm/boot/dts/rockchip/rv1106.dtsi b/arch/arm/boot/dts/rockchip/rv1106.dtsi
|
||||
--- a/arch/arm/boot/dts/rockchip/rv1106.dtsi
|
||||
+++ b/arch/arm/boot/dts/rockchip/rv1106.dtsi
|
||||
@@ -417,6 +417,15 @@
|
||||
interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>,
|
||||
<GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>;
|
||||
clock-frequency = <24000000>;
|
||||
+ /*
|
||||
+ * The boot firmware does not enter the kernel in HYP mode and leaves
|
||||
+ * CNTVOFF non-zero (bfe-core1106-sdk#35): the virtual counter the
|
||||
+ * arm32 vDSO reads runs a fixed offset away from the physical one
|
||||
+ * the kernel keeps time on. This keeps the kernel on the physical
|
||||
+ * timer and drops the vDSO clock calls, so clock_gettime() uses the
|
||||
+ * syscall and agrees with every kernel deadline.
|
||||
+ */
|
||||
+ arm,cpu-registers-not-fw-configured;
|
||||
};
|
||||
|
||||
grf: syscon@ff000000 {
|
||||
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
|
||||
--- a/drivers/clocksource/arm_arch_timer.c
|
||||
+++ b/drivers/clocksource/arm_arch_timer.c
|
||||
@@ -933,6 +933,20 @@ static void __init arch_counter_register(void)
|
||||
arch_timer_read_counter = rd;
|
||||
clocksource_counter.vdso_clock_mode = vdso_default;
|
||||
|
||||
+ /*
|
||||
+ * The arm32 vDSO always reads the virtual counter. A kernel that keeps
|
||||
+ * time on the physical counter and was not entered in HYP mode never
|
||||
+ * had CNTVOFF zeroed by the hyp stub, so the vDSO clock may sit a fixed
|
||||
+ * offset away from the kernel's and absolute deadlines taken from it
|
||||
+ * expire late. Fall back to the syscall then.
|
||||
+ */
|
||||
+ if (IS_ENABLED(CONFIG_ARM) && arch_timer_uses_ppi != ARCH_TIMER_VIRT_PPI &&
|
||||
+ !is_hyp_mode_available() &&
|
||||
+ clocksource_counter.vdso_clock_mode != VDSO_CLOCKMODE_NONE) {
|
||||
+ clocksource_counter.vdso_clock_mode = VDSO_CLOCKMODE_NONE;
|
||||
+ pr_info("physical counter without HYP: vDSO clock disabled\n");
|
||||
+ }
|
||||
+
|
||||
width = arch_counter_get_width();
|
||||
clocksource_counter.mask = CLOCKSOURCE_MASK(width);
|
||||
cyclecounter.mask = CLOCKSOURCE_MASK(width);
|
||||
@@ -0,0 +1,25 @@
|
||||
Remove the DRM_MSM_VALIDATE_XML Kconfig symbol (rebuild M0, bfe-core1106-sdk#19).
|
||||
|
||||
Its dependency $(success,$(PYTHON3) -c "import lxml") makes the expanded .config differ by host: with
|
||||
python3-lxml importable the file gains '# CONFIG_DRM_MSM_VALIDATE_XML is not set', without it the line is
|
||||
absent, so KCONFIG_SHA256 was not reproducible across hosts. The symbol only validates Qualcomm GPU register
|
||||
XML for DRM MSM developers; the panel has no Qualcomm GPU. No binary changes.
|
||||
|
||||
diff --git a/drivers/gpu/drm/msm/Kconfig b/drivers/gpu/drm/msm/Kconfig
|
||||
--- a/drivers/gpu/drm/msm/Kconfig
|
||||
+++ b/drivers/gpu/drm/msm/Kconfig
|
||||
@@ -50,14 +50,6 @@
|
||||
Only use this if you are a driver developer. This should *not*
|
||||
be enabled for production kernels. If unsure, say N.
|
||||
|
||||
-config DRM_MSM_VALIDATE_XML
|
||||
- bool "Validate XML register files against schema"
|
||||
- depends on DRM_MSM && EXPERT
|
||||
- depends on $(success,$(PYTHON3) -c "import lxml")
|
||||
- help
|
||||
- Validate XML files with register definitions against rules-fd schema.
|
||||
- This option is mostly targeting DRM MSM developers. If unsure, say N.
|
||||
-
|
||||
config DRM_MSM_KMS
|
||||
def_bool n
|
||||
depends on DRM_MSM
|
||||
+5
-2
@@ -1,8 +1,9 @@
|
||||
# The Kernel Patch Series
|
||||
|
||||
The delta that forward-ports the vendor Rockchip 5.10.160 RV1106 support onto a
|
||||
pristine upstream **linux-6.18.46**, as a reviewable, subsystem-split series. Every
|
||||
patch applies cleanly onto pristine 6.18.46 (`git apply --check`), and the whole set
|
||||
pristine upstream **linux-6.18.46**, as a reviewable, subsystem-split series. The
|
||||
series applies cleanly, in order, onto pristine 6.18.46 (`git apply --check`; a fix
|
||||
patch such as 82 edits files that an earlier patch adds), and the whole set
|
||||
reproduces the 223-file / ~136K-line delta that boots and is hardware-verified on
|
||||
`warden-c8a3` (see `../kernel/rv1106-enablement/`).
|
||||
|
||||
@@ -28,6 +29,8 @@ with `../build/warden_defconfig` -> `zImage` + `rv1106-warden.dtb`).
|
||||
| `60-wifi-aic8800.patch` | out-of-tree AIC8800 wifi/BT (the 88.5K-line vendor blob) |
|
||||
| `70-audio-codec.patch` | `rv1106_codec` + I2S wiring |
|
||||
| `80-misc-thermal-rtc-adc.patch` | tsadc, rtc-rockchip, saradc, trng, otp, gmac, goodix touch |
|
||||
| `82-arch-timer-vdso-phys-counter.patch` | arch timer: keep the arm32 vDSO clock off the virtual counter while the kernel times on the physical one (CNTVOFF left non-zero by the boot firmware, #35); checked by `tests/arch-timer/check-vdso-counter.py` |
|
||||
| `90-kconfig-no-python-symbol.patch` | drops `DRM_MSM_VALIDATE_XML` so the expanded `.config` (and `KCONFIG_SHA256`) does not depend on the host python (#19) |
|
||||
|
||||
## License
|
||||
|
||||
|
||||
+47
-1
@@ -54,7 +54,8 @@ screenshot from here is not evidence about a 5.10 panel's Wi-Fi page.
|
||||
WORK=$HOME/kbuild-out CROSS_COMPILE=arm-linux-gnueabihf- \
|
||||
WARDEN_KCONFIG_FRAGMENT=qemu/configs/virt.fragment bash build/build-kernel.sh
|
||||
|
||||
# 2. initramfs (sha256-pinned static busybox + qemu/rootfs/) and A/B disk
|
||||
# 2. initramfs (sha256-pinned static busybox + qemu/rootfs/) and A/B disk;
|
||||
# RIG_BUSYBOX=panel builds the image's own BusyBox instead (qemu/busybox/)
|
||||
bash qemu/mkinitramfs.sh
|
||||
bash qemu/mkimage.sh # options: --portal-url --state K=V --fw-version
|
||||
|
||||
@@ -73,6 +74,20 @@ daemons a bench panel already runs: flare-edge `tools/rig-pull-daemons.sh
|
||||
chardev without `--rs485`), so `warden-modbus` polls a port with nothing on
|
||||
it, as on a panel with an empty header, and never the control channel.
|
||||
|
||||
A `mosquitto` in the payload starts the panel's device bus first (socket
|
||||
`/run/warden/bus/bus.sock`, one credential file per bus user under
|
||||
`/run/warden/bus/cred/`), as S10bus does before every bus client on a panel;
|
||||
see `payload/README.md`. The rig broker takes any user and loads no plugin.
|
||||
With a test-flavor `warden-ui` and `wthctl` (flare-edge `tools/wthctl.c`, the
|
||||
test hook client) in the payload as well, a flow's `override` step pins a
|
||||
state document inside the UI: qmp.py hands the request to the control bridge
|
||||
(`@hookdoc` pieces, then `@hook override`), which sends it to `test/req/ui`
|
||||
as bus user `testhook` and answers the hook's reply. The run's first hook
|
||||
request waits until the hook answers a `ping` (retried while the bridge
|
||||
reports no answer, up to `HOOK_READY_S`): right after boot the UI is still
|
||||
taking the broker's retained replay, and an override sent then was lost
|
||||
(flare-edge #2602).
|
||||
|
||||
The VT cursor is kept off (`vt.global_cursor_default=0`): fbcon shares the
|
||||
virtio-gpu framebuffer with warden-ui and its blinking cursor would otherwise
|
||||
show up in screendumps at random (issue #18).
|
||||
@@ -85,6 +100,28 @@ does on a panel instead of rejecting every attempt. `qemu_stage_rootfs()`
|
||||
the executable bit, so the checked-out source file's own mode depends on the
|
||||
checking-out umask and cannot be trusted to arrive non-world-readable.
|
||||
|
||||
`--append warden.initchain` boots the UI the way a panel does (flare-edge
|
||||
#2210). The caller lays the panel's own scripts over the rootfs with
|
||||
`ROOTFS_OVERLAY=<dir> mkimage.sh` (only `etc/` and `usr/` at its top, no
|
||||
symlinks). Stage-2 init then starts `/etc/init.d/S00`-`S09` with `start`
|
||||
before the bus (S03warden-accounts creates the platform accounts, and the
|
||||
bus hands `cred/ui` to `warden-ui`), and `S10`-`S99` after the payload
|
||||
daemons in place of its direct root start of `warden-ui`. S99lvgl then runs
|
||||
`warden-ui-run`, which drops the UI to its account and respawns it. Rig
|
||||
differences: the splash handover is marked done (no S09splash) and
|
||||
warden-ui-run passes `-b fbdev`, not the panel's `-b drm`. A chain boot
|
||||
with no script prints `WARDEN-QEMU-INITCHAIN-EMPTY` and starts no UI.
|
||||
`tests/ui-drive.sh --init-chain <dir>` does both steps, and the drive verb
|
||||
`assert_ui_chain` judges the result: one `warden-ui` and one `warden-ui-run`,
|
||||
the UI's four uids all `warden-ui`'s, no safe-mode flag, and no exit or
|
||||
refusal in `/tmp/warden-ui.log`. `tests/scripts/init-chain-ui.txt` runs the
|
||||
check at about T+120 s.
|
||||
|
||||
A flow seed may contain `qemu-flow-setup.sh`. Stage-2 init runs it inside the
|
||||
disposable guest after mounting userdata and before starting daemons or the
|
||||
UI. A nonzero exit stops the boot. Use it only for test devices and commands
|
||||
that the virt machine does not provide.
|
||||
|
||||
## Scenarios
|
||||
|
||||
All take the virt-fragment `<zImage>`; `FLARE_EDGE=<checkout>` where noted.
|
||||
@@ -93,6 +130,7 @@ All take the virt-fragment `<zImage>`; `FLARE_EDGE=<checkout>` where noted.
|
||||
|---|---|---|
|
||||
| `stage-rootfs-perms.sh` | - | offline, no VM: `qemu_stage_rootfs()` always lands `etc/shadow` at 0600, even staged from a source copy deliberately left 0644 |
|
||||
| `seed-dir.sh` | - | offline, no VM: `mkimage.sh`'s `SEED_DIR` hook lands every seeded file under userdata/warden with its original mode (a 0600 secret included), a seeded file beats a same-named `--state` value, a `SEED_DIR` that isn't a directory fails closed, and so does an individual entry that is a symlink, a subdirectory, or named outside `[A-Za-z0-9_.-]+` -- a hyphenated key such as `gas-plant.devices` still seeds cleanly |
|
||||
| `payload-dir.sh` | - | offline, no VM: `mkimage.sh`'s `PAYLOAD_DIR` hook puts the run's own payload set (symlinked entries included, as regular 0755 files; its README.md skipped) into `/usr/bin` of both slots and nothing from `qemu/payload`, the default still reads `qemu/payload`, a `PAYLOAD_DIR` that is not a directory fails closed, and `ui-drive.sh` looks for `warden-ui` in the same directory |
|
||||
| `boot-smoke.sh` | - | sentinel-asserting boot; runs in CI inside kernel-build |
|
||||
| `portal-scenario.sh` | `FLARE_EDGE` | real flared against the desk mock portal: authenticated check-in, desired-state pull, signed tier-1 `.wfw` download; verify/stage/APPLYING as a dry run (no `WARDEN_FW_ALLOW_APPLY`) |
|
||||
| `ota-apply.sh` | `FLARE_EDGE` | the FULL apply: the `.wfw`'s bootable rootfs payload is written to rootfs_b (`run.sh --allow-apply` gates it per boot), the AvbABData in `misc` flips, and slot `_b` boots the applied version |
|
||||
@@ -100,7 +138,15 @@ All take the virt-fragment `<zImage>`; `FLARE_EDGE=<checkout>` where noted.
|
||||
| `ui-drive.sh <script>` | - | the same rig for a SEQUENCE: boots once, runs a `qmp.py drive` script of taps/swipes/screenshots in panel pixels, and FAILS if warden-ui died on the way (stage-2 init announces the exit on the console). `tests/scripts/nav-stress.txt` is the navigation regression: it reproduces the s_row_left overflow that segfaulted the UI on returning to Settings > Apps; `tests/scripts/home-leaves-fullscreen.txt` proves the `home` verb clears dashboard fullscreen, the state a hardware wake tap leaves behind (flare-edge #176); `tests/scripts/fullscreen-toggle-tracks-real-state.txt` proves a `fullscreen toggle` right after `home` (or a real tap) reads the dashboard's actual state rather than a belief `home` bypassed -- `test_qmp_drive.py`'s `FullscreenToggleTracksRealState` pins the same contract offline |
|
||||
| `real-image-boot.sh` | matched `rootfs.img` + `oem.img` | an ACTUAL flare-edge build (placed by `mkimage.sh --rootfs-image/--oem-image`) boots its own init chain to getty; binaries predating known fixes reproduce their bugs faithfully, a time machine for field issues |
|
||||
| `test-ui-drive-rs485.sh` | - | offline, no VM: a fake `run.sh` and (for one case) a fake `socat` stand in so `ui-drive.sh --rs485-devices`'s startup fails closed instead of printing a false "== rs485 simulator: ..." over a bus nothing is serving, for each of a qemu rs.sock that never appears, a socat that never links rs.pty, and an mbsim.py that dies before opening rs.ctl; also proves `cleanup()` escalates to SIGKILL for a sim process that ignores SIGTERM |
|
||||
| `rootfs-overlay.sh` | - | offline, no VM: `mkimage.sh`'s `ROOTFS_OVERLAY` hook lays a directory of panel files (flare-edge's S03warden-accounts, S99lvgl, warden-ui-run) over the rootfs of both slots with their modes kept, beside the skeleton's own files; without it there is no `/etc/init.d`; an overlay that is not a directory, names anything but `etc/` and `usr/` at its top, or holds a symlink fails closed and writes no image; `ui-drive.sh --init-chain` refuses a missing directory or one without `etc/init.d/S99lvgl` before boot |
|
||||
| `init-chain-test.sh` | - | offline, no VM: `warden_init_chain` (rootfs/etc/warden-lib.sh) starts the executable `S<NN>*` scripts of a number range in name order, names a failing one and goes on, and counts them; `warden_rig_bus_owners` hands a bus credential to its account only when the rootfs has it; sbin/init runs S00-S09 before the bus and S10-S99 instead of the direct UI start on a `warden.initchain` boot (flare-edge #2210) |
|
||||
| `run-sh-args-test.sh` | - | offline, no VM: a fake `qemu-system-arm` captures run.sh's own argv and pins the ctl/rs485 pci-serial ordering contract rootfs/sbin/init's ttyS0-vs-ttyS1 alias depends on -- the ctl device always enumerates before rs485, warden.ctl only lands on the cmdline when --ctl is given, and an rs485 pci-serial device (real or null-backed) is always present so the port count never shifts |
|
||||
| `busybox-panel-test.sh` | - | offline, no VM: the panel BusyBox inputs (qemu/busybox/). panel.config carries every setting of the image's applet patch, rig.fragment changes only STATIC, USE_BB_PWD_GRP and USE_BB_SHADOW, a Kconfig rewrite of any setting and an applet the panel lacks fail the build, applets.txt and help.txt agree, and RIG_BUSYBOX refuses an unknown value, and accepts a prebuilt panel `BUSYBOX` only when its `.inputs` match this tree (flare-edge#2210) |
|
||||
| `busybox-panel-help.sh [BIN]` | an ARM runner (binfmt or `QEMU_USER=qemu-arm`) | the built panel BusyBox against the bench capture: its applet list and every applet's `--help` equal the panel's own binary's. CI runs it in qemu-tools after `build-busybox.sh` |
|
||||
| `console-shell-test.sh` | - | offline, no VM: `warden_console_shell` (warden.shell) runs `setsid cttyhack sh` where cttyhack exists, else `setsid -c sh` on the console tty read from sysfs (the panel BusyBox has no cttyhack), else a plain sh. CI runs it under bash's `sh` and busybox `sh` |
|
||||
| `ctl-bridge-test.sh` | - | offline, no VM: runs the control bridge (`warden_ctl_bridge` in rootfs/etc/warden-lib.sh) against a fake warden-ui that answers some commands late. A reply slower than the old 5 s bound still arrives (the bound is now 30 s, `WARDEN_CTL_WAIT_S`), a timeout answers `bridge: no reply from warden-ui ...` (qmp.py raises it as a rig fault), and a timed-out command's late reply is drained instead of being read as the next command's answer (flare-edge #1448). A fake `wthctl` stands in for the hook client behind `@hookdoc`/`@hook` (flare-edge #2054): the pieces join into one request whose args are used once, only plain words reach the client, and a missing client or a request with no reply answers a `bridge:` line. CI runs it under bash's `sh` and busybox `sh` |
|
||||
| `init-rig-bus-test.sh` | - | offline, no VM: `warden_rig_bus` in rootfs/etc/warden-lib.sh against stub brokers. No broker in the payload creates nothing; a broker that listens gets the panel's layout (the `bus.sock` link, a 0400 64-hex credential per bus user, a config without password file, ACL or plugin); a broker that exits or never listens is reported within the bound; init starts the bus before the payload daemons. `WARDEN_TEST_MOSQUITTO_DIR` adds a real mosquitto carrying one message between two users logged in by credential file (flare-edge #1754) |
|
||||
| `agent-test.sh` | - | offline, no VM: the rig agent (`warden_agent` in rootfs/etc/warden-lib.sh, armed by `run.sh --agent` and `warden.agent`) answers `@run ID SECS B64` with `<<BEGIN ID>>`, the base64 of the script's output and `<<END ID RC>>`; `@chunk` pieces join into one script used once; a script past its deadline is killed with its process group and answers 124; a malformed request answers one `<<ERR ...>>` line and runs nothing; init puts the agent's port after ctl and RS485. It is the guest shell of flare-edge `tools/soak/rig-qemu.py` (M9 soak-lite). CI runs it under bash's `sh` and busybox `sh` |
|
||||
| watchdog (`run.sh --watchdog`) | - | arm `/dev/watchdog`, don't pet: the VM resets ~30 s later (verified) |
|
||||
|
||||
Scenario fine print:
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
#!/usr/bin/env bash
|
||||
# Build the rig's panel BusyBox: the image's BusyBox version with the image's
|
||||
# applet config, linked static for the rig's initramfs (flare-edge#2210).
|
||||
#
|
||||
# build-busybox.sh
|
||||
#
|
||||
# Env:
|
||||
# OUT output dir (default qemu/out); the binary lands at
|
||||
# $OUT/busybox-armv7l-panel, its rebuild key (.key) and its
|
||||
# source inputs (.inputs, see qemu_busybox_panel_inputs in
|
||||
# lib.sh) next to it
|
||||
# CROSS_COMPILE cross toolchain prefix (default arm-linux-gnueabihf-)
|
||||
# BB_SRC_TARBALL a local busybox-$BB_SRC_VER.tar.bz2 (skips the download;
|
||||
# still verified against BB_SRC_SHA256)
|
||||
# JOBS make -j (default: nproc, at most 4)
|
||||
#
|
||||
# The inputs are pinned, not the output: the source tarball by sha256 and the
|
||||
# configuration by the committed files in qemu/busybox/. Compilers differ
|
||||
# between hosts, so one host's binary hash means nothing on another; the
|
||||
# output is checked by its applet list instead (qemu/busybox/applets.txt, the
|
||||
# same list as flare-edge tests/fixtures/panel-busybox-applets.txt). A rebuild
|
||||
# is skipped when the input key (tarball, config files, compiler version)
|
||||
# matches the cached binary's.
|
||||
#
|
||||
# FAILS CLOSED: no cross compiler, a bad tarball, a configuration that the
|
||||
# BusyBox Kconfig rewrites (a symbol the version does not know), an applet
|
||||
# list that differs, or a dynamically linked result is an error, never a
|
||||
# fallback to the multiarch binary.
|
||||
set -euo pipefail
|
||||
|
||||
QEMU_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
BB_DIR="$QEMU_DIR/busybox"
|
||||
|
||||
# The source pin (BB_SRC_VER, BB_SRC_URL, BB_SRC_SHA256) lives in lib.sh,
|
||||
# beside qemu_busybox_panel_inputs, which a prebuilt binary is checked by.
|
||||
# shellcheck source=qemu/lib.sh disable=SC1091
|
||||
. "$QEMU_DIR/lib.sh"
|
||||
|
||||
# Write the panel config with every fragment line applied: the symbol's old
|
||||
# setting (set or "is not set") is dropped and the fragment's line appended.
|
||||
# Usage: bb_apply_fragment PANEL_CONFIG FRAGMENT > .config
|
||||
bb_apply_fragment() {
|
||||
local panel="$1" frag="$2" line sym pat=""
|
||||
while IFS= read -r line; do
|
||||
case "$line" in ''|'#'*) continue ;; esac
|
||||
sym="${line%%=*}"
|
||||
case "$sym" in
|
||||
CONFIG_*) ;;
|
||||
*) echo "FATAL: bad fragment line: '$line'" >&2; return 1 ;;
|
||||
esac
|
||||
pat="${pat}|^${sym}=|^# ${sym} is not set\$"
|
||||
done < "$frag"
|
||||
if [ -n "$pat" ]; then
|
||||
grep -Ev "${pat#|}" "$panel" || true
|
||||
else
|
||||
cat "$panel"
|
||||
fi
|
||||
grep -Ev '^(#|$)' "$frag"
|
||||
}
|
||||
|
||||
# The settings of a config file, one per line, sorted: "SYM=value" for a set
|
||||
# symbol and "SYM is not set" for an unset one. Comments and the header are
|
||||
# dropped, so two configs compare by what they configure.
|
||||
bb_settings() {
|
||||
sed -n -e 's/^\(CONFIG_[A-Za-z0-9_]*=.*\)$/\1/p' \
|
||||
-e 's/^# \(CONFIG_[A-Za-z0-9_]*\) is not set$/\1 is not set/p' "$1" | LC_ALL=C sort
|
||||
}
|
||||
|
||||
# Fail when Kconfig changed any setting of the config it was given (WANT)
|
||||
# while writing GOT: a symbol this BusyBox version does not know, or one whose
|
||||
# dependencies are unmet, would otherwise be dropped without a word.
|
||||
bb_check_config() {
|
||||
local want="$1" got="$2" d
|
||||
if ! d="$(diff <(bb_settings "$want") <(bb_settings "$got"))"; then
|
||||
echo "FATAL: the BusyBox $BB_SRC_VER Kconfig rewrote the panel config (< given, > written):" >&2
|
||||
printf '%s\n' "$d" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Compare the applet names in a busybox.links file (one install path per line)
|
||||
# with the committed list. Usage: bb_check_applets LINKS APPLETS_TXT
|
||||
bb_check_applets() {
|
||||
local links="$1" want="$2" d
|
||||
if ! d="$(diff <(LC_ALL=C sort -u "$want") <(sed 's|.*/||' "$links" | LC_ALL=C sort -u))"; then
|
||||
echo "FATAL: the built BusyBox applet list differs from $want (< want, > built):" >&2
|
||||
printf '%s\n' "$d" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# The cache key: everything the binary is built from.
|
||||
bb_input_key() {
|
||||
local cc="$1"
|
||||
{
|
||||
qemu_busybox_panel_inputs
|
||||
echo "$cc"
|
||||
"${cc}gcc" --version | head -n 1
|
||||
} | sha256sum | awk '{print $1}'
|
||||
}
|
||||
|
||||
bb_main() {
|
||||
local out="${OUT:-$QEMU_DIR/out}" cc="${CROSS_COMPILE:-arm-linux-gnueabihf-}"
|
||||
local jobs="${JOBS:-}" bin key src scratch tar
|
||||
bin="$out/busybox-armv7l-panel"
|
||||
command -v "${cc}gcc" >/dev/null || {
|
||||
echo "FATAL: no ${cc}gcc on PATH (apt-get install gcc-arm-linux-gnueabihf, or set CROSS_COMPILE)" >&2
|
||||
exit 1
|
||||
}
|
||||
if [ -z "$jobs" ]; then
|
||||
jobs="$(nproc)"; [ "$jobs" -le 4 ] || jobs=4
|
||||
fi
|
||||
mkdir -p "$out"
|
||||
key="$(bb_input_key "$cc")"
|
||||
if [ -f "$bin" ] && [ "$(cat "$bin.key" 2>/dev/null)" = "$key" ]; then
|
||||
qemu_busybox_panel_inputs > "$bin.inputs"
|
||||
qemu_log "panel busybox up to date ($bin)"
|
||||
return
|
||||
fi
|
||||
# A stale .inputs must never vouch for a binary while it is rebuilt.
|
||||
rm -f "$bin.inputs"
|
||||
|
||||
tar="${BB_SRC_TARBALL:-$out/busybox-${BB_SRC_VER}.tar.bz2}"
|
||||
qemu_fetch_verified "$BB_SRC_URL" "$BB_SRC_SHA256" "$tar" "busybox ${BB_SRC_VER} source" \
|
||||
"$BB_SRC_MIRROR_URL"
|
||||
|
||||
scratch="$(mktemp -d "${TMPDIR:-/tmp}/warden-busybox.XXXXXX")"
|
||||
# Expanded now on purpose: the trap must remove this run's directory.
|
||||
# shellcheck disable=SC2064
|
||||
trap "rm -rf '$scratch'" EXIT
|
||||
tar -xjf "$tar" -C "$scratch"
|
||||
src="$scratch/busybox-${BB_SRC_VER}"
|
||||
[ -d "$src" ] || { echo "FATAL: $tar has no busybox-${BB_SRC_VER}/" >&2; exit 1; }
|
||||
# Buildroot's patches for this version, as the image applies them.
|
||||
local p
|
||||
for p in "$BB_DIR"/patches/*.patch; do
|
||||
patch -d "$src" -p1 -s --no-backup-if-mismatch < "$p" || {
|
||||
echo "FATAL: $p does not apply to busybox $BB_SRC_VER" >&2
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
|
||||
bb_apply_fragment "$BB_DIR/panel.config" "$BB_DIR/rig.fragment" > "$scratch/want.config"
|
||||
cp "$scratch/want.config" "$src/.config"
|
||||
# Fixed time stamps so two builds with one compiler give one binary.
|
||||
export SOURCE_DATE_EPOCH=0 KCONFIG_NOTIMESTAMP=1 KBUILD_BUILD_TIMESTAMP="1970-01-01"
|
||||
export KBUILD_BUILD_USER=warden KBUILD_BUILD_HOST=rig
|
||||
# oldconfig with no terminal: a symbol missing from the config would stop
|
||||
# at a prompt and read EOF; the settings check below names it either way.
|
||||
make -C "$src" -s CROSS_COMPILE="$cc" oldconfig </dev/null >"$scratch/oldconfig.log" 2>&1 || {
|
||||
cat "$scratch/oldconfig.log" >&2
|
||||
echo "FATAL: make oldconfig failed" >&2
|
||||
exit 1
|
||||
}
|
||||
bb_check_config "$scratch/want.config" "$src/.config"
|
||||
qemu_log "building busybox $BB_SRC_VER (panel config, static, ${cc}gcc, -j$jobs)"
|
||||
make -C "$src" -s -j"$jobs" CROSS_COMPILE="$cc" busybox busybox.links >"$scratch/make.log" 2>&1 || {
|
||||
tail -n 40 "$scratch/make.log" >&2
|
||||
echo "FATAL: busybox build failed" >&2
|
||||
exit 1
|
||||
}
|
||||
bb_check_applets "$src/busybox.links" "$BB_DIR/applets.txt"
|
||||
if "${cc}readelf" -l "$src/busybox" | grep -q 'INTERP'; then
|
||||
echo "FATAL: the built busybox is dynamically linked (CONFIG_STATIC not applied)" >&2
|
||||
exit 1
|
||||
fi
|
||||
"${cc}readelf" -h "$src/busybox" | grep -q 'Machine:.*ARM' || {
|
||||
echo "FATAL: the built busybox is not an ARM binary" >&2
|
||||
exit 1
|
||||
}
|
||||
install -m 0755 "$src/busybox" "$bin.tmp"
|
||||
mv -f "$bin.tmp" "$bin"
|
||||
printf '%s\n' "$key" > "$bin.key"
|
||||
# For a job without the cross compiler: qemu_get_busybox accepts this
|
||||
# binary as BUSYBOX under RIG_BUSYBOX=panel when the inputs match its tree.
|
||||
qemu_busybox_panel_inputs > "$bin.inputs"
|
||||
qemu_log "panel busybox: $bin ($(sha256sum "$bin" | awk '{print $1}'))"
|
||||
}
|
||||
|
||||
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
|
||||
bb_main "$@"
|
||||
fi
|
||||
@@ -0,0 +1,36 @@
|
||||
# The panel's BusyBox, for the rig
|
||||
|
||||
`RIG_BUSYBOX=panel` (qemu/lib.sh) makes the rig run the image's own BusyBox
|
||||
instead of the busybox.net 1.31.0 multiarch binary, so a script that calls an
|
||||
applet or option the panel lacks fails in the rig as it fails on a panel
|
||||
(flare-edge#2210; #1903 `setpriv --reuid`, #2002 `stat`, #1349 `flock -w`).
|
||||
`qemu/build-busybox.sh` builds it; the default stays `multiarch` until the
|
||||
flare-edge QEMU jobs switch over.
|
||||
|
||||
| File | What it is |
|
||||
|---|---|
|
||||
| `panel.config` | The image's BusyBox 1.37.0 configuration. Made from Buildroot 2025.02.8 `package/busybox/busybox.config` (the vendor SDK's base; its header matches the `a/` side of the applet patch), with `luckfox-sdk-patches/buildroot/patches/0001-busybox-applets.patch` applied and then `yes "" \| make oldconfig` in busybox-1.37.0, as Buildroot does for a config written for an older version (it adds TIME64, GETFATTR, FIND_EXEC_OK, IP_LINK_CAN and UDHCPD_BOOTP at their defaults and drops ASH_SLEEP). The time stamp line is dropped. |
|
||||
| `rig.fragment` | The rig's only differences: a static link, and BusyBox's own passwd, group and shadow readers (a static glibc binary cannot load NSS modules). Neither adds or removes an applet or option. |
|
||||
| `patches/` | Buildroot 2025.02.8's `package/busybox/*.patch`, applied in order like the image build does (one of them is what makes `tc` build with current kernel headers). Commit-message text was changed to ASCII; the diffs are unchanged. |
|
||||
| `applets.txt` | `busybox --list` of the panel (bench a, image 417a66b), the same as flare-edge `tests/fixtures/panel-busybox-applets.txt`. The build fails when its applet list differs. |
|
||||
| `help.txt` | `busybox <applet> --help` of every applet of the panel, the same as flare-edge `tests/fixtures/panel-busybox-help.txt` (flare-edge `tools/bench/busybox-help/capture.sh`). `qemu/tests/busybox-panel-help.sh` compares the built binary with it. |
|
||||
|
||||
The Buildroot fixups in `busybox.mk` that depend on the image's Buildroot
|
||||
options (mdev, init, watchdog, less flags, crypt SHA) are not applied here;
|
||||
the applet list and the per-applet help check would show any of them that
|
||||
changed an applet or an option. When the image's BusyBox changes, update
|
||||
`panel.config` and `patches/` the same way and re-capture `applets.txt` and
|
||||
`help.txt` from a panel.
|
||||
|
||||
The inputs are pinned (source tarball sha256, these files); the output is not,
|
||||
because each host's compiler gives a different binary. The cache key in
|
||||
`$OUT/busybox-armv7l-panel.key` covers the tarball, these files and the
|
||||
compiler version.
|
||||
|
||||
A job without the cross compiler (a flare-edge flow job, given the binary its
|
||||
image build job made) sets `RIG_BUSYBOX=panel BUSYBOX=<binary>`. The build
|
||||
writes `<binary>.inputs` next to it: one sha256 over the source pin and these
|
||||
files, without the compiler (`qemu_busybox_panel_inputs` in qemu/lib.sh).
|
||||
`qemu_get_busybox` takes the prebuilt binary only when that file equals the
|
||||
value for its own tree, so a binary built from another config is refused
|
||||
rather than booted.
|
||||
@@ -0,0 +1,282 @@
|
||||
[
|
||||
[[
|
||||
addgroup
|
||||
adduser
|
||||
ar
|
||||
arch
|
||||
arp
|
||||
arping
|
||||
ascii
|
||||
ash
|
||||
awk
|
||||
base32
|
||||
base64
|
||||
basename
|
||||
bc
|
||||
blkid
|
||||
bunzip2
|
||||
bzcat
|
||||
cat
|
||||
chattr
|
||||
chgrp
|
||||
chmod
|
||||
chown
|
||||
chroot
|
||||
chrt
|
||||
chvt
|
||||
cksum
|
||||
clear
|
||||
cmp
|
||||
cp
|
||||
cpio
|
||||
crc32
|
||||
crond
|
||||
crontab
|
||||
cut
|
||||
date
|
||||
dc
|
||||
dd
|
||||
deallocvt
|
||||
delgroup
|
||||
deluser
|
||||
devmem
|
||||
df
|
||||
diff
|
||||
dirname
|
||||
dmesg
|
||||
dnsd
|
||||
dnsdomainname
|
||||
dos2unix
|
||||
du
|
||||
dumpkmap
|
||||
echo
|
||||
egrep
|
||||
eject
|
||||
env
|
||||
ether-wake
|
||||
expr
|
||||
factor
|
||||
fallocate
|
||||
false
|
||||
fbset
|
||||
fdflush
|
||||
fdformat
|
||||
fdisk
|
||||
fgrep
|
||||
find
|
||||
flock
|
||||
fold
|
||||
free
|
||||
freeramdisk
|
||||
fsck
|
||||
fsfreeze
|
||||
fstrim
|
||||
fuser
|
||||
getfattr
|
||||
getopt
|
||||
getty
|
||||
grep
|
||||
gunzip
|
||||
gzip
|
||||
halt
|
||||
hdparm
|
||||
head
|
||||
hexdump
|
||||
hexedit
|
||||
hostid
|
||||
hostname
|
||||
hwclock
|
||||
i2cdetect
|
||||
i2cdump
|
||||
i2cget
|
||||
i2cset
|
||||
i2ctransfer
|
||||
id
|
||||
ifconfig
|
||||
ifdown
|
||||
ifup
|
||||
inetd
|
||||
init
|
||||
insmod
|
||||
install
|
||||
ip
|
||||
ipaddr
|
||||
ipcrm
|
||||
ipcs
|
||||
iplink
|
||||
ipneigh
|
||||
iproute
|
||||
iprule
|
||||
iptunnel
|
||||
kill
|
||||
killall
|
||||
killall5
|
||||
klogd
|
||||
last
|
||||
less
|
||||
link
|
||||
linux32
|
||||
linux64
|
||||
linuxrc
|
||||
ln
|
||||
loadfont
|
||||
loadkmap
|
||||
logger
|
||||
login
|
||||
logname
|
||||
losetup
|
||||
ls
|
||||
lsattr
|
||||
lsmod
|
||||
lsof
|
||||
lspci
|
||||
lsscsi
|
||||
lsusb
|
||||
lzcat
|
||||
lzma
|
||||
lzopcat
|
||||
makedevs
|
||||
md5sum
|
||||
mdev
|
||||
mesg
|
||||
microcom
|
||||
mim
|
||||
mkdir
|
||||
mkdosfs
|
||||
mke2fs
|
||||
mkfifo
|
||||
mknod
|
||||
mkpasswd
|
||||
mkswap
|
||||
mktemp
|
||||
modprobe
|
||||
more
|
||||
mount
|
||||
mountpoint
|
||||
mt
|
||||
mv
|
||||
nameif
|
||||
netstat
|
||||
nice
|
||||
nl
|
||||
nohup
|
||||
nologin
|
||||
nproc
|
||||
nslookup
|
||||
nuke
|
||||
od
|
||||
openvt
|
||||
partprobe
|
||||
passwd
|
||||
paste
|
||||
patch
|
||||
pidof
|
||||
ping
|
||||
pipe_progress
|
||||
pivot_root
|
||||
poweroff
|
||||
printenv
|
||||
printf
|
||||
ps
|
||||
pwd
|
||||
rdate
|
||||
readlink
|
||||
readprofile
|
||||
realpath
|
||||
reboot
|
||||
renice
|
||||
reset
|
||||
resize
|
||||
resume
|
||||
rfkill
|
||||
rm
|
||||
rmdir
|
||||
rmmod
|
||||
route
|
||||
run-init
|
||||
run-parts
|
||||
runlevel
|
||||
sed
|
||||
seedrng
|
||||
seq
|
||||
setarch
|
||||
setconsole
|
||||
setfattr
|
||||
setkeycodes
|
||||
setlogcons
|
||||
setpriv
|
||||
setserial
|
||||
setsid
|
||||
sh
|
||||
sha1sum
|
||||
sha256sum
|
||||
sha3sum
|
||||
sha512sum
|
||||
shred
|
||||
sleep
|
||||
sort
|
||||
start-stop-daemon
|
||||
strings
|
||||
stty
|
||||
su
|
||||
sulogin
|
||||
svc
|
||||
svok
|
||||
swapoff
|
||||
swapon
|
||||
switch_root
|
||||
sync
|
||||
sysctl
|
||||
syslogd
|
||||
tail
|
||||
tar
|
||||
tc
|
||||
tee
|
||||
telnet
|
||||
telnetd
|
||||
test
|
||||
tftp
|
||||
time
|
||||
top
|
||||
touch
|
||||
tr
|
||||
traceroute
|
||||
tree
|
||||
true
|
||||
truncate
|
||||
ts
|
||||
tsort
|
||||
tty
|
||||
ubirename
|
||||
udhcpc
|
||||
uevent
|
||||
umount
|
||||
uname
|
||||
uniq
|
||||
unix2dos
|
||||
unlink
|
||||
unlzma
|
||||
unlzop
|
||||
unxz
|
||||
unzip
|
||||
uptime
|
||||
usleep
|
||||
uudecode
|
||||
uuencode
|
||||
vconfig
|
||||
vi
|
||||
vlock
|
||||
w
|
||||
watch
|
||||
watchdog
|
||||
wc
|
||||
wget
|
||||
which
|
||||
who
|
||||
whoami
|
||||
xargs
|
||||
xxd
|
||||
xz
|
||||
xzcat
|
||||
yes
|
||||
zcat
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,37 @@
|
||||
From e1690453cd84c798ca88cc4370710f65da86d986 Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
|
||||
Date: Sat, 5 Oct 2013 15:55:06 +0200
|
||||
Subject: [PATCH] networking/libiproute: use <linux/if_packet.h> instead of
|
||||
<net/if_packet.h>
|
||||
|
||||
The musl C library doesn't provide the <net/if_packet.h> since the
|
||||
corresponding kernel headers <linux/if_packet.h> already provides the
|
||||
necessary definitions. Replacing <net/if_packet.h> by
|
||||
<linux/if_packet.h> also removes the need to include
|
||||
<netpacket/packet.h>
|
||||
|
||||
This commit fixes the build of iplink with the musl C library.
|
||||
|
||||
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
|
||||
[Gustavo: update for busybox 1.22.0]
|
||||
Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
|
||||
---
|
||||
networking/libiproute/iplink.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c
|
||||
index 37ed114bc..bc526d89c 100644
|
||||
--- a/networking/libiproute/iplink.c
|
||||
+++ b/networking/libiproute/iplink.c
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
#include <net/if.h>
|
||||
/*#include <net/if_packet.h> - not needed? */
|
||||
-#include <netpacket/packet.h>
|
||||
+#include <linux/if_packet.h>
|
||||
#include <netinet/if_ether.h>
|
||||
|
||||
#include <linux/if_vlan.h>
|
||||
--
|
||||
2.48.1
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
From df20ae1280a2601a4c233ec12372d1e17db21e96 Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
|
||||
Date: Mon, 25 Nov 2013 22:51:53 +0100
|
||||
Subject: [PATCH] Makefile.flags: strip non -l arguments returned by pkg-config
|
||||
|
||||
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
|
||||
[yann.morin.1998@free.fr: refresh for 1.29.0]
|
||||
[petr.vorel@gmail.com: refresh for 1.32.0]
|
||||
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
|
||||
Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
|
||||
---
|
||||
Makefile.flags | 4 +++-
|
||||
1 file changed, 3 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/Makefile.flags b/Makefile.flags
|
||||
index 97cb4dca2..92a9063d9 100644
|
||||
--- a/Makefile.flags
|
||||
+++ b/Makefile.flags
|
||||
@@ -181,7 +181,9 @@ ifeq ($(CONFIG_SELINUX),y)
|
||||
SELINUX_PC_MODULES = libselinux libsepol
|
||||
$(eval $(call pkg_check_modules,SELINUX,$(SELINUX_PC_MODULES)))
|
||||
CPPFLAGS += $(SELINUX_CFLAGS)
|
||||
-LDLIBS += $(if $(SELINUX_LIBS),$(SELINUX_LIBS:-l%=%),$(SELINUX_PC_MODULES:lib%=%))
|
||||
+LDLIBS += $(if $(SELINUX_LIBS),\
|
||||
+ $(patsubst -l%,%,$(filter -l%,$(SELINUX_LIBS))),\
|
||||
+ $(SELINUX_PC_MODULES:lib%=%))
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_FEATURE_NSLOOKUP_BIG),y)
|
||||
--
|
||||
2.48.1
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
From 68eaf20d86d4fe0f16a914817217f386155157cc Mon Sep 17 00:00:00 2001
|
||||
From: Ariadne Conill <ariadne@dereferenced.org>
|
||||
Date: Mon, 19 Sep 2022 14:15:12 +0200
|
||||
Subject: [PATCH] libbb: sockaddr2str: ensure only printable characters are
|
||||
returned for the hostname part
|
||||
|
||||
CVE: CVE-2022-28391
|
||||
Signed-off-by: Ariadne Conill <ariadne@dereferenced.org>
|
||||
Tested-by: Radoslav Kolev <radoslav.kolev@suse.com>
|
||||
Backport from ML: http://lists.busybox.net/pipermail/busybox/2022-July/089796.html
|
||||
Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
|
||||
---
|
||||
libbb/xconnect.c | 5 +++--
|
||||
1 file changed, 3 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
|
||||
index 0e0b247b8..02c061e67 100644
|
||||
--- a/libbb/xconnect.c
|
||||
+++ b/libbb/xconnect.c
|
||||
@@ -497,8 +497,9 @@ static char* FAST_FUNC sockaddr2str(const struct sockaddr *sa, int flags)
|
||||
);
|
||||
if (rc)
|
||||
return NULL;
|
||||
+ /* ensure host contains only printable characters */
|
||||
if (flags & IGNORE_PORT)
|
||||
- return xstrdup(host);
|
||||
+ return xstrdup(printable_string(host));
|
||||
#if ENABLE_FEATURE_IPV6
|
||||
if (sa->sa_family == AF_INET6) {
|
||||
if (strchr(host, ':')) /* heh, it's not a resolved hostname */
|
||||
@@ -509,7 +510,7 @@ static char* FAST_FUNC sockaddr2str(const struct sockaddr *sa, int flags)
|
||||
#endif
|
||||
/* For now we don't support anything else, so it has to be INET */
|
||||
/*if (sa->sa_family == AF_INET)*/
|
||||
- return xasprintf("%s:%s", host, serv);
|
||||
+ return xasprintf("%s:%s", printable_string(host), serv);
|
||||
/*return xstrdup(host);*/
|
||||
}
|
||||
|
||||
--
|
||||
2.48.1
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
From 56b84c6efb9a06ae294eb92cf9634f70af443b0a Mon Sep 17 00:00:00 2001
|
||||
From: Ariadne Conill <ariadne@dereferenced.org>
|
||||
Date: Mon, 19 Sep 2022 14:15:12 +0200
|
||||
Subject: [PATCH] nslookup: sanitize all printed strings with printable_string
|
||||
|
||||
Otherwise, terminal sequences can be injected, which enables various terminal injection
|
||||
attacks from DNS results.
|
||||
|
||||
CVE: CVE-2022-28391
|
||||
Signed-off-by: Ariadne Conill <ariadne@dereferenced.org>
|
||||
Tested-by: Radoslav Kolev <radoslav.kolev@suse.com>
|
||||
Backport from ML: http://lists.busybox.net/pipermail/busybox/2022-July/089795.html
|
||||
Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
|
||||
---
|
||||
networking/nslookup.c | 10 +++++-----
|
||||
1 file changed, 5 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/networking/nslookup.c b/networking/nslookup.c
|
||||
index b67d354f7..79412477c 100644
|
||||
--- a/networking/nslookup.c
|
||||
+++ b/networking/nslookup.c
|
||||
@@ -784,7 +784,7 @@ static NOINLINE int parse_reply(const unsigned char *msg, size_t len)
|
||||
//printf("Unable to uncompress domain: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
- printf(format, ns_rr_name(rr), dname);
|
||||
+ printf(format, ns_rr_name(rr), printable_string(dname));
|
||||
break;
|
||||
|
||||
case ns_t_mx:
|
||||
@@ -799,7 +799,7 @@ static NOINLINE int parse_reply(const unsigned char *msg, size_t len)
|
||||
//printf("Cannot uncompress MX domain: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
- printf("%s\tmail exchanger = %d %s\n", ns_rr_name(rr), n, dname);
|
||||
+ printf("%s\tmail exchanger = %d %s\n", ns_rr_name(rr), n, printable_string(dname));
|
||||
break;
|
||||
|
||||
case ns_t_txt:
|
||||
@@ -811,7 +811,7 @@ static NOINLINE int parse_reply(const unsigned char *msg, size_t len)
|
||||
if (n > 0) {
|
||||
memset(dname, 0, sizeof(dname));
|
||||
memcpy(dname, ns_rr_rdata(rr) + 1, n);
|
||||
- printf("%s\ttext = \"%s\"\n", ns_rr_name(rr), dname);
|
||||
+ printf("%s\ttext = \"%s\"\n", ns_rr_name(rr), printable_string(dname));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -831,7 +831,7 @@ static NOINLINE int parse_reply(const unsigned char *msg, size_t len)
|
||||
}
|
||||
|
||||
printf("%s\tservice = %u %u %u %s\n", ns_rr_name(rr),
|
||||
- ns_get16(cp), ns_get16(cp + 2), ns_get16(cp + 4), dname);
|
||||
+ ns_get16(cp), ns_get16(cp + 2), ns_get16(cp + 4), printable_string(dname));
|
||||
break;
|
||||
|
||||
case ns_t_soa:
|
||||
@@ -860,7 +860,7 @@ static NOINLINE int parse_reply(const unsigned char *msg, size_t len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
- printf("\tmail addr = %s\n", dname);
|
||||
+ printf("\tmail addr = %s\n", printable_string(dname));
|
||||
cp += n;
|
||||
|
||||
printf("\tserial = %lu\n", ns_get32(cp));
|
||||
--
|
||||
2.48.1
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
From 9fed109be1f811069cb2f727e04c6996cd44b017 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Rapha=C3=ABl=20M=C3=A9lotte?= <raphael.melotte@mind.be>
|
||||
Date: Tue, 18 Apr 2023 15:54:43 +0200
|
||||
Subject: [PATCH] seedrng: fix getrandom() detection for non-glibc libc
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
glibc <= 2.24 does not provide getrandom(). A check for it has been
|
||||
added in 200a9669fbf6f06894e4243cccc9fc11a1a6073a and fixed in
|
||||
cb57abb46f06f4ede8d9ccbdaac67377fdf416cf.
|
||||
|
||||
However, building with a libc other than glibc can lead to the same
|
||||
problem as not every other libc has getrandom() either:
|
||||
|
||||
- uClibc provides it from v1.0.2 onwards, but requires to define
|
||||
_GNU_SOURCE (all versions - we already define it by default), and
|
||||
stddef to be included first (when using uClibc < 1.0.35 - we already
|
||||
include it through libbb.h).
|
||||
|
||||
- musl libc has getrandom(), but only from version 1.1.20 onwards. As
|
||||
musl does not provide __MUSL__ or version information, it's not
|
||||
possible to check for it like we did for glibc.
|
||||
|
||||
All of this makes it difficult (or impossible in case of musl) to
|
||||
check what we need to do to have getrandom() based on each libc
|
||||
versions.
|
||||
|
||||
On top of that, getrandom() is also not available on older kernels. As
|
||||
an example, when using a 3.10 kernel with uClibc 1.0.26, getrandom()
|
||||
is declared so compiling works, but it fails at link time because
|
||||
getrandom() is not defined.
|
||||
|
||||
To make it easier, take a similar approach to what was done for the
|
||||
crypt library: try to build a sample program to see if we have
|
||||
getrandom(). To keep it compatible with different versions of
|
||||
make (for reference see [1]), a variable for '#' is also introduced.
|
||||
|
||||
Based on the new Makefile variable, we now either use the
|
||||
libc-provided getrandom() when it's available, or use our own
|
||||
implementation when it's not (like it was the case already for glibc <
|
||||
2.25).
|
||||
|
||||
This should fix compiling with many libc/kernel combinations.
|
||||
|
||||
[1]: https://git.savannah.gnu.org/cgit/make.git/commit/?id=c6966b323811c37acedff05b576b907b06aea5f4
|
||||
|
||||
Signed-off-by: Raphael Melotte <raphael.melotte@mind.be>
|
||||
Upstream: http://lists.busybox.net/pipermail/busybox/2023-May/090317.html
|
||||
---
|
||||
Makefile.flags | 12 ++++++++++++
|
||||
miscutils/seedrng.c | 8 ++++----
|
||||
2 files changed, 16 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/Makefile.flags b/Makefile.flags
|
||||
index 92a9063d9..c8f601308 100644
|
||||
--- a/Makefile.flags
|
||||
+++ b/Makefile.flags
|
||||
@@ -162,6 +162,18 @@ ifeq ($(RT_AVAILABLE),y)
|
||||
LDLIBS += rt
|
||||
endif
|
||||
|
||||
+# GNU Make version 4.2.1 and earlier require number signs ('#')
|
||||
+# inside function invocations to be escaped, while versions 4.3+
|
||||
+# require them to be unescaped. Use a variable for it so that it works
|
||||
+# for both versions:
|
||||
+C := \#
|
||||
+# Not all libc versions have getrandom, so check for it:
|
||||
+HAVE_GETRANDOM := $(shell printf '$Cdefine _GNU_SOURCE\n$Cinclude <stddef.h>\n$Cinclude <sys/random.h>\nint main(void){char buf[256];\ngetrandom(buf,sizeof(buf),0);}' >bb_libtest.c; $(CC) $(CFLAGS) $(CFLAGS_busybox) -o /dev/null bb_libtest.c >/dev/null 2>&1 && echo "y"; rm bb_libtest.c)
|
||||
+
|
||||
+ifeq ($(HAVE_GETRANDOM),y)
|
||||
+CFLAGS += -DHAVE_GETRANDOM
|
||||
+endif
|
||||
+
|
||||
# libpam may use libpthread, libdl and/or libaudit.
|
||||
# On some platforms that requires an explicit -lpthread, -ldl, -laudit.
|
||||
# However, on *other platforms* it fails when some of those flags
|
||||
diff --git a/miscutils/seedrng.c b/miscutils/seedrng.c
|
||||
index 7a2331cb1..ba98f4d19 100644
|
||||
--- a/miscutils/seedrng.c
|
||||
+++ b/miscutils/seedrng.c
|
||||
@@ -44,8 +44,10 @@
|
||||
#include <linux/random.h>
|
||||
#include <sys/file.h>
|
||||
|
||||
-/* Fix up glibc <= 2.24 not having getrandom() */
|
||||
-#if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 24
|
||||
+/* Fix up some libc (e.g. glibc <= 2.24) not having getrandom() */
|
||||
+#if defined HAVE_GETRANDOM
|
||||
+#include <sys/random.h>
|
||||
+#else /* No getrandom */
|
||||
#include <sys/syscall.h>
|
||||
static ssize_t getrandom(void *buffer, size_t length, unsigned flags)
|
||||
{
|
||||
@@ -56,8 +58,6 @@ static ssize_t getrandom(void *buffer, size_t length, unsigned flags)
|
||||
return -1;
|
||||
# endif
|
||||
}
|
||||
-#else
|
||||
-#include <sys/random.h>
|
||||
#endif
|
||||
|
||||
/* Apparently some headers don't ship with this yet. */
|
||||
--
|
||||
2.48.1
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
From 7f0bb7f69f38298971aa8153d3fbe9b1fdda8ae7 Mon Sep 17 00:00:00 2001
|
||||
From: ctxnop <ctxnop@gmail.com>
|
||||
Date: Sun, 26 Jan 2025 20:59:20 +0100
|
||||
Subject: [PATCH] menuconfig: GCC failing saying ncurses is not found
|
||||
|
||||
Newer GCC increased diagnostics levels resulting in considering the
|
||||
test code to be invalid. The resulting message was misleading, saying
|
||||
that ncurses was not found, while the check failed for an unrelated
|
||||
reason which was hidden because GCC stderr was redirected to
|
||||
/dev/null.
|
||||
|
||||
Signed-off-by: ctxnop <ctxnop@gmail.com>
|
||||
Upstream: http://lists.busybox.net/pipermail/busybox/2024-July/090840.html
|
||||
[Fiona: rephrased commit message for clarity]
|
||||
Signed-off-by: Fiona Klute (WIWA) <fiona.klute@gmx.de>
|
||||
---
|
||||
scripts/kconfig/lxdialog/check-lxdialog.sh | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/scripts/kconfig/lxdialog/check-lxdialog.sh b/scripts/kconfig/lxdialog/check-lxdialog.sh
|
||||
index 5075ebf2d..08e4da3de 100755
|
||||
--- a/scripts/kconfig/lxdialog/check-lxdialog.sh
|
||||
+++ b/scripts/kconfig/lxdialog/check-lxdialog.sh
|
||||
@@ -45,9 +45,9 @@ trap "rm -f $tmp" 0 1 2 3 15
|
||||
|
||||
# Check if we can link to ncurses
|
||||
check() {
|
||||
- $cc -x c - -o $tmp 2>/dev/null <<'EOF'
|
||||
+ $cc -x c - -o $tmp <<'EOF'
|
||||
#include CURSES_LOC
|
||||
-main() {}
|
||||
+int main() { return 0; }
|
||||
EOF
|
||||
if [ $? != 0 ]; then
|
||||
echo " *** Unable to find the ncurses libraries or the" 1>&2
|
||||
--
|
||||
2.48.1
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
From 1dbb3073a3a8856b9446b882f797be1bb2e21a26 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= <u.kleine-koenig@pengutronix.de>
|
||||
Date: Mon, 23 Sep 2024 18:56:00 +0200
|
||||
Subject: [PATCH] tc: Fix compilation with Linux v6.8-rc1
|
||||
|
||||
Linux v6.8-rc1 removed the definitions related to CBQ:
|
||||
https://github.com/torvalds/linux/commit/33241dca486264193ed68167c8eeae1fb197f3df
|
||||
making tc fail to build.
|
||||
Add some #ifdefs to handle this missing support.
|
||||
|
||||
Upstream: http://lists.busybox.net/pipermail/busybox/2024-March/090678.html
|
||||
Bug report: https://bugs.busybox.net/show_bug.cgi?id=15931
|
||||
|
||||
Signed-off-by: Bernd Kuhls <bernd@kuhls.net>
|
||||
---
|
||||
networking/tc.c | 12 ++++++++++++
|
||||
1 file changed, 12 insertions(+)
|
||||
|
||||
diff --git a/networking/tc.c b/networking/tc.c
|
||||
index 3a79fd2d9..d08fd1359 100644
|
||||
--- a/networking/tc.c
|
||||
+++ b/networking/tc.c
|
||||
@@ -231,6 +231,13 @@ static int cbq_parse_opt(int argc, char **argv, struct nlmsghdr *n)
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
+
|
||||
+#ifndef TCA_CBQ_MAX
|
||||
+/*
|
||||
+ * Linux v6.8-rc1~131^2~60^2^2 removed the uapi definitions for CBQ.
|
||||
+ * See https://git.kernel.org/linus/33241dca48626
|
||||
+ */
|
||||
+#else
|
||||
static int cbq_print_opt(struct rtattr *opt)
|
||||
{
|
||||
struct rtattr *tb[TCA_CBQ_MAX+1];
|
||||
@@ -322,6 +329,7 @@ static int cbq_print_opt(struct rtattr *opt)
|
||||
done:
|
||||
return 0;
|
||||
}
|
||||
+#endif
|
||||
|
||||
static FAST_FUNC int print_qdisc(
|
||||
const struct sockaddr_nl *who UNUSED_PARAM,
|
||||
@@ -372,8 +380,10 @@ static FAST_FUNC int print_qdisc(
|
||||
int qqq = index_in_strings(_q_, name);
|
||||
if (qqq == 0) { /* pfifo_fast aka prio */
|
||||
prio_print_opt(tb[TCA_OPTIONS]);
|
||||
+#ifdef TCA_CBQ_MAX
|
||||
} else if (qqq == 1) { /* class based queuing */
|
||||
cbq_print_opt(tb[TCA_OPTIONS]);
|
||||
+#endif
|
||||
} else {
|
||||
/* don't know how to print options for this qdisc */
|
||||
printf("(options for %s)", name);
|
||||
@@ -442,9 +452,11 @@ static FAST_FUNC int print_class(
|
||||
int qqq = index_in_strings(_q_, name);
|
||||
if (qqq == 0) { /* pfifo_fast aka prio */
|
||||
/* nothing. */ /*prio_print_opt(tb[TCA_OPTIONS]);*/
|
||||
+#ifdef TCA_CBQ_MAX
|
||||
} else if (qqq == 1) { /* class based queuing */
|
||||
/* cbq_print_copt() is identical to cbq_print_opt(). */
|
||||
cbq_print_opt(tb[TCA_OPTIONS]);
|
||||
+#endif
|
||||
} else {
|
||||
/* don't know how to print options for this class */
|
||||
printf("(options for %s)", name);
|
||||
--
|
||||
2.48.1
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
From 88f8a046f27cb81ccc30d038465e963b8300cf1b Mon Sep 17 00:00:00 2001
|
||||
From: Valery Ushakov <uwe@stderr.spb.ru>
|
||||
Date: Wed, 24 Jan 2024 22:24:41 +0300
|
||||
Subject: [PATCH] awk.c: fix CVE-2023-42366 (bug #15874)
|
||||
|
||||
Make sure we don't read past the end of the string in next_token()
|
||||
when backslash is the last character in an (invalid) regexp.
|
||||
a fix and issue reported in bugzilla
|
||||
|
||||
https://bugs.busybox.net/show_bug.cgi?id=15874
|
||||
|
||||
Upstream-Status: Submitted [http://lists.busybox.net/pipermail/busybox/2024-May/090766.html]
|
||||
|
||||
CVE: CVE-2023-42366
|
||||
Signed-off-by: Khem Raj <raj.khem@gmail.com>
|
||||
[Thomas: https://git.openembedded.org/openembedded-core/tree/meta/recipes-core/busybox/busybox/0001-awk.c-fix-CVE-2023-42366-bug-15874.patch?id=e0ff4813b1cf4df0d851c857d57fb88d7db51bdd]
|
||||
Upstream: http://lists.busybox.net/pipermail/busybox/2024-May/090766.html
|
||||
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
|
||||
---
|
||||
editors/awk.c | 6 ++++--
|
||||
1 file changed, 4 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/editors/awk.c b/editors/awk.c
|
||||
index 64e752f4b..222e6298d 100644
|
||||
--- a/editors/awk.c
|
||||
+++ b/editors/awk.c
|
||||
@@ -1234,9 +1234,11 @@ static uint32_t next_token(uint32_t expected)
|
||||
s[-1] = bb_process_escape_sequence((const char **)&pp);
|
||||
if (*p == '\\')
|
||||
*s++ = '\\';
|
||||
- if (pp == p)
|
||||
+ if (pp == p) {
|
||||
+ if (*p == '\0')
|
||||
+ syntax_error(EMSG_UNEXP_EOS);
|
||||
*s++ = *p++;
|
||||
- else
|
||||
+ } else
|
||||
p = pp;
|
||||
}
|
||||
}
|
||||
--
|
||||
2.48.1
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
From 0583f8eda94f97e15e371e12458877b738439e8c Mon Sep 17 00:00:00 2001
|
||||
From: Khem Raj <raj.khem@gmail.com>
|
||||
Date: Sun, 7 Mar 2021 17:30:24 -0800
|
||||
Subject: [PATCH] hwclock: Check for SYS_settimeofday before calling syscall
|
||||
|
||||
Some newer architectures e.g. RISCV32 have 64bit time_t from get go and
|
||||
thusly do not have gettimeofday_time64/settimeofday_time64 implemented
|
||||
therefore check for SYS_settimeofday definition before making the
|
||||
syscall. Fixes build for riscv32 and it will bail out at runtime.
|
||||
|
||||
Upstream-Status: Submitted [http://lists.busybox.net/pipermail/busybox/2021-March/088583.html]
|
||||
Signed-off-by: Khem Raj <raj.khem@gmail.com>
|
||||
Upstream: http://lists.busybox.net/pipermail/busybox/2021-March/088583.html
|
||||
[Thomas: this issue has been discussed on the musl mailing list, and
|
||||
the musl developers' opinion is that Busybox is wrong:
|
||||
https://www.openwall.com/lists/musl/2024/03/03/2
|
||||
https://www.openwall.com/lists/musl/2024/04/07/2. The correct fix
|
||||
isn't clear, and in the mean time, the patch from Khem turns the build
|
||||
issue into a runtime error only on the problematic architecture, which
|
||||
seems like a reasonable trade-off]
|
||||
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
|
||||
---
|
||||
util-linux/hwclock.c | 7 +++++--
|
||||
1 file changed, 5 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c
|
||||
index c3fd0eb57..dea9c9a55 100644
|
||||
--- a/util-linux/hwclock.c
|
||||
+++ b/util-linux/hwclock.c
|
||||
@@ -132,6 +132,7 @@ static void show_clock(const char **pp_rtcname, int utc)
|
||||
|
||||
static void set_kernel_tz(const struct timezone *tz)
|
||||
{
|
||||
+ int ret = 1;
|
||||
#if LIBC_IS_MUSL
|
||||
/* musl libc does not pass tz argument to syscall
|
||||
* because "it's deprecated by POSIX, therefore it's fine
|
||||
@@ -140,9 +141,11 @@ static void set_kernel_tz(const struct timezone *tz)
|
||||
#if !defined(SYS_settimeofday) && defined(SYS_settimeofday_time32)
|
||||
# define SYS_settimeofday SYS_settimeofday_time32
|
||||
#endif
|
||||
- int ret = syscall(SYS_settimeofday, NULL, tz);
|
||||
+#if defined(SYS_settimeofday)
|
||||
+ ret = syscall(SYS_settimeofday, NULL, tz);
|
||||
+#endif
|
||||
#else
|
||||
- int ret = settimeofday(NULL, tz);
|
||||
+ ret = settimeofday(NULL, tz);
|
||||
#endif
|
||||
if (ret)
|
||||
bb_simple_perror_msg_and_die("settimeofday");
|
||||
--
|
||||
2.48.1
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
From bba9e99026a3dafe75f608459533e0b6d8cf3874 Mon Sep 17 00:00:00 2001
|
||||
From: Andre Przywara <andre.przywara@arm.com>
|
||||
Date: Tue, 10 Sep 2024 14:32:46 +0100
|
||||
Subject: [PATCH] libbb/sha: add missing sha-NI guard
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
The ENABLE_SHA1_HWACCEL Kconfig symbol is meant to be archicture
|
||||
agnostic, so can be enabled regardless of whether your build
|
||||
architecture provides hardware acceleration or not. At the moment only
|
||||
x86 implements this, so every piece of optimised code should be guarded
|
||||
by both ENABLE_SHA1_HWACCEL and (__x86_64__ || __i386__). This is missing
|
||||
at one place, so compiling for arm64 breaks when ENABLE_SHA1_HWACCEL is
|
||||
enabled:
|
||||
================================
|
||||
libbb/hash_md5_sha.c: In function 'sha1_end':
|
||||
libbb/hash_md5_sha.c:1316:28: error: 'sha1_process_block64_shaNI' undeclared (first use in this function); did you mean 'sha1_process_block64'?
|
||||
1316 | || ctx->process_block == sha1_process_block64_shaNI
|
||||
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
| sha1_process_block64
|
||||
libbb/hash_md5_sha.c:1316:28: note: each undeclared identifier is reported only once for each function it appears in
|
||||
make[1]: *** [scripts/Makefile.build:197: libbb/hash_md5_sha.o] Error 1
|
||||
make: *** [Makefile:744: libbb] Error 2
|
||||
================================
|
||||
|
||||
Add the missing guards around the call to sha1_process_block64_shaNI to
|
||||
fix the build on other architectures with ENABLE_SHA1_HWACCEL enabled.
|
||||
|
||||
Change-Id: I40bba388422625f4230abf15a5de23e1fdc654fc
|
||||
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
|
||||
Upstream: https://lists.busybox.net/pipermail/busybox/2024-September/090899.html
|
||||
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
|
||||
---
|
||||
libbb/hash_md5_sha.c | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c
|
||||
index 57a801459..75a61c32c 100644
|
||||
--- a/libbb/hash_md5_sha.c
|
||||
+++ b/libbb/hash_md5_sha.c
|
||||
@@ -1313,7 +1313,9 @@ unsigned FAST_FUNC sha1_end(sha1_ctx_t *ctx, void *resbuf)
|
||||
hash_size = 8;
|
||||
if (ctx->process_block == sha1_process_block64
|
||||
#if ENABLE_SHA1_HWACCEL
|
||||
+# if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
||||
|| ctx->process_block == sha1_process_block64_shaNI
|
||||
+# endif
|
||||
#endif
|
||||
) {
|
||||
hash_size = 5;
|
||||
--
|
||||
2.48.1
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
From 34d331d642c3312e1c04e4650f547f1a67abee24 Mon Sep 17 00:00:00 2001
|
||||
From: Andrej Valek <andrej.v@skyrain.eu>
|
||||
Date: Wed, 16 Oct 2024 10:15:08 +0200
|
||||
Subject: [PATCH] syslogd: fix wrong OPT_locallog flag detection
|
||||
|
||||
The OPT_locallog was set on "option_mask32" but checked on local
|
||||
"opts" variable. While this flag it's used on multiple places can't be
|
||||
has to be used with "option_mask32". Without this change syslogd
|
||||
is more-less unusable while no messages are logged locally.
|
||||
|
||||
Signed-off-by: Andrej Valek <andrej.v@skyrain.eu>
|
||||
Upstream: https://lists.busybox.net/pipermail/busybox/2024-October/090969.html
|
||||
[Thomas: this was reported as beeing needed by Bernd Kuhls at
|
||||
https://lore.kernel.org/buildroot/pan$de0bb$35c5a64$ca9b6f21$2408ff40@ID-313208.user.individual.net/,
|
||||
but also on the Busybox mailing list at
|
||||
https://lists.busybox.net/pipermail/busybox/2023-September/090499.html]
|
||||
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
|
||||
---
|
||||
sysklogd/syslogd.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
|
||||
index 7558051f0..fa03aa280 100644
|
||||
--- a/sysklogd/syslogd.c
|
||||
+++ b/sysklogd/syslogd.c
|
||||
@@ -1179,7 +1179,7 @@ int syslogd_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
- if (!ENABLE_FEATURE_REMOTE_LOG || (opts & OPT_locallog)) {
|
||||
+ if (!ENABLE_FEATURE_REMOTE_LOG || (option_mask32 & OPT_locallog)) {
|
||||
recvbuf[sz] = '\0'; /* ensure it *is* NUL terminated */
|
||||
split_escape_and_log(recvbuf, sz);
|
||||
}
|
||||
--
|
||||
2.48.1
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
# The rig's only differences from the panel's BusyBox config (panel.config).
|
||||
# Each line replaces the panel's setting for the same symbol. They change how
|
||||
# the binary links and looks up names, not which applets or options exist:
|
||||
# STATIC: the rig's initramfs has no shared libc, the panel's rootfs does.
|
||||
# USE_BB_PWD_GRP, USE_BB_SHADOW: a static glibc binary cannot load the NSS
|
||||
# modules getpwnam() needs, so BusyBox reads /etc/passwd, /etc/group and
|
||||
# /etc/shadow itself (the panel's uClibc-ng reads the same files).
|
||||
# qemu/tests/busybox-panel-test.sh refuses any other symbol here.
|
||||
CONFIG_STATIC=y
|
||||
CONFIG_USE_BB_PWD_GRP=y
|
||||
CONFIG_USE_BB_SHADOW=y
|
||||
+116
-33
@@ -4,17 +4,127 @@
|
||||
|
||||
BB_VER=1.31.0
|
||||
BB_URL="https://busybox.net/downloads/binaries/${BB_VER}-defconfig-multiarch-musl/busybox-armv7l"
|
||||
# The panel BusyBox source (RIG_BUSYBOX=panel, qemu/build-busybox.sh). From
|
||||
# https://busybox.net/downloads/busybox-1.37.0.tar.bz2.sha256, the same pin as
|
||||
# Buildroot 2025.02.8 package/busybox/busybox.hash.
|
||||
BB_SRC_VER=1.37.0
|
||||
# Read by build-busybox.sh, which sources this file.
|
||||
# shellcheck disable=SC2034
|
||||
BB_SRC_URL="https://busybox.net/downloads/busybox-${BB_SRC_VER}.tar.bz2"
|
||||
# Buildroot mirrors this exact pinned release; verification is unchanged.
|
||||
# shellcheck disable=SC2034
|
||||
BB_SRC_MIRROR_URL="https://sources.buildroot.net/busybox/busybox-${BB_SRC_VER}.tar.bz2"
|
||||
BB_SRC_SHA256=3311dff32e746499f4df0d5df04d7eb396382d7e108bb9250e7b519b837043a4
|
||||
|
||||
qemu_log() { printf '\033[36m== %s\033[0m\n' "$*"; }
|
||||
|
||||
# Fetch (or accept via $BUSYBOX) the pinned static armv7 busybox and verify it
|
||||
# against qemu/busybox.sha256. FAILS CLOSED: a missing pin refuses to build,
|
||||
# never silently skips verification, mirroring build/build-kernel.sh's
|
||||
# tarball handling. Sets $BB to the verified binary's path.
|
||||
# Download URL to DEST and verify it against the sha256 WANT. A DEST that
|
||||
# already matches is kept. FAILS CLOSED: three bounded attempts, then exit 1;
|
||||
# a mismatching download never lands at DEST.
|
||||
# Usage: qemu_fetch_verified URL WANT DEST LABEL [MIRROR_URL]
|
||||
qemu_fetch_verified() {
|
||||
local url="$1" want="$2" dest="$3" label="$4" got
|
||||
local mirror="${5:-}"
|
||||
if [ -f "$dest" ]; then
|
||||
got="$(sha256sum "$dest" | awk '{print $1}')"
|
||||
if [ "$want" = "$got" ]; then
|
||||
qemu_log "$label sha256 verified"
|
||||
return
|
||||
fi
|
||||
qemu_log "cached $label failed verification; fetching a clean copy"
|
||||
fi
|
||||
|
||||
# Every attempt is bounded: a server that answers and then stalls would
|
||||
# otherwise hold the job until its own timeout, with no retry (#1588). Below
|
||||
# 1 KiB/s for the stall window, or past the total cap, curl gives up and the
|
||||
# loop moves on. Defaults cap the worst case near 6 minutes; the tests
|
||||
# shorten them through the environment.
|
||||
local stall="${BB_FETCH_STALL_SECS:-20}" max="${BB_FETCH_MAX_SECS:-60}"
|
||||
local delay="${BB_FETCH_RETRY_DELAY:-5}"
|
||||
local attempt tmp="${dest}.download.$$"
|
||||
rm -f "$tmp"
|
||||
for attempt in 1 2 3; do
|
||||
if [ "$attempt" -gt 1 ] && [ -n "$mirror" ]; then
|
||||
url="$mirror"
|
||||
fi
|
||||
qemu_log "downloading $url (attempt $attempt/3)"
|
||||
if curl --retry 1 --retry-delay "$delay" --retry-connrefused \
|
||||
--connect-timeout "$stall" --speed-limit 1024 --speed-time "$stall" \
|
||||
--max-time "$max" -fSL "$url" -o "$tmp"; then
|
||||
got="$(sha256sum "$tmp" | awk '{print $1}')"
|
||||
if [ "$want" = "$got" ]; then
|
||||
mv -f "$tmp" "$dest"
|
||||
qemu_log "$label sha256 verified"
|
||||
return
|
||||
fi
|
||||
echo "$label sha256 mismatch on attempt $attempt: want $want got $got" >&2
|
||||
fi
|
||||
rm -f "$tmp"
|
||||
done
|
||||
echo "FATAL: could not fetch pinned $label after 3 verified attempts" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# The source inputs of the panel BusyBox, as one sha256: the pinned source
|
||||
# tarball and every committed file under qemu/busybox/ the build reads. The
|
||||
# compiler is not part of it (build-busybox.sh keys its rebuild on that too),
|
||||
# so a job without the cross compiler can check a binary another job built.
|
||||
# build-busybox.sh writes it next to the binary as <binary>.inputs.
|
||||
qemu_busybox_panel_inputs() {
|
||||
local d="$QEMU_DIR/busybox"
|
||||
{
|
||||
echo "busybox $BB_SRC_VER $BB_SRC_SHA256"
|
||||
(cd "$d" && sha256sum panel.config rig.fragment applets.txt patches/*.patch)
|
||||
} | sha256sum | awk '{print $1}'
|
||||
}
|
||||
|
||||
# Provide the rig's static armv7 busybox and set $BB to its path.
|
||||
#
|
||||
# RIG_BUSYBOX picks which one (flare-edge#2210):
|
||||
# multiarch (default) the busybox.net $BB_VER defconfig-multiarch-musl
|
||||
# binary, fetched (or accepted via $BUSYBOX) and
|
||||
# verified against qemu/busybox.sha256
|
||||
# panel the image's BusyBox version and applet config, built
|
||||
# from source by qemu/build-busybox.sh (needs a cross
|
||||
# compiler; checked by its applet list, see there).
|
||||
# With $BUSYBOX set, that prebuilt panel binary is used
|
||||
# instead (a job without the cross compiler, given the
|
||||
# binary an earlier build job made): it is accepted only
|
||||
# when its $BUSYBOX.inputs, written by build-busybox.sh,
|
||||
# equals qemu_busybox_panel_inputs of this tree, so a
|
||||
# binary built from other config files is refused.
|
||||
# FAILS CLOSED: a missing pin refuses to build, never silently skips
|
||||
# verification, mirroring build/build-kernel.sh's tarball handling; an
|
||||
# unknown RIG_BUSYBOX, or a prebuilt panel binary without matching inputs,
|
||||
# is refused.
|
||||
qemu_get_busybox() {
|
||||
local sha_file="$QEMU_DIR/busybox.sha256"
|
||||
local out="${OUT:-$QEMU_DIR/out}"
|
||||
mkdir -p "$out"
|
||||
case "${RIG_BUSYBOX:-multiarch}" in
|
||||
multiarch) ;;
|
||||
panel)
|
||||
if [ -n "${BUSYBOX:-}" ]; then
|
||||
local want got
|
||||
want="$(qemu_busybox_panel_inputs)"
|
||||
got="$(cat "$BUSYBOX.inputs" 2>/dev/null || true)"
|
||||
if [ ! -f "$BUSYBOX" ] || [ "$got" != "$want" ]; then
|
||||
echo "FATAL: BUSYBOX=$BUSYBOX is not a panel BusyBox built from this tree's qemu/busybox/ ($BUSYBOX.inputs '${got:-missing}', want '$want'): run qemu/build-busybox.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
BB="$BUSYBOX"
|
||||
qemu_log "panel busybox: prebuilt $BB (inputs $want)"
|
||||
return
|
||||
fi
|
||||
OUT="$out" bash "$QEMU_DIR/build-busybox.sh"
|
||||
BB="$out/busybox-armv7l-panel"
|
||||
return
|
||||
;;
|
||||
*)
|
||||
echo "FATAL: RIG_BUSYBOX must be multiarch or panel, not '${RIG_BUSYBOX}'" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
local sha_file="$QEMU_DIR/busybox.sha256"
|
||||
BB="${BUSYBOX:-$out/busybox-armv7l}"
|
||||
# Pin first: a missing pin refuses BEFORE downloading, same ordering as
|
||||
# build/fetch-kernel-tarball.sh.
|
||||
@@ -22,34 +132,7 @@ qemu_get_busybox() {
|
||||
echo "FATAL: no pinned sha256 for busybox (expected $sha_file): refusing to build from an unverified binary" >&2
|
||||
exit 1
|
||||
}
|
||||
local want got
|
||||
want="$(cat "$sha_file")"
|
||||
if [ -f "$BB" ]; then
|
||||
got="$(sha256sum "$BB" | awk '{print $1}')"
|
||||
if [ "$want" = "$got" ]; then
|
||||
qemu_log "busybox sha256 verified"
|
||||
return
|
||||
fi
|
||||
qemu_log "cached busybox failed verification; fetching a clean copy"
|
||||
fi
|
||||
|
||||
local attempt tmp="${BB}.download.$$"
|
||||
rm -f "$tmp"
|
||||
for attempt in 1 2 3; do
|
||||
qemu_log "downloading $BB_URL (attempt $attempt/3)"
|
||||
if curl --retry 3 --retry-delay 5 --retry-connrefused -fSL "$BB_URL" -o "$tmp"; then
|
||||
got="$(sha256sum "$tmp" | awk '{print $1}')"
|
||||
if [ "$want" = "$got" ]; then
|
||||
mv -f "$tmp" "$BB"
|
||||
qemu_log "busybox sha256 verified"
|
||||
return
|
||||
fi
|
||||
echo "busybox sha256 mismatch on attempt $attempt: want $want got $got" >&2
|
||||
fi
|
||||
rm -f "$tmp"
|
||||
done
|
||||
echo "FATAL: could not fetch pinned busybox after 3 verified attempts" >&2
|
||||
exit 1
|
||||
qemu_fetch_verified "$BB_URL" "$(cat "$sha_file")" "$BB" busybox
|
||||
}
|
||||
|
||||
# Stage the shared rootfs skeleton (qemu/rootfs/ + busybox) into $1.
|
||||
|
||||
+63
-4
@@ -15,8 +15,25 @@
|
||||
# flare-edge build's rootfs.img/oem.img matched pair) into slot A instead of
|
||||
# the busybox skeleton; slot B keeps the skeleton as a known-good fallback.
|
||||
# Env:
|
||||
# BUSYBOX path to a local busybox binary (skips the download; still verified)
|
||||
# BUSYBOX path to a local busybox binary (skips the download; still verified;
|
||||
# with RIG_BUSYBOX=panel a prebuilt panel binary, checked by its .inputs)
|
||||
# RIG_BUSYBOX multiarch (default) or panel: the image's own BusyBox, built by
|
||||
# qemu/build-busybox.sh (see qemu/busybox/README.md)
|
||||
# OUT output dir (default: qemu/out); image at $OUT/disk.img
|
||||
# PAYLOAD_DIR the directory whose binaries land in /usr/bin of both slots
|
||||
# (default qemu/payload). Lets one run boot its own payload set
|
||||
# (flare-edge's hook set for a flow that pins documents: the
|
||||
# production payload plus the test-flavor UI and wthctl) while
|
||||
# other runs read qemu/payload at the same time. Not a
|
||||
# directory: fails closed.
|
||||
# ROOTFS_OVERLAY a directory laid over the staged rootfs of both slots,
|
||||
# after the payload, with its modes kept (cp -a). Only etc/ and
|
||||
# usr/ may appear at its top, and no entry may be a symlink, so
|
||||
# it can neither replace the rig's own /init and /sbin/init nor
|
||||
# point outside the image. flare-edge #2210 stages the panel's
|
||||
# S03warden-accounts, S99lvgl and /usr/lib/warden/warden-ui-run
|
||||
# this way for a boot with warden.initchain (rootfs/sbin/init).
|
||||
# Not a directory, or a disallowed entry: fails closed.
|
||||
# SEED_DIR a directory of pre-built userdata/warden files (one file per
|
||||
# settings key, e.g. flare-edge tools/seed-fixtures.py's output)
|
||||
# copied in VERBATIM, after --portal-url/--state. Lets a caller
|
||||
@@ -72,12 +89,31 @@ trap 'rm -rf "$SCRATCH"' EXIT
|
||||
# both slots so A and B start byte-identical, like a factory flash.
|
||||
ROOT="$SCRATCH/root"
|
||||
qemu_stage_rootfs "$ROOT"
|
||||
for p in "$QEMU_DIR"/payload/*; do
|
||||
PAYLOAD_DIR="${PAYLOAD_DIR:-$QEMU_DIR/payload}"
|
||||
[ -d "$PAYLOAD_DIR" ] || { echo "FATAL: PAYLOAD_DIR '$PAYLOAD_DIR' is not a directory" >&2; exit 1; }
|
||||
for p in "$PAYLOAD_DIR"/*; do
|
||||
[ -f "$p" ] || continue
|
||||
case "$(basename "$p")" in README.md) continue ;; esac
|
||||
install -m 0755 "$p" "$ROOT/usr/bin/$(basename "$p")"
|
||||
done
|
||||
|
||||
# ROOTFS_OVERLAY (see the Env note above): checked whole before anything of
|
||||
# it is copied, so a refused overlay leaves no partial tree and no image.
|
||||
if [ -n "${ROOTFS_OVERLAY:-}" ]; then
|
||||
[ -d "$ROOTFS_OVERLAY" ] || { echo "FATAL: ROOTFS_OVERLAY '$ROOTFS_OVERLAY' is not a directory" >&2; exit 1; }
|
||||
for entry in "$ROOTFS_OVERLAY"/* "$ROOTFS_OVERLAY"/.[!.]*; do
|
||||
[ -e "$entry" ] || [ -L "$entry" ] || continue
|
||||
case "$(basename "$entry")" in
|
||||
etc|usr) [ -d "$entry" ] && [ ! -L "$entry" ] && continue ;;
|
||||
esac
|
||||
echo "FATAL: ROOTFS_OVERLAY may hold only the directories etc/ and usr/ at its top, not '$(basename "$entry")'" >&2
|
||||
exit 1
|
||||
done
|
||||
links="$(find "$ROOTFS_OVERLAY" -type l)"
|
||||
[ -z "$links" ] || { echo "FATAL: ROOTFS_OVERLAY holds symlinks: $links" >&2; exit 1; }
|
||||
cp -a "$ROOTFS_OVERLAY"/. "$ROOT/"
|
||||
fi
|
||||
|
||||
# Firmware version stamp: same path the device build writes; flared reads its
|
||||
# running version here (downgrade rules key off it).
|
||||
printf '%s\n' "$FW_VERSION" > "$ROOT/etc/warden-firmware-version"
|
||||
@@ -106,8 +142,9 @@ if [ -n "${SEED_DIR:-}" ]; then
|
||||
# on the first bad entry the same way --state fails closed above, rather
|
||||
# than copy it into the image and let it surface as a confusing read
|
||||
# later. Only a top-level plain file matches "one file per settings key"
|
||||
# (the Env note above) -- seed-fixtures.py never nests a subdirectory, and
|
||||
# neither should anything else pointed at this hook.
|
||||
# (the Env note above), with one exception, profiles/rs485/<slug>.w485p
|
||||
# (installed device profiles, checked below); seed-fixtures.py nests
|
||||
# nothing else, and neither should anything else pointed at this hook.
|
||||
#
|
||||
# Charset is seed-fixtures.py's KEY_RE, not --state's stricter
|
||||
# [A-Za-z0-9_.]+ above: seed-fixtures.py deliberately also allows '-' for
|
||||
@@ -126,6 +163,28 @@ if [ -n "${SEED_DIR:-}" ]; then
|
||||
echo "FATAL: SEED_DIR entry '$base' is a symlink (refusing to copy it into userdata verbatim)" >&2
|
||||
exit 1
|
||||
fi
|
||||
# The one directory allowed: installed RS485 device profiles, as
|
||||
# warden-modbus keeps them (/userdata/warden/profiles/rs485/<slug>.w485p),
|
||||
# so a flow can boot with a profile already installed (flare-edge#387).
|
||||
# Nothing in it but plain <slug>.w485p files directly under rs485/.
|
||||
if [ "$base" = profiles ] && [ -d "$entry" ]; then
|
||||
while IFS= read -r -d '' p; do
|
||||
rel="${p#"$entry"/}"
|
||||
if [ "$rel" = rs485 ] && [ -d "$p" ] && [ ! -L "$p" ]; then continue; fi
|
||||
case "$rel" in
|
||||
rs485/*/*) ok=0 ;;
|
||||
rs485/*.w485p) ok=1 ;;
|
||||
*) ok=0 ;;
|
||||
esac
|
||||
name="${rel#rs485/}"
|
||||
case "${name%.w485p}" in ''|*[!a-z0-9-]*) ok=0 ;; esac
|
||||
if [ "$ok" -ne 1 ] || [ -L "$p" ] || [ ! -f "$p" ]; then
|
||||
echo "FATAL: SEED_DIR entry 'profiles/$rel' is not a plain profiles/rs485/<slug>.w485p file" >&2
|
||||
exit 1
|
||||
fi
|
||||
done < <(find "$entry" -mindepth 1 -print0)
|
||||
continue
|
||||
fi
|
||||
[ -f "$entry" ] || {
|
||||
echo "FATAL: SEED_DIR entry '$base' is not a plain file (refusing to copy it into userdata verbatim)" >&2
|
||||
exit 1
|
||||
|
||||
+12
-1
@@ -4,8 +4,13 @@
|
||||
# see qemu/lib.sh).
|
||||
#
|
||||
# Env:
|
||||
# BUSYBOX path to a local busybox binary (skips the download; still verified)
|
||||
# BUSYBOX path to a local busybox binary (skips the download; still verified;
|
||||
# with RIG_BUSYBOX=panel a prebuilt panel binary, checked by its .inputs)
|
||||
# RIG_BUSYBOX multiarch (default) or panel: the image's own BusyBox, built by
|
||||
# qemu/build-busybox.sh (see qemu/busybox/README.md)
|
||||
# OUT output dir (default: qemu/out); initramfs at $OUT/initramfs.cpio.gz
|
||||
# EXTRA_DIR a directory merged into the initramfs root (a test's scripts and
|
||||
# static binaries; init runs one on warden.run=<path>)
|
||||
set -euo pipefail
|
||||
|
||||
QEMU_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
@@ -20,6 +25,12 @@ qemu_get_busybox
|
||||
SCRATCH="$(mktemp -d "${TMPDIR:-/tmp}/warden-qemu-initramfs.XXXXXX")"
|
||||
trap 'rm -rf "$SCRATCH"' EXIT
|
||||
qemu_stage_rootfs "$SCRATCH/root"
|
||||
# The kernel symbol list, so init can check it against /proc/config.gz.
|
||||
install -D -m 0644 "$QEMU_DIR/../build/required-symbols.txt" "$SCRATCH/root/etc/required-symbols.txt"
|
||||
if [ -n "${EXTRA_DIR:-}" ]; then
|
||||
[ -d "$EXTRA_DIR" ] || { echo "FATAL: EXTRA_DIR is not a directory: $EXTRA_DIR" >&2; exit 1; }
|
||||
cp -a "$EXTRA_DIR/." "$SCRATCH/root/"
|
||||
fi
|
||||
|
||||
# Pack (newc cpio, gzip). No device nodes required: /init mounts devtmpfs and
|
||||
# reopens the console itself, so the archive builds unprivileged.
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
Drop **static musl armv7** binaries in this directory (contents are
|
||||
gitignored; binaries are never committed); `qemu/mkimage.sh` copies everything
|
||||
in this directory (except this README) into `/usr/bin/` of both rootfs slots.
|
||||
`PAYLOAD_DIR=<dir>` points one run (`mkimage.sh`, `tests/ui-drive.sh`) at
|
||||
another directory instead, so a caller can boot its own set, such as
|
||||
flare-edge's hook set for a flow that pins documents, while other runs read
|
||||
this one.
|
||||
Static musl is the same target the device uses for its Rust daemons, so the
|
||||
exact production binaries run unmodified in the VM.
|
||||
|
||||
@@ -26,6 +30,13 @@ musl binary, so flare-edge `tools/rig-pull-daemons.sh --host <panel>` copies
|
||||
release and each md5 in `PULLED.txt`), minus `warden-ui`, which the rig
|
||||
needs as the fbdev+evdev build.
|
||||
|
||||
A `mosquitto` here (the static armhf broker of flare-edge
|
||||
`tools/mosquitto-build.sh armhf`) gives the guest the panel's device bus:
|
||||
stage-2 init starts it on `/run/warden/bus/bus.sock` before any daemon and
|
||||
writes a credential file per bus user to `/run/warden/bus/cred/<user>`
|
||||
(`warden_rig_bus` in `qemu/rootfs/etc/warden-lib.sh`; the broker log is
|
||||
`/tmp/mosquitto.log`). Without it the guest has no bus, as before.
|
||||
|
||||
Stage-2 init starts every `warden-*` daemon it finds here, in the panel's
|
||||
own S-number order (ai, automation, modbus, mikrotik, asic, starlink,
|
||||
stratum, flared), then `warden-ui` (the UI also needs `--display
|
||||
|
||||
@@ -41,3 +41,459 @@ warden_slot() {
|
||||
esac
|
||||
echo "$slot"
|
||||
}
|
||||
|
||||
# PID 1 must answer busybox's reboot/poweroff/halt itself: they only signal
|
||||
# PID 1 (TERM, USR2, USR1), and the kernel drops any signal PID 1 has no
|
||||
# handler for. A panel's busybox init handles them; without this the rig
|
||||
# ignored a plain `reboot` (bfe-core1106-sdk#5). The -f forms skip init, and
|
||||
# the kernel still prints its orderly "reboot: Restarting system" line.
|
||||
# WARDEN_REBOOT_CMD / WARDEN_POWEROFF_CMD exist for the host test only.
|
||||
warden_trap_power_signals() {
|
||||
trap 'echo "init: reboot requested"; sync; ${WARDEN_REBOOT_CMD:-reboot -f}' TERM
|
||||
trap 'echo "init: poweroff requested"; sync; ${WARDEN_POWEROFF_CMD:-poweroff -f}' USR2
|
||||
trap 'echo "init: halt requested"; sync; ${WARDEN_POWEROFF_CMD:-poweroff -f}' USR1
|
||||
}
|
||||
|
||||
# The warden.shell interactive shell, on the console's real tty so it gets
|
||||
# job control. BusyBox's cttyhack does that where it is built in; the panel's
|
||||
# BusyBox (qemu/build-busybox.sh, RIG_BUSYBOX=panel) has no cttyhack, so the
|
||||
# tty is read from sysfs (the last console listed is /dev/console's) and
|
||||
# setsid -c makes it the controlling terminal (flare-edge#2210).
|
||||
# WARDEN_CONSOLE_ACTIVE and WARDEN_DEV_DIR point the host test at stand-ins.
|
||||
warden_console_shell() {
|
||||
if command -v cttyhack >/dev/null 2>&1; then
|
||||
setsid cttyhack sh
|
||||
return
|
||||
fi
|
||||
_wcs_tty="$(cat "${WARDEN_CONSOLE_ACTIVE:-/sys/class/tty/console/active}" 2>/dev/null)"
|
||||
_wcs_tty="${_wcs_tty##* }"
|
||||
if [ -n "$_wcs_tty" ] && [ -c "${WARDEN_DEV_DIR:-/dev}/$_wcs_tty" ]; then
|
||||
setsid -c sh <>"${WARDEN_DEV_DIR:-/dev}/$_wcs_tty" >&0 2>&1
|
||||
else
|
||||
echo "warden.shell: no console tty found; shell without job control"
|
||||
sh
|
||||
fi
|
||||
}
|
||||
|
||||
# Idle forever in a way a trapped signal interrupts at once: a foreground
|
||||
# `sleep` would hold the trap until it returned, up to an hour later.
|
||||
warden_idle_forever() {
|
||||
while :; do
|
||||
sleep 3600 &
|
||||
wait $!
|
||||
done
|
||||
}
|
||||
|
||||
# The control bridge's command loop (/sbin/init runs it on the ctl serial
|
||||
# port): one command per line on stdin, the reply then the sentinel line
|
||||
# <<END>> on stdout. qmp.py's Ctl matches the sentinel byte for byte.
|
||||
#
|
||||
# `@cat PATH` is answered here and never forwarded: PATH's contents (or one
|
||||
# "bridge: no such file: PATH" line), which is how the json flow channel
|
||||
# reads webstatus.c's snapshot from outside the VM. `@procs` is answered
|
||||
# here too: every /proc/<pid>/stat line, for qmp.py's stall probe
|
||||
# (flare-edge #1528). Everything else goes to
|
||||
# warden-ui's FIFO, and the bridge waits for the reply file the UI renames
|
||||
# into place whole. The previous reply is removed BEFORE sending: a fixed
|
||||
# settle handed back the previous command's reply (flare-edge #152).
|
||||
#
|
||||
# The wait is bounded by WARDEN_CTL_WAIT_S (default 30 s of polling). It was
|
||||
# 5 s, and a slow QEMU host (lenovo-x3650, two TCG guests) let a page build
|
||||
# outrun it: the bridge answered an empty reply, and the UI's late reply
|
||||
# then landed after the NEXT command's remove and was read as that
|
||||
# command's answer (flare-edge #1448). Now a timeout answers one
|
||||
# "bridge: no reply from warden-ui ..." line (qmp.py treats it as a rig
|
||||
# fault), and the next command first waits, on the same bound, for the late
|
||||
# reply and discards it. A reply slower than 5 s is logged on stderr (the
|
||||
# console) with its time, for the host-speed baselines.
|
||||
#
|
||||
# `@hook WORDS` is answered here too: one request to the UI's test hook on
|
||||
# the device bus (test/req/ui, flare-edge docs/bus-test-hook.md), sent by the
|
||||
# payload's hook client (wthctl, as bus user testhook) and answered with its
|
||||
# reply JSON. WORDS are the client's own words, the verb last (`override`,
|
||||
# or `--to flared VERB` for flared's hook); the request's args JSON is the
|
||||
# text the `@hookdoc TEXT` / `@hookdoc+ TEXT` lines before it wrote (the first
|
||||
# starts it, each `+` appends), or `{}` when there were none. The args come in
|
||||
# pieces because the ctl port is a tty in cooked mode, which cuts a line at
|
||||
# 4095 bytes, and an override document may be 16 KiB. A hook request that
|
||||
# never reached the hook (no client in the payload, no bus, no reply) answers
|
||||
# one "bridge: ..." line, which qmp.py treats as a rig fault, not a verdict.
|
||||
#
|
||||
# WARDEN_CTL_FIFO, WARDEN_CTL_REPLY, WARDEN_CTL_HOOKDOC, WARDEN_WTHCTL and
|
||||
# WARDEN_BUS_RUN exist for the host test only.
|
||||
warden_ctl_bridge() {
|
||||
_wcb_fifo="${WARDEN_CTL_FIFO:-/tmp/warden-ui.ctl}"
|
||||
_wcb_reply="${WARDEN_CTL_REPLY:-/tmp/warden-ui.dbg}"
|
||||
_wcb_hookdoc="${WARDEN_CTL_HOOKDOC:-/tmp/warden-ctl-hook.args}"
|
||||
_wcb_limit=$(( ${WARDEN_CTL_WAIT_S:-30} * 20 ))
|
||||
_wcb_stale=0
|
||||
while IFS= read -r cmd; do
|
||||
[ -n "$cmd" ] || continue
|
||||
case "$cmd" in
|
||||
"@cat "*)
|
||||
path="${cmd#@cat }"
|
||||
if [ -f "$path" ]; then
|
||||
cat "$path"
|
||||
# The status json has no trailing newline; without this
|
||||
# the sentinel would share its line and the line-based
|
||||
# reader would never see it.
|
||||
echo
|
||||
else
|
||||
echo "bridge: no such file: $path"
|
||||
fi
|
||||
;;
|
||||
"@hookdoc "*)
|
||||
printf '%s' "${cmd#@hookdoc }" > "$_wcb_hookdoc"
|
||||
echo "hookdoc: $(wc -c < "$_wcb_hookdoc") bytes"
|
||||
;;
|
||||
"@hookdoc+ "*)
|
||||
if [ -f "$_wcb_hookdoc" ]; then
|
||||
printf '%s' "${cmd#@hookdoc+ }" >> "$_wcb_hookdoc"
|
||||
echo "hookdoc: $(wc -c < "$_wcb_hookdoc") bytes"
|
||||
else
|
||||
echo "bridge: @hookdoc+ without a @hookdoc before it"
|
||||
fi
|
||||
;;
|
||||
"@hook "*)
|
||||
_wcb_hook "${cmd#@hook }"
|
||||
;;
|
||||
"@procs")
|
||||
# Every process's stat line, for the driver's stall probe
|
||||
# (qmp.py stall_report, flare-edge #1528); needs no UI.
|
||||
cat /proc/[0-9]*/stat 2>/dev/null
|
||||
;;
|
||||
*)
|
||||
if [ -p "$_wcb_fifo" ]; then
|
||||
if [ "$_wcb_stale" = 1 ]; then
|
||||
_wcb_wait_reply
|
||||
_wcb_stale=0
|
||||
fi
|
||||
rm -f "$_wcb_reply"
|
||||
printf '%s\n' "$cmd" > "$_wcb_fifo"
|
||||
if _wcb_wait_reply; then
|
||||
cat "$_wcb_reply" 2>/dev/null
|
||||
else
|
||||
echo "bridge: no reply from warden-ui within $((_wcb_limit / 20)) s: $cmd"
|
||||
_wcb_stale=1
|
||||
fi
|
||||
if [ "$_wcb_n" -gt 100 ]; then
|
||||
echo "ctl bridge: slow reply, $((_wcb_n / 20)) s of polling: $cmd" >&2
|
||||
fi
|
||||
else
|
||||
echo "bridge: warden-ui control FIFO not present"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
echo "<<END>>"
|
||||
done
|
||||
}
|
||||
|
||||
# One test hook request for `@hook WORDS` (see warden_ctl_bridge). The args
|
||||
# file is used once: removed before the client runs, so a later request
|
||||
# never inherits it.
|
||||
_wcb_hook() {
|
||||
_wch_words="$1"
|
||||
_wch_args='{}'
|
||||
if [ -f "$_wcb_hookdoc" ]; then
|
||||
_wch_args="$(cat "$_wcb_hookdoc")"
|
||||
rm -f "$_wcb_hookdoc"
|
||||
fi
|
||||
# The words reach the client unquoted (one argument each), so only plain
|
||||
# verb and flag characters pass: no glob or quote can reach the shell.
|
||||
if [ -z "$(printf '%s' "$_wch_words" | tr -d ' ')" ] ||
|
||||
[ -n "$(printf '%s' "$_wch_words" | tr -d 'A-Za-z0-9_ -')" ]; then
|
||||
echo "bridge: bad hook request: $_wch_words"
|
||||
return 0
|
||||
fi
|
||||
_wch_client="${WARDEN_WTHCTL:-/usr/bin/wthctl}"
|
||||
_wch_bus="${WARDEN_BUS_RUN:-/run/warden/bus}"
|
||||
if [ ! -x "$_wch_client" ]; then
|
||||
echo "bridge: no hook client in the payload ($_wch_client)"
|
||||
return 0
|
||||
fi
|
||||
# shellcheck disable=SC2086 # one argument per checked word, see above
|
||||
_wch_out="$("$_wch_client" "$_wch_bus/bus.sock" "$_wch_bus/cred/testhook" $_wch_words "$_wch_args" 2>&1)"
|
||||
_wch_rc=$?
|
||||
# wthctl: 0 ok:true, 1 ok:false (both are the hook's answer), 2 no
|
||||
# connection or no reply.
|
||||
if [ "$_wch_rc" -le 1 ]; then
|
||||
printf '%s\n' "$_wch_out"
|
||||
else
|
||||
echo "bridge: hook request got no answer (client exit $_wch_rc): $(printf '%s' "$_wch_out" | tr '\n' ' ')"
|
||||
fi
|
||||
}
|
||||
|
||||
# Polls for a non-empty reply file every 0.05 s, up to the bridge's bound;
|
||||
# leaves the poll count in _wcb_n.
|
||||
_wcb_wait_reply() {
|
||||
_wcb_n=0
|
||||
while [ ! -s "$_wcb_reply" ]; do
|
||||
[ "$_wcb_n" -ge "$_wcb_limit" ] && return 1
|
||||
sleep 0.05
|
||||
_wcb_n=$((_wcb_n + 1))
|
||||
done
|
||||
}
|
||||
|
||||
# The rig's device bus (flare-edge #1754, the #1050 QEMU half). A panel runs
|
||||
# one mosquitto on /run/warden/bus/bus.sock (flare-edge S10bus) and every
|
||||
# daemon, the UI included, talks over it. The rig starts the same broker
|
||||
# when the payload carries one (/usr/bin/mosquitto, the static armhf build of
|
||||
# flare-edge tools/mosquitto-build.sh); a payload without it boots exactly as
|
||||
# before, with no bus.
|
||||
#
|
||||
# Same paths as the panel, so the production clients need no rig switch:
|
||||
# the socket at <bus>/sock/bus.sock with the <bus>/bus.sock link clients
|
||||
# dial, and one credential file per bus user at <bus>/cred/<user>, which a
|
||||
# client reads at every CONNECT. What the rig leaves out, on purpose: the
|
||||
# password file and ACL (the broker takes any user; the rig is a test
|
||||
# instrument and every process in it runs as root anyway) and the retain gate
|
||||
# plugin (a static broker loads no plugins). The credential files hold a
|
||||
# fresh random secret all the same, so a client finds what it expects.
|
||||
#
|
||||
# WARDEN_RIG_BUS_USERS lists the bus users that get a credential file: the
|
||||
# panel's /etc/warden/bus/users and bundled-users (flare-edge busgen output),
|
||||
# plus testhook, the user the control bridge's `@hook` client logs in as (a
|
||||
# test-flavor panel has it too).
|
||||
# WARDEN_RIG_BROKER, WARDEN_BUS_RUN, WARDEN_RIG_BUS_LOG and
|
||||
# WARDEN_RIG_BUS_WAIT_S exist for the host test only.
|
||||
warden_rig_bus() {
|
||||
_wrb_broker="${WARDEN_RIG_BROKER:-/usr/bin/mosquitto}"
|
||||
[ -x "$_wrb_broker" ] || return 0
|
||||
_wrb_dir="${WARDEN_BUS_RUN:-/run/warden/bus}"
|
||||
_wrb_log="${WARDEN_RIG_BUS_LOG:-/tmp/mosquitto.log}"
|
||||
_wrb_users="${WARDEN_RIG_BUS_USERS:-flared ui io modbus appd telemetry automation.main testhook}"
|
||||
if ! mkdir -p "$_wrb_dir/cred" "$_wrb_dir/sock"; then
|
||||
echo "init: rig bus FAILED: cannot create $_wrb_dir"
|
||||
return 1
|
||||
fi
|
||||
chmod 0751 "$_wrb_dir"
|
||||
chmod 0710 "$_wrb_dir/cred"
|
||||
# The panel's broker settings (flare-edge
|
||||
# overlay-flare-warden-ui/etc/warden/bus/mosquitto.conf) minus the
|
||||
# password file, ACL and plugin lines (see above). `user root` keeps the
|
||||
# broker from dropping to an account the rig rootfs does not have.
|
||||
cat > "$_wrb_dir/mosquitto.conf" <<WRB_CONF
|
||||
# QEMU rig broker, written by warden_rig_bus (qemu/rootfs/etc/warden-lib.sh).
|
||||
user root
|
||||
listener 0 $_wrb_dir/sock/bus.sock
|
||||
allow_anonymous true
|
||||
pid_file $_wrb_dir/sock/mosquitto.pid
|
||||
use_username_as_clientid true
|
||||
persistence false
|
||||
message_size_limit 131072
|
||||
max_packet_size 135168
|
||||
max_connections 128
|
||||
max_queued_messages 1000
|
||||
max_queued_bytes 2097152
|
||||
max_inflight_messages 20
|
||||
max_qos 1
|
||||
max_keepalive 60
|
||||
sys_interval 0
|
||||
connection_messages false
|
||||
log_dest stderr
|
||||
log_type error
|
||||
log_type warning
|
||||
WRB_CONF
|
||||
for _wrb_u in $_wrb_users; do
|
||||
case "$_wrb_u" in
|
||||
''|*/*|.*) echo "init: rig bus: bad user name '$_wrb_u' skipped"; continue ;;
|
||||
esac
|
||||
rm -f "$_wrb_dir/cred/$_wrb_u"
|
||||
(umask 077; od -An -tx1 -N32 /dev/urandom | tr -d ' \n' > "$_wrb_dir/cred/$_wrb_u")
|
||||
chmod 0400 "$_wrb_dir/cred/$_wrb_u"
|
||||
done
|
||||
warden_rig_bus_owners "$_wrb_dir"
|
||||
ln -sfn sock/bus.sock "$_wrb_dir/bus.sock"
|
||||
ln -sfn sock/mosquitto.pid "$_wrb_dir/mosquitto.pid"
|
||||
"$_wrb_broker" -c "$_wrb_dir/mosquitto.conf" > "$_wrb_log" 2>&1 &
|
||||
_wrb_pid=$!
|
||||
# Clients retry a missing socket, but a daemon started before the broker
|
||||
# listens logs a refused first dial: wait for the socket (0.1 s polls,
|
||||
# bounded) so the payload daemons find it on their first try.
|
||||
_wrb_n=0
|
||||
_wrb_limit=$(( ${WARDEN_RIG_BUS_WAIT_S:-10} * 10 ))
|
||||
while [ ! -S "$_wrb_dir/sock/bus.sock" ]; do
|
||||
if ! kill -0 "$_wrb_pid" 2>/dev/null; then
|
||||
echo "init: rig bus FAILED: the broker exited; log tail:"
|
||||
tail -n 5 "$_wrb_log" 2>/dev/null
|
||||
return 1
|
||||
fi
|
||||
if [ "$_wrb_n" -ge "$_wrb_limit" ]; then
|
||||
echo "init: rig bus FAILED: no socket after $((_wrb_limit / 10)) s"
|
||||
return 1
|
||||
fi
|
||||
sleep 0.1
|
||||
_wrb_n=$((_wrb_n + 1))
|
||||
done
|
||||
echo "init: rig bus up on $_wrb_dir/bus.sock (broker pid $_wrb_pid)"
|
||||
}
|
||||
|
||||
# warden_rig_bus_owners <bus dir>: give a credential file to the account that
|
||||
# reads it, when the rootfs has that account. The rig rootfs has none of the
|
||||
# platform accounts, so by default this changes nothing and every client runs
|
||||
# as root. A boot through the shipped init chain (warden.initchain, see
|
||||
# warden_init_chain) creates them first with S03warden-accounts; then the UI
|
||||
# runs as warden-ui, as on a panel, and needs its own credential: S10bus there
|
||||
# makes cred/<user> 0400 owned by the daemon's account in a cred directory of
|
||||
# group warden-bus, mode 0710. Pairs are user=account.
|
||||
# WARDEN_RIG_BUS_OWNERS, WARDEN_RIG_PASSWD and WARDEN_RIG_GROUP exist for the
|
||||
# host test only.
|
||||
warden_rig_bus_owners() {
|
||||
_wro_passwd="${WARDEN_RIG_PASSWD:-/etc/passwd}"
|
||||
_wro_group="${WARDEN_RIG_GROUP:-/etc/group}"
|
||||
if grep -q '^warden-bus:' "$_wro_group" 2>/dev/null; then
|
||||
chgrp warden-bus "$1/cred" || echo "init: rig bus: chgrp warden-bus $1/cred failed"
|
||||
fi
|
||||
for _wro_pair in ${WARDEN_RIG_BUS_OWNERS:-ui=warden-ui}; do
|
||||
_wro_user="${_wro_pair%%=*}"
|
||||
_wro_acct="${_wro_pair#*=}"
|
||||
[ -f "$1/cred/$_wro_user" ] || continue
|
||||
grep -q "^$_wro_acct:" "$_wro_passwd" 2>/dev/null || continue
|
||||
if chown "$_wro_acct" "$1/cred/$_wro_user"; then
|
||||
echo "init: rig bus: cred/$_wro_user belongs to $_wro_acct"
|
||||
else
|
||||
echo "init: rig bus: chown $_wro_acct cred/$_wro_user failed"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# warden_init_chain <first> <last>: start the shipped SysV scripts numbered
|
||||
# <first> to <last> (S<NN>name, both bounds included), in name order, each
|
||||
# with `start`, as the panel's rcS does. Used only on a boot with
|
||||
# warden.initchain on the command line, where the caller laid the panel's own
|
||||
# scripts into /etc/init.d with mkimage.sh's ROOTFS_OVERLAY (flare-edge #2210:
|
||||
# S03warden-accounts, S99lvgl and /usr/lib/warden/warden-ui-run, so the UI
|
||||
# starts through its privilege drop, respawn loop and safe mode instead of
|
||||
# directly as root). The rig skeleton itself has no /etc/init.d. A script
|
||||
# that fails is named on the console and the chain goes on, as rcS does.
|
||||
# Prints how many scripts it started. WARDEN_INITD exists for the host test.
|
||||
warden_init_chain() {
|
||||
_wic_dir="${WARDEN_INITD:-/etc/init.d}"
|
||||
_wic_ran=0
|
||||
for _wic_s in "$_wic_dir"/S[0-9][0-9]*; do
|
||||
if [ ! -f "$_wic_s" ] || [ ! -x "$_wic_s" ]; then continue; fi
|
||||
_wic_name="${_wic_s##*/}"
|
||||
_wic_n="${_wic_name#S}"
|
||||
_wic_n="${_wic_n%"${_wic_n#??}"}"
|
||||
# test(1) reads "08" as decimal eight, so no leading zero is cut.
|
||||
if [ "$_wic_n" -lt "$1" ] || [ "$_wic_n" -gt "$2" ]; then continue; fi
|
||||
echo "init: chain $_wic_name start" >&2
|
||||
if "$_wic_s" start >&2; then
|
||||
:
|
||||
else
|
||||
echo "init: chain $_wic_name start FAILED rc=$?" >&2
|
||||
fi
|
||||
_wic_ran=$((_wic_ran + 1))
|
||||
done
|
||||
echo "$_wic_ran"
|
||||
}
|
||||
|
||||
# The rig agent (flare-edge M9 soak-lite, d10 6.5): a shell inside the guest
|
||||
# for a host-side rig that must read state and change it (tools/soak/rig-qemu.py:
|
||||
# bus reads and writes, the clock, /proc for metrics). /sbin/init runs it on
|
||||
# its own pci-serial port, only on a boot with warden.agent on the command
|
||||
# line (run.sh --agent). It is part of the rig rootfs, which no panel image
|
||||
# carries; the flow channels (ctl bridge, test hook) are untouched by it.
|
||||
#
|
||||
# One request per line on stdin, every answer framed so the host never needs
|
||||
# a timeout to know a reply is complete:
|
||||
#
|
||||
# @ping -> <<PONG>>
|
||||
# @chunk ID B64 -> <<OK ID BYTES>> appends B64 to ID's script text
|
||||
# @run ID SECS [B64] -> <<BEGIN ID>>, the base64 of the script's stdout
|
||||
# and stderr, <<END ID RC>>
|
||||
# anything else -> <<ERR reason>>
|
||||
#
|
||||
# The script is the base64 text of the @chunk lines for ID, then the @run
|
||||
# line's own B64, decoded and run by sh with stdin from /dev/null. The agent
|
||||
# port is a tty in cooked mode, which cuts a line at 4095 bytes, hence the
|
||||
# chunks. ID is [A-Za-z0-9_-] (1 to 32 characters), SECS 1 to 3600. A script
|
||||
# still running after SECS seconds is killed with its whole process group and
|
||||
# answers RC 124, as timeout(1) does; the panel BusyBox has no timeout applet.
|
||||
# WARDEN_AGENT_DIR exists for the host test only.
|
||||
warden_agent() {
|
||||
_wa_dir="${WARDEN_AGENT_DIR:-/tmp/warden-agent}"
|
||||
mkdir -p "$_wa_dir"
|
||||
while IFS= read -r _wa_line; do
|
||||
# A cooked tty may hand the line over with a trailing CR.
|
||||
_wa_line="${_wa_line%"$(printf '\r')"}"
|
||||
[ -n "$_wa_line" ] || continue
|
||||
set -f
|
||||
# shellcheck disable=SC2086 # split into words on purpose, globbing off
|
||||
set -- $_wa_line
|
||||
set +f
|
||||
case "$1" in
|
||||
@ping) echo "<<PONG>>" ;;
|
||||
@chunk)
|
||||
if [ "$#" -ne 3 ] || ! _wa_id_ok "$2" || ! _wa_b64_ok "$3"; then
|
||||
echo "<<ERR bad chunk>>"
|
||||
continue
|
||||
fi
|
||||
printf '%s' "$3" >> "$_wa_dir/$2.b64"
|
||||
echo "<<OK $2 $(wc -c < "$_wa_dir/$2.b64" | tr -d ' ')>>"
|
||||
;;
|
||||
@run)
|
||||
if [ "$#" -lt 3 ] || [ "$#" -gt 4 ] || ! _wa_id_ok "$2" ||
|
||||
! _wa_secs_ok "$3" || { [ "$#" -eq 4 ] && ! _wa_b64_ok "$4"; }; then
|
||||
echo "<<ERR bad run>>"
|
||||
continue
|
||||
fi
|
||||
[ "$#" -eq 4 ] && printf '%s' "$4" >> "$_wa_dir/$2.b64"
|
||||
_wa_run "$2" "$3"
|
||||
;;
|
||||
*) echo "<<ERR unknown request>>" ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
_wa_id_ok() {
|
||||
case "$1" in ""|*[!A-Za-z0-9_-]*) return 1 ;; esac
|
||||
[ "${#1}" -le 32 ]
|
||||
}
|
||||
|
||||
_wa_b64_ok() {
|
||||
case "$1" in ""|*[!A-Za-z0-9+/=]*) return 1 ;; esac
|
||||
return 0
|
||||
}
|
||||
|
||||
_wa_secs_ok() {
|
||||
case "$1" in ""|*[!0-9]*) return 1 ;; esac
|
||||
[ "${#1}" -le 4 ] && [ "$1" -ge 1 ] && [ "$1" -le 3600 ]
|
||||
}
|
||||
|
||||
# _wa_run ID SECS: decode, run under the deadline, answer, forget ID.
|
||||
_wa_run() {
|
||||
_wr_b64="$_wa_dir/$1.b64"
|
||||
_wr_sh="$_wa_dir/$1.sh"
|
||||
_wr_out="$_wa_dir/$1.out"
|
||||
if [ ! -s "$_wr_b64" ] || ! base64 -d < "$_wr_b64" > "$_wr_sh" 2>/dev/null ||
|
||||
[ ! -s "$_wr_sh" ]; then
|
||||
rm -f "$_wr_b64" "$_wr_sh"
|
||||
echo "<<ERR bad script $1>>"
|
||||
return 0
|
||||
fi
|
||||
rm -f "$_wr_b64"
|
||||
# setsid: the script leads its own process group, so a timeout kills
|
||||
# every process it started, not only its shell.
|
||||
setsid sh "$_wr_sh" < /dev/null > "$_wr_out" 2>&1 &
|
||||
_wr_pid=$!
|
||||
_wr_n=0
|
||||
_wr_limit=$(($2 * 10))
|
||||
_wr_late=0
|
||||
while kill -0 "$_wr_pid" 2>/dev/null; do
|
||||
if [ "$_wr_n" -ge "$_wr_limit" ]; then
|
||||
kill -KILL "-$_wr_pid" 2>/dev/null || kill -KILL "$_wr_pid" 2>/dev/null
|
||||
_wr_late=1
|
||||
break
|
||||
fi
|
||||
sleep 0.1
|
||||
_wr_n=$((_wr_n + 1))
|
||||
done
|
||||
wait "$_wr_pid" 2>/dev/null
|
||||
_wr_rc=$?
|
||||
[ "$_wr_late" = 1 ] && _wr_rc=124
|
||||
echo "<<BEGIN $1>>"
|
||||
[ -s "$_wr_out" ] && base64 < "$_wr_out"
|
||||
echo "<<END $1 $_wr_rc>>"
|
||||
rm -f "$_wr_sh" "$_wr_out"
|
||||
}
|
||||
|
||||
+50
-1
@@ -18,6 +18,53 @@ mount -t sysfs sysfs /sys
|
||||
|
||||
echo "WARDEN-QEMU-BOOT-OK"
|
||||
|
||||
# Kernel contract (rebuild M0): every symbol of build/required-symbols.txt (staged
|
||||
# as /etc/required-symbols.txt by mkinitramfs.sh) is in the running kernel's
|
||||
# /proc/config.gz, the cgroup v2 controllers the platform limits with are there,
|
||||
# and pressure stall information is on. boot-smoke.sh greps these markers.
|
||||
if [ -r /etc/required-symbols.txt ]; then
|
||||
if [ -e /proc/config.gz ] && zcat /proc/config.gz > /config.run 2>/dev/null; then
|
||||
miss=""; nsym=0
|
||||
while read -r line; do
|
||||
case "$line" in
|
||||
CONFIG_*=*)
|
||||
nsym=$((nsym + 1))
|
||||
grep -qxF "$line" /config.run || miss="$miss $line" ;;
|
||||
"# CONFIG_"*" is not set")
|
||||
sym="${line#\# }"; sym="${sym% is not set}"; nsym=$((nsym + 1))
|
||||
grep -q "^$sym=" /config.run && miss="$miss ${sym}(set)" ;;
|
||||
esac
|
||||
done < /etc/required-symbols.txt
|
||||
if [ -z "$miss" ]; then echo "WARDEN-QEMU-SYMBOLS-OK $nsym"
|
||||
else echo "WARDEN-QEMU-SYMBOLS-MISSING$miss"; fi
|
||||
else
|
||||
echo "WARDEN-QEMU-SYMBOLS-MISSING /proc/config.gz"
|
||||
fi
|
||||
mkdir -p /sys/fs/cgroup
|
||||
mount -t cgroup2 none /sys/fs/cgroup 2>/dev/null
|
||||
echo "WARDEN-QEMU-CGROUP-CONTROLLERS $(cat /sys/fs/cgroup/cgroup.controllers 2>/dev/null)"
|
||||
psi_missing=""
|
||||
for f in cpu memory io; do [ -r "/proc/pressure/$f" ] || psi_missing="$psi_missing $f"; done
|
||||
if [ -z "$psi_missing" ]; then echo "WARDEN-QEMU-PSI-OK"; else echo "WARDEN-QEMU-PSI-MISSING$psi_missing"; fi
|
||||
fi
|
||||
|
||||
# warden.run=<path>: run a script that mkinitramfs.sh staged from EXTRA_DIR, then
|
||||
# power off. Used by the M0 limit tests (tools/m0/limits-test.sh in flare-edge).
|
||||
read -r CMDLINE < /proc/cmdline
|
||||
for w in $CMDLINE; do
|
||||
case "$w" in warden.run=*) RUN_SCRIPT="${w#warden.run=}" ;; esac
|
||||
done
|
||||
if [ -n "${RUN_SCRIPT:-}" ]; then
|
||||
if [ -x "$RUN_SCRIPT" ]; then
|
||||
echo "WARDEN-QEMU-RUN-BEGIN $RUN_SCRIPT"
|
||||
"$RUN_SCRIPT"
|
||||
echo "WARDEN-QEMU-RUN-END rc=$?"
|
||||
else
|
||||
echo "WARDEN-QEMU-RUN-MISSING $RUN_SCRIPT"
|
||||
fi
|
||||
poweroff -f
|
||||
fi
|
||||
|
||||
# With a virtio disk attached, hand over to the stage-1 rc (by-name symlinks,
|
||||
# slot select, switch_root). It only returns on failure; then fall through to
|
||||
# the diskless shell/poweroff behavior below.
|
||||
@@ -28,7 +75,9 @@ fi
|
||||
|
||||
if grep -qw warden.shell /proc/cmdline; then
|
||||
echo "warden.shell: interactive shell (exit to power off)"
|
||||
setsid cttyhack sh
|
||||
# shellcheck source=qemu/rootfs/etc/warden-lib.sh disable=SC1091
|
||||
. /etc/warden-lib.sh
|
||||
warden_console_shell
|
||||
fi
|
||||
|
||||
poweroff -f
|
||||
|
||||
+78
-58
@@ -48,7 +48,7 @@ mount_fatal() {
|
||||
echo "WARDEN-QEMU-MOUNT-FAILED $1"
|
||||
if grep -qw warden.shell /proc/cmdline; then
|
||||
echo "warden.shell: post-mortem shell (exit powers off)"
|
||||
setsid cttyhack sh
|
||||
warden_console_shell
|
||||
fi
|
||||
poweroff -f
|
||||
fi
|
||||
@@ -57,6 +57,16 @@ mount_fatal userdata /userdata
|
||||
mount_fatal "oem${slot}" /oem
|
||||
mkdir -p /userdata/warden
|
||||
|
||||
# A flow may seed an opt-in guest fixture before the UI and payload daemons
|
||||
# start. The file lives only in this disposable QEMU disk image. Fail the
|
||||
# boot if setup fails so a flow cannot pass against an unprepared guest.
|
||||
if [ -f /userdata/warden/qemu-flow-setup.sh ]; then
|
||||
if ! /bin/busybox sh /userdata/warden/qemu-flow-setup.sh; then
|
||||
echo "FATAL: QEMU flow setup failed"
|
||||
poweroff -f
|
||||
fi
|
||||
fi
|
||||
|
||||
# RS485: warden-modbus hardcodes /dev/ttyS4 at compile time; alias it to the
|
||||
# VM's RS485 pci-serial UART (needs the virt.fragment kernel). run.sh lists
|
||||
# the control channel's port first when there is one (warden.ctl on the
|
||||
@@ -98,6 +108,28 @@ export WARDEN_HARD_RESET=0
|
||||
# Production init scripts create this volatile socket directory before their
|
||||
# daemons start. The compact QEMU rootfs must provide the same contract.
|
||||
mkdir -p /run/warden
|
||||
# warden.initchain (flare-edge #2210): the UI starts through the panel's own
|
||||
# scripts, laid into /etc/init.d and /usr/lib/warden by mkimage.sh's
|
||||
# ROOTFS_OVERLAY, not directly as root below. Scripts S00 to S09 (the
|
||||
# accounts) run before the bus, which then hands each account its
|
||||
# credential, and S10 to S99 run where the direct UI start would. The rig
|
||||
# has no S09splash, so the splash handover is marked done, and its UI is the
|
||||
# fbdev build, so warden-ui-run passes "-b fbdev" instead of the panel's
|
||||
# "-b drm". A chain boot without any script fails loudly: a direct start
|
||||
# there would pass a check that asked for the shipped chain.
|
||||
initchain=0
|
||||
if grep -qw warden.initchain /proc/cmdline; then
|
||||
initchain=1
|
||||
echo "init: shipped init chain (warden.initchain)"
|
||||
export WARDEN_UI_ARGS="-b fbdev"
|
||||
: > /tmp/splash.done
|
||||
chain_early="$(warden_init_chain 0 9)"
|
||||
fi
|
||||
# The device bus, when the payload carries a broker (warden_rig_bus): up
|
||||
# before the daemons, as S10bus is before every bus client on the panel. A
|
||||
# failed start is logged and the boot goes on: the clients keep dialing, and
|
||||
# a flow that needs the bus fails on its own checks.
|
||||
warden_rig_bus || true
|
||||
# OTA apply is opt-in per boot (run.sh --allow-apply): writing rootfs_b is
|
||||
# safe inside disk.img but must never be the default posture.
|
||||
if grep -qw warden.fwapply /proc/cmdline; then
|
||||
@@ -105,14 +137,14 @@ if grep -qw warden.fwapply /proc/cmdline; then
|
||||
echo "init: OTA APPLY ENABLED (warden.fwapply)"
|
||||
fi
|
||||
# The same daemons the panel's SysV scripts start, in their S-number order
|
||||
# (S92 ai, S93 automation, S94 modbus, S95 mikrotik, S96 asic/starlink/
|
||||
# stratum, S97 flared), each with no arguments and no environment, exactly
|
||||
# as start-stop-daemon runs them there. A daemon that cannot live on -M virt
|
||||
# (S21 modbus, S22 automation, S92 ai, S95 mikrotik, S96 asic/starlink/
|
||||
# stratum, S97 flared; flare-edge#348), each with no arguments and no
|
||||
# environment, exactly as start-stop-daemon runs them there. A daemon that cannot live on -M virt
|
||||
# (warden-ai wants the NPU) exits into its log and the UI shows the same
|
||||
# "not running" it would show on a panel whose daemon died; that is the
|
||||
# panel's behaviour, not a rig substitute for it. warden-watchdog stays out:
|
||||
# it and a payload flared do not mix (README).
|
||||
for d in /usr/bin/warden-ai /usr/bin/warden-automation /usr/bin/warden-modbus \
|
||||
for d in /usr/bin/warden-modbus /usr/bin/warden-automation /usr/bin/warden-ai \
|
||||
/usr/bin/warden-mikrotik /usr/bin/warden-asic /usr/bin/warden-starlink \
|
||||
/usr/bin/warden-stratum /usr/bin/warden-flared; do
|
||||
if [ -x "$d" ]; then
|
||||
@@ -122,10 +154,19 @@ for d in /usr/bin/warden-ai /usr/bin/warden-automation /usr/bin/warden-modbus \
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$initchain" = 1 ]; then
|
||||
chain_late="$(warden_init_chain 10 99)"
|
||||
if [ "$((chain_early + chain_late))" -eq 0 ]; then
|
||||
echo "WARDEN-QEMU-INITCHAIN-EMPTY: warden.initchain but no /etc/init.d/S* script; the UI is not started"
|
||||
else
|
||||
echo "init: chain started $((chain_early + chain_late)) script(s)"
|
||||
fi
|
||||
fi
|
||||
|
||||
# The UI (LVGL fbdev+evdev build from flare-edge tools/build-ui-vm.sh) needs
|
||||
# virtio-gpu's fbdev: present only with run.sh --display on|headless AND the
|
||||
# virt.fragment kernel.
|
||||
if [ -x /usr/bin/warden-ui ] && [ -c /dev/fb0 ]; then
|
||||
# virt.fragment kernel. A chain boot started it above, through S99lvgl.
|
||||
if [ "$initchain" = 0 ] && [ -x /usr/bin/warden-ui ] && [ -c /dev/fb0 ]; then
|
||||
echo "init: starting warden-ui (fbdev)"
|
||||
# Announce the exit on the CONSOLE, not just in the log. A UI that dies
|
||||
# mid-scenario otherwise looks exactly like a UI that stopped repainting:
|
||||
@@ -182,62 +223,41 @@ if grep -qw warden.ctl /proc/cmdline && [ -c /dev/ttyS0 ]; then
|
||||
# mode: the host discards echoed input, and a whole line arrives per
|
||||
# read.
|
||||
exec 3<> "$ctl"
|
||||
while IFS= read -r cmd <&3; do
|
||||
[ -n "$cmd" ] || continue
|
||||
case "$cmd" in
|
||||
"@cat "*)
|
||||
# A bridge-local command, never forwarded to warden-ui's
|
||||
# FIFO: `@cat PATH` reads PATH directly off the GUEST's
|
||||
# own filesystem and answers with it, which is how the
|
||||
# json flow channel gets webstatus.c's snapshot out to
|
||||
# the host driving the VM from outside. `-f` so a
|
||||
# directory or device node reports as missing rather than
|
||||
# cat hanging or erroring oddly.
|
||||
path="${cmd#@cat }"
|
||||
if [ -f "$path" ]; then
|
||||
cat "$path" >&3
|
||||
# Force a newline after the file's own bytes: the
|
||||
# status json (webstatus.c) is written with NO
|
||||
# trailing newline, and without this the sentinel
|
||||
# below would land on the SAME line as the content
|
||||
# and the reader (qmp.py Ctl.send, line-based) would
|
||||
# block forever waiting for a line that never comes.
|
||||
echo >&3
|
||||
else
|
||||
echo "bridge: no such file: $path" >&3
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
if [ -p /tmp/warden-ui.ctl ]; then
|
||||
# Remove the previous reply BEFORE sending, then wait
|
||||
# for the new one to appear (the UI renames it into
|
||||
# place whole). A fixed settle used to hand back the
|
||||
# previous command's reply whenever a page took longer
|
||||
# than 0.3 s to build (flare-edge #152); this is the
|
||||
# same recipe tools/warden-ctl uses over SSH.
|
||||
rm -f /tmp/warden-ui.dbg
|
||||
printf '%s\n' "$cmd" > /tmp/warden-ui.ctl
|
||||
n=0
|
||||
while [ ! -s /tmp/warden-ui.dbg ] && [ "$n" -lt 100 ]; do
|
||||
sleep 0.05
|
||||
n=$((n + 1))
|
||||
done
|
||||
cat /tmp/warden-ui.dbg 2>/dev/null >&3
|
||||
else
|
||||
echo "bridge: warden-ui control FIFO not present" >&3
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
echo "<<END>>" >&3
|
||||
done
|
||||
# The loop itself is warden_ctl_bridge (/etc/warden-lib.sh), where
|
||||
# the host test reaches it.
|
||||
warden_ctl_bridge <&3 >&3
|
||||
) &
|
||||
fi
|
||||
|
||||
# Rig agent (run.sh --agent, warden.agent on the command line): a shell for a
|
||||
# host-side rig that reads and changes guest state, such as the QEMU soak rig
|
||||
# (flare-edge tools/soak/rig-qemu.py). Its pci-serial port comes after the
|
||||
# ctl port (when there is one) and the always-present RS485 port, so it is
|
||||
# ttyS2 with warden.ctl and ttyS1 without; the ctl/RS485 order above is
|
||||
# unchanged. Echo is turned off so the host reads only the agent's frames.
|
||||
# The protocol is warden_agent (/etc/warden-lib.sh). Rig rootfs only: no
|
||||
# panel image carries it.
|
||||
if grep -qw warden.agent /proc/cmdline; then
|
||||
if grep -qw warden.ctl /proc/cmdline; then agent=/dev/ttyS2; else agent=/dev/ttyS1; fi
|
||||
if [ -c "$agent" ]; then
|
||||
echo "init: rig agent on $agent"
|
||||
(
|
||||
exec 4<> "$agent"
|
||||
stty -echo <&4 2>/dev/null || echo "init: rig agent: stty -echo failed"
|
||||
warden_agent <&4 >&4 2>/dev/null
|
||||
) &
|
||||
else
|
||||
echo "init: rig agent: $agent missing (needs the virt.fragment kernel)"
|
||||
fi
|
||||
fi
|
||||
|
||||
if grep -qw warden.shell /proc/cmdline; then
|
||||
echo "warden.shell: interactive shell (exit powers off)"
|
||||
setsid cttyhack sh
|
||||
warden_console_shell
|
||||
poweroff -f
|
||||
fi
|
||||
|
||||
# Hold: daemons run, console idles, scenarios drive the VM from outside.
|
||||
while :; do sleep 3600; done
|
||||
# Hold: daemons run, console idles, scenarios drive the VM from outside. As
|
||||
# PID 1 this shell must honour reboot/poweroff/halt itself (#5).
|
||||
warden_trap_power_signals
|
||||
warden_idle_forever
|
||||
|
||||
+20
-1
@@ -17,6 +17,10 @@
|
||||
# --ctl SOCK unix socket to warden-ui's debug channel (nav/page/hit),
|
||||
# bridged by init from a pci-serial port; the rig-side
|
||||
# twin of tools/warden-ctl over SSH on a real panel
|
||||
# --agent SOCK unix socket to the rig agent (warden_agent in
|
||||
# rootfs/etc/warden-lib.sh): a guest shell for host-side
|
||||
# rigs such as flare-edge tools/soak/rig-qemu.py; a third
|
||||
# pci-serial after ctl and rs485, so their order holds
|
||||
# --watchdog add i6300esb watchdog, reset on expiry (fragment kernel)
|
||||
# --qmp SOCK QMP unix socket (screendump, input-send-event, quit)
|
||||
# --display MODE off (default, -nographic) | on (gtk window) | headless
|
||||
@@ -25,6 +29,9 @@
|
||||
# --http-port N hostfwd 127.0.0.1:N -> guest :80 (default 8080; 0 disables)
|
||||
# --api-port N hostfwd 127.0.0.1:N -> guest :28443 (default 28443; 0 disables)
|
||||
# --shell interactive shell in the guest instead of daemon hold
|
||||
# --append STR extra kernel command line words (for example
|
||||
# warden.run=/m0/limits-test.sh: init runs that script from
|
||||
# the initramfs and powers off)
|
||||
# --allow-apply let flared ACTUALLY apply OTA firmware (writes rootfs_b
|
||||
# inside disk.img, safe in the VM, never the default)
|
||||
set -euo pipefail
|
||||
@@ -35,9 +42,10 @@ QEMU_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
OUT="${OUT:-$QEMU_DIR/out}"
|
||||
|
||||
KERNEL="" INITRD="$OUT/initramfs.cpio.gz" DISK="" NO_DISK=0 SLOT="_a"
|
||||
RTC="" RS485="" CTL="" WATCHDOG=0 QMP="" DISPLAY_MODE="off" SHELL_FLAG=0 ALLOW_APPLY=0
|
||||
RTC="" RS485="" CTL="" AGENT="" WATCHDOG=0 QMP="" DISPLAY_MODE="off" SHELL_FLAG=0 ALLOW_APPLY=0
|
||||
SSH_PORT=2222 HTTP_PORT=8080 API_PORT=28443
|
||||
EXTRA=()
|
||||
EXTRA_APPEND=""
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
@@ -49,6 +57,7 @@ while [ $# -gt 0 ]; do
|
||||
--rtc) RTC="${2:?}"; shift 2 ;;
|
||||
--rs485) RS485="${2:?}"; shift 2 ;;
|
||||
--ctl) CTL="${2:?}"; shift 2 ;;
|
||||
--agent) AGENT="${2:?}"; shift 2 ;;
|
||||
--watchdog) WATCHDOG=1; shift ;;
|
||||
--qmp) QMP="${2:?}"; shift 2 ;;
|
||||
--display) DISPLAY_MODE="${2:?}"; shift 2 ;;
|
||||
@@ -56,6 +65,7 @@ while [ $# -gt 0 ]; do
|
||||
--http-port) HTTP_PORT="${2:?}"; shift 2 ;;
|
||||
--api-port) API_PORT="${2:?}"; shift 2 ;;
|
||||
--shell) SHELL_FLAG=1; shift ;;
|
||||
--append) EXTRA_APPEND="${2:?}"; shift 2 ;;
|
||||
--allow-apply) ALLOW_APPLY=1; shift ;;
|
||||
--) shift; EXTRA=("$@"); break ;;
|
||||
*) echo "FATAL: unknown argument '$1' (see header of $0)" >&2; exit 1 ;;
|
||||
@@ -111,6 +121,7 @@ if [ -n "$DISK" ] && [ "$NO_DISK" -eq 0 ]; then
|
||||
-device "virtio-blk-device,drive=vd0" )
|
||||
fi
|
||||
[ "$SHELL_FLAG" -eq 1 ] && APPEND="$APPEND warden.shell"
|
||||
[ -n "$EXTRA_APPEND" ] && APPEND="$APPEND $EXTRA_APPEND"
|
||||
# Tells init the FIRST 8250 is the control bridge. Without this marker init
|
||||
# bridges nothing, so a VM launched with --rs485 alone never has its Modbus
|
||||
# wire mistaken for the debug channel.
|
||||
@@ -137,6 +148,14 @@ if [ -n "$RS485" ]; then
|
||||
else
|
||||
ARGS+=( -chardev "null,id=rs485" -device "pci-serial,chardev=rs485" )
|
||||
fi
|
||||
# The rig agent comes LAST of the pci-serial ports, so ctl stays ttyS0 and
|
||||
# rs485 stays where init looks for it; init finds the agent at ttyS1 (no
|
||||
# ctl) or ttyS2 (with ctl), and only with warden.agent on the cmdline.
|
||||
if [ -n "$AGENT" ]; then
|
||||
APPEND="$APPEND warden.agent"
|
||||
ARGS+=( -chardev "socket,id=agent,path=$AGENT,server=on,wait=off"
|
||||
-device "pci-serial,chardev=agent" )
|
||||
fi
|
||||
[ -n "$QMP" ] && ARGS+=( -qmp "unix:$QMP,server=on,wait=off" )
|
||||
|
||||
case "$DISPLAY_MODE" in
|
||||
|
||||
Executable
+121
@@ -0,0 +1,121 @@
|
||||
#!/usr/bin/env bash
|
||||
# Host test for the rig agent, warden_agent in qemu/rootfs/etc/warden-lib.sh
|
||||
# (flare-edge M9 soak-lite). Feeds request lines on stdin, as the host rig
|
||||
# does over the agent's serial port, and checks the framed answers: a script
|
||||
# runs and answers its output in base64 with its exit code, chunks join into
|
||||
# one script, a script past its deadline is killed with its children and
|
||||
# answers 124, and malformed requests answer one <<ERR ...>> line and run
|
||||
# nothing.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
LIB="$HERE/../rootfs/etc/warden-lib.sh"
|
||||
# Unquoted where it runs: WARDEN_TEST_SH may be "busybox sh", the rig's shell.
|
||||
SH="${WARDEN_TEST_SH:-sh}"
|
||||
WORK="$(mktemp -d)" || exit 1
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
FAIL=0
|
||||
CHECKS=0
|
||||
|
||||
check() { # check <label> <command...>
|
||||
CHECKS=$((CHECKS + 1))
|
||||
if "${@:2}"; then
|
||||
echo "[PASS] $1"
|
||||
else
|
||||
echo "[FAIL] $1"
|
||||
FAIL=1
|
||||
fi
|
||||
}
|
||||
|
||||
b64() { printf '%s' "$1" | base64 -w0; }
|
||||
|
||||
agent() { # agent <name> <lines...>: run the agent over the lines
|
||||
local name="$1"
|
||||
shift
|
||||
# $SH unquoted (it may be "busybox sh"); the quoted script is meant literally.
|
||||
# shellcheck disable=SC2086,SC2016
|
||||
printf '%s\n' "$@" |
|
||||
env WARDEN_AGENT_DIR="$WORK/agent-$name" \
|
||||
$SH -c '. "$1"; warden_agent' sh "$LIB" > "$WORK/$name.out" 2> "$WORK/$name.err"
|
||||
}
|
||||
|
||||
same() { # same <file> <expected lines...>
|
||||
local file="$1"
|
||||
shift
|
||||
diff <(printf '%s\n' "$@") "$file" > "$WORK/diff" || { cat "$WORK/diff"; return 1; }
|
||||
}
|
||||
|
||||
# The body between <<BEGIN ID>> and <<END ID ...>>, decoded.
|
||||
body() { # body <file> <id>
|
||||
awk -v b="<<BEGIN $2>>" -v e="<<END $2 " '$0 == b {on = 1; next} index($0, e) == 1 {on = 0} on' "$1" |
|
||||
base64 -d
|
||||
}
|
||||
|
||||
agent basic @ping "@run a1 10 $(b64 'echo hello; echo oops >&2; exit 3')"
|
||||
check "ping and a run answer framed lines" \
|
||||
grep -qx '<<PONG>>' "$WORK/basic.out"
|
||||
check "the run ends with its exit code" grep -qx '<<END a1 3>>' "$WORK/basic.out"
|
||||
check "stdout and stderr come back in base64" \
|
||||
same <(body "$WORK/basic.out" a1) hello oops
|
||||
|
||||
# Chunks: the script text arrives in pieces, then @run with no B64 of its own
|
||||
# and once more with a last piece on the run line.
|
||||
# shellcheck disable=SC2016 # the guest's shell expands it, not this one
|
||||
script='i=0; while [ $i -lt 3 ]; do echo line$i; i=$((i + 1)); done'
|
||||
whole="$(b64 "$script")"
|
||||
agent chunks "@chunk c1 ${whole:0:20}" "@chunk c1 ${whole:20}" "@run c1 10" \
|
||||
"@chunk c2 ${whole:0:12}" "@run c2 10 ${whole:12}"
|
||||
check "chunks acknowledge the bytes so far" \
|
||||
grep -qx "<<OK c1 20>>" "$WORK/chunks.out"
|
||||
check "chunked script runs whole" same <(body "$WORK/chunks.out" c1) line0 line1 line2
|
||||
check "a last piece on the run line joins the chunks" \
|
||||
same <(body "$WORK/chunks.out" c2) line0 line1 line2
|
||||
check "a script's text is used once" \
|
||||
test -z "$(ls -A "$WORK/agent-chunks" 2>/dev/null)"
|
||||
|
||||
# Deadline: the script and the child it started both die; RC 124.
|
||||
start=$(date +%s)
|
||||
agent late "@run t1 1 $(b64 "sleep 30 & echo \$! > $WORK/child.pid; sleep 30")" @ping
|
||||
took=$(( $(date +%s) - start ))
|
||||
check "a script past its deadline answers 124" grep -qx '<<END t1 124>>' "$WORK/late.out"
|
||||
check "the deadline holds (took ${took}s)" test "$took" -le 5
|
||||
child="$(cat "$WORK/child.pid" 2>/dev/null)"
|
||||
# Gone or a zombie: in a CI job container PID 1 reaps nothing, so a killed
|
||||
# orphan stays a zombie that kill -0 still finds.
|
||||
gone() { [ ! -r "/proc/$1/stat" ] || [ "$(sed 's/.*) //' "/proc/$1/stat" | cut -d' ' -f1)" = Z ]; }
|
||||
check "the script's child is killed too" bash -c "[ -n '$child' ] && $(declare -f gone); sleep 0.5; gone '$child'"
|
||||
check "the agent answers after a timeout" grep -qx '<<PONG>>' "$WORK/late.out"
|
||||
|
||||
# Malformed requests: one error line each, nothing runs.
|
||||
touch_b64="$(b64 "touch $WORK/ran")"
|
||||
agent bad "@run bad/id 10 $touch_b64" "@run b1 0 $touch_b64" "@run b1 99999 $touch_b64" \
|
||||
"@run b1 10 not*base64" "@chunk b2" "@run b3 10" "frobnicate" "@run b4 10 $(b64 'x') extra" \
|
||||
"@run b5 10 ===="
|
||||
check "malformed requests answer one error line each" \
|
||||
same "$WORK/bad.out" '<<ERR bad run>>' '<<ERR bad run>>' '<<ERR bad run>>' '<<ERR bad run>>' \
|
||||
'<<ERR bad chunk>>' '<<ERR bad script b3>>' '<<ERR unknown request>>' '<<ERR bad run>>' \
|
||||
'<<ERR bad script b5>>'
|
||||
check "no malformed request ran anything" test ! -e "$WORK/ran"
|
||||
|
||||
# A trailing CR (a cooked tty line) is not part of the last word.
|
||||
agent cr "$(printf '@ping\r')" "$(printf '@run r1 10 %s\r' "$(b64 'echo ok')")"
|
||||
check "a trailing CR is ignored" bash -c "grep -qx '<<PONG>>' '$WORK/cr.out' && grep -qx '<<END r1 0>>' '$WORK/cr.out'"
|
||||
|
||||
# A request with glob characters in a word does not expand them.
|
||||
agent glob "@run * 10 $(b64 'echo no')"
|
||||
check "a glob word is not expanded" same "$WORK/glob.out" '<<ERR bad run>>'
|
||||
|
||||
# sbin/init arms the agent only on warden.agent, on the port after ctl and
|
||||
# RS485 (ttyS2 with warden.ctl, ttyS1 without), with echo off.
|
||||
INIT="$HERE/../rootfs/sbin/init"
|
||||
check "init arms the agent only with warden.agent" grep -q 'grep -qw warden.agent /proc/cmdline' "$INIT"
|
||||
check "init picks ttyS2 with ctl and ttyS1 without" \
|
||||
grep -q 'if grep -qw warden.ctl /proc/cmdline; then agent=/dev/ttyS2; else agent=/dev/ttyS1; fi' "$INIT"
|
||||
check "init turns echo off on the agent port" grep -q 'stty -echo <&4' "$INIT"
|
||||
|
||||
if [ "$FAIL" = 0 ]; then
|
||||
echo "agent tests: OK ($CHECKS checks)"
|
||||
else
|
||||
echo "agent tests: FAILED"
|
||||
exit 1
|
||||
fi
|
||||
@@ -44,4 +44,20 @@ grep -q "WARDEN-QEMU-BOOT-OK" "$LOG" || {
|
||||
echo "FATAL: boot sentinel WARDEN-QEMU-BOOT-OK not found in console log" >&2
|
||||
exit 1
|
||||
}
|
||||
echo "boot smoke OK"
|
||||
# Kernel contract (rebuild M0): init checked build/required-symbols.txt against the
|
||||
# running kernel's /proc/config.gz, the cgroup v2 controllers and PSI. A missing
|
||||
# marker is as fatal as a MISSING one: the check must have run.
|
||||
grep -q "^WARDEN-QEMU-SYMBOLS-OK " "$LOG" || {
|
||||
echo "FATAL: the required-symbols check did not pass: $(grep -E 'WARDEN-QEMU-SYMBOLS' "$LOG" | head -1)" >&2
|
||||
exit 1
|
||||
}
|
||||
ctl="$(sed -n 's/^WARDEN-QEMU-CGROUP-CONTROLLERS //p' "$LOG" | head -1 | tr -d '\r')"
|
||||
for c in cpu memory pids; do
|
||||
case " $ctl " in *" $c "*) ;; *)
|
||||
echo "FATAL: cgroup v2 controller '$c' missing in the guest (have: '$ctl')" >&2; exit 1 ;; esac
|
||||
done
|
||||
grep -q "^WARDEN-QEMU-PSI-OK" "$LOG" || {
|
||||
echo "FATAL: pressure stall information is not available: $(grep -E 'WARDEN-QEMU-PSI' "$LOG" | head -1)" >&2
|
||||
exit 1
|
||||
}
|
||||
echo "boot smoke OK (symbols, cgroup controllers [$ctl], PSI)"
|
||||
|
||||
@@ -69,4 +69,54 @@ cp "$SCRATCH/good" "$SCRATCH/cached/busybox-armv7l"
|
||||
OUT="$SCRATCH/cached" qemu_get_busybox
|
||||
test "$(cat "$FAKE_CURL_COUNT")" = 0
|
||||
|
||||
# A server that answers and then stalls must not hang the fetch (#1588). This
|
||||
# runs the real curl against a local listener that sends headers and a few
|
||||
# bytes, then goes silent; the short limits keep the test fast.
|
||||
PATH="${PATH//"$FAKE_BIN:"/}"
|
||||
python3 - "$SCRATCH/stall-port" <<'STALL' &
|
||||
import os, socket, sys, threading, time
|
||||
srv = socket.socket()
|
||||
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
srv.bind(("127.0.0.1", 0))
|
||||
srv.listen(16)
|
||||
with open(sys.argv[1] + ".tmp", "w") as f:
|
||||
f.write(str(srv.getsockname()[1]))
|
||||
os.rename(sys.argv[1] + ".tmp", sys.argv[1])
|
||||
held = []
|
||||
def serve(conn):
|
||||
try:
|
||||
conn.recv(4096)
|
||||
conn.sendall(b"HTTP/1.1 200 OK\r\nContent-Length: 1000000\r\n\r\nstall")
|
||||
held.append(conn)
|
||||
time.sleep(600)
|
||||
except OSError:
|
||||
pass
|
||||
while True:
|
||||
c, _ = srv.accept()
|
||||
threading.Thread(target=serve, args=(c,), daemon=True).start()
|
||||
STALL
|
||||
STALL_PID=$!
|
||||
trap 'kill "$STALL_PID" 2>/dev/null || true; rm -rf "$SCRATCH"' EXIT
|
||||
for _ in $(seq 100); do [ -s "$SCRATCH/stall-port" ] && break; sleep 0.1; done
|
||||
test -s "$SCRATCH/stall-port"
|
||||
BB_URL="http://127.0.0.1:$(cat "$SCRATCH/stall-port")/busybox"
|
||||
start=$SECONDS
|
||||
# The bash -c program expands its own positional arguments.
|
||||
# shellcheck disable=SC2016
|
||||
if (OUT="$SCRATCH/stalled" BB_FETCH_STALL_SECS=1 BB_FETCH_MAX_SECS=3 \
|
||||
BB_FETCH_RETRY_DELAY=1 timeout 60 bash -c \
|
||||
'set -euo pipefail; source "$1"; QEMU_DIR="$2"; BB_URL="$3"; qemu_get_busybox' \
|
||||
_ "$TEST_DIR/../lib.sh" "$QEMU_DIR" "$BB_URL") >"$SCRATCH/stall.log" 2>&1; then
|
||||
echo "FAIL: a stalled download was accepted" >&2
|
||||
exit 1
|
||||
fi
|
||||
elapsed=$((SECONDS - start))
|
||||
if ! grep -q 'after 3 verified attempts' "$SCRATCH/stall.log"; then
|
||||
echo "FAIL: a stalled download hung instead of failing (${elapsed}s)" >&2
|
||||
cat "$SCRATCH/stall.log" >&2
|
||||
exit 1
|
||||
fi
|
||||
test "$elapsed" -lt 45
|
||||
test ! -e "$SCRATCH/stalled/busybox-armv7l"
|
||||
|
||||
echo "busybox fetch tests passed"
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
# Check a built panel BusyBox against the bench capture (flare-edge#2210):
|
||||
# its applet list must equal qemu/busybox/applets.txt and every applet's
|
||||
# --help text must equal qemu/busybox/help.txt, which lists the options each
|
||||
# applet of the panel's own binary accepts. The binary is ARM: the host runs
|
||||
# it through binfmt, or through $QEMU_USER (e.g. qemu-arm) when set.
|
||||
#
|
||||
# bash qemu/tests/busybox-panel-help.sh [BIN] (default qemu/out/busybox-armv7l-panel)
|
||||
set -euo pipefail
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
BB_DIR="$HERE/../busybox"
|
||||
BIN="${1:-$HERE/../out/busybox-armv7l-panel}"
|
||||
[ -x "$BIN" ] || { echo "FATAL: no busybox binary at $BIN (run qemu/build-busybox.sh)" >&2; exit 1; }
|
||||
export LC_ALL=C
|
||||
SCRATCH="$(mktemp -d "${TMPDIR:-/tmp}/bb-panel-help.XXXXXX")"
|
||||
trap 'rm -rf "$SCRATCH"' EXIT
|
||||
# Word splitting is wanted: QEMU_USER may carry arguments.
|
||||
# shellcheck disable=SC2206
|
||||
RUN=(${QEMU_USER:-} "$BIN")
|
||||
|
||||
"${RUN[@]}" --list | sort > "$SCRATCH/list.txt" || {
|
||||
echo "FATAL: $BIN does not run here (no binfmt for ARM? set QEMU_USER=qemu-arm)" >&2
|
||||
exit 1
|
||||
}
|
||||
if ! diff -u <(sort "$BB_DIR/applets.txt") "$SCRATCH/list.txt"; then
|
||||
echo "FAIL: the applet list differs from qemu/busybox/applets.txt (- panel, + built)" >&2
|
||||
exit 1
|
||||
fi
|
||||
# Same shape as flare-edge tools/bench/busybox-help/capture.sh: the banner
|
||||
# line (version and build date) and blank lines dropped.
|
||||
while IFS= read -r a; do
|
||||
echo "== $a"
|
||||
"${RUN[@]}" "$a" --help 2>&1 | sed 1d | sed '/^$/d' || true
|
||||
done < "$SCRATCH/list.txt" > "$SCRATCH/help.txt"
|
||||
if ! diff -u <(grep -v '^#' "$BB_DIR/help.txt") "$SCRATCH/help.txt"; then
|
||||
echo "FAIL: --help differs from the panel's (qemu/busybox/help.txt; - panel, + built)" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "busybox-panel-help: $(wc -l < "$SCRATCH/list.txt") applets, list and --help equal to the panel's"
|
||||
@@ -0,0 +1,185 @@
|
||||
#!/usr/bin/env bash
|
||||
# Offline checks for the rig's panel BusyBox inputs (qemu/busybox/,
|
||||
# qemu/build-busybox.sh, RIG_BUSYBOX in qemu/lib.sh), flare-edge#2210. No
|
||||
# compiler, network or VM: the build helpers run against small stand-in files.
|
||||
#
|
||||
# bash qemu/tests/busybox-panel-test.sh
|
||||
set -uo pipefail
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
QEMU_DIR="$(cd "$HERE/.." && pwd)"
|
||||
REPO="$(cd "$QEMU_DIR/.." && pwd)"
|
||||
BB_DIR="$QEMU_DIR/busybox"
|
||||
SCRATCH="$(mktemp -d "${TMPDIR:-/tmp}/bb-panel-test.XXXXXX")"
|
||||
trap 'rm -rf "$SCRATCH"' EXIT
|
||||
FAIL=0
|
||||
pass() { printf '[PASS] %s\n' "$1"; }
|
||||
fail() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
|
||||
export LC_ALL=C
|
||||
|
||||
# shellcheck source=qemu/build-busybox.sh disable=SC1091
|
||||
. "$QEMU_DIR/build-busybox.sh"
|
||||
# The sourced script sets -e for its own run; these checks report each failure.
|
||||
set +e
|
||||
|
||||
# 1. Every setting the image's applet patch makes is in the panel config.
|
||||
PATCH="$REPO/luckfox-sdk-patches/buildroot/patches/0001-busybox-applets.patch"
|
||||
missing="$(sed -n -e 's/^+\(CONFIG_[A-Za-z0-9_]*=.*\)$/\1/p' \
|
||||
-e 's/^+\(# CONFIG_[A-Za-z0-9_]* is not set\)$/\1/p' "$PATCH" |
|
||||
while IFS= read -r l; do grep -qxF -- "$l" "$BB_DIR/panel.config" || printf '%s\n' "$l"; done)"
|
||||
n="$(grep -cE '^\+(CONFIG_|# CONFIG_)' "$PATCH")"
|
||||
if [ "$n" -gt 0 ] && [ -z "$missing" ]; then
|
||||
pass "panel.config carries all $n settings of the image's applet patch"
|
||||
else
|
||||
fail "panel.config lacks settings of $PATCH: ${missing:-none read}"
|
||||
fi
|
||||
|
||||
# 2. The rig differs from the panel only in linking and name lookup.
|
||||
got="$(grep -Ev '^(#|$)' "$BB_DIR/rig.fragment" | sed 's/=.*//' | sort | tr '\n' ' ')"
|
||||
if [ "$got" = "CONFIG_STATIC CONFIG_USE_BB_PWD_GRP CONFIG_USE_BB_SHADOW " ]; then
|
||||
pass "rig.fragment sets only STATIC, USE_BB_PWD_GRP and USE_BB_SHADOW"
|
||||
else
|
||||
fail "rig.fragment sets symbols beyond linking and name lookup: $got"
|
||||
fi
|
||||
|
||||
# 3. Applying the fragment replaces exactly its symbols.
|
||||
bb_apply_fragment "$BB_DIR/panel.config" "$BB_DIR/rig.fragment" > "$SCRATCH/rig.config"
|
||||
d="$(diff <(bb_settings "$BB_DIR/panel.config") <(bb_settings "$SCRATCH/rig.config"))"
|
||||
want_d="$(printf '%s\n' '< CONFIG_STATIC is not set' '< CONFIG_USE_BB_PWD_GRP is not set' \
|
||||
'< CONFIG_USE_BB_SHADOW is not set' '> CONFIG_STATIC=y' '> CONFIG_USE_BB_PWD_GRP=y' \
|
||||
'> CONFIG_USE_BB_SHADOW=y')"
|
||||
if [ "$(grep -E '^[<>]' <<<"$d" | sort)" = "$want_d" ]; then
|
||||
pass "the rig config is the panel config with the three fragment lines"
|
||||
else
|
||||
fail "the rig config differs from the panel config by: $d"
|
||||
fi
|
||||
printf 'CONFIG_A=y\n# CONFIG_B is not set\nCONFIG_C="x"\n' > "$SCRATCH/p.config"
|
||||
printf '# note\nNOT_A_SYMBOL=y\n' > "$SCRATCH/bad.fragment"
|
||||
if ! bb_apply_fragment "$SCRATCH/p.config" "$SCRATCH/bad.fragment" >/dev/null 2>"$SCRATCH/frag.err" &&
|
||||
grep -q 'bad fragment line' "$SCRATCH/frag.err"; then
|
||||
pass "a fragment line that is not CONFIG_* is refused"
|
||||
else
|
||||
fail "a bad fragment line was accepted"
|
||||
fi
|
||||
|
||||
# 4. A Kconfig rewrite of any setting fails and names it.
|
||||
cp "$SCRATCH/p.config" "$SCRATCH/same.config"
|
||||
printf '#\n# a header\n' >> "$SCRATCH/same.config"
|
||||
if bb_check_config "$SCRATCH/p.config" "$SCRATCH/same.config" 2>/dev/null; then
|
||||
pass "a config that only gained comments passes the rewrite check"
|
||||
else
|
||||
fail "the rewrite check failed a config with the same settings"
|
||||
fi
|
||||
printf 'CONFIG_A=y\nCONFIG_C="x"\n' > "$SCRATCH/dropped.config"
|
||||
if ! bb_check_config "$SCRATCH/p.config" "$SCRATCH/dropped.config" 2>"$SCRATCH/cfg.err" &&
|
||||
grep -q 'CONFIG_B is not set' "$SCRATCH/cfg.err"; then
|
||||
pass "a setting Kconfig dropped fails the rewrite check, named"
|
||||
else
|
||||
fail "a dropped setting passed the rewrite check"
|
||||
fi
|
||||
|
||||
# 5. The applet check compares names, not install paths.
|
||||
printf 'b\na\n' > "$SCRATCH/applets.txt"
|
||||
printf '/bin/a\n/usr/sbin/b\n' > "$SCRATCH/ok.links"
|
||||
printf '/bin/a\n/usr/sbin/b\n/usr/bin/timeout\n' > "$SCRATCH/extra.links"
|
||||
if bb_check_applets "$SCRATCH/ok.links" "$SCRATCH/applets.txt" 2>/dev/null; then
|
||||
pass "the same applets under install paths pass"
|
||||
else
|
||||
fail "matching applets failed the applet check"
|
||||
fi
|
||||
if ! bb_check_applets "$SCRATCH/extra.links" "$SCRATCH/applets.txt" 2>"$SCRATCH/app.err" &&
|
||||
grep -q '> timeout' "$SCRATCH/app.err"; then
|
||||
pass "an applet the panel lacks fails the applet check, named"
|
||||
else
|
||||
fail "an extra applet passed the applet check"
|
||||
fi
|
||||
|
||||
# 6. The two bench fixtures agree: applets.txt is help.txt's applet list.
|
||||
if [ -s "$BB_DIR/applets.txt" ] && [ -z "$(sort "$BB_DIR/applets.txt" | uniq -d)" ] &&
|
||||
[ "$(sort "$BB_DIR/applets.txt")" = "$(sed -n 's/^== //p' "$BB_DIR/help.txt" | sort)" ]; then
|
||||
pass "applets.txt ($(wc -l < "$BB_DIR/applets.txt") applets) matches help.txt"
|
||||
else
|
||||
fail "applets.txt and help.txt list different applets (or duplicates)"
|
||||
fi
|
||||
|
||||
# 7. RIG_BUSYBOX refusals, before any download or build.
|
||||
run_get() { (QEMU_DIR="$QEMU_DIR" OUT="$SCRATCH/out" qemu_get_busybox) >/dev/null 2>"$SCRATCH/get.err"; }
|
||||
if ! RIG_BUSYBOX=bogus run_get && grep -q 'RIG_BUSYBOX must be multiarch or panel' "$SCRATCH/get.err"; then
|
||||
pass "an unknown RIG_BUSYBOX is refused"
|
||||
else
|
||||
fail "an unknown RIG_BUSYBOX was accepted"
|
||||
fi
|
||||
|
||||
# 7b. A prebuilt panel binary (a flow job without the cross compiler) is taken
|
||||
# only with a .inputs equal to this tree's qemu_busybox_panel_inputs.
|
||||
inputs="$(QEMU_DIR="$QEMU_DIR" qemu_busybox_panel_inputs)"
|
||||
if [[ "$inputs" =~ ^[0-9a-f]{64}$ ]]; then
|
||||
pass "qemu_busybox_panel_inputs is one sha256"
|
||||
else
|
||||
fail "qemu_busybox_panel_inputs gave '$inputs'"
|
||||
fi
|
||||
mkdir -p "$SCRATCH/pre"
|
||||
printf 'stand-in\n' > "$SCRATCH/pre/bb"
|
||||
if ! RIG_BUSYBOX=panel BUSYBOX="$SCRATCH/pre/bb" run_get && grep -q 'is not a panel BusyBox built from' "$SCRATCH/get.err" &&
|
||||
grep -q "inputs 'missing'" "$SCRATCH/get.err"; then
|
||||
pass "a prebuilt panel BUSYBOX without .inputs is refused"
|
||||
else
|
||||
fail "a prebuilt panel BUSYBOX without .inputs was accepted"
|
||||
fi
|
||||
printf '%s\n' "$(printf '%s' "$inputs" | tr '0-9a-f' '1-9a-f0')" > "$SCRATCH/pre/bb.inputs"
|
||||
if ! RIG_BUSYBOX=panel BUSYBOX="$SCRATCH/pre/bb" run_get && grep -q 'is not a panel BusyBox built from' "$SCRATCH/get.err"; then
|
||||
pass "a prebuilt panel BUSYBOX built from other inputs is refused"
|
||||
else
|
||||
fail "a prebuilt panel BUSYBOX with other inputs was accepted"
|
||||
fi
|
||||
printf '%s\n' "$inputs" > "$SCRATCH/pre/bb.inputs"
|
||||
got_bb="$(RIG_BUSYBOX=panel BUSYBOX="$SCRATCH/pre/bb" QEMU_DIR="$QEMU_DIR" OUT="$SCRATCH/out" \
|
||||
bash -c '. "$QEMU_DIR/lib.sh"; set -euo pipefail; qemu_get_busybox >/dev/null; printf %s "$BB"' 2>"$SCRATCH/get.err")"
|
||||
if [ "$got_bb" = "$SCRATCH/pre/bb" ] && [ ! -e "$SCRATCH/out/busybox-armv7l-panel" ]; then
|
||||
pass "a prebuilt panel BUSYBOX with matching .inputs is used as is, nothing built"
|
||||
else
|
||||
fail "a prebuilt panel BUSYBOX with matching .inputs was not used (BB='$got_bb': $(cat "$SCRATCH/get.err"))"
|
||||
fi
|
||||
if ! RIG_BUSYBOX=panel BUSYBOX="$SCRATCH/pre/none" run_get && grep -q 'is not a panel BusyBox built from' "$SCRATCH/get.err"; then
|
||||
pass "a prebuilt panel BUSYBOX that does not exist is refused"
|
||||
else
|
||||
fail "a missing prebuilt panel BUSYBOX was accepted"
|
||||
fi
|
||||
# Every committed input file is in the inputs hash: a config edit changes it.
|
||||
mkdir -p "$SCRATCH/qcopy"
|
||||
cp -a "$QEMU_DIR/busybox" "$SCRATCH/qcopy/"
|
||||
printf '# CONFIG_TIMEOUT is not set\n' >> "$SCRATCH/qcopy/busybox/panel.config"
|
||||
other="$(QEMU_DIR="$SCRATCH/qcopy" qemu_busybox_panel_inputs)"
|
||||
first_patch="$(find "$SCRATCH/qcopy/busybox/patches" -maxdepth 1 -type f -name '*.patch' | sort | head -n 1)"
|
||||
printf 'x\n' >> "$first_patch"
|
||||
other2="$(QEMU_DIR="$SCRATCH/qcopy" qemu_busybox_panel_inputs)"
|
||||
if [ "$other" != "$inputs" ] && [ "$other2" != "$other" ]; then
|
||||
pass "a panel.config or patch edit changes qemu_busybox_panel_inputs"
|
||||
else
|
||||
fail "qemu_busybox_panel_inputs ignored a panel.config or patch edit"
|
||||
fi
|
||||
|
||||
# 8. No cross compiler: the build fails closed, it never falls back.
|
||||
if ! CROSS_COMPILE=no-such-cross- OUT="$SCRATCH/out" bash "$QEMU_DIR/build-busybox.sh" >/dev/null 2>"$SCRATCH/cc.err" &&
|
||||
grep -q 'no no-such-cross-gcc on PATH' "$SCRATCH/cc.err" && [ ! -e "$SCRATCH/out/busybox-armv7l-panel" ]; then
|
||||
pass "a missing cross compiler fails the build with no binary"
|
||||
else
|
||||
fail "the build did not fail closed without a cross compiler"
|
||||
fi
|
||||
|
||||
# 9. The Buildroot patches are there and every one is a patch.
|
||||
np=0
|
||||
for p in "$BB_DIR"/patches/*.patch; do
|
||||
grep -q '^+++ ' "$p" || fail "$p has no diff"
|
||||
np=$((np + 1))
|
||||
done
|
||||
if [ "$np" -eq 11 ]; then
|
||||
pass "the 11 Buildroot 2025.02.8 busybox patches are present"
|
||||
else
|
||||
fail "expected 11 Buildroot busybox patches, found $np"
|
||||
fi
|
||||
|
||||
if [ "$FAIL" -ne 0 ]; then
|
||||
echo "busybox-panel: FAILED"
|
||||
exit 1
|
||||
fi
|
||||
echo "busybox-panel: all checks passed"
|
||||
Executable
+92
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env bash
|
||||
# The sourced downloader runs before the later production-call test stub.
|
||||
# shellcheck disable=SC2218
|
||||
set -euo pipefail
|
||||
|
||||
TEST_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
QEMU_DIR="$(cd "$TEST_DIR/.." && pwd)"
|
||||
SCRATCH="$(mktemp -d "${TMPDIR:-/tmp}/busybox-source-mirror.XXXXXX")"
|
||||
trap 'rm -rf "$SCRATCH"' EXIT
|
||||
|
||||
mkdir -p "$SCRATCH/bin"
|
||||
printf 'pinned source fixture' > "$SCRATCH/good"
|
||||
WANT="$(sha256sum "$SCRATCH/good" | awk '{print $1}')"
|
||||
export MIRROR_LOG="$SCRATCH/requests" MIRROR_GOOD="$SCRATCH/good"
|
||||
export MIRROR_MODE=good
|
||||
cat > "$SCRATCH/bin/curl" <<'CURL'
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
url= out=
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
-o) shift; out="$1" ;;
|
||||
https://*) url="$1" ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
printf '%s\n' "$url" >> "$MIRROR_LOG"
|
||||
[ -n "$out" ] || exit 2
|
||||
case "$url" in
|
||||
https://primary.invalid/source) exit 28 ;;
|
||||
https://mirror.invalid/source)
|
||||
if [ "$MIRROR_MODE" = good ]; then cp "$MIRROR_GOOD" "$out";
|
||||
else printf 'corrupt mirror response' > "$out"; fi ;;
|
||||
*) exit 2 ;;
|
||||
esac
|
||||
CURL
|
||||
chmod 0755 "$SCRATCH/bin/curl"
|
||||
export PATH="$SCRATCH/bin:$PATH"
|
||||
# shellcheck source=qemu/lib.sh disable=SC1091
|
||||
source "$QEMU_DIR/lib.sh"
|
||||
|
||||
qemu_fetch_verified https://primary.invalid/source "$WANT" \
|
||||
"$SCRATCH/fetched" source https://mirror.invalid/source
|
||||
cmp "$SCRATCH/good" "$SCRATCH/fetched"
|
||||
printf '%s\n' https://primary.invalid/source https://mirror.invalid/source > "$SCRATCH/expected"
|
||||
cmp "$MIRROR_LOG" "$SCRATCH/expected"
|
||||
echo 'PASS primary timeout uses verified mirror'
|
||||
|
||||
: > "$MIRROR_LOG"
|
||||
qemu_fetch_verified https://primary.invalid/source "$WANT" \
|
||||
"$SCRATCH/fetched" source https://mirror.invalid/source
|
||||
test ! -s "$MIRROR_LOG"
|
||||
echo 'PASS verified cache avoids both sources'
|
||||
|
||||
export MIRROR_MODE=bad
|
||||
: > "$MIRROR_LOG"
|
||||
if (qemu_fetch_verified https://primary.invalid/source "$WANT" \
|
||||
"$SCRATCH/refused" source https://mirror.invalid/source) > "$SCRATCH/refusal" 2>&1; then
|
||||
echo 'FAIL corrupt mirror was accepted' >&2
|
||||
exit 1
|
||||
fi
|
||||
test "$(wc -l < "$MIRROR_LOG")" -eq 3
|
||||
test ! -e "$SCRATCH/refused"
|
||||
test -z "$(find "$SCRATCH" -maxdepth 1 -name 'refused.download.*' -print -quit)"
|
||||
grep -q 'after 3 verified attempts' "$SCRATCH/refusal"
|
||||
echo 'PASS corrupt mirror refused within three attempts'
|
||||
|
||||
# Exercise the production source call with the downloader intercepted only
|
||||
# after build-busybox.sh loads its constants. Refuse before extraction.
|
||||
# shellcheck source=qemu/build-busybox.sh disable=SC1091
|
||||
source "$QEMU_DIR/build-busybox.sh"
|
||||
mkdir -p "$SCRATCH/toolchain"
|
||||
printf '#!/bin/sh\nexit 0\n' > "$SCRATCH/toolchain/fake-gcc"
|
||||
chmod 0755 "$SCRATCH/toolchain/fake-gcc"
|
||||
qemu_fetch_verified() {
|
||||
[ "$1" = "$BB_SRC_URL" ] && [ "$2" = "$BB_SRC_SHA256" ]
|
||||
[ "$5" = "$BB_SRC_MIRROR_URL" ]
|
||||
printf '%s\n' 'production mirror call verified' > "$SCRATCH/wired"
|
||||
return 42
|
||||
}
|
||||
set +e
|
||||
(set -e; OUT="$SCRATCH/build" CROSS_COMPILE="$SCRATCH/toolchain/fake-" JOBS=1 bb_main) \
|
||||
> "$SCRATCH/wiring-log" 2>&1
|
||||
status=$?
|
||||
set -e
|
||||
if [ "$status" -ne 42 ]; then
|
||||
cat "$SCRATCH/wiring-log" >&2
|
||||
echo 'FAIL production source call did not stop at the verified downloader' >&2
|
||||
exit 1
|
||||
fi
|
||||
grep -qx 'production mirror call verified' "$SCRATCH/wired"
|
||||
echo 'PASS production source fetch supplies pinned mirror'
|
||||
@@ -0,0 +1,78 @@
|
||||
#!/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"
|
||||
Executable
+183
@@ -0,0 +1,183 @@
|
||||
#!/usr/bin/env bash
|
||||
# Host test for the rig's control bridge, warden_ctl_bridge in
|
||||
# qemu/rootfs/etc/warden-lib.sh (flare-edge #1448). A fake warden-ui reads
|
||||
# the FIFO and renames each reply into place, as warden_debug.c does; some
|
||||
# commands answer late. Checks: a reply slower than the old 5 s bound still
|
||||
# arrives, a timeout answers the explicit no-reply line, and the late reply
|
||||
# of a timed-out command is never handed to the next command. A fake hook
|
||||
# client stands in for wthctl behind `@hookdoc` / `@hook` (the test hook
|
||||
# over the device bus, flare-edge #2054).
|
||||
set -uo pipefail
|
||||
# Job control: the fake UI leads its own process group, so one kill stops
|
||||
# its pending sleep too.
|
||||
set -m
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
LIB="$HERE/../rootfs/etc/warden-lib.sh"
|
||||
# Unquoted where it runs: WARDEN_TEST_SH may be "busybox sh", the rig's shell.
|
||||
SH="${WARDEN_TEST_SH:-sh}"
|
||||
WORK="$(mktemp -d)" || exit 1
|
||||
UI_PID=
|
||||
stop_ui() {
|
||||
[ -n "$UI_PID" ] || return 0
|
||||
{ kill -KILL -- "-$UI_PID"; wait "$UI_PID"; } 2>/dev/null
|
||||
UI_PID=
|
||||
}
|
||||
cleanup() {
|
||||
stop_ui
|
||||
rm -rf "$WORK"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
FAIL=0
|
||||
CHECKS=0
|
||||
|
||||
check() { # check <label> <command...>
|
||||
CHECKS=$((CHECKS + 1))
|
||||
if "${@:2}"; then
|
||||
echo "[PASS] $1"
|
||||
else
|
||||
echo "[FAIL] $1"
|
||||
FAIL=1
|
||||
fi
|
||||
}
|
||||
|
||||
# The fake UI: "slowN" answers after N tenths of a second, anything else at
|
||||
# once. Replies are "reply:<command>", written to a temp file and renamed.
|
||||
start_ui() {
|
||||
mkfifo "$WORK/ctl"
|
||||
(
|
||||
while :; do
|
||||
IFS= read -r cmd < "$WORK/ctl" || continue
|
||||
case "$cmd" in
|
||||
slow*) sleep "$(awk -v t="${cmd#slow}" 'BEGIN { print t / 10 }')" ;;
|
||||
esac
|
||||
printf 'reply:%s\n' "$cmd" > "$WORK/dbg.tmp"
|
||||
mv "$WORK/dbg.tmp" "$WORK/dbg"
|
||||
done
|
||||
) &
|
||||
UI_PID=$!
|
||||
}
|
||||
|
||||
run_bridge() { # run_bridge <name> <wait s or ""> <lines...>
|
||||
local name="$1" wait="$2"
|
||||
shift 2
|
||||
# $SH unquoted (it may be "busybox sh"); the quoted script is meant literally.
|
||||
# shellcheck disable=SC2086,SC2016
|
||||
printf '%s\n' "$@" |
|
||||
env WARDEN_CTL_FIFO="$WORK/ctl" WARDEN_CTL_REPLY="$WORK/dbg" \
|
||||
${wait:+WARDEN_CTL_WAIT_S="$wait"} \
|
||||
$SH -c '. "$1"; warden_ctl_bridge' sh "$LIB" > "$WORK/$name.out" 2> "$WORK/$name.err"
|
||||
}
|
||||
|
||||
same() { # same <file> <expected lines...>
|
||||
local file="$1"
|
||||
shift
|
||||
diff <(printf '%s\n' "$@") "$file" > "$WORK/diff" || { cat "$WORK/diff"; return 1; }
|
||||
}
|
||||
|
||||
start_ui
|
||||
|
||||
# A 1 s bound, a 1.5 s reply: the explicit no-reply line, then the next
|
||||
# command gets ITS reply, not the late one (the desync behind #1448).
|
||||
run_bridge timeout 1 fast1 slow15 fast2
|
||||
check "timeout answers no-reply; the late reply is not the next answer" \
|
||||
same "$WORK/timeout.out" reply:fast1 '<<END>>' \
|
||||
'bridge: no reply from warden-ui within 1 s: slow15' '<<END>>' \
|
||||
reply:fast2 '<<END>>'
|
||||
|
||||
# The default bound: a 6 s reply (over the old 5 s) still arrives, and the
|
||||
# console note gives its time.
|
||||
run_bridge slow "" slow60 after
|
||||
check "default bound: a 6 s reply arrives" \
|
||||
same "$WORK/slow.out" reply:slow60 '<<END>>' reply:after '<<END>>'
|
||||
check "slow reply logged on stderr" grep -Eq "^ctl bridge: slow reply, [5-7] s of polling: slow60\$" "$WORK/slow.err"
|
||||
check "fast reply not logged" bash -c "! grep -q after '$WORK/slow.err'"
|
||||
|
||||
# @cat is answered by the bridge itself, with a newline after the file.
|
||||
printf '{"a":1}' > "$WORK/status.json"
|
||||
run_bridge cat 1 "@cat $WORK/status.json" "@cat $WORK/missing"
|
||||
check "@cat answers the file and a missing-file line" \
|
||||
same "$WORK/cat.out" '{"a":1}' '<<END>>' "bridge: no such file: $WORK/missing" '<<END>>'
|
||||
|
||||
# No FIFO: one line, no wait.
|
||||
stop_ui
|
||||
rm -f "$WORK/ctl"
|
||||
run_bridge nofifo 1 page
|
||||
check "missing FIFO answers at once" \
|
||||
same "$WORK/nofifo.out" 'bridge: warden-ui control FIFO not present' '<<END>>'
|
||||
|
||||
# @procs: the process table for the stall probe (flare-edge #1528), answered
|
||||
# by the bridge itself, so it works with no UI at all.
|
||||
procs_ok() {
|
||||
grep -Eq '^[0-9]+ \(.*\) [A-Z] ' "$WORK/procs.out" &&
|
||||
[ "$(tail -n 1 "$WORK/procs.out")" = '<<END>>' ] &&
|
||||
! grep -q 'FIFO not present' "$WORK/procs.out"
|
||||
}
|
||||
run_bridge procs 1 @procs
|
||||
check "@procs lists process stat lines without the UI" procs_ok
|
||||
|
||||
# @hookdoc / @hookdoc+ / @hook: the fake client logs its argv one per line
|
||||
# and answers by verb (ok:true, ok:false with exit 1, or no reply, exit 2).
|
||||
cat > "$WORK/wthctl" <<'FAKE'
|
||||
#!/bin/sh
|
||||
log="$(dirname "$0")/hook.log"
|
||||
printf '%s\n' "$@" "--" >> "$log"
|
||||
for last; do :; done
|
||||
case "$*" in
|
||||
*" refuse "*) echo '{"v":1,"ok":false,"err":{"code":"E_NOT_FOUND"}}'; exit 1 ;;
|
||||
*" silent "*) echo "wthctl: no reply (-3)" >&2; exit 2 ;;
|
||||
esac
|
||||
printf '{"v":1,"ok":true,"data":{"args":%s}}\n' "$last"
|
||||
FAKE
|
||||
chmod +x "$WORK/wthctl"
|
||||
run_hook() { # run_hook <name> <client> <lines...>
|
||||
local name="$1" client="$2"
|
||||
shift 2
|
||||
rm -f "$WORK/hook.log" "$WORK/hook.args"
|
||||
# $SH unquoted (it may be "busybox sh"); the quoted script is meant literally.
|
||||
# shellcheck disable=SC2086,SC2016
|
||||
printf '%s\n' "$@" |
|
||||
env WARDEN_CTL_FIFO="$WORK/ctl" WARDEN_CTL_REPLY="$WORK/dbg" WARDEN_CTL_WAIT_S=1 \
|
||||
WARDEN_CTL_HOOKDOC="$WORK/hook.args" WARDEN_WTHCTL="$client" WARDEN_BUS_RUN="$WORK/bus" \
|
||||
$SH -c '. "$1"; warden_ctl_bridge' sh "$LIB" > "$WORK/$name.out" 2> "$WORK/$name.err"
|
||||
}
|
||||
|
||||
run_hook pieces "$WORK/wthctl" '@hookdoc {"topic":"io/state/x",' '@hookdoc+ "doc":{"why":"two words"}}' \
|
||||
'@hook override' '@hook override'
|
||||
check "@hookdoc pieces join into one request; the args are used once" \
|
||||
same "$WORK/pieces.out" 'hookdoc: 22 bytes' '<<END>>' 'hookdoc: 49 bytes' '<<END>>' \
|
||||
'{"v":1,"ok":true,"data":{"args":{"topic":"io/state/x","doc":{"why":"two words"}}}}' '<<END>>' \
|
||||
'{"v":1,"ok":true,"data":{"args":{}}}' '<<END>>'
|
||||
check "the client gets the bus socket, the testhook credential, the verb and the args" \
|
||||
same "$WORK/hook.log" "$WORK/bus/bus.sock" "$WORK/bus/cred/testhook" override \
|
||||
'{"topic":"io/state/x","doc":{"why":"two words"}}' -- \
|
||||
"$WORK/bus/bus.sock" "$WORK/bus/cred/testhook" override '{}' --
|
||||
|
||||
run_hook words "$WORK/wthctl" '@hook --to flared guard_evidence' '@hook override;touch x' \
|
||||
'@hook ov*' '@hook ' '@hookdoc+ {}'
|
||||
check "client words pass one by one; a word with other characters is refused" \
|
||||
same "$WORK/words.out" '{"v":1,"ok":true,"data":{"args":{}}}' '<<END>>' \
|
||||
'bridge: bad hook request: override;touch x' '<<END>>' 'bridge: bad hook request: ov*' '<<END>>' \
|
||||
'bridge: bad hook request: ' '<<END>>' \
|
||||
'bridge: @hookdoc+ without a @hookdoc before it' '<<END>>'
|
||||
check "the refused words never ran the client" \
|
||||
same "$WORK/hook.log" "$WORK/bus/bus.sock" "$WORK/bus/cred/testhook" --to flared guard_evidence '{}' --
|
||||
|
||||
run_hook answers "$WORK/wthctl" '@hook refuse' '@hook silent'
|
||||
check "ok:false is the hook's answer; no reply is a bridge line" \
|
||||
same "$WORK/answers.out" '{"v":1,"ok":false,"err":{"code":"E_NOT_FOUND"}}' '<<END>>' \
|
||||
'bridge: hook request got no answer (client exit 2): wthctl: no reply (-3)' '<<END>>'
|
||||
|
||||
run_hook noclient "$WORK/absent" '@hookdoc {}' '@hook override' '@hook override'
|
||||
check "no client in the payload answers a bridge line and drops the args" \
|
||||
same "$WORK/noclient.out" 'hookdoc: 2 bytes' '<<END>>' \
|
||||
"bridge: no hook client in the payload ($WORK/absent)" '<<END>>' \
|
||||
"bridge: no hook client in the payload ($WORK/absent)" '<<END>>'
|
||||
check "the args file is gone after a request" test ! -e "$WORK/hook.args"
|
||||
|
||||
if [ "$FAIL" = 0 ]; then
|
||||
echo "ctl-bridge tests: OK ($CHECKS checks)"
|
||||
else
|
||||
echo "ctl-bridge tests: FAILED"
|
||||
exit 1
|
||||
fi
|
||||
Executable
+124
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env bash
|
||||
# Host test for the rig's shipped-init-chain boot (flare-edge #2210):
|
||||
# warden_init_chain and warden_rig_bus_owners in qemu/rootfs/etc/warden-lib.sh,
|
||||
# and the warden.initchain wiring in qemu/rootfs/sbin/init. Offline, no VM.
|
||||
#
|
||||
# warden_init_chain <first> <last> starts the executable S<NN>* scripts of
|
||||
# that number range in name order with `start`, names a failing one and
|
||||
# goes on, reads "08" and "09" as decimal (test, not shell arithmetic), and prints how many it started.
|
||||
# warden_rig_bus_owners hands a credential file to its account only when
|
||||
# the passwd database has that account.
|
||||
# sbin/init runs S00-S09 before the bus and S10-S99 before the direct UI
|
||||
# start, which a chain boot skips, and says so when the chain is empty.
|
||||
#
|
||||
# bash init-chain-test.sh (WARDEN_TEST_SH="busybox sh" for the rig shell)
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
LIB="$HERE/../rootfs/etc/warden-lib.sh"
|
||||
INIT="$HERE/../rootfs/sbin/init"
|
||||
SH="${WARDEN_TEST_SH:-sh}"
|
||||
WORK="$(mktemp -d "${TMPDIR:-/tmp}/warden-init-chain.XXXXXX")" || exit 1
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
FAIL=0
|
||||
CHECKS=0
|
||||
check() { # check <label> <command...>
|
||||
CHECKS=$((CHECKS + 1))
|
||||
if "${@:2}"; then echo "[PASS] $1"; else echo "[FAIL] $1"; FAIL=1; fi
|
||||
}
|
||||
|
||||
# Stub scripts: each appends "<name> <arg>" to the log; S20bad fails.
|
||||
D="$WORK/init.d"
|
||||
mkdir -p "$D"
|
||||
# shellcheck disable=SC2016 # $1 belongs to the stub script
|
||||
stub() { # stub <name> [rc]
|
||||
printf '#!/bin/sh\necho "%s $1" >> "%s"\nexit %s\n' "$1" "$WORK/log" "${2:-0}" > "$D/$1"
|
||||
chmod 0755 "$D/$1"
|
||||
}
|
||||
stub S03warden-accounts
|
||||
stub S08eight
|
||||
stub S09splash
|
||||
stub S10bus
|
||||
stub S20bad 3
|
||||
stub S99lvgl
|
||||
stub S01runtime
|
||||
# shellcheck disable=SC2016 # $1 belongs to the stub script
|
||||
printf '#!/bin/sh\necho "S50off $1" >> "%s"\n' "$WORK/log" > "$D/S50off" # not executable
|
||||
printf 'x\n' > "$D/README"
|
||||
mkdir -p "$D/S60dir"
|
||||
|
||||
chain() { # chain <first> <last>: stdout to $WORK/out, stderr to $WORK/err
|
||||
: > "$WORK/log"
|
||||
# shellcheck disable=SC2086,SC2016
|
||||
WARDEN_INITD="$D" $SH -c '. "$1"; warden_init_chain "$2" "$3"' sh "$LIB" "$1" "$2" \
|
||||
> "$WORK/out" 2> "$WORK/err"
|
||||
}
|
||||
|
||||
chain 0 9
|
||||
check "early range starts S01, S03, S08, S09 in name order" \
|
||||
test "$(cat "$WORK/log")" = "S01runtime start
|
||||
S03warden-accounts start
|
||||
S08eight start
|
||||
S09splash start"
|
||||
check "early range prints its count (4)" test "$(cat "$WORK/out")" = 4
|
||||
check "early range names each start on the console" grep -q '^init: chain S08eight start$' "$WORK/err"
|
||||
|
||||
chain 10 99
|
||||
check "late range starts S10, S20, S99 and skips the non-executable S50 and the directory S60" \
|
||||
test "$(cat "$WORK/log")" = "S10bus start
|
||||
S20bad start
|
||||
S99lvgl start"
|
||||
check "late range counts the failed script as started (3)" test "$(cat "$WORK/out")" = 3
|
||||
check "a failing script is named with its status" grep -q '^init: chain S20bad start FAILED rc=3$' "$WORK/err"
|
||||
|
||||
chain 9 9
|
||||
check "a one-number range starts only that number" test "$(cat "$WORK/log")" = "S09splash start"
|
||||
|
||||
rm -rf "$D"; mkdir -p "$D"
|
||||
chain 0 99
|
||||
check "no scripts: nothing runs and the count is 0" test "$(cat "$WORK/out")" = 0
|
||||
# shellcheck disable=SC2086,SC2016
|
||||
WARDEN_INITD="$WORK/none" $SH -c '. "$1"; warden_init_chain 0 99' sh "$LIB" > "$WORK/out" 2>&1
|
||||
check "a missing init.d directory counts 0" test "$(cat "$WORK/out")" = 0
|
||||
|
||||
# warden_rig_bus_owners: the test's own account stands in for warden-ui
|
||||
# (chown to oneself needs no root).
|
||||
me="$(id -un)"
|
||||
B="$WORK/bus"
|
||||
mkdir -p "$B/cred"
|
||||
: > "$B/cred/ui"; : > "$B/cred/flared"
|
||||
printf '%s:x:%s:%s::/:/bin/sh\n' "$me" "$(id -u)" "$(id -g)" > "$WORK/passwd"
|
||||
printf 'root:x:0:\n' > "$WORK/group"
|
||||
owners() { # owners <pairs>
|
||||
# shellcheck disable=SC2086,SC2016
|
||||
WARDEN_RIG_BUS_OWNERS="$1" WARDEN_RIG_PASSWD="$WORK/passwd" WARDEN_RIG_GROUP="$WORK/group" \
|
||||
$SH -c '. "$1"; warden_rig_bus_owners "$2"' sh "$LIB" "$B" > "$WORK/out" 2>&1
|
||||
}
|
||||
owners "ui=$me"
|
||||
check "a credential whose account exists is handed to it" grep -qx "init: rig bus: cred/ui belongs to $me" "$WORK/out"
|
||||
owners "ui=warden-ui-absent flared=$me-absent"
|
||||
check "accounts the rootfs lacks change nothing (the rig default)" test ! -s "$WORK/out"
|
||||
owners "nosuch=$me"
|
||||
check "a user without a credential file is skipped" test ! -s "$WORK/out"
|
||||
owners ""
|
||||
check "the default pair is ui=warden-ui" test ! -s "$WORK/out"
|
||||
|
||||
# sbin/init wiring, read from the script itself.
|
||||
line_of() { grep -n -m1 -e "$1" "$INIT" | cut -d: -f1; }
|
||||
early="$(line_of 'warden_init_chain 0 9')"
|
||||
bus="$(line_of '^warden_rig_bus ')"
|
||||
late="$(line_of 'warden_init_chain 10 99')"
|
||||
daemons="$(line_of '^for d in /usr/bin/warden-')"
|
||||
ui="$(line_of 'if .*-x /usr/bin/warden-ui')"
|
||||
check "init runs S00-S09 before the rig bus" test -n "$early" -a -n "$bus" -a "${early:-0}" -lt "${bus:-0}"
|
||||
check "init runs S10-S99 after the payload daemons and before the direct UI start" \
|
||||
test -n "$late" -a -n "$daemons" -a -n "$ui" -a "${daemons:-0}" -lt "${late:-0}" -a "${late:-0}" -lt "${ui:-0}"
|
||||
# shellcheck disable=SC2016 # a literal pattern
|
||||
check "the direct UI start is skipped on a chain boot" grep -q '^if \[ "$initchain" = 0 \] && \[ -x /usr/bin/warden-ui \]' "$INIT"
|
||||
check "the chain is armed only by warden.initchain on the command line" grep -q 'grep -qw warden.initchain /proc/cmdline' "$INIT"
|
||||
check "a chain boot passes the fbdev backend to warden-ui-run" grep -q 'export WARDEN_UI_ARGS="-b fbdev"' "$INIT"
|
||||
check "an empty chain is reported, not replaced by the direct start" grep -q 'WARDEN-QEMU-INITCHAIN-EMPTY' "$INIT"
|
||||
|
||||
echo "init-chain: $CHECKS checks"
|
||||
if [ "$FAIL" -ne 0 ]; then echo "init-chain: FAILED"; exit 1; fi
|
||||
echo "init-chain: all checks passed"
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
# The rig's /sbin/init starts the Warden daemons in the panel's S-number
|
||||
# order (flare-edge#348): warden-modbus (S21modbus) before warden-automation
|
||||
# (S22automation), since an automation's device command goes through
|
||||
# warden-modbus, and both before the other app backends and flared. Reads
|
||||
# the daemon list from the init script's own start loop.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
INIT="$HERE/../rootfs/sbin/init"
|
||||
FAIL=0
|
||||
|
||||
order=$(awk '
|
||||
/^for d in \/usr\/bin\/warden-/ { on = 1 }
|
||||
on {
|
||||
last = ($0 ~ /; do$/)
|
||||
for (i = 1; i <= NF; i++) if ($i ~ /^\/usr\/bin\/warden-/) { w = $i; sub(/;$/, "", w); print w }
|
||||
if (last) exit
|
||||
}' "$INIT")
|
||||
|
||||
want="/usr/bin/warden-modbus
|
||||
/usr/bin/warden-automation
|
||||
/usr/bin/warden-ai
|
||||
/usr/bin/warden-mikrotik
|
||||
/usr/bin/warden-asic
|
||||
/usr/bin/warden-starlink
|
||||
/usr/bin/warden-stratum
|
||||
/usr/bin/warden-flared"
|
||||
|
||||
if [ "$order" = "$want" ]; then
|
||||
echo "PASS: rig init starts the daemons in the panel's S-number order"
|
||||
else
|
||||
echo "FAIL: rig init daemon order differs from the panel's S-number order"
|
||||
diff <(printf '%s\n' "$want") <(printf '%s\n' "$order")
|
||||
FAIL=1
|
||||
fi
|
||||
exit "$FAIL"
|
||||
Executable
+88
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regression test for bfe-core1106-sdk#5: the rig's PID 1 script ignored
|
||||
# busybox reboot/poweroff/halt, which only signal PID 1. Runs the real
|
||||
# helpers from qemu/rootfs/etc/warden-lib.sh in a plain sh with stub
|
||||
# commands, idles it the way /sbin/init does, sends each signal and requires
|
||||
# the matching action within two seconds. Each signal goes out only once the
|
||||
# shell has its handler installed (SigCgt), so a slow start cannot turn the
|
||||
# signal's default action into a false failure (bfe-core1106-sdk#22).
|
||||
set -uo pipefail
|
||||
# Job control: each case's shell leads its own process group, so cleanup can
|
||||
# kill the whole group. An orphaned `sleep 3600` would otherwise keep this
|
||||
# script's output pipe open for an hour when a case fails.
|
||||
set -m
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
LIB="$HERE/../rootfs/etc/warden-lib.sh"
|
||||
SH="${WARDEN_TEST_SH:-sh}"
|
||||
WORK="$(mktemp -d)" || exit 1
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
FAIL=0
|
||||
# Hang backstop for the handler install; a quiet host takes milliseconds.
|
||||
TRAP_WAIT_S="${WARDEN_TEST_TRAP_WAIT_S:-10}"
|
||||
|
||||
# Succeeds once <pid> catches <signal>: its bit is set in /proc SigCgt.
|
||||
catches() { # catches <pid> <signal name>
|
||||
local mask num
|
||||
mask="$(awk '/^SigCgt:/ { print $2 }' "/proc/$1/status" 2>/dev/null)"
|
||||
num="$(kill -l "$2")" || return 1
|
||||
[ -n "$mask" ] && (( (16#$mask >> (num - 1)) & 1 ))
|
||||
}
|
||||
|
||||
# Waits up to TRAP_WAIT_S for <pid> to catch <signal>.
|
||||
wait_trapped() { # wait_trapped <pid> <signal name>
|
||||
local n=0 limit=$((TRAP_WAIT_S * 10))
|
||||
until catches "$1" "$2"; do
|
||||
[ "$n" -ge "$limit" ] && return 1
|
||||
sleep 0.1; n=$((n + 1))
|
||||
done
|
||||
}
|
||||
|
||||
# <delay> holds the handler install back, as a loaded runner does.
|
||||
run_case() { # run_case <signal> <expected marker> <label> [delay s]
|
||||
local sig="$1" want="$2" label="$3" delay="${4:-0}" out="$WORK/$1.out"
|
||||
: > "$out"
|
||||
WARDEN_REBOOT_CMD="eval echo reboot >> $out; exit 0" \
|
||||
WARDEN_POWEROFF_CMD="eval echo poweroff >> $out; exit 0" \
|
||||
"$SH" -c "sleep $delay; . '$LIB'; warden_trap_power_signals; warden_idle_forever" &
|
||||
local pid=$!
|
||||
if ! wait_trapped "$pid" "$sig"; then
|
||||
echo "[FAIL] $label (SIG$sig handler not installed within ${TRAP_WAIT_S} s)"
|
||||
FAIL=1
|
||||
kill -KILL -- "-$pid" 2>/dev/null
|
||||
wait "$pid" 2>/dev/null
|
||||
return
|
||||
fi
|
||||
kill -"$sig" "$pid"
|
||||
local n=0
|
||||
while ! grep -qx "$want" "$out" && [ "$n" -lt 20 ]; do
|
||||
sleep 0.1; n=$((n + 1))
|
||||
done
|
||||
if grep -qx "$want" "$out"; then
|
||||
echo "[PASS] $label"
|
||||
else
|
||||
echo "[FAIL] $label (got: $(tr '\n' ' ' < "$out"))"; FAIL=1
|
||||
fi
|
||||
kill -KILL -- "-$pid" 2>/dev/null
|
||||
wait "$pid" 2>/dev/null
|
||||
}
|
||||
|
||||
run_case TERM reboot "SIGTERM (busybox reboot) reboots at once"
|
||||
run_case USR2 poweroff "SIGUSR2 (busybox poweroff) powers off at once"
|
||||
run_case USR1 poweroff "SIGUSR1 (busybox halt) powers off at once"
|
||||
# Regression for bfe-core1106-sdk#22: the old fixed 0.5 s sleep sent SIGTERM
|
||||
# before this shell installed its trap, killing it with nothing written.
|
||||
run_case TERM reboot "SIGTERM after a slow handler install still reboots" 1.5
|
||||
|
||||
# The wait itself must fail, not hang or pass, when no handler ever appears.
|
||||
"$SH" -c 'sleep 3600' &
|
||||
pid=$!
|
||||
if TRAP_WAIT_S=1 wait_trapped "$pid" TERM; then
|
||||
echo "[FAIL] wait_trapped reported a handler a plain shell never installs"; FAIL=1
|
||||
else
|
||||
echo "[PASS] wait_trapped gives up on a shell without a handler"
|
||||
fi
|
||||
kill -KILL -- "-$pid" 2>/dev/null
|
||||
wait "$pid" 2>/dev/null
|
||||
|
||||
exit "$FAIL"
|
||||
Executable
+176
@@ -0,0 +1,176 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC2317 # the checks and the cleanup run through check() and trap
|
||||
# Host test for the rig's device bus, warden_rig_bus in
|
||||
# qemu/rootfs/etc/warden-lib.sh (flare-edge #1754, #1050). Checks:
|
||||
# - a payload without a broker boots as before: nothing created, status 0
|
||||
# - with a broker: the panel's layout (sock/bus.sock and the bus.sock link,
|
||||
# one 0400 credential file of 64 hex digits per bus user, each its own),
|
||||
# a config with the listener and no password file, ACL or plugin
|
||||
# - a broker that exits, or never listens, is reported and returns 1
|
||||
# within the wait bound
|
||||
# - a user name that is not a plain file name gets no file
|
||||
# - /sbin/init starts the bus before the payload daemons
|
||||
# A stub broker (python3, binds the configured listener) stands in for
|
||||
# mosquitto. With WARDEN_TEST_MOSQUITTO_DIR set to a directory holding
|
||||
# mosquitto, mosquitto_pub and mosquitto_sub (flare-edge
|
||||
# tools/build-host-mosquitto.sh), the real broker also carries one message
|
||||
# between two users that log in with their credential files.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
LIB="$HERE/../rootfs/etc/warden-lib.sh"
|
||||
INIT="$HERE/../rootfs/sbin/init"
|
||||
SH="${WARDEN_TEST_SH:-sh}"
|
||||
WORK="$(mktemp -d)" || exit 1
|
||||
cleanup() {
|
||||
# The brokers outlive the shell that started them, as on the rig; each
|
||||
# has this test's folder in its argv (the stub that never listens writes
|
||||
# its pid instead).
|
||||
pkill -f -- "$WORK/" 2>/dev/null
|
||||
[ -f "$STUB/mute.pid" ] && kill "$(cat "$STUB/mute.pid")" 2>/dev/null
|
||||
rm -rf "$WORK"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
STUB="$WORK/stubs"
|
||||
mkdir -p "$STUB"
|
||||
FAIL=0
|
||||
|
||||
check() { # check <label> <command...>
|
||||
if "${@:2}"; then
|
||||
echo "[PASS] $1"
|
||||
else
|
||||
echo "[FAIL] $1"
|
||||
FAIL=1
|
||||
fi
|
||||
}
|
||||
|
||||
# Stub brokers: argv is "-c <conf>", as the lib calls mosquitto.
|
||||
# good: binds the listener path from the config and stays.
|
||||
# exits: dies at once. mute: stays and never listens.
|
||||
cat > "$STUB/good" <<'PY'
|
||||
#!/usr/bin/env python3
|
||||
import socket, sys, time
|
||||
conf = sys.argv[sys.argv.index("-c") + 1]
|
||||
lines = open(conf).read().splitlines()
|
||||
path = [l.split()[2] for l in lines if l.startswith("listener ")][0]
|
||||
time.sleep(0.3)
|
||||
s = socket.socket(socket.AF_UNIX)
|
||||
s.bind(path)
|
||||
s.listen(1)
|
||||
print("stub broker listening", flush=True)
|
||||
time.sleep(600)
|
||||
PY
|
||||
printf '#!/bin/sh\necho "Error: stub broker refused" >&2\nexit 3\n' > "$STUB/exits"
|
||||
cat > "$STUB/mute" <<'EOF'
|
||||
#!/bin/sh
|
||||
echo $$ > "${0%/*}/mute.pid"
|
||||
exec sleep 600
|
||||
EOF
|
||||
chmod +x "$STUB/good" "$STUB/exits" "$STUB/mute"
|
||||
|
||||
run_bus() { # run_bus <case> <broker> [VAR=value...]: output in <case>/out, status in <case>/rc
|
||||
local name="$1" broker="$2"
|
||||
shift 2
|
||||
mkdir -p "$WORK/$name"
|
||||
# $SH unquoted: WARDEN_TEST_SH may be "busybox sh". The lib is sourced
|
||||
# inside, so the quoted script is meant literally.
|
||||
# shellcheck disable=SC2086,SC2016
|
||||
env WARDEN_RIG_BROKER="$broker" WARDEN_BUS_RUN="$WORK/$name/bus" \
|
||||
WARDEN_RIG_BUS_LOG="$WORK/$name/broker.log" "$@" \
|
||||
$SH -c '. "$1"; warden_rig_bus' sh "$LIB" > "$WORK/$name/out" 2>&1
|
||||
echo $? > "$WORK/$name/rc"
|
||||
}
|
||||
rc_is() { [ "$(cat "$WORK/$1/rc")" = "$2" ]; }
|
||||
out_has() { grep -qF -- "$2" "$WORK/$1/out"; }
|
||||
|
||||
# 1. No broker in the payload.
|
||||
run_bus none "$WORK/no-such-broker"
|
||||
check "no broker: status 0" rc_is none 0
|
||||
check "no broker: nothing created" test ! -e "$WORK/none/bus"
|
||||
check "no broker: silent" test ! -s "$WORK/none/out"
|
||||
|
||||
# 2. A broker that listens.
|
||||
run_bus good "$STUB/good" WARDEN_RIG_BUS_USERS="flared ui modbus ../evil .hidden automation.main"
|
||||
B="$WORK/good/bus"
|
||||
check "broker up: status 0" rc_is good 0
|
||||
check "broker up: reported" out_has good "init: rig bus up on $B/bus.sock"
|
||||
check "broker up: socket listens" test -S "$B/sock/bus.sock"
|
||||
check "broker up: bus.sock link resolves to the socket" test "$(readlink "$B/bus.sock")" = sock/bus.sock -a -S "$B/bus.sock"
|
||||
creds_ok() {
|
||||
local u f seen=""
|
||||
for u in flared ui modbus automation.main; do
|
||||
f="$B/cred/$u"
|
||||
[ -f "$f" ] || { echo "missing $f"; return 1; }
|
||||
[ "$(stat -c %a "$f")" = 400 ] || { echo "$f mode $(stat -c %a "$f")"; return 1; }
|
||||
grep -qxE '[0-9a-f]{64}' "$f" || { echo "$f is not 64 hex digits"; return 1; }
|
||||
case " $seen " in *" $(cat "$f") "*) echo "$f repeats a secret"; return 1 ;; esac
|
||||
seen="$seen $(cat "$f")"
|
||||
done
|
||||
}
|
||||
check "broker up: one 0400 64-hex credential per user, all different" creds_ok
|
||||
check "broker up: a name with a slash gets no file" test ! -e "$B/evil"
|
||||
check "broker up: a dot name gets no file" test ! -e "$B/cred/.hidden"
|
||||
check "broker up: bad names reported" out_has good "bad user name '../evil' skipped"
|
||||
check "broker up: cred/ is 0710" test "$(stat -c %a "$B/cred")" = 710
|
||||
conf_ok() {
|
||||
local c="$B/mosquitto.conf"
|
||||
grep -qx "listener 0 $B/sock/bus.sock" "$c" &&
|
||||
grep -qx 'allow_anonymous true' "$c" &&
|
||||
grep -qx 'use_username_as_clientid true' "$c" &&
|
||||
! grep -qE '^(password_file|acl_file|plugin)' "$c"
|
||||
}
|
||||
check "broker up: config has the listener and no password file, ACL or plugin" conf_ok
|
||||
|
||||
# 3. A broker that exits at once.
|
||||
run_bus exits "$STUB/exits" WARDEN_RIG_BUS_WAIT_S=5
|
||||
check "broker exits: status 1" rc_is exits 1
|
||||
check "broker exits: reported with its log" out_has exits "init: rig bus FAILED: the broker exited"
|
||||
check "broker exits: log tail shown" out_has exits "stub broker refused"
|
||||
|
||||
# 4. A broker that never listens.
|
||||
start=$(date +%s)
|
||||
run_bus mute "$STUB/mute" WARDEN_RIG_BUS_WAIT_S=1
|
||||
took=$(( $(date +%s) - start ))
|
||||
[ -f "$STUB/mute.pid" ] && kill "$(cat "$STUB/mute.pid")" 2>/dev/null
|
||||
check "silent broker: status 1" rc_is mute 1
|
||||
check "silent broker: reported" out_has mute "init: rig bus FAILED: no socket after 1 s"
|
||||
check "silent broker: gave up within the bound (${took} s)" test "$took" -le 4
|
||||
|
||||
# 5. /sbin/init: the bus before the payload daemon loop.
|
||||
order_ok() {
|
||||
local bus loop
|
||||
bus=$(grep -n '^warden_rig_bus' "$INIT" | head -1 | cut -d: -f1)
|
||||
loop=$(grep -n '^for d in /usr/bin/warden-' "$INIT" | head -1 | cut -d: -f1)
|
||||
[ -n "$bus" ] && [ -n "$loop" ] && [ "$bus" -lt "$loop" ]
|
||||
}
|
||||
check "init: the rig bus starts before the payload daemons" order_ok
|
||||
|
||||
# 6. The real broker, when one is given.
|
||||
MQ="${WARDEN_TEST_MOSQUITTO_DIR:-}"
|
||||
if [ -n "$MQ" ] && [ -x "$MQ/mosquitto" ] && [ -x "$MQ/mosquitto_sub" ] && [ -x "$MQ/mosquitto_pub" ]; then
|
||||
run_bus real "$MQ/mosquitto" WARDEN_RIG_BUS_USERS="modbus ui"
|
||||
R="$WORK/real/bus"
|
||||
check "real broker: up" rc_is real 0
|
||||
real_message() {
|
||||
local got
|
||||
"$MQ/mosquitto_sub" --unix "$R/bus.sock" -u ui -P "$(cat "$R/cred/ui")" \
|
||||
-t 'modbus/state/test' -C 1 -W 10 > "$WORK/real/sub.out" 2>&1 &
|
||||
local sub=$!
|
||||
sleep 0.5
|
||||
"$MQ/mosquitto_pub" --unix "$R/bus.sock" -u modbus -P "$(cat "$R/cred/modbus")" \
|
||||
-t 'modbus/state/test' -m rig-bus-ok || return 1
|
||||
wait "$sub"
|
||||
got=$(cat "$WORK/real/sub.out")
|
||||
[ "$got" = rig-bus-ok ] || { echo "subscriber got: $got"; return 1; }
|
||||
}
|
||||
check "real broker: ui receives what modbus publishes, both logged in by credential file" real_message
|
||||
else
|
||||
echo "[SKIP] real broker (set WARDEN_TEST_MOSQUITTO_DIR)"
|
||||
fi
|
||||
|
||||
if [ "$FAIL" -eq 0 ]; then
|
||||
echo "PASS: rig bus"
|
||||
else
|
||||
echo "FAIL: rig bus"
|
||||
fi
|
||||
exit "$FAIL"
|
||||
Executable
+179
@@ -0,0 +1,179 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regression test for mkimage.sh's PAYLOAD_DIR hook (see its Env note): a run
|
||||
# may boot its own payload set instead of qemu/payload, so flare-edge can boot
|
||||
# the hook set (production payload plus the test-flavor UI and wthctl) for a
|
||||
# flow that pins documents while other flows of the same batch read
|
||||
# qemu/payload at the same time (flare-edge #2054).
|
||||
#
|
||||
# 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 payload-dir.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-payload-dir.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
|
||||
|
||||
# The default set and the run's own set name the same binary differently,
|
||||
# so each image shows which directory it was built from.
|
||||
printf 'default-ui\n' > "$QEMU_DIR/payload/warden-ui"
|
||||
printf 'default only\n' > "$QEMU_DIR/payload/warden-default-only"
|
||||
ALT="$SCRATCH/alt"
|
||||
mkdir -p "$ALT"
|
||||
printf 'alt-ui\n' > "$ALT/warden-ui"
|
||||
printf 'readme\n' > "$ALT/README.md"
|
||||
printf 'linked tool\n' > "$SCRATCH/wthctl.real"
|
||||
ln -s "$SCRATCH/wthctl.real" "$ALT/wthctl"
|
||||
|
||||
# --- scenario 1: PAYLOAD_DIR replaces qemu/payload in both slots ---
|
||||
OUT1="$SCRATCH/out1"
|
||||
if OUT="$OUT1" BUSYBOX="$BUSYBOX_BIN" PAYLOAD_DIR="$ALT" \
|
||||
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"
|
||||
ui="$(debugfs -R "cat /usr/bin/warden-ui" "$IMG" 2>/dev/null)"
|
||||
if [ "$ui" = "alt-ui" ]; then
|
||||
pass "PAYLOAD_DIR: $slot carries the run's own warden-ui"
|
||||
else
|
||||
fail "PAYLOAD_DIR: $slot warden-ui = '$ui', want 'alt-ui'"
|
||||
fi
|
||||
tool="$(debugfs -R "cat /usr/bin/wthctl" "$IMG" 2>/dev/null)"
|
||||
if [ "$tool" = "linked tool" ]; then
|
||||
pass "PAYLOAD_DIR: $slot gets a symlinked entry's content"
|
||||
else
|
||||
fail "PAYLOAD_DIR: $slot wthctl = '$tool', want the symlink target's content"
|
||||
fi
|
||||
mode="$(debugfs -R "stat /usr/bin/wthctl" "$IMG" 2>/dev/null | grep -oE 'Mode: *[0-7]+' | grep -oE '[0-7]+$')"
|
||||
if [ "$mode" = "0755" ]; then
|
||||
pass "PAYLOAD_DIR: $slot installs a regular 0755 file for the symlink"
|
||||
else
|
||||
fail "PAYLOAD_DIR: $slot wthctl mode '$mode', want 0755"
|
||||
fi
|
||||
if debugfs -R "stat /usr/bin/warden-default-only" "$IMG" 2>&1 | grep -q 'File not found'; then
|
||||
pass "PAYLOAD_DIR: $slot has nothing from qemu/payload"
|
||||
else
|
||||
fail "PAYLOAD_DIR: $slot carries qemu/payload's warden-default-only"
|
||||
fi
|
||||
if debugfs -R "stat /usr/bin/README.md" "$IMG" 2>&1 | grep -q 'File not found'; then
|
||||
pass "PAYLOAD_DIR: $slot skips the set's README.md"
|
||||
else
|
||||
fail "PAYLOAD_DIR: $slot carries the set's README.md"
|
||||
fi
|
||||
done
|
||||
else
|
||||
fail "PAYLOAD_DIR: mkimage.sh exited nonzero with a valid payload dir (see $SCRATCH/mkimage1.log)"
|
||||
fi
|
||||
|
||||
# --- scenario 2: no PAYLOAD_DIR still reads qemu/payload ---
|
||||
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"
|
||||
ui="$(debugfs -R "cat /usr/bin/warden-ui" "$IMG" 2>/dev/null)"
|
||||
if [ "$ui" = "default-ui" ]; then
|
||||
pass "no PAYLOAD_DIR: rootfs_a carries qemu/payload's warden-ui"
|
||||
else
|
||||
fail "no PAYLOAD_DIR: rootfs_a warden-ui = '$ui', want 'default-ui'"
|
||||
fi
|
||||
else
|
||||
fail "no PAYLOAD_DIR: mkimage.sh exited nonzero (see $SCRATCH/mkimage2.log)"
|
||||
fi
|
||||
|
||||
# --- scenario 3: a PAYLOAD_DIR that is not a directory fails closed ---
|
||||
NOTADIR="$SCRATCH/notadir"
|
||||
: > "$NOTADIR"
|
||||
OUT3="$SCRATCH/out3"
|
||||
err3="$(OUT="$OUT3" BUSYBOX="$BUSYBOX_BIN" PAYLOAD_DIR="$NOTADIR" \
|
||||
bash "$QEMU_DIR/mkimage.sh" 2>&1 1>/dev/null)"
|
||||
rc3=$?
|
||||
if [ "$rc3" -ne 0 ] && printf '%s' "$err3" | grep -qF "FATAL: PAYLOAD_DIR '$NOTADIR' is not a directory"; then
|
||||
pass "PAYLOAD_DIR: a non-directory path fails closed with the FATAL message"
|
||||
else
|
||||
fail "PAYLOAD_DIR: non-directory path gave rc=$rc3, stderr='$err3' (want nonzero + the FATAL message)"
|
||||
fi
|
||||
[ -e "$OUT3/disk.img" ] && fail "PAYLOAD_DIR: a disk image was written for a non-directory payload dir"
|
||||
|
||||
# --- scenario 4: ui-drive.sh looks for warden-ui in PAYLOAD_DIR ---
|
||||
# An empty set fails its warden-ui check before anything is built; the set
|
||||
# with a warden-ui gets past it and stops at the next check, because the
|
||||
# PATH it runs with holds only dirname (no qemu-system-arm), so no VM boots.
|
||||
EMPTY="$SCRATCH/empty"
|
||||
mkdir -p "$EMPTY" "$SCRATCH/nobin"
|
||||
ln -s "$(command -v dirname)" "$SCRATCH/nobin/dirname"
|
||||
BASH_BIN="$(command -v bash)"
|
||||
printf 'page Demo\n' > "$SCRATCH/drive.txt"
|
||||
: > "$SCRATCH/zImage"
|
||||
err4="$(PAYLOAD_DIR="$EMPTY" PATH="$SCRATCH/nobin" "$BASH_BIN" "$QEMU_DIR/tests/ui-drive.sh" \
|
||||
"$SCRATCH/zImage" "$SCRATCH/drive.txt" "$SCRATCH/drive-out" 2>&1)"
|
||||
if printf '%s' "$err4" | grep -qF "FATAL: no warden-ui in $EMPTY"; then
|
||||
pass "ui-drive.sh: a PAYLOAD_DIR without warden-ui is refused, naming the directory"
|
||||
else
|
||||
fail "ui-drive.sh: PAYLOAD_DIR without warden-ui gave '$err4'"
|
||||
fi
|
||||
chmod +x "$ALT/warden-ui"
|
||||
err5="$(PAYLOAD_DIR="$ALT" PATH="$SCRATCH/nobin" "$BASH_BIN" "$QEMU_DIR/tests/ui-drive.sh" \
|
||||
"$SCRATCH/zImage" "$SCRATCH/drive.txt" "$SCRATCH/drive-out" 2>&1)"
|
||||
if printf '%s' "$err5" | grep -qF "qemu-system-arm not on PATH" && ! printf '%s' "$err5" | grep -q "no warden-ui"; then
|
||||
pass "ui-drive.sh: a PAYLOAD_DIR with warden-ui passes the payload check"
|
||||
else
|
||||
fail "ui-drive.sh: PAYLOAD_DIR with an executable warden-ui gave '$err5' (want the qemu-system-arm check next)"
|
||||
fi
|
||||
|
||||
if [ "$FAIL" -ne 0 ]; then
|
||||
echo "payload-dir: FAILED"
|
||||
exit 1
|
||||
fi
|
||||
echo "payload-dir: all scenarios passed"
|
||||
+479
-21
@@ -42,6 +42,28 @@ a real panel, so these verbs mean the same thing on the rig and on hardware:
|
||||
address, answers nothing) or put it back; needs
|
||||
--rs485-control (ui-drive.sh --rs485-devices)
|
||||
ctl WORDS... raw passthrough for anything the channel grows
|
||||
override TOPIC DOC|null
|
||||
pin the state document TOPIC inside warden-ui
|
||||
(DOC: one compact JSON object or array) or unpin
|
||||
it (null), through the UI's test hook on the
|
||||
device bus (flare-edge docs/bus-test-hook.md),
|
||||
which the bridge's `@hook` reaches with the
|
||||
payload's wthctl. ok when the hook answers
|
||||
ok:true, fail on its ok:false (the err is the
|
||||
detail), fatal when the request never reached
|
||||
the hook (no bus, no wthctl, no reply). Needs a
|
||||
broker, wthctl and a test-flavor warden-ui in the
|
||||
payload
|
||||
assert_ui_chain [ACCOUNT]
|
||||
the UI runs the way a panel starts it (a boot
|
||||
through ui-drive.sh --init-chain, flare-edge
|
||||
#2210): exactly one warden-ui and one
|
||||
warden-ui-run loop, the UI's real, effective,
|
||||
saved and filesystem uids all ACCOUNT's
|
||||
(default warden-ui, never 0), no safe-mode flag
|
||||
(/run/warden/ui-safe-mode) and no exit or
|
||||
refusal in /tmp/warden-ui.log. Read with
|
||||
`@procs` and `@cat` over the control channel
|
||||
assert_page MENU/TAB the active page is exactly this
|
||||
assert_hit X Y CLASS [box=X1,Y1,WxH] [TEXT...]
|
||||
a real tap at X,Y lands on an object of CLASS,
|
||||
@@ -154,7 +176,13 @@ def _load_imgtools():
|
||||
|
||||
AXIS_MAX = 32767
|
||||
TAP_HOLD_S = 0.35
|
||||
TAP_OBSERVE_TIMEOUT_S = 2.0
|
||||
# How long the runner waits for the guest to count an injected press or
|
||||
# release. A behaviour check, not a budget: a loaded runner (two TCG VMs on a
|
||||
# shared host) has taken longer than 2 s to count the release that opens the
|
||||
# drawer (flare-edge#1138), so the wait is a hang backstop. A wait longer than
|
||||
# INPUT_SLOW_NOTE_S still passes and says so in the step's detail.
|
||||
TAP_OBSERVE_TIMEOUT_S = 20.0
|
||||
INPUT_SLOW_NOTE_S = 2.0
|
||||
|
||||
# Bounds every blocking read on the QMP socket -- the greeting banner, the
|
||||
# qmp_capabilities handshake, and every screendump/tap/quit round trip --
|
||||
@@ -166,6 +194,17 @@ TAP_OBSERVE_TIMEOUT_S = 2.0
|
||||
# wedged qemu-system-arm cannot outlive the script.
|
||||
QMP_TIMEOUT_S = 20.0
|
||||
|
||||
# Bounds each recv() on the control channel. It must outlast the bridge's
|
||||
# own reply wait (WARDEN_CTL_WAIT_S, 30 s of 0.05 s polls, which take longer
|
||||
# in wall time on a slow TCG guest), so a slow UI reaches the driver as the
|
||||
# bridge's explicit "no reply" line rather than a bare socket timeout.
|
||||
CTL_TIMEOUT_S = 90.0
|
||||
|
||||
# The bridge's own answer when warden-ui did not reply within its bound
|
||||
# (Ctl.NO_REPLY; a module constant too because the offline tests swap the
|
||||
# Ctl class out).
|
||||
BRIDGE_NO_REPLY = "bridge: no reply from warden-ui"
|
||||
|
||||
# Where webstatus.c (ui-src/src/warden/webstatus.c) publishes its atomic
|
||||
# snapshot inside the guest. assert_json/wait_json `@cat` this path over the
|
||||
# control channel; see the bridge in rootfs/sbin/init.
|
||||
@@ -223,19 +262,36 @@ def do_tap(s, f, ax, ay, hold=TAP_HOLD_S):
|
||||
|
||||
|
||||
def wait_input_count(ctx, field, before):
|
||||
"""Wait until one guest input counter advances."""
|
||||
"""Wait until one guest input counter advances.
|
||||
|
||||
Records the longest wait of the current verb in ctx.input_wait_s, so a
|
||||
slow guest shows in the results without failing the step."""
|
||||
if before is None:
|
||||
time.sleep(0.05)
|
||||
return True
|
||||
deadline = time.monotonic() + TAP_OBSERVE_TIMEOUT_S
|
||||
start = time.monotonic()
|
||||
deadline = start + TAP_OBSERVE_TIMEOUT_S
|
||||
while time.monotonic() < deadline:
|
||||
now = parse_stats(ctx.ctl.send("stats")).get(field)
|
||||
if now is not None and now != before:
|
||||
waited = time.monotonic() - start
|
||||
ctx.input_wait_s = max(getattr(ctx, "input_wait_s", 0.0), waited)
|
||||
return True
|
||||
time.sleep(0.02)
|
||||
return False
|
||||
|
||||
|
||||
def input_verdict(ctx, observed):
|
||||
"""The (status, detail) of a tap, swipe or fling from its observation."""
|
||||
if not observed:
|
||||
return ("fail", "input press or release was not consumed within "
|
||||
f"{TAP_OBSERVE_TIMEOUT_S:g} seconds")
|
||||
waited = getattr(ctx, "input_wait_s", 0.0)
|
||||
if waited > INPUT_SLOW_NOTE_S:
|
||||
return "ok", f"slow guest: input consumed after {waited:.1f} s"
|
||||
return "ok", ""
|
||||
|
||||
|
||||
def do_observed_tap(ctx, ax, ay):
|
||||
"""Wait until the guest consumes both halves of a tap."""
|
||||
before = parse_stats(ctx.ctl.send("stats"))
|
||||
@@ -244,6 +300,7 @@ def do_observed_tap(ctx, ax, ay):
|
||||
return True
|
||||
|
||||
send_events(ctx.s, ctx.f, [abs_ev("x", ax), abs_ev("y", ay), btn_ev(True)])
|
||||
ctx.tap_sent = True
|
||||
pressed = False
|
||||
try:
|
||||
pressed = wait_input_count(ctx, "presses", before.get("presses"))
|
||||
@@ -326,12 +383,12 @@ class Ctl:
|
||||
# rootfs/sbin/init's ctl bridge (the FIFO-to-socket relay this class
|
||||
# talks to). Nothing enforces the two staying in sync -- a sentinel
|
||||
# changed on one side and not the other means send() below blocks until
|
||||
# its own 15s timeout on every ctl-dependent step, with nothing at that
|
||||
# its own CTL_TIMEOUT_S on every ctl-dependent step, with nothing at that
|
||||
# point pointing back at this mismatch as the cause.
|
||||
SENTINEL = "<<END>>"
|
||||
|
||||
# A real reply (a hit's box, the status JSON) is at most a few KB. The
|
||||
# 15s socket timeout below bounds each individual recv(), not the total
|
||||
# socket timeout below bounds each individual recv(), not the total
|
||||
# bytes accepted, so a peer that keeps streaming data fast enough to beat
|
||||
# that per-call timeout, but never emits a newline or SENTINEL, would
|
||||
# otherwise grow self.buf without limit and exhaust host memory before
|
||||
@@ -339,7 +396,13 @@ class Ctl:
|
||||
# silent or closes outright already does.
|
||||
MAX_BUF = 256 * 1024
|
||||
|
||||
def __init__(self, path, timeout=15.0):
|
||||
# The bridge's own answer when warden-ui did not reply within its bound
|
||||
# (warden_ctl_bridge in rootfs/etc/warden-lib.sh, flare-edge #1448).
|
||||
NO_REPLY = BRIDGE_NO_REPLY
|
||||
|
||||
def __init__(self, path, timeout=None):
|
||||
if timeout is None:
|
||||
timeout = CTL_TIMEOUT_S
|
||||
self.sock = socket.socket(socket.AF_UNIX)
|
||||
self.sock.settimeout(timeout)
|
||||
self.sock.connect(path)
|
||||
@@ -368,7 +431,177 @@ class Ctl:
|
||||
if line.strip() == cmd.strip():
|
||||
continue
|
||||
lines.append(line)
|
||||
return "\n".join(lines).strip()
|
||||
reply = "\n".join(lines).strip()
|
||||
# A UI that did not answer in time is a rig fault, not evidence: an
|
||||
# empty reply judged as "page is ''" hid it (flare-edge #1448).
|
||||
if reply.startswith(self.NO_REPLY):
|
||||
raise RuntimeError(f"control channel: {reply}")
|
||||
return reply
|
||||
|
||||
|
||||
# Stall probe (flare-edge #1528). When a step fails because warden-ui did not
|
||||
# answer (the bridge's no-reply line) or did not consume an injected press,
|
||||
# the driver samples the host, the VM's vCPU thread and the guest over
|
||||
# STALL_WINDOW_S and appends one line to the step's detail, so the job log
|
||||
# itself says whether the host starved the VM, the guest CPU was saturated
|
||||
# (and by which processes), the guest waited on I/O, or the guest sat idle
|
||||
# while warden-ui was blocked. Re-run jobs lose their artifacts; the job log
|
||||
# keeps this line. At most STALL_REPORTS_MAX probes per run, since each one
|
||||
# costs the window.
|
||||
STALL_WINDOW_S = 2.0
|
||||
STALL_REPORTS_MAX = 3
|
||||
INPUT_NOT_CONSUMED = "was not consumed within"
|
||||
|
||||
|
||||
def is_stall(detail):
|
||||
"""Whether a failed step's detail is warden-ui not answering."""
|
||||
return BRIDGE_NO_REPLY in detail or INPUT_NOT_CONSUMED in detail
|
||||
|
||||
|
||||
def parse_proc_stat(text):
|
||||
"""Guest /proc/stat -> (cpu jiffies list, procs_running, procs_blocked);
|
||||
None when the text has no aggregate cpu line."""
|
||||
cpu, running, blocked = None, None, None
|
||||
for line in text.splitlines():
|
||||
parts = line.split()
|
||||
if not parts:
|
||||
continue
|
||||
if parts[0] == "cpu":
|
||||
cpu = [int(x) for x in parts[1:] if x.isdigit()]
|
||||
elif parts[0] == "procs_running" and len(parts) > 1:
|
||||
running = int(parts[1])
|
||||
elif parts[0] == "procs_blocked" and len(parts) > 1:
|
||||
blocked = int(parts[1])
|
||||
if not cpu or len(cpu) < 5:
|
||||
return None
|
||||
return cpu, running, blocked
|
||||
|
||||
|
||||
def parse_procs(text):
|
||||
"""/proc/<pid>/stat lines (the bridge's `@procs`) -> {pid: (comm, state,
|
||||
utime + stime)}. The comm may hold spaces or parentheses, so the fields
|
||||
are counted from its last ')'."""
|
||||
out = {}
|
||||
for line in text.splitlines():
|
||||
head, sep, tail = line.rpartition(")")
|
||||
if not sep or " (" not in head:
|
||||
continue
|
||||
pid, _, comm = head.partition(" (")
|
||||
fields = tail.split()
|
||||
if not pid.strip().isdigit() or len(fields) < 13:
|
||||
continue
|
||||
try:
|
||||
ticks = int(fields[11]) + int(fields[12])
|
||||
except ValueError:
|
||||
continue
|
||||
out[int(pid)] = (comm, fields[0], ticks)
|
||||
return out
|
||||
|
||||
|
||||
def guest_cpu_delta(a, b):
|
||||
"""Two parse_proc_stat() samples -> (busy share, iowait share) of the
|
||||
guest CPU over the window, or None when nothing was counted."""
|
||||
if a is None or b is None:
|
||||
return None
|
||||
d = [y - x for x, y in zip(a[0], b[0])]
|
||||
total = sum(d)
|
||||
if total <= 0:
|
||||
return None
|
||||
idle, iowait = d[3], d[4]
|
||||
return (total - idle - iowait) / total, iowait / total
|
||||
|
||||
|
||||
def top_procs(a, b, total_ticks, n=3):
|
||||
"""The N guest processes that used the most CPU between two parse_procs()
|
||||
samples, as 'comm share%' strings, and the comms in state D at the end."""
|
||||
used = []
|
||||
for pid, (comm, _state, ticks) in b.items():
|
||||
before = a.get(pid)
|
||||
if before is not None and ticks > before[2]:
|
||||
used.append((ticks - before[2], comm))
|
||||
used.sort(reverse=True)
|
||||
top = [f"{comm} {100 * t / total_ticks:.0f}%" for t, comm in used[:n]] if total_ticks > 0 else []
|
||||
dstate = sorted({comm for comm, state, _ in b.values() if state == "D"})
|
||||
return top, dstate
|
||||
|
||||
|
||||
def stall_verdict(vcpu_share, guest, blocked, dstate):
|
||||
"""One phrase naming the most likely cause from the probe's numbers."""
|
||||
if vcpu_share is not None and vcpu_share < 0.6:
|
||||
return "the host starves the VM (its vCPU thread ran under 60% of a core)"
|
||||
if guest is None:
|
||||
return "the guest did not answer the probe"
|
||||
busy, iowait = guest
|
||||
if busy >= 0.9:
|
||||
return "the guest CPU is saturated"
|
||||
if iowait >= 0.3 or blocked or dstate:
|
||||
return "the guest waits on I/O"
|
||||
return "the guest is mostly idle: warden-ui is blocked, not starved"
|
||||
|
||||
|
||||
def _read(path):
|
||||
try:
|
||||
with open(path) as fh:
|
||||
return fh.read()
|
||||
except OSError:
|
||||
return ""
|
||||
|
||||
|
||||
def _host_psi(kind):
|
||||
m = re.search(r"some avg10=([0-9.]+)", _read(f"/proc/pressure/{kind}"))
|
||||
return f"{float(m.group(1)):.0f}%" if m else "n/a"
|
||||
|
||||
|
||||
def _thread_ticks(tids):
|
||||
total = 0
|
||||
for tid in tids:
|
||||
fields = _read(f"/proc/{tid}/stat").rpartition(")")[2].split()
|
||||
if len(fields) < 13:
|
||||
return None
|
||||
total += int(fields[11]) + int(fields[12])
|
||||
return total
|
||||
|
||||
|
||||
def _guest_sample(ctl):
|
||||
try:
|
||||
return parse_proc_stat(ctl.send("@cat /proc/stat")), parse_procs(ctl.send("@procs"))
|
||||
except (RuntimeError, OSError):
|
||||
return None, {}
|
||||
|
||||
|
||||
def stall_report(ctx):
|
||||
"""Sample the host, the vCPU thread and the guest over STALL_WINDOW_S and
|
||||
describe them in one line (see the block comment above STALL_WINDOW_S)."""
|
||||
try:
|
||||
tids = [c["thread-id"] for c in rpc(ctx.s, ctx.f, {"execute": "query-cpus-fast"})]
|
||||
except (RuntimeError, OSError, KeyError, TypeError, ValueError):
|
||||
tids = []
|
||||
hz = os.sysconf("SC_CLK_TCK")
|
||||
v0 = _thread_ticks(tids) if tids else None
|
||||
g0, p0 = _guest_sample(ctx.ctl) if ctx.ctl else (None, {})
|
||||
t0 = time.monotonic()
|
||||
time.sleep(STALL_WINDOW_S)
|
||||
v1 = _thread_ticks(tids) if tids else None
|
||||
g1, p1 = _guest_sample(ctx.ctl) if ctx.ctl else (None, {})
|
||||
window = time.monotonic() - t0
|
||||
vcpu = (v1 - v0) / (hz * window) if v0 is not None and v1 is not None else None
|
||||
guest = guest_cpu_delta(g0, g1)
|
||||
blocked = g1[2] if g1 else None
|
||||
total_ticks = sum(y - x for x, y in zip(g0[0], g1[0])) if g0 and g1 else 0
|
||||
top, dstate = top_procs(p0, p1, total_ticks)
|
||||
load = os.getloadavg()[0]
|
||||
parts = [f"stall probe ({window:.1f} s): {stall_verdict(vcpu, guest, blocked, dstate)}",
|
||||
f"host load {load:.1f}/{os.cpu_count()} cpus, psi cpu {_host_psi('cpu')} "
|
||||
f"io {_host_psi('io')}",
|
||||
"vcpu " + (f"{100 * vcpu:.0f}% of a core" if vcpu is not None else "n/a")]
|
||||
if guest is None:
|
||||
parts.append("guest n/a")
|
||||
else:
|
||||
parts.append(f"guest busy {100 * guest[0]:.0f}% iowait {100 * guest[1]:.0f}%, "
|
||||
f"running {g1[1]} blocked {g1[2]}")
|
||||
parts.append("top " + (", ".join(top) if top else "n/a"))
|
||||
parts.append("D " + (", ".join(dstate) if dstate else "none"))
|
||||
return "; ".join(parts)
|
||||
|
||||
|
||||
HIT_RE = re.compile(r'^hit \d+,\d+: (\S+)(?: text="(.*)" box=(-?\d+),(-?\d+),(\d+)x(\d+))?$')
|
||||
@@ -401,7 +634,7 @@ def poll_until(check, timeout_s, period=0.5):
|
||||
they all mean the same thing by a timeout.
|
||||
|
||||
A CHECK that raises RuntimeError or OSError -- the control channel
|
||||
dying mid-poll, e.g. a socket.timeout past Ctl's own 15s per-call
|
||||
dying mid-poll, e.g. a socket.timeout past Ctl's own CTL_TIMEOUT_S per-call
|
||||
timeout -- stops polling right there instead of retrying a channel
|
||||
that is probably gone, and comes back with FATAL true so the caller
|
||||
records a `fatal` row (the same idea as ConsoleWatch.check() turning a
|
||||
@@ -728,6 +961,16 @@ class Ctx:
|
||||
self.rs485_control = rs485_control
|
||||
self.outdir = outdir
|
||||
self.script_path = script_path
|
||||
# Set by drive() before each step: the command after this one, and the
|
||||
# console size when the step before this one began (flare-edge#233).
|
||||
self.next_cmd = None
|
||||
self.prev_step_console = 0
|
||||
# The longest input-count wait of the current tap, swipe or fling.
|
||||
self.input_wait_s = 0.0
|
||||
# Stall probes run so far (STALL_REPORTS_MAX bounds them).
|
||||
self.stall_reports = 0
|
||||
# The UI's test hook answered a ping (hook_wait_ready).
|
||||
self.hook_ready = False
|
||||
|
||||
def need_ctl(self, lineno, cmd):
|
||||
if self.ctl is None:
|
||||
@@ -786,24 +1029,36 @@ def verb_shot(ctx, lineno, cmd, args, line):
|
||||
|
||||
def verb_tap(ctx, lineno, cmd, args, line):
|
||||
x, y = int(args[0]), int(args[1])
|
||||
observed = do_observed_tap(ctx, to_axis(x, ctx.size), to_axis(y, ctx.size))
|
||||
return (("ok", "") if observed else
|
||||
("fail", "input press or release was not consumed within 2 seconds"))
|
||||
ctx.tap_sent = False
|
||||
ctx.input_wait_s = 0.0
|
||||
try:
|
||||
observed = do_observed_tap(ctx, to_axis(x, ctx.size), to_axis(y, ctx.size))
|
||||
except (RuntimeError, OSError):
|
||||
# A tap whose correct outcome is a reboot (the next step is
|
||||
# expect_reboot) can lose the control channel while its press/release
|
||||
# counts are still being polled: init tears warden-ui down first. Once
|
||||
# the press went out that is the tap working, not failing; the reboot
|
||||
# step judges the outcome (flare-edge#233). Anywhere else, or before
|
||||
# anything was sent, it stays a fatal step.
|
||||
if ctx.next_cmd == "expect_reboot" and ctx.tap_sent:
|
||||
return "ok", "tap sent; the control channel closed as the guest went down"
|
||||
raise
|
||||
return input_verdict(ctx, observed)
|
||||
|
||||
|
||||
def verb_swipe(ctx, lineno, cmd, args, line):
|
||||
ms = int(args[4]) if len(args) > 4 else 400
|
||||
ctx.input_wait_s = 0.0
|
||||
observed = do_observed_swipe(
|
||||
ctx, int(args[0]), int(args[1]), int(args[2]), int(args[3]), ms)
|
||||
return (("ok", "") if observed else
|
||||
("fail", "input press or release was not consumed within 2 seconds"))
|
||||
return input_verdict(ctx, observed)
|
||||
|
||||
|
||||
def verb_fling(ctx, lineno, cmd, args, line):
|
||||
ctx.input_wait_s = 0.0
|
||||
observed = do_observed_swipe(
|
||||
ctx, int(args[0]), int(args[1]), int(args[2]), int(args[3]), ms=120)
|
||||
return (("ok", "") if observed else
|
||||
("fail", "input press or release was not consumed within 2 seconds"))
|
||||
return input_verdict(ctx, observed)
|
||||
|
||||
|
||||
def verb_sleep(ctx, lineno, cmd, args, line):
|
||||
@@ -829,10 +1084,11 @@ def verb_expect_reboot(ctx, lineno, cmd, args, line):
|
||||
timeout = float(args[0])
|
||||
if not ctx.console_path:
|
||||
sys.exit(f"FATAL: {ctx.script_path}:{lineno}: '{cmd}' needs --console")
|
||||
try:
|
||||
start = os.path.getsize(ctx.console_path)
|
||||
except OSError:
|
||||
start = 0
|
||||
# From the start of the step BEFORE this one, not this one: the action
|
||||
# that reboots (a tap, usually) runs in that step, and a fast guest can
|
||||
# print its restart line before expect_reboot even begins (flare-edge#233).
|
||||
# A line from any earlier step still does not count.
|
||||
start = ctx.prev_step_console
|
||||
deadline = time.monotonic() + timeout
|
||||
|
||||
def console_since_start():
|
||||
@@ -926,6 +1182,186 @@ def verb_rs485(ctx, lineno, cmd, args, line):
|
||||
return ("ok" if reply.startswith("ok") else "fail"), reply
|
||||
|
||||
|
||||
# The bridge's `@hookdoc` piece size: the ctl port is a tty in cooked mode,
|
||||
# which cuts a line at 4095 bytes, and an override document may be 16 KiB.
|
||||
HOOK_PIECE = 2000
|
||||
# A concrete topic: no wildcard, no empty level, no leading slash, nothing a
|
||||
# drive line could not carry as one word.
|
||||
HOOK_TOPIC = re.compile(r"^[A-Za-z0-9_.%-]+(/[A-Za-z0-9_.%-]+)*$")
|
||||
|
||||
|
||||
def hook_request(ctl, words, args):
|
||||
"""One request to a test hook through the bridge (`@hookdoc` pieces, then
|
||||
`@hook WORDS`) -> the reply text. A refused piece is a channel fault."""
|
||||
text = json.dumps(args, separators=(",", ":"), ensure_ascii=True)
|
||||
for at in range(0, len(text), HOOK_PIECE):
|
||||
op = "@hookdoc" if at == 0 else "@hookdoc+"
|
||||
reply = ctl.send(f"{op} {text[at:at + HOOK_PIECE]}")
|
||||
if not reply.startswith("hookdoc: "):
|
||||
raise RuntimeError(f"control channel: hook args refused: {reply}")
|
||||
return ctl.send(f"@hook {words}")
|
||||
|
||||
|
||||
# The bridge's line for a hook request whose client got no reply (_wcb_hook
|
||||
# in rootfs/etc/warden-lib.sh).
|
||||
HOOK_NO_ANSWER = "bridge: hook request got no answer"
|
||||
# How long the run's first hook request waits for the UI's hook to answer a
|
||||
# ping, and the pause between two pings. Each ping is bounded by the hook
|
||||
# client itself (wthctl: 5 s for the UI).
|
||||
HOOK_READY_S = 90.0
|
||||
HOOK_READY_POLL_S = 1.0
|
||||
|
||||
|
||||
def hook_wait_ready(ctx):
|
||||
"""Wait, once per run, until the UI's test hook answers a `ping` -> None,
|
||||
or the fatal detail when it never did.
|
||||
|
||||
The hook takes requests from the device bus, which the UI drains under a
|
||||
per-tick budget (libwardenbus WBUS_TICK_PACKETS / WBUS_TICK_BUDGET_US).
|
||||
Right after boot it is still taking the broker's retained replay, and a
|
||||
request queued behind it misses both the client's 5 s bound and its own
|
||||
5 s message expiry: an override sent then was lost, or applied with its
|
||||
reply lost (flare-edge #2602). ping changes nothing, so it is the one
|
||||
request that is safe to repeat; the step's own request is sent once,
|
||||
after a ping came back. Replies come back in request order, so a late
|
||||
answer to an earlier ping is gone before that request goes out.
|
||||
|
||||
Anything other than "no answer" ends the wait: a missing client or a
|
||||
reply that is not JSON is reported by the step's own request."""
|
||||
if ctx.hook_ready:
|
||||
return None
|
||||
deadline = time.monotonic() + HOOK_READY_S
|
||||
pings = 0
|
||||
while True:
|
||||
pings += 1
|
||||
reply = hook_request(ctx.ctl, "ping", {})
|
||||
if not reply.startswith(HOOK_NO_ANSWER):
|
||||
break
|
||||
if time.monotonic() >= deadline:
|
||||
return (f"the UI test hook answered no ping in {HOOK_READY_S:.0f} s "
|
||||
f"({pings} sent): {reply}")
|
||||
time.sleep(HOOK_READY_POLL_S)
|
||||
ctx.hook_ready = judge_hook_reply(reply)[0] == "ok"
|
||||
return None
|
||||
|
||||
|
||||
def judge_hook_reply(reply):
|
||||
"""(status, detail) for a hook reply: ok:true passes, ok:false fails with
|
||||
the hook's err, and anything else (a bridge line, no JSON) is fatal: the
|
||||
step never reached a hook that could judge it."""
|
||||
if reply.startswith("bridge: "):
|
||||
return "fatal", reply
|
||||
try:
|
||||
doc = json.loads(reply)
|
||||
except ValueError:
|
||||
return "fatal", f"hook reply is not JSON: {reply!r}"
|
||||
if not isinstance(doc, dict) or not isinstance(doc.get("ok"), bool):
|
||||
return "fatal", f"hook reply has no ok member: {reply!r}"
|
||||
if doc["ok"]:
|
||||
return "ok", ""
|
||||
return "fail", json.dumps(doc.get("err"), sort_keys=True)
|
||||
|
||||
|
||||
def verb_override(ctx, lineno, cmd, args, line):
|
||||
# override TOPIC DOC|null (flowc.py action_override). The document is
|
||||
# the rest of the line, which may hold spaces inside its strings.
|
||||
ctx.need_ctl(lineno, cmd)
|
||||
topic, _, doc_text = line[len(cmd):].strip().partition(" ")
|
||||
if not HOOK_TOPIC.match(topic):
|
||||
return "fatal", f"override topic {topic!r} is not one concrete topic"
|
||||
try:
|
||||
doc = json.loads(doc_text)
|
||||
except ValueError:
|
||||
return "fatal", f"override document is not JSON: {doc_text!r}"
|
||||
if doc is not None and not isinstance(doc, (dict, list)):
|
||||
return "fatal", "override document must be an object, an array or null"
|
||||
not_ready = hook_wait_ready(ctx)
|
||||
if not_ready:
|
||||
return "fatal", not_ready
|
||||
return judge_hook_reply(hook_request(ctx.ctl, "override", {"topic": topic, "doc": doc}))
|
||||
|
||||
|
||||
UI_CHAIN_SAFE_FLAG = "/run/warden/ui-safe-mode"
|
||||
UI_CHAIN_LOG = "/tmp/warden-ui.log"
|
||||
UI_CHAIN_NO_FILE = "bridge: no such file: "
|
||||
# warden-ui-run's own lines in the log S99lvgl points it at: a restart
|
||||
# ("warden-ui exited N") or the end of the loop ("refusing to run the UI").
|
||||
UI_CHAIN_LOG_BAD = re.compile(r"warden-ui-run: .*(exited|refusing|already running)|exited \d+")
|
||||
|
||||
|
||||
def account_uid(passwd_text, account):
|
||||
"""The account's uid from passwd text, or None."""
|
||||
for line in passwd_text.splitlines():
|
||||
f = line.split(":")
|
||||
if len(f) >= 3 and f[0] == account and f[2].isdigit():
|
||||
return int(f[2])
|
||||
return None
|
||||
|
||||
|
||||
def status_uids(status_text):
|
||||
"""The four uids of a /proc/<pid>/status Uid line, or None."""
|
||||
for line in status_text.splitlines():
|
||||
parts = line.split()
|
||||
if parts and parts[0] == "Uid:" and len(parts) >= 5:
|
||||
try:
|
||||
return [int(x) for x in parts[1:5]]
|
||||
except ValueError:
|
||||
return None
|
||||
return None
|
||||
|
||||
|
||||
def judge_ui_chain(procs_text, passwd_text, status_of, safe_reply, log_text, account):
|
||||
"""Problems with a UI started through the shipped init chain; empty
|
||||
when it runs as a panel runs it. status_of(pid) -> that pid's
|
||||
/proc/<pid>/status text."""
|
||||
problems = []
|
||||
want = account_uid(passwd_text, account)
|
||||
if want is None:
|
||||
problems.append(f"no account {account} in /etc/passwd (S03warden-accounts did not run)")
|
||||
elif want == 0:
|
||||
problems.append(f"account {account} has uid 0")
|
||||
procs = parse_procs(procs_text)
|
||||
live = {pid: comm for pid, (comm, state, _t) in procs.items() if state != "Z"}
|
||||
uis = sorted(pid for pid, comm in live.items() if comm == "warden-ui")
|
||||
loops = sorted(pid for pid, comm in live.items() if comm == "warden-ui-run")
|
||||
if len(uis) != 1:
|
||||
problems.append(f"{len(uis)} warden-ui processes, want 1 (pids {uis})")
|
||||
if len(loops) != 1:
|
||||
problems.append(f"{len(loops)} warden-ui-run loops, want 1 (pids {loops})")
|
||||
for pid in uis:
|
||||
seen = status_uids(status_of(pid))
|
||||
if seen is None:
|
||||
problems.append(f"warden-ui pid {pid}: no Uid line")
|
||||
elif want not in (None, 0) and seen != [want] * 4:
|
||||
problems.append(f"warden-ui pid {pid} runs with uids {seen}, not {account} ({want})")
|
||||
if not safe_reply.startswith(UI_CHAIN_NO_FILE):
|
||||
problems.append(f"safe mode is on ({UI_CHAIN_SAFE_FLAG} exists)")
|
||||
if log_text.startswith(UI_CHAIN_NO_FILE):
|
||||
problems.append(f"no {UI_CHAIN_LOG}: S99lvgl never started the UI")
|
||||
else:
|
||||
bad = [line for line in log_text.splitlines() if UI_CHAIN_LOG_BAD.search(line)]
|
||||
if bad:
|
||||
problems.append(f"{UI_CHAIN_LOG}: {bad[0]!r}" + (f" (+{len(bad) - 1} more)" if len(bad) > 1 else ""))
|
||||
return problems
|
||||
|
||||
|
||||
def verb_assert_ui_chain(ctx, lineno, cmd, args, line):
|
||||
# assert_ui_chain [ACCOUNT] (flare-edge #2210): the UI came up through
|
||||
# S03warden-accounts, S99lvgl and warden-ui-run, and stays up as its
|
||||
# account. A missing process is a `fail`: that is exactly the bug class
|
||||
# (#1903's setpriv left no UI), not a rig fault.
|
||||
ctx.need_ctl(lineno, cmd)
|
||||
account = args[0] if args else "warden-ui"
|
||||
problems = judge_ui_chain(
|
||||
ctx.ctl.send("@procs"),
|
||||
ctx.ctl.send("@cat /etc/passwd"),
|
||||
lambda pid: ctx.ctl.send(f"@cat /proc/{pid}/status"),
|
||||
ctx.ctl.send(f"@cat {UI_CHAIN_SAFE_FLAG}"),
|
||||
ctx.ctl.send(f"@cat {UI_CHAIN_LOG}"),
|
||||
account)
|
||||
return ("fail", "; ".join(problems)) if problems else ("ok", "")
|
||||
|
||||
|
||||
def verb_assert_page(ctx, lineno, cmd, args, line):
|
||||
ctx.need_ctl(lineno, cmd)
|
||||
want = " ".join(args)
|
||||
@@ -1145,6 +1581,7 @@ VERBS = {
|
||||
"ctl": verb_query,
|
||||
"rs485": verb_rs485,
|
||||
"assert_page": verb_assert_page,
|
||||
"assert_ui_chain": verb_assert_ui_chain,
|
||||
"assert_hit": verb_assert_hit,
|
||||
"wait_hit": verb_wait_hit,
|
||||
"assert_json": verb_assert_json,
|
||||
@@ -1156,6 +1593,7 @@ VERBS = {
|
||||
"wait_region": verb_wait_region,
|
||||
"assert_ocr": verb_assert_ocr,
|
||||
"expect_reboot": verb_expect_reboot,
|
||||
"override": verb_override,
|
||||
}
|
||||
|
||||
|
||||
@@ -1182,12 +1620,24 @@ def drive(s, f, script_path, outdir, size, ctl_path=None, console_path=None, ref
|
||||
console_path)
|
||||
console = ConsoleWatch(console_path)
|
||||
|
||||
def console_size():
|
||||
try:
|
||||
return os.path.getsize(console_path) if console_path else 0
|
||||
except OSError:
|
||||
return 0
|
||||
|
||||
steps = []
|
||||
for lineno, raw in enumerate(lines, 1):
|
||||
line = raw.split("#", 1)[0].strip()
|
||||
if not line:
|
||||
continue
|
||||
if line:
|
||||
steps.append((lineno, line))
|
||||
step_console = console_size()
|
||||
|
||||
for i, (lineno, line) in enumerate(steps):
|
||||
parts = line.split()
|
||||
cmd, args = parts[0], parts[1:]
|
||||
ctx.next_cmd = steps[i + 1][1].split()[0] if i + 1 < len(steps) else None
|
||||
ctx.prev_step_console, step_console = step_console, console_size()
|
||||
|
||||
handler = VERBS.get(cmd)
|
||||
if handler is None:
|
||||
@@ -1217,6 +1667,14 @@ def drive(s, f, script_path, outdir, size, ctl_path=None, console_path=None, ref
|
||||
# Recorded the same as any other fatal row: the run keeps going
|
||||
# past it.
|
||||
result = ("fatal", str(e))
|
||||
if (result is not None and result[0] != "ok" and len(result) > 1
|
||||
and is_stall(str(result[1])) and ctx.stall_reports < STALL_REPORTS_MAX):
|
||||
ctx.stall_reports += 1
|
||||
try:
|
||||
probe = stall_report(ctx)
|
||||
except (RuntimeError, OSError, ValueError) as e:
|
||||
probe = f"stall probe failed: {e}"
|
||||
result = (result[0], f"{result[1]}; {probe}")
|
||||
if result is not None:
|
||||
record(lineno, line, *result)
|
||||
|
||||
|
||||
Executable
+179
@@ -0,0 +1,179 @@
|
||||
#!/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'"
|
||||
|
||||
# --- scenario 4: ui-drive.sh --init-chain checks its directory before boot ---
|
||||
# Its PATH holds only dirname, so a directory that passes stops at the
|
||||
# qemu-system-arm check and no VM boots.
|
||||
mkdir -p "$SCRATCH/nobin" "$SCRATCH/pl"
|
||||
ln -s "$(command -v dirname)" "$SCRATCH/nobin/dirname"
|
||||
BASH_BIN="$(command -v bash)"
|
||||
printf 'sleep 1\n' > "$SCRATCH/drive.txt"
|
||||
: > "$SCRATCH/zImage"
|
||||
printf '#!/bin/sh\n' > "$SCRATCH/pl/warden-ui"; chmod +x "$SCRATCH/pl/warden-ui"
|
||||
drive_err() { # drive_err <init-chain dir>
|
||||
PAYLOAD_DIR="$SCRATCH/pl" PATH="$SCRATCH/nobin" "$BASH_BIN" "$QEMU_DIR/tests/ui-drive.sh" \
|
||||
--init-chain "$1" "$SCRATCH/zImage" "$SCRATCH/drive.txt" "$SCRATCH/drive-out" 2>&1
|
||||
}
|
||||
err="$(drive_err "$SCRATCH/no-such-dir")"
|
||||
if printf '%s' "$err" | grep -qF "is not a directory"; then pass "ui-drive.sh: --init-chain with no directory is refused"
|
||||
else fail "ui-drive.sh: --init-chain missing dir gave '$err'"; fi
|
||||
mkdir -p "$SCRATCH/no-lvgl/etc/init.d"
|
||||
err="$(drive_err "$SCRATCH/no-lvgl")"
|
||||
if printf '%s' "$err" | grep -qF "has no etc/init.d/S99lvgl"; then pass "ui-drive.sh: --init-chain without S99lvgl is refused"
|
||||
else fail "ui-drive.sh: --init-chain without S99lvgl gave '$err'"; fi
|
||||
err="$(drive_err "$OV")"
|
||||
if printf '%s' "$err" | grep -qF "qemu-system-arm not on PATH"; then pass "ui-drive.sh: a chain directory with S99lvgl passes its checks"
|
||||
else fail "ui-drive.sh: --init-chain with S99lvgl gave '$err'"; fi
|
||||
|
||||
if [ "$FAIL" -ne 0 ]; then
|
||||
echo "rootfs-overlay: FAILED"
|
||||
exit 1
|
||||
fi
|
||||
echo "rootfs-overlay: all scenarios passed"
|
||||
@@ -140,6 +140,36 @@ if run_case "$argv" --ctl "$SCRATCH/ctl.sock" --rs485 "$SCRATCH/rs.sock"; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# --- case: --agent (the rig agent, flare-edge M9 soak-lite) -> its
|
||||
# pci-serial comes LAST, after ctl and rs485, so neither moves, and
|
||||
# warden.agent lands on the cmdline only with the flag -------------------
|
||||
if ! grep -qw 'warden.agent' "$SCRATCH/argv-both.txt" && ! grep -qF 'id=agent' "$SCRATCH/argv-both.txt"; then
|
||||
pass "no --agent: no agent chardev and no warden.agent"
|
||||
else
|
||||
fail "no --agent: an agent chardev or warden.agent appeared unrequested"
|
||||
fi
|
||||
for combo in "agent-ctl:--ctl $SCRATCH/ctl.sock" "agent-alone:"; do
|
||||
name="${combo%%:*}" extra="${combo#*:}"
|
||||
argv="$SCRATCH/argv-$name.txt"
|
||||
# shellcheck disable=SC2086 # extra is a word list on purpose
|
||||
if run_case "$argv" $extra --rs485 "$SCRATCH/rs.sock" --agent "$SCRATCH/agent.sock"; then
|
||||
ag_ln="$(chardev_line "$argv" "socket,id=agent,path=$SCRATCH/agent.sock,")"
|
||||
rs_ln="$(chardev_line "$argv" "socket,id=rs485,path=$SCRATCH/rs.sock,")"
|
||||
ctl_ln="$(chardev_line "$argv" "socket,id=ctl,")"
|
||||
if [ -n "$ag_ln" ] && [ -n "$rs_ln" ] && [ "$rs_ln" -lt "$ag_ln" ] &&
|
||||
{ [ -z "$ctl_ln" ] || [ "$ctl_ln" -lt "$rs_ln" ]; }; then
|
||||
pass "$name: agent chardev (line $ag_ln) comes after rs485 (line $rs_ln) and ctl (${ctl_ln:-none})"
|
||||
else
|
||||
fail "$name: expected ctl < rs485 < agent, got ctl=$ctl_ln rs485=$rs_ln agent=$ag_ln"
|
||||
fi
|
||||
if grep -qF 'pci-serial,chardev=agent' "$argv" && grep -qw 'warden.agent' "$argv"; then
|
||||
pass "$name: agent pci-serial device and warden.agent present"
|
||||
else
|
||||
fail "$name: agent pci-serial device or warden.agent missing"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$FAIL" -eq 0 ]; then
|
||||
echo "ALL RUN.SH ARGV TESTS PASSED"
|
||||
exit 0
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
# The UI as a panel starts it (flare-edge #2210), run with
|
||||
# ui-drive.sh --init-chain <dir with the panel's S03warden-accounts,
|
||||
# S99lvgl, /usr/lib/warden/warden-ui-run and uid-check.sh> <zImage> this
|
||||
# ui-drive.sh hands this script over once the UI has drawn a frame and the
|
||||
# control bridge is up, about 20 to 40 s after boot under TCG. The sleep
|
||||
# brings the check to roughly T+120 s, past three restarts and the 5 s
|
||||
# hold-down, so a UI that only lives a few seconds per start is not seen as
|
||||
# up, and a loop that gave up has had time to set safe mode.
|
||||
echo init chain: waiting to about T+120 s
|
||||
sleep 90
|
||||
assert_ui_chain warden-ui
|
||||
@@ -186,5 +186,42 @@ else
|
||||
fail "SEED_DIR: mkimage.sh rejected a valid hyphenated key (see $SCRATCH/mkimage6.log)"
|
||||
fi
|
||||
|
||||
# --- scenario 7: an installed RS485 profile, profiles/rs485/<slug>.w485p,
|
||||
# seeds into userdata/warden/profiles/rs485/ (flare-edge#387) ---
|
||||
SEED7="$SCRATCH/seed7"
|
||||
mkdir -p "$SEED7/profiles/rs485"
|
||||
printf '{"w485p_version":1}\n' > "$SEED7/profiles/rs485/acme-gen-ctl.w485p"
|
||||
OUT7="$SCRATCH/out7"
|
||||
if OUT="$OUT7" BUSYBOX="$BUSYBOX_BIN" SEED_DIR="$SEED7" \
|
||||
bash "$QEMU_DIR/mkimage.sh" > "$SCRATCH/mkimage7.log" 2>&1; then
|
||||
UIMG7="$SCRATCH/userdata7.img"
|
||||
extract_userdata "$OUT7/disk.img" "$UIMG7"
|
||||
prof="$(debugfs -R "cat /warden/profiles/rs485/acme-gen-ctl.w485p" "$UIMG7" 2>/dev/null)"
|
||||
if [ "$prof" = '{"w485p_version":1}' ]; then
|
||||
pass "SEED_DIR: an installed profile seeds into profiles/rs485/"
|
||||
else
|
||||
fail "SEED_DIR: profiles/rs485/acme-gen-ctl.w485p = '$prof'"
|
||||
fi
|
||||
else
|
||||
fail "SEED_DIR: mkimage.sh rejected a profiles/rs485/<slug>.w485p seed (see $SCRATCH/mkimage7.log)"
|
||||
fi
|
||||
|
||||
# --- scenario 8: anything else under profiles/ fails closed ---
|
||||
for bad in "rs485/x.json" "rs485/Bad.w485p" "other/x.w485p" "rs485/sub/x.w485p" "rs485/link.w485p"; do
|
||||
SEED8="$SCRATCH/seed8"
|
||||
rm -rf "$SEED8"
|
||||
mkdir -p "$SEED8/profiles/$(dirname "$bad")"
|
||||
if [ "$bad" = rs485/link.w485p ]; then ln -s /etc/passwd "$SEED8/profiles/$bad"; else printf 'x\n' > "$SEED8/profiles/$bad"; fi
|
||||
OUT8="$SCRATCH/out8"
|
||||
rm -rf "$OUT8"
|
||||
err8="$(OUT="$OUT8" BUSYBOX="$BUSYBOX_BIN" SEED_DIR="$SEED8" bash "$QEMU_DIR/mkimage.sh" 2>&1 1>/dev/null)"
|
||||
rc8=$?
|
||||
if [ "$rc8" -ne 0 ] && printf '%s' "$err8" | grep -qF "is not a plain profiles/rs485/<slug>.w485p file"; then
|
||||
pass "SEED_DIR: profiles/$bad fails closed"
|
||||
else
|
||||
fail "SEED_DIR: profiles/$bad gave rc=$rc8, stderr='$err8'"
|
||||
fi
|
||||
done
|
||||
|
||||
[ "$FAIL" -eq 0 ] && echo "ALL SEED_DIR TESTS PASSED" || echo "SEED_DIR TESTS FAILED"
|
||||
[ "$FAIL" -eq 0 ]
|
||||
|
||||
@@ -13,8 +13,11 @@ was never compared with the one the reference was captured under.
|
||||
|
||||
python3 test_qmp_drive.py
|
||||
"""
|
||||
import atexit
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -28,6 +31,15 @@ HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path.insert(0, HERE)
|
||||
import qmp # noqa: E402
|
||||
|
||||
# Every temp dir this module makes (a drive's out dir per run_script, the
|
||||
# console and QMP socket dirs) lands under one root per run, removed at exit,
|
||||
# so a run leaves $TMPDIR as it found it (bfe-core1106-sdk#30: about 40 dirs
|
||||
# per run used to stay behind). The prefix is short: an AF_UNIX socket path
|
||||
# under it must stay inside about 108 bytes.
|
||||
_TMP_ROOT = tempfile.mkdtemp(prefix="qdt.")
|
||||
tempfile.tempdir = _TMP_ROOT
|
||||
atexit.register(shutil.rmtree, _TMP_ROOT, True)
|
||||
|
||||
SIZE = 64
|
||||
|
||||
|
||||
@@ -339,6 +351,52 @@ class PureHelpers(unittest.TestCase):
|
||||
self.assertEqual(len(calls), 2)
|
||||
self.assertEqual(calls[-1], [qmp.btn_ev(False)])
|
||||
|
||||
def _swipe_on_fake_clock(self, release_at_s):
|
||||
"""verb_swipe against a guest that counts the press at once and the
|
||||
release only once release_at_s of fake time has passed (None: never).
|
||||
Returns the verdict and the fake time the verb took."""
|
||||
clock = [0.0]
|
||||
replies = iter(["presses: 0\nreleases: 0"]) # the baseline read
|
||||
|
||||
def send(cmd):
|
||||
late = release_at_s is not None and clock[0] >= release_at_s
|
||||
return next(replies, f"presses: 1\nreleases: {1 if late else 0}")
|
||||
|
||||
ctx = SimpleNamespace(s=None, f=None, size=720,
|
||||
ctl=SimpleNamespace(send=send), input_wait_s=0.0)
|
||||
|
||||
def sleep(seconds):
|
||||
clock[0] += seconds
|
||||
|
||||
saved = qmp.send_events, qmp.time.sleep, qmp.time.monotonic
|
||||
qmp.send_events = lambda _s, _f, _events: None
|
||||
qmp.time.sleep = sleep
|
||||
qmp.time.monotonic = lambda: clock[0]
|
||||
try:
|
||||
verdict = qmp.verb_swipe(ctx, 1, "swipe", ["2", "350", "520", "352", "3000"], "")
|
||||
finally:
|
||||
qmp.send_events, qmp.time.sleep, qmp.time.monotonic = saved
|
||||
return verdict, clock[0]
|
||||
|
||||
def test_swipe_release_counted_late_on_a_loaded_guest_passes(self):
|
||||
# flare-edge#1138: the release that opens the drawer was counted
|
||||
# after more than 2 s on a loaded runner; the old 2 s bound failed
|
||||
# the swipe although the guest handled it. It passes, with a note.
|
||||
(status, detail), _ = self._swipe_on_fake_clock(release_at_s=3.0 + 2.5)
|
||||
self.assertEqual(status, "ok")
|
||||
self.assertIn("slow guest: input consumed after 2.5 s", detail)
|
||||
|
||||
def test_swipe_release_counted_promptly_has_no_note(self):
|
||||
(status, detail), _ = self._swipe_on_fake_clock(release_at_s=3.0 + 0.5)
|
||||
self.assertEqual((status, detail), ("ok", ""))
|
||||
|
||||
def test_swipe_release_never_counted_fails_at_the_backstop(self):
|
||||
(status, detail), took = self._swipe_on_fake_clock(release_at_s=None)
|
||||
self.assertEqual(status, "fail")
|
||||
self.assertIn(f"within {qmp.TAP_OBSERVE_TIMEOUT_S:g} seconds", detail)
|
||||
# Bounded: the 3 s drag plus the backstop, and not much more.
|
||||
self.assertLess(took, 3.0 + qmp.TAP_OBSERVE_TIMEOUT_S + 1.0)
|
||||
|
||||
def test_every_pixel_round_trips_through_lvgl_calibration(self):
|
||||
# lv_evdev.c _evdev_calibrate: px = axis * (width - 1) / AXIS_MAX,
|
||||
# integer division. A tap requested at px must land at px, for every
|
||||
@@ -800,6 +858,310 @@ class DriveVerbs(unittest.TestCase):
|
||||
self.assertEqual([r["status"] for r in rows], ["ok"])
|
||||
|
||||
|
||||
class HookCtl(FakeCtl):
|
||||
"""The bridge's `@hookdoc` / `@hook` commands (warden_ctl_bridge) over a
|
||||
fake test hook: the pieces are joined as the bridge joins them, and the
|
||||
hook's answer is whatever ANSWERS maps the joined args to."""
|
||||
|
||||
sent = []
|
||||
answer = staticmethod(lambda words, args: '{"v":1,"ok":true,"data":{}}')
|
||||
refuse_pieces = False
|
||||
|
||||
def __init__(self, path, timeout=15.0):
|
||||
super().__init__(path, timeout)
|
||||
self.doc = None
|
||||
|
||||
def send(self, cmd):
|
||||
HookCtl.sent.append(cmd)
|
||||
if cmd.startswith("@hookdoc+ "):
|
||||
self.doc += cmd[len("@hookdoc+ "):]
|
||||
return f"hookdoc: {len(self.doc)} bytes"
|
||||
if cmd.startswith("@hookdoc "):
|
||||
if HookCtl.refuse_pieces:
|
||||
return "bridge: something else"
|
||||
self.doc = cmd[len("@hookdoc "):]
|
||||
return f"hookdoc: {len(self.doc)} bytes"
|
||||
if cmd.startswith("@hook "):
|
||||
args, self.doc = json.loads(self.doc or "{}"), None
|
||||
return HookCtl.answer(cmd[len("@hook "):], args)
|
||||
return super().send(cmd)
|
||||
|
||||
|
||||
class OverrideVerb(unittest.TestCase):
|
||||
def setUp(self):
|
||||
HookCtl.sent = []
|
||||
HookCtl.answer = staticmethod(lambda words, args: '{"v":1,"ok":true,"data":{}}')
|
||||
HookCtl.refuse_pieces = False
|
||||
self.ready = (qmp.HOOK_READY_S, qmp.HOOK_READY_POLL_S)
|
||||
qmp.HOOK_READY_S, qmp.HOOK_READY_POLL_S = 0.0, 0.0
|
||||
|
||||
def tearDown(self):
|
||||
qmp.HOOK_READY_S, qmp.HOOK_READY_POLL_S = self.ready
|
||||
|
||||
def test_pin_and_unpin_reach_the_hook_as_one_request_each(self):
|
||||
seen = []
|
||||
|
||||
def answer(words, args):
|
||||
seen.append((words, args))
|
||||
return '{"v":1,"ok":true,"data":{"pinned":1}}'
|
||||
HookCtl.answer = staticmethod(answer)
|
||||
rc, by, rows = run_script(
|
||||
'override io/state/failsafe {"last_trip":{"why":"two words"},"ack":false}\n'
|
||||
"override io/state/failsafe null\n", ctl_cls=HookCtl)
|
||||
self.assertIsNone(rc, rows)
|
||||
self.assertEqual([r["status"] for r in rows], ["ok", "ok"])
|
||||
self.assertEqual(seen, [
|
||||
("ping", {}),
|
||||
("override", {"topic": "io/state/failsafe",
|
||||
"doc": {"last_trip": {"why": "two words"}, "ack": False}}),
|
||||
("override", {"topic": "io/state/failsafe", "doc": None}),
|
||||
])
|
||||
|
||||
def test_a_large_document_goes_in_pieces_under_the_tty_line_limit(self):
|
||||
seen = []
|
||||
|
||||
def answer(words, args):
|
||||
if words != "ping":
|
||||
seen.append(args)
|
||||
return '{"v":1,"ok":true}'
|
||||
HookCtl.answer = staticmethod(answer)
|
||||
doc = {"rows": ["x" * 100] * 120}
|
||||
rc, by, rows = run_script(
|
||||
"override cfg/state/big " + json.dumps(doc, separators=(",", ":")) + "\n",
|
||||
ctl_cls=HookCtl)
|
||||
self.assertEqual(rows[0]["status"], "ok", rows)
|
||||
self.assertEqual(seen, [{"topic": "cfg/state/big", "doc": doc}])
|
||||
# The pieces after the readiness ping (which sends {} in one piece).
|
||||
after_ping = HookCtl.sent[HookCtl.sent.index("@hook ping") + 1:]
|
||||
pieces = [c for c in after_ping if c.startswith("@hookdoc")]
|
||||
self.assertGreater(len(pieces), 5)
|
||||
self.assertTrue(pieces[0].startswith("@hookdoc {"))
|
||||
self.assertTrue(all(c.startswith("@hookdoc+ ") for c in pieces[1:]))
|
||||
self.assertTrue(all(len(c) < 4095 for c in HookCtl.sent), "a line over the tty limit")
|
||||
self.assertEqual(HookCtl.sent[-1], "@hook override")
|
||||
|
||||
def test_the_hooks_refusal_is_a_fail_with_its_err(self):
|
||||
HookCtl.answer = staticmethod(lambda words, args: json.dumps(
|
||||
{"v": 1, "ok": False, "err": {"code": "E_NOT_FOUND", "msg": "no filter covers it"}}))
|
||||
rc, by, rows = run_script('override io/state/nope {"a":1}\n', ctl_cls=HookCtl)
|
||||
self.assertEqual(rc, 1)
|
||||
self.assertEqual(rows[0]["status"], "fail")
|
||||
self.assertIn("E_NOT_FOUND", rows[0]["detail"])
|
||||
|
||||
def test_a_request_that_never_reached_the_hook_is_fatal(self):
|
||||
for reply in ("bridge: no hook client in the payload (/usr/bin/wthctl)",
|
||||
"bridge: hook request got no answer (client exit 2): wthctl: no reply (-3)",
|
||||
"not json", '{"v":1}', "[true]"):
|
||||
HookCtl.answer = staticmethod(lambda words, args, r=reply: r)
|
||||
rc, by, rows = run_script('override io/state/x {"a":1}\n', ctl_cls=HookCtl)
|
||||
self.assertEqual(rows[0]["status"], "fatal", reply)
|
||||
|
||||
def test_the_first_override_waits_for_the_hook_to_answer_a_ping(self):
|
||||
# flare-edge #2602: right after boot the UI's hook answered nothing
|
||||
# for a while; the override must be sent once, after a ping came back.
|
||||
qmp.HOOK_READY_S = 60.0
|
||||
seen = []
|
||||
lost = [2]
|
||||
|
||||
def answer(words, args):
|
||||
seen.append(words)
|
||||
if words == "ping" and lost[0]:
|
||||
lost[0] -= 1
|
||||
return "bridge: hook request got no answer (client exit 2): wthctl: no reply (-5)"
|
||||
return '{"v":1,"ok":true,"data":{}}'
|
||||
HookCtl.answer = staticmethod(answer)
|
||||
rc, by, rows = run_script(
|
||||
'override io/state/failsafe {"a":1}\n'
|
||||
"override io/state/failsafe null\n", ctl_cls=HookCtl)
|
||||
self.assertIsNone(rc, rows)
|
||||
self.assertEqual([r["status"] for r in rows], ["ok", "ok"])
|
||||
self.assertEqual(seen, ["ping", "ping", "ping", "override", "override"])
|
||||
|
||||
def test_a_hook_that_never_answers_a_ping_is_fatal_and_gets_no_override(self):
|
||||
HookCtl.answer = staticmethod(lambda words, args: (
|
||||
"bridge: hook request got no answer (client exit 2): wthctl: no reply (-5)"))
|
||||
rc, by, rows = run_script('override io/state/x {"a":1}\nwake\n', ctl_cls=HookCtl)
|
||||
self.assertEqual([r["status"] for r in rows], ["fatal", "ok"])
|
||||
self.assertIn("answered no ping", rows[0]["detail"])
|
||||
self.assertIn("@hook ping", HookCtl.sent)
|
||||
self.assertNotIn("@hook override", HookCtl.sent)
|
||||
|
||||
def test_a_ping_that_is_not_ok_leaves_the_verdict_to_the_override(self):
|
||||
# A hook that answers but refuses ping (an older hook) is still a
|
||||
# hook: the override goes out and its own reply is judged, and the
|
||||
# next override pings again rather than trusting it.
|
||||
seen = []
|
||||
|
||||
def answer(words, args):
|
||||
seen.append(words)
|
||||
if words == "ping":
|
||||
return '{"v":1,"ok":false,"err":{"code":"E_UNKNOWN_VERB"}}'
|
||||
return '{"v":1,"ok":true}'
|
||||
HookCtl.answer = staticmethod(answer)
|
||||
rc, by, rows = run_script(
|
||||
'override io/state/x {"a":1}\noverride io/state/x null\n', ctl_cls=HookCtl)
|
||||
self.assertEqual([r["status"] for r in rows], ["ok", "ok"])
|
||||
self.assertEqual(seen, ["ping", "override", "ping", "override"])
|
||||
|
||||
def test_a_refused_piece_is_fatal_for_the_step_only(self):
|
||||
HookCtl.refuse_pieces = True
|
||||
rc, by, rows = run_script('override io/state/x {"a":1}\nwake\n', ctl_cls=HookCtl)
|
||||
self.assertEqual([r["status"] for r in rows], ["fatal", "ok"])
|
||||
self.assertIn("hook args refused", rows[0]["detail"])
|
||||
self.assertNotIn("@hook override", HookCtl.sent)
|
||||
|
||||
def test_a_malformed_line_is_fatal_and_sends_nothing(self):
|
||||
rc, by, rows = run_script(
|
||||
'override io/state/+ {"a":1}\n'
|
||||
'override /io/state {"a":1}\n'
|
||||
"override io//state null\n"
|
||||
"override io/state/x {broken\n"
|
||||
"override io/state/x 5\n"
|
||||
'override io/state/x "text"\n'
|
||||
"override io/state/x\n", ctl_cls=HookCtl)
|
||||
self.assertEqual([r["status"] for r in rows], ["fatal"] * 7, rows)
|
||||
self.assertEqual(HookCtl.sent, [])
|
||||
|
||||
|
||||
def stat_line(pid, comm, state="S"):
|
||||
"""A /proc/<pid>/stat line with enough fields for parse_procs."""
|
||||
return f"{pid} ({comm}) {state} 1 1 1 0 -1 4194560 0 0 0 0 7 3 0 0 20 0 1 0 100"
|
||||
|
||||
|
||||
class ChainCtl(FakeCtl):
|
||||
"""A guest booted through the shipped init chain: what `@procs` and
|
||||
`@cat` answer there. Class attributes are the scenario."""
|
||||
|
||||
procs = [stat_line(1, "init"), stat_line(310, "warden-ui-run"), stat_line(311, "warden-ui")]
|
||||
passwd = "root:x:0:0:root:/root:/bin/sh\nwarden-ui:x:970:970::/var/empty:/bin/false\n"
|
||||
uids = {311: "970\t970\t970\t970"}
|
||||
files = {"/tmp/warden-ui.log": "Starting\nLVGL up\n"}
|
||||
sent = []
|
||||
|
||||
def send(self, cmd):
|
||||
ChainCtl.sent.append(cmd)
|
||||
if cmd == "@procs":
|
||||
return "\n".join(ChainCtl.procs)
|
||||
if cmd == "@cat /etc/passwd":
|
||||
return ChainCtl.passwd
|
||||
m = re.match(r"@cat /proc/(\d+)/status$", cmd)
|
||||
if m:
|
||||
pid = int(m.group(1))
|
||||
if pid not in ChainCtl.uids:
|
||||
return f"bridge: no such file: /proc/{pid}/status"
|
||||
return f"Name:\twarden-ui\nState:\tS (sleeping)\nUid:\t{ChainCtl.uids[pid]}\nGid:\t970\t970\t970\t970\n"
|
||||
if cmd.startswith("@cat "):
|
||||
path = cmd[len("@cat "):]
|
||||
if path in ChainCtl.files:
|
||||
return ChainCtl.files[path]
|
||||
return f"bridge: no such file: {path}"
|
||||
return super().send(cmd)
|
||||
|
||||
|
||||
class UiChainVerb(unittest.TestCase):
|
||||
"""assert_ui_chain (flare-edge #2210): the UI started through
|
||||
S03warden-accounts, S99lvgl and warden-ui-run, and runs as its account."""
|
||||
|
||||
def setUp(self):
|
||||
ChainCtl.procs = [stat_line(1, "init"), stat_line(310, "warden-ui-run"), stat_line(311, "warden-ui")]
|
||||
ChainCtl.passwd = "root:x:0:0:root:/root:/bin/sh\nwarden-ui:x:970:970::/var/empty:/bin/false\n"
|
||||
ChainCtl.uids = {311: "970\t970\t970\t970"}
|
||||
ChainCtl.files = {"/tmp/warden-ui.log": "Starting\nLVGL up\n"}
|
||||
ChainCtl.sent = []
|
||||
|
||||
def verdict(self, line="assert_ui_chain"):
|
||||
rc, by, rows = run_script(line + "\n", ctl_cls=ChainCtl)
|
||||
return rc, rows[0]
|
||||
|
||||
def test_a_ui_running_as_its_account_passes(self):
|
||||
rc, row = self.verdict()
|
||||
self.assertIsNone(rc, row)
|
||||
self.assertEqual(row["status"], "ok", row)
|
||||
self.assertIn("@cat /proc/311/status", ChainCtl.sent)
|
||||
self.assertIn("@cat /run/warden/ui-safe-mode", ChainCtl.sent)
|
||||
|
||||
def test_the_1903_class_no_ui_after_the_loop_gave_up_fails(self):
|
||||
# BusyBox setpriv without --reuid: every start exits 1, the loop
|
||||
# sets safe mode, and the log has the exits.
|
||||
ChainCtl.procs = [stat_line(1, "init"), stat_line(310, "warden-ui-run")]
|
||||
ChainCtl.uids = {}
|
||||
ChainCtl.files = {
|
||||
"/tmp/warden-ui.log": "setpriv: unrecognized option '--reuid=warden-ui'\n"
|
||||
"warden-ui-run: warden-ui exited 1\n" * 3,
|
||||
"/run/warden/ui-safe-mode": "",
|
||||
}
|
||||
rc, row = self.verdict()
|
||||
self.assertEqual(rc, 1)
|
||||
self.assertEqual(row["status"], "fail")
|
||||
self.assertIn("0 warden-ui processes, want 1", row["detail"])
|
||||
self.assertIn("safe mode is on", row["detail"])
|
||||
self.assertIn("warden-ui exited 1", row["detail"])
|
||||
self.assertIn("(+2 more)", row["detail"])
|
||||
|
||||
def test_a_ui_left_running_as_root_fails(self):
|
||||
ChainCtl.uids = {311: "0\t0\t0\t0"}
|
||||
rc, row = self.verdict()
|
||||
self.assertEqual(row["status"], "fail")
|
||||
self.assertIn("runs with uids [0, 0, 0, 0], not warden-ui (970)", row["detail"])
|
||||
|
||||
def test_one_uid_of_four_left_behind_fails(self):
|
||||
ChainCtl.uids = {311: "970\t970\t0\t970"}
|
||||
rc, row = self.verdict()
|
||||
self.assertIn("uids [970, 970, 0, 970]", row["detail"])
|
||||
|
||||
def test_no_account_fails(self):
|
||||
ChainCtl.passwd = "root:x:0:0:root:/root:/bin/sh\n"
|
||||
rc, row = self.verdict()
|
||||
self.assertIn("no account warden-ui in /etc/passwd", row["detail"])
|
||||
|
||||
def test_an_account_with_uid_0_fails(self):
|
||||
ChainCtl.passwd = "warden-ui:x:0:0::/:/bin/false\n"
|
||||
rc, row = self.verdict()
|
||||
self.assertIn("account warden-ui has uid 0", row["detail"])
|
||||
|
||||
def test_the_direct_start_without_a_loop_fails(self):
|
||||
# The rig's own direct start: no warden-ui-run, no log.
|
||||
ChainCtl.procs = [stat_line(1, "init"), stat_line(311, "warden-ui")]
|
||||
ChainCtl.files = {}
|
||||
rc, row = self.verdict()
|
||||
self.assertIn("0 warden-ui-run loops, want 1", row["detail"])
|
||||
self.assertIn("no /tmp/warden-ui.log", row["detail"])
|
||||
|
||||
def test_two_uis_or_two_loops_fail_and_zombies_do_not_count(self):
|
||||
ChainCtl.procs = [stat_line(310, "warden-ui-run"), stat_line(320, "warden-ui-run"),
|
||||
stat_line(311, "warden-ui"), stat_line(312, "warden-ui"),
|
||||
stat_line(313, "warden-ui", "Z")]
|
||||
ChainCtl.uids = {311: "970\t970\t970\t970", 312: "970\t970\t970\t970"}
|
||||
rc, row = self.verdict()
|
||||
self.assertIn("2 warden-ui processes, want 1 (pids [311, 312])", row["detail"])
|
||||
self.assertIn("2 warden-ui-run loops", row["detail"])
|
||||
|
||||
def test_a_restart_in_the_log_fails_even_with_the_ui_back_up(self):
|
||||
ChainCtl.files = {"/tmp/warden-ui.log": "warden-ui-run: warden-ui exited 139\n"}
|
||||
rc, row = self.verdict()
|
||||
self.assertEqual(row["status"], "fail")
|
||||
self.assertIn("exited 139", row["detail"])
|
||||
|
||||
def test_a_refused_start_in_the_log_fails(self):
|
||||
ChainCtl.files = {"/tmp/warden-ui.log":
|
||||
"warden-ui-run: no setpriv with --reuid and no su; refusing to run the UI as root\n"}
|
||||
rc, row = self.verdict()
|
||||
self.assertIn("refusing", row["detail"])
|
||||
|
||||
def test_another_account_can_be_named(self):
|
||||
ChainCtl.passwd = "kiosk:x:980:980::/:/bin/false\n"
|
||||
ChainCtl.uids = {311: "980\t980\t980\t980"}
|
||||
rc, row = self.verdict("assert_ui_chain kiosk")
|
||||
self.assertEqual(row["status"], "ok", row)
|
||||
|
||||
def test_pure_helpers(self):
|
||||
self.assertEqual(qmp.account_uid("a:x:5:5::/:/bin/sh\nb:x:x:1::/:/\n", "a"), 5)
|
||||
self.assertIsNone(qmp.account_uid("a:x:5:5::/:/bin/sh\n", "b"))
|
||||
self.assertIsNone(qmp.account_uid("b:x:nope:1::/:/\n", "b"))
|
||||
self.assertEqual(qmp.status_uids("Uid:\t1\t2\t3\t4\n"), [1, 2, 3, 4])
|
||||
self.assertIsNone(qmp.status_uids("Gid:\t1\t2\t3\t4\n"))
|
||||
|
||||
|
||||
class ConsoleWatchTests(unittest.TestCase):
|
||||
"""ConsoleWatch replaced a ui_exited() that reread and rescanned the
|
||||
WHOLE console log on every one of drive()'s per-step checks -- O(steps *
|
||||
@@ -924,6 +1286,68 @@ class ExpectReboot(unittest.TestCase):
|
||||
self.assertIn("without the kernel's orderly restart line", rows[-1]["detail"])
|
||||
|
||||
|
||||
class RebootTapRace(unittest.TestCase):
|
||||
"""flare-edge#233: a tap whose outcome is a reboot races init tearing
|
||||
warden-ui down. The control channel can close while the tap's press and
|
||||
release counts are still being polled, and the guest can print its restart
|
||||
line before expect_reboot starts. Both are the tap working."""
|
||||
|
||||
CONSOLE_LINE = b"init: reboot requested\n[ 17.8] reboot: Restarting system\n"
|
||||
|
||||
def run_race(self, script, console_before=b""):
|
||||
d = tempfile.mkdtemp(prefix="console.")
|
||||
console = os.path.join(d, "console.log")
|
||||
with open(console, "wb") as fh:
|
||||
fh.write(console_before)
|
||||
line = self.CONSOLE_LINE
|
||||
|
||||
class RebootingCtl(FakeCtl):
|
||||
"""First stats answers (the tap's baseline); the next one, the
|
||||
press poll, finds the guest already going down: the restart line
|
||||
is on the console and the channel is closed."""
|
||||
def send(self, cmd):
|
||||
if cmd == "stats" and self.stats_calls >= 1:
|
||||
with open(console, "ab") as fh:
|
||||
fh.write(line)
|
||||
raise RuntimeError("control channel closed")
|
||||
return super().send(cmd)
|
||||
|
||||
def rpc(sock, sock_file, obj):
|
||||
if obj.get("execute") == "query-status":
|
||||
raise RuntimeError("QMP connection closed")
|
||||
return fake_rpc(sock, sock_file, obj)
|
||||
|
||||
return run_script(script, ctl_cls=RebootingCtl, rpc_fn=rpc, console_path=console)
|
||||
|
||||
def test_reboot_tap_losing_the_channel_then_expect_reboot_passes(self):
|
||||
rc, by, rows = self.run_race("tap 10 10\nexpect_reboot 2\n")
|
||||
self.assertIsNone(rc, rows)
|
||||
self.assertEqual([r["status"] for r in rows], ["ok", "ok"], rows)
|
||||
self.assertIn("control channel closed", rows[0]["detail"])
|
||||
|
||||
def test_the_same_channel_loss_before_any_other_step_is_still_fatal(self):
|
||||
rc, by, rows = self.run_race("tap 10 10\nsleep 0\n")
|
||||
self.assertEqual(rows[0]["status"], "fatal", rows)
|
||||
|
||||
def test_a_restart_line_from_two_steps_back_still_does_not_count(self):
|
||||
# The restart line is already on the console before the script; the
|
||||
# reboot step may look back one step, not to the start of the run.
|
||||
d = tempfile.mkdtemp(prefix="console.")
|
||||
console = os.path.join(d, "console.log")
|
||||
with open(console, "wb") as fh:
|
||||
fh.write(b"reboot: Restarting system\n")
|
||||
|
||||
def rpc(sock, sock_file, obj):
|
||||
if obj.get("execute") == "query-status":
|
||||
raise RuntimeError("QMP connection closed")
|
||||
return fake_rpc(sock, sock_file, obj)
|
||||
|
||||
rc, by, rows = run_script("sleep 0\nexpect_reboot 1\n", rpc_fn=rpc,
|
||||
console_path=console)
|
||||
self.assertEqual(rc, 1)
|
||||
self.assertIn("without the kernel's orderly restart line", rows[-1]["detail"])
|
||||
|
||||
|
||||
class FullscreenToggleTracksRealState(unittest.TestCase):
|
||||
"""qemu/tests/scripts/fullscreen-toggle-tracks-real-state.txt, offline:
|
||||
`home` clears the dashboard's real fullscreen state directly, and a
|
||||
@@ -1051,6 +1475,49 @@ class CtlSocketProtocol(unittest.TestCase):
|
||||
th.join(timeout=2)
|
||||
self.assertEqual(got, "the actual reply")
|
||||
|
||||
def test_bridge_no_reply_line_raises_as_a_rig_fault(self):
|
||||
# flare-edge #1448: a UI slower than the bridge's wait came back as
|
||||
# an empty reply and was judged "page is ''". The bridge now says
|
||||
# so, and that line must stop the flow as a rig fault.
|
||||
def server():
|
||||
self.server_sock.recv(4096)
|
||||
self.server_sock.sendall(
|
||||
b"bridge: no reply from warden-ui within 30 s: page\n<<END>>\n")
|
||||
|
||||
th = threading.Thread(target=server, daemon=True)
|
||||
th.start()
|
||||
try:
|
||||
with self.assertRaises(RuntimeError) as cm:
|
||||
self.ctl.send("page")
|
||||
finally:
|
||||
th.join(timeout=2)
|
||||
self.assertIn("no reply from warden-ui", str(cm.exception))
|
||||
|
||||
def test_bridge_no_such_file_stays_an_ordinary_reply(self):
|
||||
# Only the no-reply line is a fault; @cat's missing-file answer is
|
||||
# a detail the json channel handles itself.
|
||||
def server():
|
||||
self.server_sock.recv(4096)
|
||||
self.server_sock.sendall(b"bridge: no such file: /x\n<<END>>\n")
|
||||
|
||||
th = threading.Thread(target=server, daemon=True)
|
||||
th.start()
|
||||
try:
|
||||
got = self.ctl.send("@cat /x")
|
||||
finally:
|
||||
th.join(timeout=2)
|
||||
self.assertEqual(got, "bridge: no such file: /x")
|
||||
|
||||
def test_ctl_timeout_outlasts_the_bridge_wait(self):
|
||||
# The bridge polls up to 30 s (more wall time on a slow guest); a
|
||||
# shorter socket timeout would turn its explicit answer into a bare
|
||||
# socket.timeout. Read the bridge default from the rootfs itself.
|
||||
lib = os.path.join(HERE, "..", "rootfs", "etc", "warden-lib.sh")
|
||||
with open(lib) as f:
|
||||
m = re.search(r"WARDEN_CTL_WAIT_S:-(\d+)", f.read())
|
||||
self.assertIsNotNone(m, "warden_ctl_bridge default wait not found")
|
||||
self.assertGreaterEqual(qmp.CTL_TIMEOUT_S, 2 * int(m.group(1)))
|
||||
|
||||
def test_leftover_bytes_after_sentinel_carry_over_to_the_next_send(self):
|
||||
# One write carries this reply's SENTINEL immediately followed by
|
||||
# bytes belonging to the NEXT command's reply -- proving self.buf
|
||||
@@ -1209,5 +1676,133 @@ class JsonStatusFetch(unittest.TestCase):
|
||||
self.assertGreaterEqual(time.monotonic() - t0, 0.6)
|
||||
|
||||
|
||||
|
||||
def _proc_stat(user, idle, iowait=0, running=1, blocked=0):
|
||||
return (f"cpu {user} 0 0 {idle} {iowait} 0 0 0 0 0\ncpu0 {user} 0 0 {idle} {iowait} 0 0 0 0 0\n"
|
||||
f"ctxt 1\nprocs_running {running}\nprocs_blocked {blocked}\n")
|
||||
|
||||
|
||||
def _pid_line(pid, comm, state, utime, stime=0):
|
||||
rest = " ".join(["0"] * 10)
|
||||
return f"{pid} ({comm}) {state} 1 1 1 0 -1 0 0 0 0 0 {utime} {stime} {rest}"
|
||||
|
||||
|
||||
class StallProbe(unittest.TestCase):
|
||||
"""flare-edge #1528: a step that fails because warden-ui did not answer
|
||||
carries one probe line saying why (host starving the VM, guest CPU
|
||||
saturated, guest I/O wait, or an idle guest with a blocked UI)."""
|
||||
|
||||
def test_parsers(self):
|
||||
st = qmp.parse_proc_stat(_proc_stat(5, 7, 2, running=3, blocked=1))
|
||||
self.assertEqual(st, ([5, 0, 0, 7, 2, 0, 0, 0, 0, 0], 3, 1))
|
||||
self.assertIsNone(qmp.parse_proc_stat("bridge: no such file: /proc/stat"))
|
||||
procs = qmp.parse_procs(_pid_line(7, "warden ui) x", "R", 40, 2) + "\n"
|
||||
+ _pid_line(9, "sh", "D", 1) + "\njunk\n")
|
||||
self.assertEqual(procs, {7: ("warden ui) x", "R", 42), 9: ("sh", "D", 1)})
|
||||
|
||||
def test_verdicts(self):
|
||||
self.assertIn("starves the VM", qmp.stall_verdict(0.3, (1.0, 0.0), 0, []))
|
||||
self.assertIn("did not answer", qmp.stall_verdict(0.99, None, None, []))
|
||||
self.assertIn("saturated", qmp.stall_verdict(0.99, (0.95, 0.0), 0, []))
|
||||
self.assertIn("I/O", qmp.stall_verdict(0.99, (0.2, 0.5), 1, ["warden-ui"]))
|
||||
self.assertIn("I/O", qmp.stall_verdict(None, (0.1, 0.0), 0, ["warden-ui"]))
|
||||
self.assertIn("idle", qmp.stall_verdict(0.99, (0.05, 0.0), 0, []))
|
||||
|
||||
def test_cpu_delta_and_top(self):
|
||||
a = qmp.parse_proc_stat(_proc_stat(100, 100))
|
||||
b = qmp.parse_proc_stat(_proc_stat(190, 110))
|
||||
busy, iowait = qmp.guest_cpu_delta(a, b)
|
||||
self.assertAlmostEqual(busy, 0.9)
|
||||
self.assertEqual(iowait, 0.0)
|
||||
p0 = qmp.parse_procs(_pid_line(7, "warden-ui", "R", 10) + "\n" + _pid_line(8, "flared", "S", 5))
|
||||
p1 = qmp.parse_procs(_pid_line(7, "warden-ui", "R", 80) + "\n" + _pid_line(8, "flared", "D", 25))
|
||||
top, dstate = qmp.top_procs(p0, p1, 100)
|
||||
self.assertEqual(top, ["warden-ui 70%", "flared 20%"])
|
||||
self.assertEqual(dstate, ["flared"])
|
||||
|
||||
def _drive_no_reply(self, script):
|
||||
class NoReplyCtl(FakeCtl):
|
||||
samples = 0
|
||||
|
||||
def send(self, cmd):
|
||||
if cmd == "@cat /proc/stat":
|
||||
NoReplyCtl.samples += 1
|
||||
n = NoReplyCtl.samples
|
||||
return _proc_stat(100 * n, 10)
|
||||
if cmd == "@procs":
|
||||
n = NoReplyCtl.samples
|
||||
return _pid_line(7, "warden-ui", "R", 95 * n) + "\n" + _pid_line(8, "sh", "S", 5 * n)
|
||||
if cmd == "page":
|
||||
raise RuntimeError("control channel: bridge: no reply from warden-ui "
|
||||
"within 30 s: page")
|
||||
return super().send(cmd)
|
||||
|
||||
def rpc_fn(sock, sock_file, obj):
|
||||
if obj.get("execute") == "query-cpus-fast":
|
||||
# No vCPU thread to sample here (test_vcpu_thread_ticks
|
||||
# covers the sampling); the verdict then rests on the guest.
|
||||
return []
|
||||
return fake_rpc(sock, sock_file, obj)
|
||||
|
||||
saved = qmp.STALL_WINDOW_S
|
||||
qmp.STALL_WINDOW_S = 0.05
|
||||
try:
|
||||
return run_script(script, ctl_cls=NoReplyCtl, rpc_fn=rpc_fn)
|
||||
finally:
|
||||
qmp.STALL_WINDOW_S = saved
|
||||
|
||||
def test_no_reply_steps_carry_a_bounded_probe(self):
|
||||
rc, _by, rows = self._drive_no_reply("assert_page Demo/Rows\n" * 4 + "assert_stat fps lt 0\n")
|
||||
self.assertEqual(rc, 1)
|
||||
self.assertEqual([r["status"] for r in rows], ["fatal"] * 4 + ["fail"])
|
||||
probed = [r["detail"] for r in rows if "stall probe" in r["detail"]]
|
||||
self.assertEqual(len(probed), qmp.STALL_REPORTS_MAX, rows)
|
||||
first = rows[0]["detail"]
|
||||
self.assertTrue(first.startswith("control channel: bridge: no reply"), first)
|
||||
self.assertIn("the guest CPU is saturated", first)
|
||||
self.assertIn("top warden-ui 95%, sh 5%", first)
|
||||
self.assertIn("vcpu n/a", first)
|
||||
self.assertIn("guest busy 100% iowait 0%", first)
|
||||
# A plain mismatch is not a stall and gets no probe.
|
||||
self.assertNotIn("stall probe", rows[4]["detail"])
|
||||
|
||||
def test_vcpu_thread_ticks(self):
|
||||
tid = threading.get_native_id()
|
||||
before = qmp._thread_ticks([tid])
|
||||
end = time.process_time() + 0.3
|
||||
while time.process_time() < end:
|
||||
pass
|
||||
self.assertGreater(qmp._thread_ticks([tid]), before)
|
||||
self.assertIsNone(qmp._thread_ticks([2 ** 22 + 12345]))
|
||||
|
||||
def test_unconsumed_input_is_a_stall(self):
|
||||
self.assertTrue(qmp.is_stall(qmp.input_verdict(SimpleNamespace(), False)[1]))
|
||||
self.assertTrue(qmp.is_stall("control channel: bridge: no reply from warden-ui within 30 s: hit"))
|
||||
self.assertFalse(qmp.is_stall("obj moved: box=1,2,3x4"))
|
||||
|
||||
class TempDirs(unittest.TestCase):
|
||||
# One test per kind of temp dir this module makes: a drive's out dir
|
||||
# (run_script), a console dir and a QMP socket dir.
|
||||
CHILD_TESTS = (
|
||||
"DriveVerbs.test_shot_and_region_names_cannot_escape_outdir",
|
||||
"ConsoleWatchTests.test_finds_a_marker_split_across_two_reads_and_caches_it",
|
||||
"QmpSocketTimeout.test_main_bounds_a_wedged_qmp_peer_instead_of_hanging_forever",
|
||||
)
|
||||
|
||||
@unittest.skipIf(os.environ.get("QMP_DRIVE_TEMP_CHILD"), "the child run itself")
|
||||
def test_a_run_leaves_tmpdir_as_it_found_it(self):
|
||||
fresh = tempfile.mkdtemp(prefix="fresh.", dir=os.path.dirname(_TMP_ROOT))
|
||||
try:
|
||||
env = dict(os.environ, TMPDIR=fresh, QMP_DRIVE_TEMP_CHILD="1")
|
||||
child = subprocess.run(
|
||||
[sys.executable, os.path.abspath(__file__), *self.CHILD_TESTS],
|
||||
env=env, capture_output=True, text=True, timeout=120)
|
||||
self.assertEqual(child.returncode, 0, child.stderr[-2000:])
|
||||
self.assertIn(f"Ran {len(self.CHILD_TESTS)} tests", child.stderr)
|
||||
self.assertEqual(os.listdir(fresh), [])
|
||||
finally:
|
||||
shutil.rmtree(fresh, ignore_errors=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=1)
|
||||
|
||||
+26
-14
@@ -36,24 +36,35 @@
|
||||
set -euo pipefail
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # qemu/tests/
|
||||
QDIR="$(cd "$HERE/.." && pwd)" # qemu/
|
||||
# shellcheck source=qemu/tests/ui-start.sh disable=SC1091
|
||||
. "$HERE/ui-start.sh"
|
||||
|
||||
SEED_FILE=""
|
||||
REFS_FILE=""
|
||||
RS485_DEVICES=""
|
||||
INIT_CHAIN=""
|
||||
ARGS=()
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--seed) SEED_FILE="${2:?--seed needs a manifest path}"; shift 2 ;;
|
||||
--refs) REFS_FILE="${2:?--refs needs a path}"; shift 2 ;;
|
||||
--rs485-devices) RS485_DEVICES="${2:?--rs485-devices needs ADDR:SLUG[,...]}"; shift 2 ;;
|
||||
--init-chain) INIT_CHAIN="${2:?--init-chain needs a directory}"; shift 2 ;;
|
||||
--) shift; ARGS+=("$@"); break ;;
|
||||
-*) echo "FATAL: unknown option '$1' (usage: $0 [--seed FILE] [--refs FILE] [--rs485-devices LIST] <zImage> <script> [out-dir])" >&2; exit 1 ;;
|
||||
-*) echo "FATAL: unknown option '$1' (usage: $0 [--seed FILE] [--refs FILE] [--rs485-devices LIST] [--init-chain DIR] <zImage> <script> [out-dir])" >&2; exit 1 ;;
|
||||
*) ARGS+=("$1"); shift ;;
|
||||
esac
|
||||
done
|
||||
ZIMAGE="${ARGS[0]:-}"
|
||||
SCRIPT="${ARGS[1]:-}"
|
||||
OUTDIR="${ARGS[2]:-$QDIR/out/ui-drive}"
|
||||
if [ -n "$INIT_CHAIN" ]; then
|
||||
[ -d "$INIT_CHAIN" ] || { echo "FATAL: --init-chain '$INIT_CHAIN' is not a directory" >&2; exit 1; }
|
||||
[ -f "$INIT_CHAIN/etc/init.d/S99lvgl" ] || {
|
||||
echo "FATAL: --init-chain '$INIT_CHAIN' has no etc/init.d/S99lvgl: the UI would never start" >&2; exit 1; }
|
||||
ROOTFS_OVERLAY="$(cd "$INIT_CHAIN" && pwd)"
|
||||
export ROOTFS_OVERLAY
|
||||
fi
|
||||
|
||||
if [ -z "$ZIMAGE" ] || [ ! -f "$ZIMAGE" ]; then
|
||||
echo "FATAL: usage: $0 [--seed FILE] [--refs FILE] [--rs485-devices LIST] <zImage> <script> [out-dir]: the virt.fragment kernel variant" >&2
|
||||
@@ -71,8 +82,16 @@ if [ -n "$SEED_FILE" ] && { [ -z "${FLARE_EDGE:-}" ] || [ ! -f "$FLARE_EDGE/tool
|
||||
echo "FATAL: --seed needs FLARE_EDGE to point at a flare-edge checkout (seed-fixtures.py not found under '${FLARE_EDGE:-}')" >&2
|
||||
exit 1
|
||||
fi
|
||||
[ -x "$QDIR/payload/warden-ui" ] || {
|
||||
echo "FATAL: no qemu/payload/warden-ui: build it with flare-edge tools/build-ui-vm.sh" >&2
|
||||
# --init-chain DIR
|
||||
# boot the UI through the panel's shipped init scripts
|
||||
# (flare-edge #2210): DIR is laid over the rootfs with
|
||||
# mkimage.sh's ROOTFS_OVERLAY and the VM boots with
|
||||
# warden.initchain, so stage-2 init starts /etc/init.d/S*
|
||||
# instead of warden-ui directly. qmp.py's assert_ui_chain
|
||||
# verb judges the result.
|
||||
# PAYLOAD_DIR (mkimage.sh's Env note) picks another payload set for this run.
|
||||
[ -x "${PAYLOAD_DIR:-$QDIR/payload}/warden-ui" ] || {
|
||||
echo "FATAL: no warden-ui in ${PAYLOAD_DIR:-qemu/payload}: build it with flare-edge tools/build-ui-vm.sh" >&2
|
||||
exit 1
|
||||
}
|
||||
command -v qemu-system-arm >/dev/null || {
|
||||
@@ -171,6 +190,7 @@ for _attempt in 1 2 3; do
|
||||
: > "$WORK/console.log"
|
||||
bash "$QDIR/run.sh" --kernel "$ZIMAGE" --display headless --qmp "$WORK/qmp.sock" \
|
||||
--ctl "$WORK/ctl.sock" ${RS485_DEVICES:+--rs485 "$WORK/rs.sock"} \
|
||||
${INIT_CHAIN:+--append warden.initchain} \
|
||||
--ssh-port "$PORT" --http-port $((PORT + 1)) --api-port $((PORT + 2)) \
|
||||
> "$WORK/console.log" 2>&1 &
|
||||
QEMU_PID=$!
|
||||
@@ -234,17 +254,9 @@ if [ -n "$RS485_DEVICES" ]; then
|
||||
fi
|
||||
|
||||
echo "== waiting for warden-ui"
|
||||
deadline=$((SECONDS + 180))
|
||||
while [ $SECONDS -lt $deadline ]; do
|
||||
grep -aq 'init: starting warden-ui' "$WORK/console.log" && break
|
||||
kill -0 "$QEMU_PID" 2>/dev/null || { echo "FATAL: VM exited early" >&2; tail -25 "$WORK/console.log" >&2; exit 1; }
|
||||
sleep 2
|
||||
done
|
||||
grep -aq 'init: starting warden-ui' "$WORK/console.log" || {
|
||||
echo "FATAL: warden-ui never started (no fb0? wrong kernel?)" >&2
|
||||
tail -25 "$WORK/console.log" >&2
|
||||
exit 1
|
||||
}
|
||||
# A chain boot reports the start through the chain, not the direct-start line
|
||||
# (ui-start.sh, flare-edge#2295).
|
||||
wait_ui_started "$WORK/console.log" "$QEMU_PID" 180 "$([ -n "$INIT_CHAIN" ] && echo 1 || echo 0)" || exit 1
|
||||
|
||||
# A started process is not a rendered frame. Poll screendumps until the panel
|
||||
# stops being a single flat colour, on a bounded deadline: TCG renders CPU-bound
|
||||
|
||||
+3
-11
@@ -13,6 +13,8 @@ set -euo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # qemu/tests/
|
||||
QDIR="$(cd "$HERE/.." && pwd)" # qemu/
|
||||
# shellcheck source=qemu/tests/ui-start.sh disable=SC1091
|
||||
. "$HERE/ui-start.sh"
|
||||
|
||||
ZIMAGE="${1:-}"
|
||||
OUTDIR="${2:-$QDIR/out}"
|
||||
@@ -66,17 +68,7 @@ if [ -z "$QEMU_PID" ] || ! kill -0 "$QEMU_PID" 2>/dev/null; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
deadline=$((SECONDS + 120))
|
||||
while [ $SECONDS -lt $deadline ]; do
|
||||
grep -aq 'init: starting warden-ui' "$WORK/console.log" && break
|
||||
kill -0 "$QEMU_PID" 2>/dev/null || { echo "FATAL: VM exited early" >&2; tail -25 "$WORK/console.log" >&2; exit 1; }
|
||||
sleep 2
|
||||
done
|
||||
grep -aq 'init: starting warden-ui' "$WORK/console.log" || {
|
||||
echo "FATAL: warden-ui never started (no fb0? wrong kernel?)" >&2
|
||||
tail -25 "$WORK/console.log" >&2
|
||||
exit 1
|
||||
}
|
||||
wait_ui_started "$WORK/console.log" "$QEMU_PID" 120 0 || exit 1
|
||||
|
||||
qmp() { python3 "$HERE/qmp.py" "$WORK/qmp.sock" "$@"; }
|
||||
|
||||
|
||||
Executable
+152
@@ -0,0 +1,152 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC2016 # the single-quoted $ strings are literal patterns and child-shell args
|
||||
# Host test for qemu/tests/ui-start.sh (flare-edge#2295): the console line
|
||||
# ui-drive.sh and ui-shot.sh wait for before driving the UI. Offline, no VM.
|
||||
#
|
||||
# flare-edge job 99350 (the first "QEMU UI shipped init chain" run) booted
|
||||
# the chain cleanly but ui-drive.sh waited 180 s for the direct-start line,
|
||||
# which a warden.initchain boot never prints. This test pins:
|
||||
# - every marker ui-start.sh waits for is printed by rootfs/sbin/init or
|
||||
# rootfs/etc/warden-lib.sh, in the mode it is used for;
|
||||
# - a chain-boot console (the 99350 lines) counts as started in chain
|
||||
# mode, and a direct-start console in direct mode;
|
||||
# - an empty chain and a failed S99lvgl fail at once, not at the deadline;
|
||||
# - a dead VM and a silent console fail with their own messages;
|
||||
# - ui-drive.sh and ui-shot.sh wait through ui-start.sh only, and
|
||||
# ui-drive.sh passes chain mode exactly when --init-chain is given.
|
||||
#
|
||||
# bash ui-start-test.sh
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
INIT="$HERE/../rootfs/sbin/init"
|
||||
LIB="$HERE/../rootfs/etc/warden-lib.sh"
|
||||
WORK="$(mktemp -d "${TMPDIR:-/tmp}/warden-ui-start.XXXXXX")" || exit 1
|
||||
VMPID=""
|
||||
# shellcheck disable=SC2317 # called from the EXIT trap
|
||||
cleanup() { [ -n "$VMPID" ] && kill "$VMPID" 2>/dev/null; rm -rf "$WORK"; }
|
||||
trap cleanup EXIT
|
||||
FAIL=0
|
||||
CHECKS=0
|
||||
check() { # check <label> <command...>
|
||||
CHECKS=$((CHECKS + 1))
|
||||
if "${@:2}"; then echo "[PASS] $1"; else echo "[FAIL] $1"; FAIL=1; fi
|
||||
}
|
||||
|
||||
# shellcheck source=qemu/tests/ui-start.sh disable=SC1091
|
||||
. "$HERE/ui-start.sh"
|
||||
UI_START_POLL=0.1
|
||||
export UI_START_POLL
|
||||
|
||||
# --- the markers are the ones init prints -----------------------------------
|
||||
check "direct-start marker is echoed by sbin/init" \
|
||||
grep -qF "echo \"$UI_START_DIRECT" "$INIT"
|
||||
check "chain marker is echoed by sbin/init" \
|
||||
grep -qF "echo \"$UI_START_CHAIN" "$INIT"
|
||||
check "empty-chain marker is echoed by sbin/init" \
|
||||
grep -qF "echo \"$UI_FAIL_CHAIN_EMPTY" "$INIT"
|
||||
check "the chain marker is printed only on a chain boot" \
|
||||
awk -v m="echo \"$UI_START_CHAIN" '
|
||||
/^if \[ "\$initchain" = 1 \]; then/ { inchain = 1 }
|
||||
inchain && /^fi$/ { inchain = 0 }
|
||||
index($0, m) { found = 1; if (!inchain) bad = 1 }
|
||||
END { exit !(found && !bad) }' "$INIT"
|
||||
check "the direct-start marker is printed only on a direct boot" \
|
||||
awk -v m="echo \"$UI_START_DIRECT" '
|
||||
/^if \[ "\$initchain" = 0 \]/ { indirect = 1 }
|
||||
indirect && /^fi$/ { indirect = 0 }
|
||||
index($0, m) { found = 1; if (!indirect) bad = 1 }
|
||||
END { exit !(found && !bad) }' "$INIT"
|
||||
check "ui_start_marker picks the mode's marker" \
|
||||
test "$(ui_start_marker 0)|$(ui_start_marker 1)" = "$UI_START_DIRECT|$UI_START_CHAIN"
|
||||
|
||||
# The S99lvgl failure line, from the real warden_init_chain with a failing stub.
|
||||
D="$WORK/init.d"
|
||||
mkdir -p "$D"
|
||||
printf '#!/bin/sh\nexit 4\n' > "$D/S99lvgl"
|
||||
chmod 0755 "$D/S99lvgl"
|
||||
WARDEN_INITD="$D" sh -c '. "$1"; warden_init_chain 10 99' sh "$LIB" > /dev/null 2> "$WORK/lvgl-fail.err"
|
||||
check "warden_init_chain prints the S99lvgl failure line ui-start.sh watches for" \
|
||||
grep -qF "$UI_FAIL_CHAIN_LVGL rc=4" "$WORK/lvgl-fail.err"
|
||||
|
||||
# --- console fixtures -------------------------------------------------------
|
||||
# Chain boot, as flare-edge job 99350 printed it.
|
||||
cat > "$WORK/chain.log" <<'EOF'
|
||||
WARDEN-QEMU-ROOTFS-OK slot=_a
|
||||
init: shipped init chain (warden.initchain)
|
||||
init: chain S03warden-accounts start
|
||||
Creating platform accounts: OK
|
||||
init: rig bus up on /run/warden/bus/bus.sock (broker pid 253)
|
||||
init: starting warden-modbus
|
||||
init: starting warden-flared
|
||||
init: chain S99lvgl start
|
||||
warden-ui: no backlight device
|
||||
Starting Warden UI: OK
|
||||
init: chain started 2 script(s)
|
||||
init: control bridge on /dev/ttyS0
|
||||
EOF
|
||||
cat > "$WORK/direct.log" <<'EOF'
|
||||
WARDEN-QEMU-ROOTFS-OK slot=_a
|
||||
init: starting warden-modbus
|
||||
init: starting warden-ui (fbdev)
|
||||
EOF
|
||||
cat > "$WORK/empty-chain.log" <<'EOF'
|
||||
init: shipped init chain (warden.initchain)
|
||||
init: starting warden-flared
|
||||
WARDEN-QEMU-INITCHAIN-EMPTY: warden.initchain but no /etc/init.d/S* script; the UI is not started
|
||||
EOF
|
||||
{ head -n 8 "$WORK/chain.log"; cat "$WORK/lvgl-fail.err"; } > "$WORK/lvgl-fail.log"
|
||||
: > "$WORK/silent.log"
|
||||
|
||||
sleep 60 &
|
||||
VMPID=$!
|
||||
|
||||
run_wait() { # run_wait <log> <secs> <chain>: rc in $RC, stderr in $WORK/err, seconds in $TOOK
|
||||
local t0=$SECONDS
|
||||
wait_ui_started "$WORK/$1" "$VMPID" "$2" "$3" 2> "$WORK/err"
|
||||
RC=$?
|
||||
TOOK=$((SECONDS - t0))
|
||||
}
|
||||
|
||||
run_wait chain.log 5 1
|
||||
check "chain console counts as started in chain mode (flare-edge#2295)" test "$RC" = 0
|
||||
run_wait chain.log 0 0
|
||||
check "the same console is not a direct start (the 99350 failure)" test "$RC" = 1
|
||||
check "a direct-mode timeout names the direct start" \
|
||||
grep -qF "warden-ui never started" "$WORK/err"
|
||||
run_wait direct.log 5 0
|
||||
check "direct console counts as started in direct mode" test "$RC" = 0
|
||||
run_wait direct.log 0 1
|
||||
check "a direct console is not a chain start" test "$RC" = 1
|
||||
check "a chain-mode timeout names the chain marker" \
|
||||
grep -qF "the shipped init chain never reported its start" "$WORK/err"
|
||||
run_wait empty-chain.log 30 1
|
||||
check "an empty chain fails" test "$RC" = 1
|
||||
check "an empty chain fails at once, not at the deadline" test "$TOOK" -lt 5
|
||||
check "an empty chain says why" grep -qF "has no /etc/init.d/S* script" "$WORK/err"
|
||||
run_wait lvgl-fail.log 30 1
|
||||
check "a failed S99lvgl fails" test "$RC" = 1
|
||||
check "a failed S99lvgl fails at once" test "$TOOK" -lt 5
|
||||
check "a failed S99lvgl names its status" grep -qF "S99lvgl start FAILED rc=4" "$WORK/err"
|
||||
run_wait silent.log 1 1
|
||||
check "a silent console times out" test "$RC" = 1
|
||||
|
||||
kill "$VMPID" 2>/dev/null
|
||||
wait "$VMPID" 2>/dev/null
|
||||
run_wait silent.log 30 1
|
||||
check "a dead VM fails at once with its own message" \
|
||||
sh -c 'test "$1" = 1 && test "$2" -lt 5 && grep -qF "VM exited early" "$3"' sh "$RC" "$TOOK" "$WORK/err"
|
||||
VMPID=""
|
||||
|
||||
# --- the drivers use it -----------------------------------------------------
|
||||
for s in ui-drive.sh ui-shot.sh; do
|
||||
check "$s sources ui-start.sh" grep -qF '. "$HERE/ui-start.sh"' "$HERE/$s"
|
||||
check "$s waits through wait_ui_started" grep -q '^wait_ui_started ' "$HERE/$s"
|
||||
done
|
||||
check "no driver greps a UI start marker of its own" \
|
||||
sh -c '! grep -lF "init: starting warden-ui" "$1"/*.sh | grep -v "/ui-start.sh$" | grep -v "/ui-start-test.sh$" | grep -q .' sh "$HERE"
|
||||
check "ui-drive.sh waits in chain mode exactly when --init-chain is given" \
|
||||
grep -qF 'wait_ui_started "$WORK/console.log" "$QEMU_PID" 180 "$([ -n "$INIT_CHAIN" ] && echo 1 || echo 0)"' "$HERE/ui-drive.sh"
|
||||
|
||||
echo "ui-start: $CHECKS checks, $([ "$FAIL" = 0 ] && echo OK || echo FAILED)"
|
||||
exit "$FAIL"
|
||||
@@ -0,0 +1,61 @@
|
||||
# shellcheck shell=bash
|
||||
# Sourced by ui-drive.sh and ui-shot.sh: wait for stage-2 init to report the
|
||||
# UI started, from the VM console log.
|
||||
#
|
||||
# The console line depends on how the UI is started (rootfs/sbin/init):
|
||||
# direct start (default) "init: starting warden-ui (fbdev)"
|
||||
# shipped chain (warden.initchain, ui-drive.sh --init-chain)
|
||||
# "init: chain started N script(s)", after
|
||||
# the panel's S99lvgl ran; the direct start
|
||||
# line is never printed (flare-edge#2295)
|
||||
# A chain boot that cannot start the UI says so at once, so these fail fast
|
||||
# instead of spending the whole deadline:
|
||||
# "WARDEN-QEMU-INITCHAIN-EMPTY" no /etc/init.d/S* script at all
|
||||
# "init: chain S99lvgl start FAILED rc=N" the UI's own script failed
|
||||
# qemu/tests/ui-start-test.sh checks every marker here against sbin/init.
|
||||
|
||||
UI_START_DIRECT='init: starting warden-ui'
|
||||
UI_START_CHAIN='init: chain started '
|
||||
UI_FAIL_CHAIN_EMPTY='WARDEN-QEMU-INITCHAIN-EMPTY'
|
||||
UI_FAIL_CHAIN_LVGL='init: chain S99lvgl start FAILED'
|
||||
|
||||
# ui_start_marker <initchain 0|1>: the console line that means "UI started".
|
||||
ui_start_marker() {
|
||||
if [ "${1:-0}" = 1 ]; then printf '%s' "$UI_START_CHAIN"; else printf '%s' "$UI_START_DIRECT"; fi
|
||||
}
|
||||
|
||||
# wait_ui_started <console.log> <qemu pid> <seconds> <initchain 0|1>
|
||||
# Returns 0 once the UI is reported started; prints a FATAL line and the
|
||||
# console tail to stderr and returns 1 on a VM exit, a chain failure or the
|
||||
# deadline.
|
||||
wait_ui_started() {
|
||||
local log="$1" pid="$2" secs="$3" chain="${4:-0}" marker deadline
|
||||
marker="$(ui_start_marker "$chain")"
|
||||
deadline=$((SECONDS + secs))
|
||||
while :; do
|
||||
grep -aqF "$marker" "$log" && return 0
|
||||
if [ "$chain" = 1 ]; then
|
||||
if grep -aqF "$UI_FAIL_CHAIN_EMPTY" "$log"; then
|
||||
echo "FATAL: the init chain has no /etc/init.d/S* script, so warden-ui is not started" >&2
|
||||
tail -25 "$log" >&2
|
||||
return 1
|
||||
fi
|
||||
if grep -aqF "$UI_FAIL_CHAIN_LVGL" "$log"; then
|
||||
echo "FATAL: S99lvgl failed in the shipped init chain: $(grep -aF "$UI_FAIL_CHAIN_LVGL" "$log" | head -1)" >&2
|
||||
tail -25 "$log" >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
kill -0 "$pid" 2>/dev/null || { echo "FATAL: VM exited early" >&2; tail -25 "$log" >&2; return 1; }
|
||||
[ $SECONDS -lt $deadline ] || break
|
||||
sleep "${UI_START_POLL:-2}"
|
||||
done
|
||||
grep -aqF "$marker" "$log" && return 0
|
||||
if [ "$chain" = 1 ]; then
|
||||
echo "FATAL: the shipped init chain never reported its start ('$marker' not on the console)" >&2
|
||||
else
|
||||
echo "FATAL: warden-ui never started (no fb0? wrong kernel?)" >&2
|
||||
fi
|
||||
tail -25 "$log" >&2
|
||||
return 1
|
||||
}
|
||||
Executable
+109
@@ -0,0 +1,109 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check that a patched kernel tree keeps the arm32 vDSO clock off the
|
||||
virtual counter when the kernel times on the physical one (bfe-core1106-sdk#35).
|
||||
|
||||
On the RV1106 the boot firmware does not enter the kernel in HYP mode and
|
||||
leaves CNTVOFF non-zero. The DT timer node lists no virtual-timer PPI, so the
|
||||
kernel keeps time on the physical counter, while the arm32 vDSO always reads
|
||||
the virtual counter: clock_gettime() then runs about 739 s ahead of the kernel
|
||||
clock and every absolute deadline taken from it expires late (flare-edge#2319).
|
||||
|
||||
Two guards must both be present in the patched tree:
|
||||
|
||||
1. Every armv7/armv8 timer node in the RV1106 device trees that has no
|
||||
virtual-timer PPI (GIC_PPI 11) carries `arm,cpu-registers-not-fw-configured`,
|
||||
which makes arch/arm/kernel/vdso.c drop the vDSO clock symbols.
|
||||
2. drivers/clocksource/arm_arch_timer.c sets the counter's vdso_clock_mode to
|
||||
VDSO_CLOCKMODE_NONE on arm32 when the kernel uses the physical counter
|
||||
without HYP mode (the safety net for a device tree without the property).
|
||||
|
||||
Usage: check-vdso-counter.py <patched kernel source dir>
|
||||
Exit 0 when both hold, 1 with one FAIL line per problem, 2 on bad usage.
|
||||
"""
|
||||
import pathlib
|
||||
import re
|
||||
import sys
|
||||
|
||||
DTS_GLOB = "arch/arm/boot/dts/rockchip/rv1106*.dts*"
|
||||
TIMER_C = "drivers/clocksource/arm_arch_timer.c"
|
||||
PROPERTY = "arm,cpu-registers-not-fw-configured"
|
||||
|
||||
|
||||
def strip_comments(text):
|
||||
text = re.sub(r"/\*.*?\*/", "", text, flags=re.S)
|
||||
return re.sub(r"//[^\n]*", "", text)
|
||||
|
||||
|
||||
def timer_nodes(text):
|
||||
"""Yield the body of every node whose compatible is an arch timer."""
|
||||
for m in re.finditer(r"\b[\w@,.-]+\s*\{", text):
|
||||
depth, i = 1, m.end()
|
||||
while depth and i < len(text):
|
||||
depth += {"{": 1, "}": -1}.get(text[i], 0)
|
||||
i += 1
|
||||
body = text[m.end():i - 1]
|
||||
# Only the node's own properties, not its children's.
|
||||
own = re.sub(r"\{.*\}", "", body, flags=re.S)
|
||||
if re.search(r'compatible\s*=\s*"arm,armv[78]-timer"', own):
|
||||
yield own
|
||||
|
||||
|
||||
def check_dts(root):
|
||||
problems, seen = [], 0
|
||||
for path in sorted(root.glob(DTS_GLOB)):
|
||||
text = strip_comments(path.read_text(errors="replace"))
|
||||
for own in timer_nodes(text):
|
||||
seen += 1
|
||||
has_virt = re.search(r"GIC_PPI\s+11\b", own) is not None
|
||||
has_prop = re.search(r"(^|[\s;])" + re.escape(PROPERTY) + r"\s*;", own) is not None
|
||||
if not has_virt and not has_prop:
|
||||
problems.append(f"{path.relative_to(root)}: timer node has no virtual-timer "
|
||||
f"PPI and no {PROPERTY}")
|
||||
if not seen:
|
||||
problems.append(f"no arm,armv7-timer node found under {DTS_GLOB}")
|
||||
return problems
|
||||
|
||||
|
||||
def check_timer_c(root):
|
||||
path = root / TIMER_C
|
||||
if not path.is_file():
|
||||
return [f"{TIMER_C} missing"]
|
||||
text = strip_comments(path.read_text(errors="replace"))
|
||||
m = re.search(r"static void __init arch_counter_register\(void\)\s*\{", text)
|
||||
if not m:
|
||||
return [f"{TIMER_C}: arch_counter_register() not found"]
|
||||
depth, i = 1, m.end()
|
||||
while depth and i < len(text):
|
||||
depth += {"{": 1, "}": -1}.get(text[i], 0)
|
||||
i += 1
|
||||
body = text[m.end():i - 1]
|
||||
guard = re.search(
|
||||
r"if\s*\(\s*IS_ENABLED\(CONFIG_ARM\)\s*&&\s*"
|
||||
r"arch_timer_uses_ppi\s*!=\s*ARCH_TIMER_VIRT_PPI\s*&&\s*"
|
||||
r"!\s*is_hyp_mode_available\(\)[^{]*\{([^}]*)\}", body)
|
||||
if not guard or not re.search(
|
||||
r"clocksource_counter\.vdso_clock_mode\s*=\s*VDSO_CLOCKMODE_NONE\s*;", guard.group(1)):
|
||||
return [f"{TIMER_C}: arch_counter_register() lacks the arm32 physical-counter "
|
||||
"vDSO fallback (vdso_clock_mode = VDSO_CLOCKMODE_NONE)"]
|
||||
default_at = body.find("clocksource_counter.vdso_clock_mode = vdso_default;")
|
||||
if default_at < 0 or default_at > guard.start():
|
||||
return [f"{TIMER_C}: the vDSO fallback must come after the vdso_default assignment"]
|
||||
return []
|
||||
|
||||
|
||||
def main(argv):
|
||||
if len(argv) != 2 or not pathlib.Path(argv[1]).is_dir():
|
||||
print("usage: check-vdso-counter.py <patched kernel source dir>", file=sys.stderr)
|
||||
return 2
|
||||
root = pathlib.Path(argv[1])
|
||||
problems = check_dts(root) + check_timer_c(root)
|
||||
for p in problems:
|
||||
print(f"FAIL: {p}")
|
||||
if problems:
|
||||
return 1
|
||||
print("vdso-counter: ok (DT property and arm32 physical-counter fallback present)")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv))
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
#!/bin/bash
|
||||
# Regression tests for tests/arch-timer/check-vdso-counter.py (bfe-core1106-sdk#35).
|
||||
#
|
||||
# The checker guards the fix for the vDSO clock running 739 s ahead of the
|
||||
# kernel clock on the RV1106: the DT timer property and the arm32 fallback in
|
||||
# arm_arch_timer.c. Each case builds a small fake kernel tree and expects an
|
||||
# exit status; the real patched tree is checked in CI's patches-apply job.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
CHECK="$HERE/check-vdso-counter.py"
|
||||
TMP="$(mktemp -d)"
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
|
||||
TIMER_NODE_GOOD=' timer {
|
||||
compatible = "arm,armv7-timer";
|
||||
interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>,
|
||||
<GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>;
|
||||
clock-frequency = <24000000>;
|
||||
arm,cpu-registers-not-fw-configured;
|
||||
};'
|
||||
TIMER_NODE_BARE=' timer {
|
||||
compatible = "arm,armv7-timer";
|
||||
interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>,
|
||||
<GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>;
|
||||
clock-frequency = <24000000>;
|
||||
};'
|
||||
TIMER_NODE_COMMENTED=' timer {
|
||||
compatible = "arm,armv7-timer";
|
||||
interrupts = <GIC_PPI 13 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>,
|
||||
<GIC_PPI 14 (GIC_CPU_MASK_SIMPLE(1) | IRQ_TYPE_LEVEL_HIGH)>;
|
||||
/* arm,cpu-registers-not-fw-configured; */
|
||||
};'
|
||||
TIMER_NODE_VIRT=' timer {
|
||||
compatible = "arm,armv7-timer";
|
||||
interrupts = <GIC_PPI 13 IRQ_TYPE_LEVEL_LOW>, <GIC_PPI 14 IRQ_TYPE_LEVEL_LOW>,
|
||||
<GIC_PPI 11 IRQ_TYPE_LEVEL_LOW>, <GIC_PPI 10 IRQ_TYPE_LEVEL_LOW>;
|
||||
};'
|
||||
TIMER_NODE_CHILD=' timer {
|
||||
compatible = "arm,armv7-timer";
|
||||
interrupts = <GIC_PPI 13 IRQ_TYPE_LEVEL_LOW>, <GIC_PPI 14 IRQ_TYPE_LEVEL_LOW>;
|
||||
sub {
|
||||
arm,cpu-registers-not-fw-configured;
|
||||
};
|
||||
};'
|
||||
|
||||
GUARD=' if (IS_ENABLED(CONFIG_ARM) && arch_timer_uses_ppi != ARCH_TIMER_VIRT_PPI &&
|
||||
!is_hyp_mode_available() &&
|
||||
clocksource_counter.vdso_clock_mode != VDSO_CLOCKMODE_NONE) {
|
||||
clocksource_counter.vdso_clock_mode = VDSO_CLOCKMODE_NONE;
|
||||
pr_info("physical counter without HYP: vDSO clock disabled\n");
|
||||
}'
|
||||
GUARD_WRONG=' if (IS_ENABLED(CONFIG_ARM) && arch_timer_uses_ppi != ARCH_TIMER_VIRT_PPI &&
|
||||
!is_hyp_mode_available()) {
|
||||
pr_info("physical counter without HYP\n");
|
||||
}'
|
||||
DEFAULT=' clocksource_counter.vdso_clock_mode = vdso_default;'
|
||||
|
||||
mk_tree() { # mk_tree <name> <dtsi timer node> <timer.c body before> <body after>
|
||||
local d="$TMP/$1"
|
||||
mkdir -p "$d/arch/arm/boot/dts/rockchip" "$d/drivers/clocksource"
|
||||
printf '/ {\n\tcpus { cpu@0 { reg = <0>; }; };\n%s\n};\n' "$2" \
|
||||
> "$d/arch/arm/boot/dts/rockchip/rv1106.dtsi"
|
||||
printf '#include "rv1106.dtsi"\n/ { model = "x"; };\n' \
|
||||
> "$d/arch/arm/boot/dts/rockchip/rv1106-warden.dts"
|
||||
printf 'static void __init arch_counter_register(void)\n{\n\tu64 (*rd)(void);\n%s\n\n%s\n\twidth = 56;\n}\n' \
|
||||
"$3" "$4" > "$d/drivers/clocksource/arm_arch_timer.c"
|
||||
echo "$d"
|
||||
}
|
||||
|
||||
fails=0 n=0
|
||||
expect() { # expect <name> <exit> <tree>
|
||||
local got out
|
||||
out="$(python3 "$CHECK" "$3" 2>&1)"; got=$?
|
||||
n=$((n + 1))
|
||||
if [ "$got" = "$2" ]; then
|
||||
echo "PASS: $1"
|
||||
else
|
||||
echo "FAIL: $1 (wanted exit $2, got $got)"
|
||||
while IFS= read -r line; do echo " $line"; done <<< "$out"
|
||||
fails=$((fails + 1))
|
||||
fi
|
||||
}
|
||||
|
||||
expect "fixed tree passes" 0 "$(mk_tree good "$TIMER_NODE_GOOD" "$DEFAULT" "$GUARD")"
|
||||
expect "timer node without the property fails" 1 "$(mk_tree bare "$TIMER_NODE_BARE" "$DEFAULT" "$GUARD")"
|
||||
expect "property only inside a comment fails" 1 "$(mk_tree comm "$TIMER_NODE_COMMENTED" "$DEFAULT" "$GUARD")"
|
||||
expect "property only in a child node fails" 1 "$(mk_tree child "$TIMER_NODE_CHILD" "$DEFAULT" "$GUARD")"
|
||||
expect "timer node with a virtual PPI needs no property" 0 "$(mk_tree virt "$TIMER_NODE_VIRT" "$DEFAULT" "$GUARD")"
|
||||
expect "missing arm32 fallback fails" 1 "$(mk_tree noguard "$TIMER_NODE_GOOD" "$DEFAULT" "")"
|
||||
expect "fallback that does not set VDSO_CLOCKMODE_NONE fails" 1 "$(mk_tree wrong "$TIMER_NODE_GOOD" "$DEFAULT" "$GUARD_WRONG")"
|
||||
expect "fallback before the vdso_default assignment fails" 1 "$(mk_tree order "$TIMER_NODE_GOOD" "$GUARD" "$DEFAULT")"
|
||||
expect "no timer node at all fails" 1 "$(mk_tree none "" "$DEFAULT" "$GUARD")"
|
||||
|
||||
d="$(mk_tree m2 "$TIMER_NODE_GOOD" "$DEFAULT" "$GUARD")"
|
||||
printf '/ {\n%s\n};\n' "$TIMER_NODE_BARE" > "$d/arch/arm/boot/dts/rockchip/rv1106-warden-m2.dts"
|
||||
expect "a second board DTS without the property fails" 1 "$d"
|
||||
|
||||
rm -f "$d/drivers/clocksource/arm_arch_timer.c"
|
||||
expect "missing arm_arch_timer.c fails" 1 "$d"
|
||||
|
||||
n=$((n + 1))
|
||||
if python3 "$CHECK" >/dev/null 2>&1; [ $? = 2 ]; then echo "PASS: no argument is a usage error"
|
||||
else echo "FAIL: no argument is a usage error"; fails=$((fails + 1)); fi
|
||||
|
||||
if [ "$fails" -ne 0 ]; then
|
||||
echo "check-vdso-counter: $fails of $n FAILED"; exit 1
|
||||
fi
|
||||
echo "check-vdso-counter: all $n passed"
|
||||
@@ -0,0 +1,120 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regression tests for build/fetch-kernel-tarball.sh (#1588).
|
||||
#
|
||||
# Runs the real script, copied into a fixture dir so its own HERE-relative pin
|
||||
# lookup finds a pin we control, with a fake curl first on PATH: no network,
|
||||
# and the outcome of each fetch is exact. Covers:
|
||||
# - curl is bounded (connect timeout, stall abort, total cap), so a server
|
||||
# that answers and then stalls cannot hold the job until its timeout;
|
||||
# - a failed fetch leaves no partial tarball behind, so the next run fetches
|
||||
# again instead of taking the partial file as present;
|
||||
# - a good fetch is verified and kept; a present, matching tarball is reused.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
SCRIPT="$HERE/../../build/fetch-kernel-tarball.sh"
|
||||
[ -f "$SCRIPT" ] || { echo "FAIL: script not found at $SCRIPT"; exit 1; }
|
||||
KVER="$(sed -n 's/^KVER=//p' "$SCRIPT")"
|
||||
[ -n "$KVER" ] || { echo "FAIL: no KVER in $SCRIPT"; exit 1; }
|
||||
|
||||
FAIL=0
|
||||
ok() { printf '[PASS] %s\n' "$1"; }
|
||||
bad() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
|
||||
|
||||
TMP="$(mktemp -d)"
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
|
||||
setup() { # setup <case-name> -> prints the fixture dir
|
||||
local dir="$TMP/$1"
|
||||
mkdir -p "$dir/bin"
|
||||
cp "$SCRIPT" "$dir/fetch-kernel-tarball.sh"
|
||||
printf 'good-bytes' | sha256sum | awk '{print $1}' \
|
||||
> "$dir/linux-$KVER.tar.xz.sha256"
|
||||
printf '%s' "$dir"
|
||||
}
|
||||
|
||||
# fake_curl <dir> <mode>: records its argv in <dir>/argv and its call count in
|
||||
# <dir>/count. Modes: good (writes the pinned bytes), partial (writes a few
|
||||
# bytes, then fails the way curl does on a timeout), never (must not run).
|
||||
fake_curl() {
|
||||
local dir="$1" mode="$2"
|
||||
# These single-quoted lines are the literal source of the fake program.
|
||||
# shellcheck disable=SC2016
|
||||
printf '%s\n' '#!/bin/sh' \
|
||||
'dir=$(dirname "$(dirname "$0")")' \
|
||||
'printf "%s\n" "$*" > "$dir/argv"' \
|
||||
'echo x >> "$dir/count"' \
|
||||
'out=' \
|
||||
'while [ "$#" -gt 0 ]; do' \
|
||||
' if [ "$1" = "-o" ]; then shift; out="$1"; fi' \
|
||||
' shift' \
|
||||
'done' \
|
||||
'[ -n "$out" ] || exit 2' \
|
||||
"case $mode in" \
|
||||
' good) printf good-bytes > "$out" ;;' \
|
||||
' partial) printf good > "$out"; exit 28 ;;' \
|
||||
' *) echo "curl should not have run" >&2; exit 1 ;;' \
|
||||
'esac' > "$dir/bin/curl"
|
||||
chmod +x "$dir/bin/curl"
|
||||
}
|
||||
|
||||
run() { # run <dir> <dest> -> output in $OUT, status in $RC
|
||||
local dir="$1" dest="$2"
|
||||
OUT="$(PATH="$dir/bin:$PATH" bash "$dir/fetch-kernel-tarball.sh" "$dest" 2>&1)"
|
||||
RC=$?
|
||||
}
|
||||
|
||||
# --- case A: a good fetch is bounded, verified and kept ---------------------
|
||||
dir="$(setup case-a)"
|
||||
fake_curl "$dir" good
|
||||
run "$dir" "$dir/linux.tar.xz"
|
||||
if [ "$RC" -eq 0 ] && [ -f "$dir/linux.tar.xz" ] \
|
||||
&& printf '%s' "$OUT" | grep -q 'tarball sha256 verified'; then
|
||||
ok "good fetch: verified and kept"
|
||||
else
|
||||
bad "good fetch: verified and kept (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
for flag in --connect-timeout --speed-limit --speed-time --max-time; do
|
||||
if grep -q -- "$flag" "$dir/argv"; then
|
||||
ok "curl carries $flag"
|
||||
else
|
||||
bad "curl carries $flag (argv: $(cat "$dir/argv"))"
|
||||
fi
|
||||
done
|
||||
if ls "$dir"/linux.tar.xz.download.* >/dev/null 2>&1; then
|
||||
bad "good fetch: no download temp file left"
|
||||
else
|
||||
ok "good fetch: no download temp file left"
|
||||
fi
|
||||
|
||||
# --- case B: a failed fetch leaves nothing, and the next run fetches again --
|
||||
dir="$(setup case-b)"
|
||||
fake_curl "$dir" partial
|
||||
run "$dir" "$dir/linux.tar.xz"
|
||||
if [ "$RC" -ne 0 ] && [ ! -e "$dir/linux.tar.xz" ] \
|
||||
&& ! ls "$dir"/linux.tar.xz.download.* >/dev/null 2>&1; then
|
||||
ok "failed fetch: no partial tarball left"
|
||||
else
|
||||
bad "failed fetch: no partial tarball left (rc=$RC, files: $(ls "$dir"))"
|
||||
fi
|
||||
fake_curl "$dir" good
|
||||
run "$dir" "$dir/linux.tar.xz"
|
||||
if [ "$RC" -eq 0 ] && [ "$(wc -l < "$dir/count")" -eq 2 ]; then
|
||||
ok "run after a failed fetch downloads again and passes"
|
||||
else
|
||||
bad "run after a failed fetch downloads again and passes (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
# --- case C: a present, matching tarball is reused without curl -------------
|
||||
dir="$(setup case-c)"
|
||||
printf 'good-bytes' > "$dir/linux.tar.xz"
|
||||
fake_curl "$dir" never
|
||||
run "$dir" "$dir/linux.tar.xz"
|
||||
if [ "$RC" -eq 0 ] && [ ! -e "$dir/count" ]; then
|
||||
ok "present tarball: reused, curl never invoked"
|
||||
else
|
||||
bad "present tarball: reused, curl never invoked (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
[ "$FAIL" -eq 0 ] && echo "fetch-kernel-tarball tests passed"
|
||||
exit "$FAIL"
|
||||
@@ -37,9 +37,13 @@ scripts=(
|
||||
"qemu/tests/stage-rootfs-perms.sh"
|
||||
"tests/fetch-vendor/run-fetch-vendor-tests.sh"
|
||||
"tests/fetch-buildroot-tarball/run-fetch-buildroot-tarball-tests.sh"
|
||||
"tests/unpack-buildroot/run-unpack-buildroot-tests.sh"
|
||||
"tests/mk-bootimg/run-boot-img-validate-tests.sh"
|
||||
"tests/mk-bootimg/run-help-tests.sh"
|
||||
"tests/mk-bootimg/run-ci-wiring-tests.sh"
|
||||
"qemu/tests/busybox-panel-test.sh"
|
||||
"qemu/tests/busybox-panel-help.sh"
|
||||
"qemu/tests/console-shell-test.sh"
|
||||
)
|
||||
|
||||
fail=0
|
||||
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bash
|
||||
# Offline test: the QEMU initramfs scripts pass the same shellcheck the qemu-tools CI job runs
|
||||
# (issue #18: `for w in $(cat /proc/cmdline)` failed it with SC2013), and the check really fires.
|
||||
# Skips with a notice when shellcheck is not installed (CI installs it).
|
||||
set -uo pipefail
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO="$(cd "$HERE/../.." && pwd)"
|
||||
TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
|
||||
FAIL=0
|
||||
ok() { printf '[PASS] %s\n' "$1"; }
|
||||
bad() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
|
||||
|
||||
if ! command -v shellcheck >/dev/null 2>&1; then
|
||||
echo "[SKIP] shellcheck is not installed"; exit 0
|
||||
fi
|
||||
|
||||
cd "$REPO" || exit 1
|
||||
if shellcheck -x qemu/rootfs/init qemu/rootfs/etc/rc qemu/rootfs/sbin/init > "$TMP/out" 2>&1; then
|
||||
ok "qemu/rootfs scripts pass shellcheck"
|
||||
else
|
||||
bad "qemu/rootfs scripts fail shellcheck"; head -20 "$TMP/out"
|
||||
fi
|
||||
|
||||
if grep -q 'read -r CMDLINE < /proc/cmdline' qemu/rootfs/init; then
|
||||
ok "init reads /proc/cmdline into a variable"
|
||||
else
|
||||
bad "init no longer reads /proc/cmdline into a variable"
|
||||
fi
|
||||
|
||||
# the old form must be red
|
||||
# shellcheck disable=SC2016 # the text is the literal old source line
|
||||
old_loop='for w in $(cat /proc/cmdline); do'
|
||||
sed -e '/^read -r CMDLINE < \/proc\/cmdline$/d' -e "s|^for w in \\\$CMDLINE; do\$|$old_loop|" qemu/rootfs/init > "$TMP/init-old"
|
||||
grep -qF "$old_loop" "$TMP/init-old" || bad "the doctored copy was not built"
|
||||
out="$(shellcheck -x "$TMP/init-old" 2>&1 || true)"
|
||||
if printf '%s' "$out" | grep -q 'SC2013'; then
|
||||
ok "doctored: the cat-in-a-for-loop form is reported as SC2013"
|
||||
else
|
||||
bad "doctored: the old form was not caught"
|
||||
fi
|
||||
|
||||
if [ "$FAIL" -eq 0 ]; then echo "ALL QEMU-INIT SHELLCHECK TESTS PASSED"; else echo "QEMU-INIT SHELLCHECK TESTS FAILED"; fi
|
||||
exit $FAIL
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
# The final kernel .config, and so KCONFIG_SHA256, must not depend on the host's python (issue #19):
|
||||
# DRM_MSM_VALIDATE_XML used to be visible only where python3 could import lxml, adding one line to the
|
||||
# file. Runs the config-only expansion twice, once with a python3 whose `import lxml` works and once with
|
||||
# one where it fails, and requires the same digest. Proven red on a copy of the tree without
|
||||
# patches/90-kconfig-no-python-symbol.patch (when this host's python3 has lxml; otherwise the red case
|
||||
# is skipped with a notice). Needs the pinned kernel tarball: KERNEL_TARBALL=<path>, or skipped.
|
||||
set -uo pipefail
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO="$(cd "$HERE/../.." && pwd)"
|
||||
TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
|
||||
FAIL=0
|
||||
ok() { printf '[PASS] %s\n' "$1"; }
|
||||
bad() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
|
||||
|
||||
if [ -z "${KERNEL_TARBALL:-}" ] || [ ! -f "$KERNEL_TARBALL" ]; then
|
||||
echo "[SKIP] set KERNEL_TARBALL to the pinned linux-6.18.46.tar.xz"; exit 0
|
||||
fi
|
||||
command -v python >/dev/null || { echo "[SKIP] needs 'python' on PATH (SDK quirk)"; exit 0; }
|
||||
REAL_PY="$(command -v python3)"
|
||||
|
||||
# a python3 on which `import lxml` fails, everything else passes through
|
||||
mkdir -p "$TMP/nolxml"
|
||||
cat > "$TMP/nolxml/python3" <<PYEOF
|
||||
#!/bin/sh
|
||||
case "\$*" in *"import lxml"*) exit 1 ;; esac
|
||||
exec "$REAL_PY" "\$@"
|
||||
PYEOF
|
||||
chmod +x "$TMP/nolxml/python3"
|
||||
# and one where it succeeds even if lxml is not installed
|
||||
mkdir -p "$TMP/lxml"
|
||||
cat > "$TMP/lxml/python3" <<PYEOF
|
||||
#!/bin/sh
|
||||
case "\$*" in *"import lxml"*) exit 0 ;; esac
|
||||
exec "$REAL_PY" "\$@"
|
||||
PYEOF
|
||||
chmod +x "$TMP/lxml/python3"
|
||||
|
||||
digest() { # digest <tree root> <path prefix dir>
|
||||
local root="$1" pfx="$2" work
|
||||
work="$(mktemp -d "$TMP/w.XXXXXX")"
|
||||
PATH="$pfx:$PATH" KERNEL_TARBALL="$KERNEL_TARBALL" WORK="$work" WARDEN_CONFIG_ONLY=1 \
|
||||
CONFIG_OUT="$work/final.config" CROSS_COMPILE="${CROSS_COMPILE:-arm-linux-gnueabihf-}" \
|
||||
bash "$root/build/build-kernel.sh" > "$work/log" 2>&1 || { tail -5 "$work/log" >&2; echo FAILED; return; }
|
||||
cat "$work/final.config.sha256"
|
||||
}
|
||||
|
||||
a="$(digest "$REPO" "$TMP/lxml")"; b="$(digest "$REPO" "$TMP/nolxml")"
|
||||
if [ "$a" != FAILED ] && [ "$a" = "$b" ]; then ok "the config digest is the same with and without a working import lxml ($a)"
|
||||
else bad "the config digest depends on the host python: with lxml $a, without $b"; fi
|
||||
|
||||
# red case: a tree without the patch
|
||||
mkdir -p "$TMP/old/patches"
|
||||
cp -r "$REPO/build" "$TMP/old/build"
|
||||
for p in "$REPO"/patches/*.patch; do [ "$(basename "$p")" = 90-kconfig-no-python-symbol.patch ] || cp "$p" "$TMP/old/patches/"; done
|
||||
oa="$(digest "$TMP/old" "$TMP/lxml")"; ob="$(digest "$TMP/old" "$TMP/nolxml")"
|
||||
if [ "$oa" = FAILED ] || [ "$ob" = FAILED ]; then bad "the doctored tree did not expand"
|
||||
elif [ "$oa" != "$ob" ]; then ok "doctored: without the patch the digests differ ($oa vs $ob), so this test can fail"
|
||||
else bad "doctored: the digests are equal even without the patch; the test proves nothing on this tarball"; fi
|
||||
|
||||
if [ "$FAIL" -eq 0 ]; then echo "ALL CONFIG-DETERMINISM TESTS PASSED"; else echo "CONFIG-DETERMINISM TESTS FAILED"; fi
|
||||
exit $FAIL
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env bash
|
||||
# Offline tests for the required-symbols mechanism (rebuild M0):
|
||||
# build/lib-required-symbols.sh, the symbol lists, and build-kernel.sh's
|
||||
# WARDEN_CONFIG_ONLY entry checks. No kernel tarball, no compiler.
|
||||
#
|
||||
# What a regression here costs: olddefconfig drops a defconfig line whose symbol
|
||||
# or dependencies are missing without a word (flare-edge#533 shipped a firewall
|
||||
# that quietly skipped IPv6 that way), so the assertion against the final
|
||||
# .config is the only thing between a dropped symbol and a panel. This proves the
|
||||
# assertion itself fires, on fake .config files, for every failure shape.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO="$(cd "$HERE/../.." && pwd)"
|
||||
LIB="$REPO/build/lib-required-symbols.sh"
|
||||
REQ="$REPO/build/required-symbols.txt"
|
||||
PROBE="$REPO/build/probe-symbols.txt"
|
||||
TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
|
||||
FAIL=0
|
||||
ok() { printf '[PASS] %s\n' "$1"; }
|
||||
bad() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
|
||||
|
||||
# shellcheck source=build/lib-required-symbols.sh
|
||||
. "$LIB"
|
||||
|
||||
# A .config that satisfies a list: every =y line verbatim, every unset line
|
||||
# absent (Kconfig writes "# CONFIG_X is not set" for those).
|
||||
mkconfig() { # <list> <out>
|
||||
{ req_assertions "$1" | grep -v '^# '
|
||||
req_assertions "$1" | grep '^# '
|
||||
echo 'CONFIG_SOMETHING_ELSE=y'; } > "$2"
|
||||
}
|
||||
|
||||
# The probe list may be empty once every probe has passed (build-kernel.sh then skips it);
|
||||
# PROBES is the list to pass along: the probe list when it holds assertions, nothing otherwise.
|
||||
PROBES=(); [ -n "$(req_assertions "$PROBE")" ] && PROBES=("$PROBE")
|
||||
mkconfig "$REQ" "$TMP/good-req"; : > "$TMP/good-probe"; [ "${#PROBES[@]}" = 0 ] || mkconfig "$PROBE" "$TMP/good-probe"; cat "$TMP/good-req" "$TMP/good-probe" > "$TMP/good"
|
||||
req_assert_config "$TMP/good" "$REQ" ${PROBES[@]+"${PROBES[@]}"} >/dev/null 2>&1 \
|
||||
&& ok "a config that satisfies both lists passes" || bad "a satisfying config was refused"
|
||||
|
||||
n=$(req_assertions "$REQ" | wc -l)
|
||||
[ "$n" -ge 40 ] && ok "required-symbols.txt holds $n assertions" || bad "required-symbols.txt holds only $n assertions"
|
||||
|
||||
# every =y assertion must be refused when its line is missing, one at a time
|
||||
missing_ok=0; missing_bad=0
|
||||
while IFS= read -r line; do
|
||||
case "$line" in CONFIG_*=y) ;; *) continue ;; esac
|
||||
grep -vxF "$line" "$TMP/good" > "$TMP/cfg-missing"
|
||||
if req_assert_config "$TMP/cfg-missing" "$REQ" ${PROBES[@]+"${PROBES[@]}"} >/dev/null 2>&1; then missing_bad=$((missing_bad+1)); echo " not caught: $line"
|
||||
else missing_ok=$((missing_ok+1)); fi
|
||||
done < <(req_assertions "$REQ"; req_assertions "$PROBE")
|
||||
[ "$missing_bad" = 0 ] && ok "dropping any one of $missing_ok =y assertions fails the check" || bad "$missing_bad dropped symbols were not caught"
|
||||
|
||||
# =m is not =y
|
||||
sed 's/^CONFIG_NFT_CT=y$/CONFIG_NFT_CT=m/' "$TMP/good" > "$TMP/cfg-m"
|
||||
req_assert_config "$TMP/cfg-m" "$REQ" ${PROBES[@]+"${PROBES[@]}"} >/dev/null 2>&1 && bad "a modular symbol was accepted" || ok "a symbol built as a module is refused"
|
||||
|
||||
# unset assertions: a live value fails, absence and 'is not set' pass
|
||||
for sym in $(req_assertions "$REQ" | sed -n 's/^# \(CONFIG_[A-Z0-9_]*\) is not set$/\1/p'); do
|
||||
{ cat "$TMP/good"; echo "$sym=y"; } > "$TMP/cfg-set"
|
||||
req_assert_config "$TMP/cfg-set" "$REQ" ${PROBES[@]+"${PROBES[@]}"} >/dev/null 2>&1 && bad "$sym=y was accepted although it must stay unset" || ok "$sym=y is refused (must stay unset)"
|
||||
grep -vF "$sym" "$TMP/good" > "$TMP/cfg-absent"
|
||||
req_assert_config "$TMP/cfg-absent" "$REQ" ${PROBES[@]+"${PROBES[@]}"} >/dev/null 2>&1 && ok "$sym absent from the config is accepted" || bad "$sym absent from the config was refused"
|
||||
done
|
||||
|
||||
# No suspend (Noah 2026-10-09): CONFIG_SUSPEND and CONFIG_PM_SLEEP are asserted unset, the
|
||||
# defconfig carries the explicit unset (SUSPEND defaults to y), and a config that
|
||||
# turns either back on is refused by name.
|
||||
DEFCONFIG="$REPO/build/warden_defconfig"
|
||||
for sym in CONFIG_SUSPEND CONFIG_PM_SLEEP; do
|
||||
req_assertions "$REQ" | grep -qxF "# $sym is not set" \
|
||||
&& ok "required-symbols.txt asserts $sym unset" || bad "required-symbols.txt does not assert $sym unset"
|
||||
{ cat "$TMP/good"; echo "$sym=y"; } > "$TMP/cfg-suspend"
|
||||
out=$(req_assert_config "$TMP/cfg-suspend" "$REQ" ${PROBES[@]+"${PROBES[@]}"} 2>&1) && bad "$sym=y was accepted" \
|
||||
|| { printf '%s' "$out" | grep -q "$sym" && ok "$sym=y is refused naming $sym" || bad "$sym=y was refused without naming it"; }
|
||||
done
|
||||
grep -qxF '# CONFIG_SUSPEND is not set' "$DEFCONFIG" \
|
||||
&& ok "warden_defconfig carries the explicit # CONFIG_SUSPEND is not set" \
|
||||
|| bad "warden_defconfig lost the explicit # CONFIG_SUSPEND is not set (the Kconfig default is y)"
|
||||
grep -qE '^CONFIG_SUSPEND=' "$DEFCONFIG" && bad "warden_defconfig sets CONFIG_SUSPEND" || ok "warden_defconfig does not set CONFIG_SUSPEND"
|
||||
|
||||
# Probe V3 passed (2026-10-09): the hardware RNG symbols are required, the probe list is empty, and
|
||||
# the config digest does not move because the defconfig already built them in.
|
||||
for sym in CONFIG_HW_RANDOM CONFIG_HW_RANDOM_ROCKCHIP; do
|
||||
req_assertions "$REQ" | grep -qxF "$sym=y" && ok "required-symbols.txt asserts $sym=y (V3 passed)" || bad "required-symbols.txt lost $sym=y"
|
||||
grep -qxF "$sym=y" "$DEFCONFIG" && ok "warden_defconfig builds $sym in" || bad "warden_defconfig does not set $sym=y"
|
||||
{ cat "$TMP/good"; } | grep -vxF "$sym=y" > "$TMP/cfg-norng"
|
||||
out=$(req_assert_config "$TMP/cfg-norng" "$REQ" 2>&1) && bad "a config without $sym was accepted" \
|
||||
|| { printf '%s' "$out" | grep -q "$sym" && ok "a config without $sym is refused naming it" || bad "refusal did not name $sym"; }
|
||||
done
|
||||
[ -z "$(req_assertions "$PROBE")" ] && ok "probe-symbols.txt is empty: every probe has passed" \
|
||||
|| ok "probe-symbols.txt holds $(req_assertions "$PROBE" | wc -l) pending probe symbol(s)"
|
||||
|
||||
# fail-closed shapes
|
||||
: > "$TMP/empty"
|
||||
req_assert_config "$TMP/empty" "$REQ" >/dev/null 2>&1 && bad "an empty config was accepted" || ok "an empty config is refused"
|
||||
req_assert_config "$TMP/good" "$TMP/no-such-list" >/dev/null 2>&1 && bad "a missing list was accepted" || ok "a missing symbol list is refused"
|
||||
printf '## only comments\n# a comment\n' > "$TMP/no-assertions"
|
||||
req_assert_config "$TMP/good" "$TMP/no-assertions" >/dev/null 2>&1 && bad "a list with no assertions was accepted" || ok "a list with no assertions is refused"
|
||||
|
||||
# comment handling: a prose line starting "# CONFIG_" without "is not set" is a comment
|
||||
printf '## c\n# CONFIG_PROSE is the name of a thing\nCONFIG_REAL=y\n' > "$TMP/prose"
|
||||
[ "$(req_assertions "$TMP/prose")" = "CONFIG_REAL=y" ] && ok "a prose comment is not an assertion" || bad "a prose comment was parsed as an assertion"
|
||||
|
||||
# the lists: a symbol is asserted once, in one list
|
||||
dups=$( { req_assertions "$REQ"; req_assertions "$PROBE"; } | sed 's/^# //; s/ is not set//; s/=.*//' | sort | uniq -d | tr '\n' ' ')
|
||||
# a symbol that passed its probe moves to the required list; it must not stay in both
|
||||
[ -z "$dups" ] && ok "no symbol is asserted twice across the lists" || bad "symbols asserted twice: $dups"
|
||||
|
||||
# build-kernel.sh entry checks (they run before the tarball is touched)
|
||||
BK="$REPO/build/build-kernel.sh"
|
||||
out=$(WARDEN_CONFIG_ONLY=2 bash "$BK" 2>&1); rc=$?
|
||||
[ "$rc" != 0 ] && printf '%s' "$out" | grep -q 'WARDEN_CONFIG_ONLY must be 0 or 1' \
|
||||
&& ok "WARDEN_CONFIG_ONLY=2 is refused" || bad "WARDEN_CONFIG_ONLY=2 was not refused"
|
||||
mkdir -p "$TMP/bin"; printf '#!/bin/sh\nexit 0\n' > "$TMP/bin/python"; chmod +x "$TMP/bin/python"
|
||||
out=$(env -u WORK -u CONFIG_OUT PATH="$TMP/bin:$PATH" WARDEN_CONFIG_ONLY=1 bash "$BK" 2>&1); rc=$?
|
||||
[ "$rc" != 0 ] && printf '%s' "$out" | grep -q 'needs CONFIG_OUT' \
|
||||
&& ok "config-only with a scratch WORK and no CONFIG_OUT is refused (the result would be deleted)" \
|
||||
|| bad "config-only without CONFIG_OUT was not refused: $out"
|
||||
|
||||
# wiring text
|
||||
grep -q 'req_assert_config "\$SRC/.config" "\$REQ_SYMBOLS" \${PROBE_LISTS' "$BK" \
|
||||
&& ok "build-kernel.sh asserts both lists" || bad "build-kernel.sh does not assert the lists"
|
||||
grep -q 'for sym in CONFIG_' "$BK" && bad "build-kernel.sh has a hand-written symbol list again" || ok "build-kernel.sh has no hand-written list"
|
||||
|
||||
if [ "$FAIL" -eq 0 ]; then echo "ALL REQUIRED-SYMBOLS TESTS PASSED"; else echo "REQUIRED-SYMBOLS TESTS FAILED"; fi
|
||||
exit $FAIL
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regression tests for build/unpack-buildroot.sh (blueflare/bfe-core1106-sdk#4).
|
||||
#
|
||||
# A clean vendor checkout plus luckfox-sdk-patches/ could not build WardenOS
|
||||
# because nothing put buildroot-2025.02.8 where the SDK builds it. The unpack
|
||||
# script is now the thing that does, and the persistent CI SDK depends on it
|
||||
# leaving an existing tree alone. These cases pin both halves: a fresh SDK
|
||||
# gets a complete tree, an existing tree is never touched or re-fetched, and
|
||||
# every refusal (unpatched selectors, a bad tarball, a half-present tree, a
|
||||
# failed fetch) leaves no tree and no scratch directory behind.
|
||||
#
|
||||
# Runs the real script, copied beside a stub fetch-buildroot-tarball.sh that
|
||||
# copies a local fixture tarball instead of downloading. No network, no SDK.
|
||||
set -uo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||
SCRIPT="$HERE/../../build/unpack-buildroot.sh"
|
||||
[ -f "$SCRIPT" ] || { echo "FAIL: script not found at $SCRIPT"; exit 1; }
|
||||
|
||||
FAIL=0
|
||||
ok() { printf '[PASS] %s\n' "$1"; }
|
||||
bad() { printf '[FAIL] %s\n' "$1"; FAIL=1; }
|
||||
|
||||
TMP="$(mktemp -d)" || { echo "FAIL: mktemp -d failed"; exit 1; }
|
||||
[ -d "$TMP" ] || { echo "FAIL: mktemp -d failed"; exit 1; }
|
||||
trap 'rm -rf "$TMP"' EXIT
|
||||
|
||||
VER=2025.02.8
|
||||
|
||||
# Fixture tarballs: a minimal Buildroot-shaped tree, and one without Makefile.
|
||||
mk_tarball() { # mk_tarball <out.tar.xz> <with-makefile:0|1>
|
||||
local out="$1" mf="$2" src
|
||||
src="$(mktemp -d "$TMP/src.XXXXXX")"
|
||||
mkdir -p "$src/buildroot-$VER/configs" "$src/buildroot-$VER/package/busybox"
|
||||
printf 'CONFIG\n' > "$src/buildroot-$VER/package/busybox/busybox.config"
|
||||
[ "$mf" = 1 ] && printf 'all:\n' > "$src/buildroot-$VER/Makefile"
|
||||
tar -cJf "$out" -C "$src" "buildroot-$VER"
|
||||
}
|
||||
mk_tarball "$TMP/good.tar.xz" 1
|
||||
mk_tarball "$TMP/nomakefile.tar.xz" 0
|
||||
|
||||
# setup <case> <tarball-or-FAIL> -> fixture dir holding build/ and sdk/
|
||||
setup() {
|
||||
local dir="$TMP/$1" src="$2"
|
||||
mkdir -p "$dir/build" "$dir/sdk/project" "$dir/sdk/sysdrv/source/buildroot"
|
||||
cp "$SCRIPT" "$dir/build/unpack-buildroot.sh"
|
||||
{
|
||||
echo '#!/usr/bin/env bash'
|
||||
echo "BRVER=$VER"
|
||||
echo "echo fetch-called >> \"$dir/fetch-calls\""
|
||||
if [ "$src" = FAIL ]; then echo 'exit 1'; else echo "cp \"$src\" \"\$1\""; fi
|
||||
} > "$dir/build/fetch-buildroot-tarball.sh"
|
||||
# shellcheck disable=SC2016 # build.sh carries the literal text
|
||||
printf 'BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/buildroot-%s\n' "$VER" \
|
||||
> "$dir/sdk/project/build.sh"
|
||||
printf 'BUILDROOT_VER ?= buildroot-%s\n' "$VER" > "$dir/sdk/sysdrv/Makefile"
|
||||
printf '%s' "$dir"
|
||||
}
|
||||
|
||||
run() { # run <dir> -> $OUT, $RC
|
||||
OUT="$(bash "$1/build/unpack-buildroot.sh" "$1/sdk" 2>&1)"; RC=$?
|
||||
}
|
||||
tree() { printf '%s' "$1/sdk/sysdrv/source/buildroot/buildroot-$VER"; }
|
||||
fetches() { [ -f "$1/fetch-calls" ] && wc -l < "$1/fetch-calls" || echo 0; }
|
||||
no_scratch() { ! compgen -G "$1/sdk/sysdrv/source/buildroot/.unpack-buildroot.*" >/dev/null; }
|
||||
|
||||
# A. Fresh SDK: fetched once, unpacked to the selected path, no scratch left.
|
||||
d="$(setup fresh "$TMP/good.tar.xz")"; run "$d"
|
||||
if [ "$RC" -eq 0 ] && [ -f "$(tree "$d")/Makefile" ] && [ -f "$(tree "$d")/package/busybox/busybox.config" ] \
|
||||
&& [ "$(fetches "$d")" -eq 1 ] && no_scratch "$d"; then
|
||||
ok "fresh SDK: tree unpacked, one fetch, no scratch left"
|
||||
else
|
||||
bad "fresh SDK: tree unpacked, one fetch, no scratch left (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
# B. Rerun on that SDK: already present, no second fetch, content untouched.
|
||||
printf 'LOCAL\n' > "$(tree "$d")/package/busybox/busybox.config"
|
||||
run "$d"
|
||||
if [ "$RC" -eq 0 ] && printf '%s' "$OUT" | grep -q 'tree already present' \
|
||||
&& [ "$(fetches "$d")" -eq 1 ] && grep -qx LOCAL "$(tree "$d")/package/busybox/busybox.config"; then
|
||||
ok "existing tree: left alone, not re-fetched"
|
||||
else
|
||||
bad "existing tree: left alone, not re-fetched (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
# C. project/build.sh still selects the vendor tree: refuse, fetch nothing.
|
||||
d="$(setup unpatched-build "$TMP/good.tar.xz")"
|
||||
# shellcheck disable=SC2016 # build.sh carries the literal text
|
||||
printf 'BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/buildroot-2023.02.6\n' > "$d/sdk/project/build.sh"
|
||||
run "$d"
|
||||
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'project/build.sh selects' \
|
||||
&& [ "$(fetches "$d")" -eq 0 ] && [ ! -e "$(tree "$d")" ]; then
|
||||
ok "unpatched project/build.sh: refused before fetching"
|
||||
else
|
||||
bad "unpatched project/build.sh: refused before fetching (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
# D. sysdrv/Makefile still selects the vendor tree: refuse, fetch nothing.
|
||||
d="$(setup unpatched-make "$TMP/good.tar.xz")"
|
||||
printf 'BUILDROOT_VER ?= buildroot-2023.02.6\n' > "$d/sdk/sysdrv/Makefile"
|
||||
run "$d"
|
||||
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'sysdrv/Makefile selects' \
|
||||
&& [ "$(fetches "$d")" -eq 0 ] && [ ! -e "$(tree "$d")" ]; then
|
||||
ok "unpatched sysdrv/Makefile: refused before fetching"
|
||||
else
|
||||
bad "unpatched sysdrv/Makefile: refused before fetching (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
# E. Tarball without a Buildroot Makefile: refuse, no tree, no scratch.
|
||||
d="$(setup bad-tarball "$TMP/nomakefile.tar.xz")"; run "$d"
|
||||
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'did not contain' \
|
||||
&& [ ! -e "$(tree "$d")" ] && no_scratch "$d"; then
|
||||
ok "tarball without Makefile: refused, nothing left behind"
|
||||
else
|
||||
bad "tarball without Makefile: refused, nothing left behind (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
# F. A half-present tree (an interrupted hand unpack): refuse, keep it as is.
|
||||
d="$(setup half-tree "$TMP/good.tar.xz")"
|
||||
mkdir -p "$(tree "$d")/output"; printf 'keep\n' > "$(tree "$d")/output/marker"
|
||||
run "$d"
|
||||
if [ "$RC" -ne 0 ] && printf '%s' "$OUT" | grep -q 'not a complete Buildroot tree' \
|
||||
&& [ -f "$(tree "$d")/output/marker" ] && [ "$(fetches "$d")" -eq 0 ]; then
|
||||
ok "half-present tree: refused and left untouched"
|
||||
else
|
||||
bad "half-present tree: refused and left untouched (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
# G. Fetch fails (network down, sha256 mismatch): nonzero, no tree.
|
||||
d="$(setup fetch-fails FAIL)"; run "$d"
|
||||
if [ "$RC" -ne 0 ] && [ ! -e "$(tree "$d")" ] && no_scratch "$d"; then
|
||||
ok "failed fetch: nonzero, no tree"
|
||||
else
|
||||
bad "failed fetch: nonzero, no tree (rc=$RC, out=$OUT)"
|
||||
fi
|
||||
|
||||
if [ "$FAIL" -eq 0 ]; then echo "ALL UNPACK-BUILDROOT TESTS PASSED"; else echo "UNPACK-BUILDROOT TESTS FAILED"; fi
|
||||
exit "$FAIL"
|
||||
Reference in New Issue
Block a user