qemu init: read the command line without for-in-cat (blueflare/bfe-core1106-sdk#18)
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
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
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
8615f7c13a
commit
0589829619
@@ -113,6 +113,8 @@ jobs:
|
||||
qemu/rootfs/sbin/init qemu/rootfs/init tests/mk-bootimg/*.sh \
|
||||
tests/fetch-vendor/*.sh tests/fetch-buildroot-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
|
||||
|
||||
+2
-1
@@ -50,7 +50,8 @@ 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).
|
||||
for w in $(cat /proc/cmdline); do
|
||||
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
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user