ci / test (push) Canceled after 0s
ci / mcdc (push) Canceled after 0s
ci / bench (push) Canceled after 0s
ci / bench (pull_request) Canceled after 0s
ci / qemu-tools (pull_request) Canceled after 0s
ci / quality (push) Canceled after 0s
ci / kernel-symbols (pull_request) Canceled after 0s
ci / badges (push) Canceled after 0s
ci / prune-artifacts (pull_request) Canceled after 0s
ci / badges (pull_request) Canceled after 0s
ci / qemu-tools (push) Canceled after 0s
ci / kernel-symbols (push) Canceled after 0s
ci / test (pull_request) Canceled after 0s
ci / patches-apply (push) Canceled after 0s
ci / mcdc (pull_request) Canceled after 0s
ci / prune-artifacts (push) Canceled after 0s
ci / kernel-build (push) Canceled after 0s
ci / patches-apply (pull_request) Canceled after 0s
ci / kernel-build (pull_request) Canceled after 0s
ci / quality (pull_request) Canceled after 0s
shellcheck 0.9 in the qemu-tools CI job reports SC2013 for `for w in $(cat /proc/cmdline)` and exits non-zero, which kept CI red on the M0 kernel branch since the warden.run entry was added. Read /proc/cmdline into a variable and loop over its words. Regression test: tests/qemu-init/run-init-shellcheck-tests.sh (run by the qemu-tools job) shellchecks the rootfs scripts and proves the old form red on a doctored copy. Fixes #18. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cxh2piVufTWbzKTmUafTkk
44 lines
1.7 KiB
Bash
Executable File
44 lines
1.7 KiB
Bash
Executable File
#!/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
|