The collected-module gate moves to build/lib-module-gate.sh, which build-kernel.sh sources. Every WARDEN_MODULES_COLLECT module must carry this kernel's vermagic before it is copied, and the test-only directory needs CONFIG_WARDEN_TEST_HANG=m after olddefconfig. The grep-only checks of run-test-hang-tests.sh never ran either refusal path. run-module-gate-tests.sh runs them on fixtures, with no kernel tree and no compiler: a stale module is refused and not copied, in the test-only list and in the aic8800 release list, and a symbol that is not =m is refused. Accepting every vermagic fails five of its checks (mutation check). run-missing-tools-tests.sh lists find and cp among its base tools: the collection step and the fixtures use them. Refs blueflare/bfe-core1106-sdk#56 Refs flare-edge sp/m4a-e-f5-kernel-hang-module (F5, AT-M4-01, AT-M4-12) Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B1W6qGNpGNtFT7nhShpH56
181 lines
8.0 KiB
Bash
Executable File
181 lines
8.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Hermetic tests for the collected-module gate (build/lib-module-gate.sh): a
|
|
# module whose vermagic is not this kernel's is refused before it is copied,
|
|
# in the test-only list and in a release list (aic8800), and the test-only
|
|
# directory needs CONFIG_WARDEN_TEST_HANG=m. Fixtures only: no kernel tree, no
|
|
# compiler, no network. The refusal paths run with a module of the wrong
|
|
# vermagic, which the grep-only checks in run-test-hang-tests.sh never did.
|
|
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; }
|
|
|
|
# shellcheck source=build/lib-module-gate.sh
|
|
. "$REPO/build/lib-module-gate.sh"
|
|
|
|
KREL=6.18.46
|
|
GOOD="6.18.46 SMP preempt mod_unload ARMv7 p2v8"
|
|
STALE="5.10.0 SMP preempt mod_unload ARMv7"
|
|
|
|
# mkko <file> <vermagic>: a fixture module whose .modinfo holds the vermagic as
|
|
# a NUL-separated string, the way a built .ko does.
|
|
mkko() {
|
|
mkdir -p "$(dirname "$1")"
|
|
printf '\177ELF\000\000\000modinfo\000license=GPL\000vermagic=%s\000depends=\000' "$2" > "$1"
|
|
}
|
|
|
|
# expect <label> <want status> <command...>: the command's status is checked.
|
|
expect() {
|
|
local label=$1 want=$2 rc
|
|
shift 2
|
|
"$@" > "$TMP/out" 2>&1; rc=$?
|
|
if [ "$rc" -eq "$want" ]; then ok "$label"; else bad "$label (status $rc, want $want): $(tr '\n' ' ' < "$TMP/out")"; fi
|
|
}
|
|
|
|
# expect_msg <label> <want status> <text> <command...>: the status and the
|
|
# FATAL text (a fixed string) must both be there.
|
|
expect_msg() {
|
|
local label=$1 want=$2 text=$3 rc
|
|
shift 3
|
|
"$@" > "$TMP/out" 2>&1; rc=$?
|
|
if [ "$rc" -eq "$want" ] && grep -qF -- "$text" "$TMP/out"; then
|
|
ok "$label"
|
|
else
|
|
bad "$label (status $rc, want $want, text '$text'): $(tr '\n' ' ' < "$TMP/out")"
|
|
fi
|
|
}
|
|
|
|
# --- the vermagic of one module ---------------------------------------------
|
|
|
|
mkko "$TMP/v/good.ko" "$GOOD"
|
|
expect "a module of this kernel's vermagic passes" 0 module_vermagic_check "$KREL" "$TMP/v/good.ko"
|
|
mkko "$TMP/v/stale.ko" "$STALE"
|
|
expect_msg "a 5.10 module is refused, the vermagic named" 1 "is not this kernel's '6.18.46'" \
|
|
module_vermagic_check "$KREL" "$TMP/v/stale.ko"
|
|
mkko "$TMP/v/rc.ko" "6.18.46-rc1 SMP preempt mod_unload ARMv7"
|
|
expect_msg "a release that only starts with this kernel's string is refused" 1 "is not this kernel's" \
|
|
module_vermagic_check "$KREL" "$TMP/v/rc.ko"
|
|
printf '\177ELF\000\000\000modinfo\000license=GPL\000depends=\000' > "$TMP/v/none.ko"
|
|
expect_msg "a module with no vermagic is refused" 1 "has no vermagic" \
|
|
module_vermagic_check "$KREL" "$TMP/v/none.ko"
|
|
expect_msg "an empty kernel release is refused" 1 "kernel release is empty" \
|
|
module_vermagic_check "" "$TMP/v/good.ko"
|
|
|
|
# --- the collected list: copied only when every module passes ----------------
|
|
|
|
# The test-only list: a module of this kernel is collected and counted.
|
|
T1="$TMP/tree-good"
|
|
mkko "$T1/drivers/warden-test/warden_hang.ko" "$GOOD"
|
|
mkdir -p "$TMP/out-good"
|
|
if collect_modules "$T1" drivers/warden-test "$KREL" "$TMP/out-good" \
|
|
&& [ "$COLLECTED" = 1 ] && [ -f "$TMP/out-good/warden_hang.ko" ]; then
|
|
ok "the test-only list collects the module of this kernel (count 1, copied)"
|
|
else
|
|
bad "the test-only list collects the module of this kernel (count ${COLLECTED:-unset})"
|
|
fi
|
|
|
|
# The test-only list with a stale module: refused, and the stale .ko is not copied.
|
|
T2="$TMP/tree-stale-test"
|
|
mkko "$T2/drivers/warden-test/warden_hang.ko" "$STALE"
|
|
mkdir -p "$TMP/out-stale-test"
|
|
collect_modules "$T2" drivers/warden-test "$KREL" "$TMP/out-stale-test" > "$TMP/out" 2>&1; rc=$?
|
|
if [ "$rc" -eq 1 ] && grep -qF "is not this kernel's '6.18.46'" "$TMP/out" \
|
|
&& [ ! -e "$TMP/out-stale-test/warden_hang.ko" ]; then
|
|
ok "a stale module in the test-only list is refused and not copied"
|
|
else
|
|
bad "a stale module in the test-only list is refused and not copied (status $rc): $(tr '\n' ' ' < "$TMP/out")"
|
|
fi
|
|
|
|
# A release list (aic8800, as ci.yml lists it) gets the same gate: one stale
|
|
# module among good ones refuses the list and the stale module is not copied.
|
|
T3="$TMP/tree-stale-release"
|
|
D3=drivers/net/wireless/aic8800
|
|
mkko "$T3/$D3/aic8800_fdrv.ko" "$STALE"
|
|
mkko "$T3/$D3/aic8800_btlpm.ko" "$GOOD"
|
|
mkdir -p "$TMP/out-stale-release"
|
|
collect_modules "$T3" "$D3" "$KREL" "$TMP/out-stale-release" > "$TMP/out" 2>&1; rc=$?
|
|
if [ "$rc" -eq 1 ] && grep -qF "is not this kernel's" "$TMP/out" \
|
|
&& [ ! -e "$TMP/out-stale-release/aic8800_fdrv.ko" ]; then
|
|
ok "a stale module in a release list (aic8800) is refused and not copied"
|
|
else
|
|
bad "a stale module in a release list (aic8800) is refused and not copied (status $rc)"
|
|
fi
|
|
|
|
# A good release list collects every module.
|
|
T4="$TMP/tree-good-release"
|
|
mkko "$T4/$D3/aic8800_fdrv.ko" "$GOOD"
|
|
mkko "$T4/$D3/aic8800_btlpm.ko" "$GOOD"
|
|
mkdir -p "$TMP/out-good-release"
|
|
if collect_modules "$T4" "$D3" "$KREL" "$TMP/out-good-release" && [ "$COLLECTED" = 2 ]; then
|
|
ok "a good release list collects both modules (count 2)"
|
|
else
|
|
bad "a good release list collects both modules (count ${COLLECTED:-unset})"
|
|
fi
|
|
|
|
expect_msg "a listed directory missing from the tree is refused" 1 "not in tree" \
|
|
collect_modules "$TMP/tree-absent" drivers/warden-test "$KREL" "$TMP/out-good"
|
|
mkdir -p "$TMP/tree-empty/drivers/warden-test"
|
|
expect_msg "a listed directory with no module is refused" 1 "no .ko produced" \
|
|
collect_modules "$TMP/tree-empty" drivers/warden-test "$KREL" "$TMP/out-good"
|
|
|
|
# --- the test symbol: which directory needs it, and what it must be ----------
|
|
|
|
if [ "$(test_symbol_of drivers/warden-test)" = WARDEN_TEST_HANG ]; then
|
|
ok "the test-only directory maps to CONFIG_WARDEN_TEST_HANG"
|
|
else
|
|
bad "the test-only directory maps to CONFIG_WARDEN_TEST_HANG"
|
|
fi
|
|
if [ -z "$(test_symbol_of drivers/net/wireless/aic8800)" ]; then
|
|
ok "a release directory needs no test symbol"
|
|
else
|
|
bad "a release directory needs no test symbol"
|
|
fi
|
|
|
|
printf 'CONFIG_WARDEN_TEST_HANG=m\n' > "$TMP/cfg-m"
|
|
expect "=m after olddefconfig passes for the test-only directory" 0 \
|
|
require_test_config "$TMP/cfg-m" drivers/warden-test
|
|
printf 'CONFIG_WARDEN_TEST_HANG=y\n' > "$TMP/cfg-y"
|
|
expect_msg "=y is refused (it would not give a .ko)" 1 "needs CONFIG_WARDEN_TEST_HANG=m" \
|
|
require_test_config "$TMP/cfg-y" drivers/warden-test
|
|
printf '# CONFIG_WARDEN_TEST_HANG is not set\n' > "$TMP/cfg-unset"
|
|
expect_msg "an unset symbol is refused (the dependency was unmet)" 1 "did not survive olddefconfig" \
|
|
require_test_config "$TMP/cfg-unset" drivers/warden-test
|
|
: > "$TMP/cfg-none"
|
|
expect_msg "a configuration without the symbol is refused" 1 "did not survive olddefconfig" \
|
|
require_test_config "$TMP/cfg-none" drivers/warden-test
|
|
expect "a missing configuration file is refused" 1 \
|
|
require_test_config "$TMP/cfg-absent" drivers/warden-test
|
|
expect "a release list needs no symbol in any configuration" 0 \
|
|
require_test_config "$TMP/cfg-none" drivers/net/wireless/aic8800
|
|
|
|
# --- build-kernel.sh runs the gate on every collected list ------------------
|
|
|
|
BK="$REPO/build/build-kernel.sh"
|
|
if grep -q '^\. "\$HERE/lib-module-gate\.sh"$' "$BK"; then
|
|
ok "build-kernel.sh sources the module gate"
|
|
else
|
|
bad "build-kernel.sh sources the module gate"
|
|
fi
|
|
if grep -q 'collect_modules "\$SRC" "\$d" "\$KREL" "\$MODOUT" || exit 1' "$BK"; then
|
|
ok "build-kernel.sh collects every listed directory through collect_modules"
|
|
else
|
|
bad "build-kernel.sh collects every listed directory through collect_modules"
|
|
fi
|
|
if grep -q 'require_test_config "\$SRC/.config" "\$d" || exit 1' "$BK"; then
|
|
ok "build-kernel.sh asserts the test symbol after olddefconfig"
|
|
else
|
|
bad "build-kernel.sh asserts the test symbol after olddefconfig"
|
|
fi
|
|
if grep -v '^[[:space:]]*#' "$BK" | grep -q 'WARDEN_TEST_HANG\|warden-test'; then
|
|
bad "build-kernel.sh names the test directory or symbol in code (it belongs in the gate)"
|
|
else
|
|
ok "build-kernel.sh names the test directory and symbol only in comments"
|
|
fi
|
|
|
|
if [ "$FAIL" -eq 0 ]; then echo "module-gate: all checks passed"; else echo "module-gate: FAILED"; fi
|
|
exit "$FAIL"
|