build/lib-module-gate.sh is sourced and has no shebang, so the CI shellcheck run over build/*.sh reports SC2148 on it. Add the directive that build/lib-required-symbols.sh already carries. Comment only: no behaviour change. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B1W6qGNpGNtFT7nhShpH56
72 lines
2.8 KiB
Bash
72 lines
2.8 KiB
Bash
# shellcheck shell=bash
|
|
# Gate for the kernel modules a build collects (WARDEN_MODULES_COLLECT in
|
|
# build-kernel.sh). Sourced, not run: reading it changes nothing.
|
|
#
|
|
# Every collected module must carry this kernel's vermagic, so a module built
|
|
# against another tree, or a hand-copied .ko, cannot reach an image. A
|
|
# directory that needs a test-only Kconfig symbol must find it =m after
|
|
# olddefconfig. tests/test-hang/run-module-gate-tests.sh runs these functions
|
|
# against fixtures, including the refusal paths.
|
|
|
|
# The test-only Kconfig symbol a collected directory needs (empty for the rest).
|
|
# Release and debug builds list no test directory, so they get no symbol.
|
|
test_symbol_of() {
|
|
case "$1" in
|
|
drivers/warden-test) echo WARDEN_TEST_HANG ;;
|
|
*) : ;;
|
|
esac
|
|
}
|
|
|
|
# module_vermagic_check <kernel release> <module file>: 0 when the module's
|
|
# vermagic is "<release> " (the release, then a space), else 1 with a FATAL line.
|
|
module_vermagic_check() {
|
|
local krel=$1 ko=$2 vm
|
|
if [ -z "$krel" ]; then
|
|
echo "FATAL: kernel release is empty" >&2
|
|
return 1
|
|
fi
|
|
# vermagic is a NUL-separated .modinfo string; one printable run per line.
|
|
vm="$(tr -c '[:print:]' '\n' < "$ko" | grep -m1 '^vermagic=' || true)"
|
|
case "$vm" in
|
|
"vermagic=$krel "*) return 0 ;;
|
|
'') echo "FATAL: $(basename "$ko") has no vermagic" >&2 ;;
|
|
*) echo "FATAL: $(basename "$ko") vermagic '${vm#vermagic=}' is not this kernel's '$krel'" >&2 ;;
|
|
esac
|
|
return 1
|
|
}
|
|
|
|
# collect_modules <source tree> <dir> <kernel release> <out dir>: copies every
|
|
# .ko under <source tree>/<dir> into <out dir>, each only after it passed
|
|
# module_vermagic_check. Sets COLLECTED to the count. Returns 1 at the first
|
|
# module that fails, when the directory is missing, or when it yields none.
|
|
collect_modules() {
|
|
local src=$1 d=$2 krel=$3 out=$4 ko
|
|
COLLECTED=0
|
|
if [ ! -d "$src/$d" ]; then
|
|
echo "FATAL: WARDEN_MODULES_COLLECT dir '$d' not in tree" >&2
|
|
return 1
|
|
fi
|
|
while IFS= read -r ko; do
|
|
module_vermagic_check "$krel" "$ko" || return 1
|
|
cp "$ko" "$out/" || return 1
|
|
COLLECTED=$((COLLECTED + 1))
|
|
done < <(find "$src/$d" -name '*.ko')
|
|
if [ "$COLLECTED" -eq 0 ]; then
|
|
echo "FATAL: no .ko produced under '$d'" >&2
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# require_test_config <kernel .config> <dir>: a directory with a test symbol
|
|
# must find it =m in the configuration after olddefconfig (an unmet dependency
|
|
# drops the symbol without a word). Returns 1 with a FATAL line otherwise.
|
|
require_test_config() {
|
|
local cfg=$1 d=$2 sym
|
|
sym="$(test_symbol_of "$d")"
|
|
[ -n "$sym" ] || return 0
|
|
if ! grep -qx "CONFIG_${sym}=m" "$cfg" 2>/dev/null; then
|
|
echo "FATAL: $d needs CONFIG_${sym}=m, which did not survive olddefconfig" >&2
|
|
return 1
|
|
fi
|
|
}
|