Files
bfe-core1106-sdk/tests/unpack-buildroot/run-unpack-buildroot-tests.sh
T
NoahandClaude Opus 5.5 67da1141a0
ci / badges (push) Skipped
ci / mcdc (push) Successful in 18s
ci / test (push) Successful in 17s
ci / bench (push) Successful in 5s
ci / qemu-tools (push) Successful in 41s
ci / patches-apply (push) Successful in 20s
ci / prune-artifacts (push) Skipped
ci / kernel-build (push) Skipped
ci / quality (push) Successful in 31s
ci / test (pull_request) Successful in 15s
ci / mcdc (pull_request) Successful in 13s
ci / bench (pull_request) Successful in 5s
ci / qemu-tools (pull_request) Successful in 39s
ci / patches-apply (pull_request) Successful in 14s
ci / kernel-build (pull_request) Skipped
ci / prune-artifacts (pull_request) Skipped
ci / quality (pull_request) Successful in 27s
ci / badges (pull_request) Skipped
build: unpack the pinned Buildroot tree into the vendor SDK
build/unpack-buildroot.sh fetches buildroot-2025.02.8 through
fetch-buildroot-tarball.sh (sha256-pinned) and unpacks it to
sysdrv/source/buildroot/buildroot-2025.02.8, the tree the patched
project/build.sh and sysdrv/Makefile select. It refuses an SDK whose
selectors are not patched, leaves an existing tree alone, and never leaves a
partial tree at the final path. flare-edge's build-firmware.sh calls it right
after applying luckfox-sdk-patches/.

Offline regression tests cover the fresh unpack, the existing-tree no-op and
every refusal path; the qemu-tools job runs and shellchecks them.

Refs #4

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01441BzdGcvQmXkiN2qDjfZg
2026-09-28 11:10:53 -06:00

139 lines
6.1 KiB
Bash
Executable File

#!/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"