Skip to content

Commit 7046388

Browse files
committed
Undo clang-format damage to tests/replay script
1 parent e2506dc commit 7046388

1 file changed

Lines changed: 77 additions & 82 deletions

File tree

tests/replay

Lines changed: 77 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,51 @@
1-
#!/ bin / sh
2-
#This file is part of KASLD - https: // github.com/bcoles/kasld
1+
#!/bin/sh
2+
# This file is part of KASLD - https://github.com/bcoles/kasld
33
#
4-
#replay — end - to - end smoke harness : run the real kasld binary over captured
5-
#fixtures.
4+
# replay — end-to-end smoke harness: run the real kasld binary over captured
5+
# fixtures.
66
#
7-
#For each fixture under tests / fixtures / < arch> / < host> /, \
8-
reconstruct a scratch
9-
#sysroot from its captured filesystem state and run `kasld - v` over it.The
10-
#check is that kasld RUNS to completion — parses the fixture, resolves the
11-
#engine, renders a summary — without crashing.There is no in - process oracle to
12-
#diff against and no stored golden master : the committed fixture is just
13-
#sysroot / +meta.txt + sizes.txt, and nothing depends on the volatile verbose
14-
#output.Truth - containment and per - \
15-
rule soundness are covered by the pure unit
16-
#tests(make check / test_engine / test_engine_integration); this is the
17-
#end - to - end "does the real binary run on real captured layouts" check.
7+
# For each fixture under tests/fixtures/<arch>/<host>/, reconstruct a scratch
8+
# sysroot from its captured filesystem state and run `kasld -v` over it. The
9+
# check is that kasld RUNS to completion — parses the fixture, resolves the
10+
# engine, renders a summary — without crashing. There is no in-process oracle to
11+
# diff against and no stored golden master: the committed fixture is just
12+
# sysroot/ + meta.txt + sizes.txt, and nothing depends on the volatile verbose
13+
# output. Truth-containment and per-rule soundness are covered by the pure unit
14+
# tests (make check / test_engine / test_engine_integration); this is the
15+
# end-to-end "does the real binary run on real captured layouts" check.
1816
#
19-
#Two modes:
20-
#- Native(KASLD_NATIVE = 1) : run host - arch fixtures directly, no qemu.CI runs
21-
#this(x86_64 + x86_32 on an x86_64 runner); foreign - arch fixtures skip.
22-
#- Default : run every fixture, using qemu - user for foreign arches.Needs the
23-
#cross binaries from `make cross` and qemu - user in QEMU_DIR.
17+
# Two modes:
18+
# - Native (KASLD_NATIVE=1): run host-arch fixtures directly, no qemu. CI runs
19+
# this (x86_64 + x86_32 on an x86_64 runner); foreign-arch fixtures skip.
20+
# - Default: run every fixture, using qemu-user for foreign arches. Needs the
21+
# cross binaries from `make cross` and qemu-user in QEMU_DIR.
2422
#
25-
#Only a crash(death by signal) is a failure.A run yielding no results or no
26-
#summary is informational : foreign - arch component children do not exec under
27-
#nested qemu - user, so those fixtures legitimately produce nothing under
28-
#emulation, \
29-
and whether a leak / probe component fires is environment - dependent.
23+
# Only a crash (death by signal) is a failure. A run yielding no results or no
24+
# summary is informational: foreign-arch component children do not exec under
25+
# nested qemu-user, so those fixtures legitimately produce nothing under
26+
# emulation, and whether a leak/probe component fires is environment-dependent.
3027
#
31-
#Usage : tests / replay[FIXTURE_DIR...](default : all under tests / fixtures)
32-
#Env : QEMU_DIR(default / home / user / qemu / build)
33-
#BUILD_DIR(default./ build)
34-
#KASLD_NATIVE = 1 run host - arch fixtures directly, no qemu(CI mode).
35-
#Foreign - arch fixtures are skipped; the binary is taken
36-
#from build / < arch> - */ (any triple, gnu or musl).
37-
#KEEP = 1 keep the scratch sysroot of the last fixture for inspection
38-
#-- -
39-
#<bcoles @gmail.com>
40-
41-
set - u
42-
43-
ROOT = $(CDPATH ='' cd-- "$(dirname -- " $0 ")/.." && pwd) QEMU_DIR =
44-
${QEMU_DIR : -/ home / user / qemu / build} BUILD_DIR =
45-
${BUILD_DIR : -$ROOT / build} FIXROOT = $ROOT / tests /
46-
fixtures
47-
48-
#Map a raw `uname - m` to "<build-subdir> <qemu-binary>".Endianness lives in
49-
#the raw machine string(mips vs mipsel, ppc64 vs ppc64le), which is why this
50-
#keys on uname_m_raw, not the coarser canonical arch.
51-
target_for() {
28+
# Usage: tests/replay [FIXTURE_DIR ...] (default: all under tests/fixtures)
29+
# Env: QEMU_DIR (default /home/user/qemu/build)
30+
# BUILD_DIR (default ./build)
31+
# KASLD_NATIVE=1 run host-arch fixtures directly, no qemu (CI mode).
32+
# Foreign-arch fixtures are skipped; the binary is taken
33+
# from build/<arch>-*/ (any triple, gnu or musl).
34+
# KEEP=1 keep the scratch sysroot of the last fixture for inspection
35+
# ---
36+
# <bcoles@gmail.com>
37+
38+
set -u
39+
40+
ROOT=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd)
41+
QEMU_DIR=${QEMU_DIR:-/home/user/qemu/build}
42+
BUILD_DIR=${BUILD_DIR:-$ROOT/build}
43+
FIXROOT=$ROOT/tests/fixtures
44+
45+
# Map a raw `uname -m` to "<build-subdir> <qemu-binary>". Endianness lives in
46+
# the raw machine string (mips vs mipsel, ppc64 vs ppc64le), which is why this
47+
# keys on uname_m_raw, not the coarser canonical arch.
48+
target_for() {
5249
case "$1" in
5350
x86_64) echo "x86_64-linux-musl qemu-x86_64" ;;
5451
i686 | i386) echo "i686-unknown-linux-musl qemu-i386" ;;
@@ -72,11 +69,11 @@ ${BUILD_DIR : -$ROOT / build} FIXROOT = $ROOT / tests /
7269
esac
7370
}
7471

75-
#Native(KASLD_NATIVE = 1) helpers : run host - runnable fixtures with no qemu.
72+
# Native (KASLD_NATIVE=1) helpers: run host-runnable fixtures with no qemu.
7673
HOST_ARCH=$(uname -m)
7774

78-
#True if the host can execute fixtures of uname_m_raw $1 directly.An x86_64
79-
#host also runs 32 - bit x86; otherwise the arch must match exactly.
75+
# True if the host can execute fixtures of uname_m_raw $1 directly. An x86_64
76+
# host also runs 32-bit x86; otherwise the arch must match exactly.
8077
native_ok() {
8178
case "$HOST_ARCH" in
8279
x86_64 | amd64) case "$1" in x86_64 | i686 | i386) return 0 ;; esac ;;
@@ -85,11 +82,9 @@ native_ok() {
8582
return 1
8683
}
8784

88-
#Echo a build / < \
89-
arch> - */ dir holding a host - runnable kasld for uname_m_raw $1,
90-
# or nothing.Globs the arch prefix so any triple matches(x86_64 - linux - \
91-
gnu from
92-
# `make`, x86_64 - linux - musl from `make cross`, i686 - linux - gnu, ...).
85+
# Echo a build/<arch>-*/ dir holding a host-runnable kasld for uname_m_raw $1,
86+
# or nothing. Globs the arch prefix so any triple matches (x86_64-linux-gnu from
87+
# `make`, x86_64-linux-musl from `make cross`, i686-linux-gnu, ...).
9388
native_bindir() {
9489
case "$1" in
9590
x86_64) set -- "$BUILD_DIR"/x86_64-* ;;
@@ -101,13 +96,13 @@ native_bindir() {
10196
done
10297
}
10398

104-
#Pull "key:value" out of a fixture meta.txt(collect's format).
99+
# Pull "key:value" out of a fixture meta.txt (collect's format).
105100
meta() { grep -E "^$2:" "$1/meta.txt" 2>/dev/null | head -1 | sed -E 's/^[^:]*:[[:space:]]*//'; }
106101

107102
pass=0; fail=0; skip=0; scratch_keep=""
108103

109104
for fx in "${@:-$FIXROOT/*/*}"; do
110-
#Expand the default glob; skip non - dirs.
105+
# Expand the default glob; skip non-dirs.
111106
for d in $fx; do
112107
[ -d "$d" ] || continue
113108
name=$(echo "$d" | sed "s#$FIXROOT/##")
@@ -120,7 +115,7 @@ for fx in "${@:-$FIXROOT/*/*}"; do
120115
release=$(meta "$d" kernel_release)
121116

122117
if [ "${KASLD_NATIVE:-0}" = 1 ]; then
123-
#No qemu : only fixtures the host can run directly; binary from build /.
118+
# No qemu: only fixtures the host can run directly; binary from build/.
124119
if ! native_ok "$machine"; then
125120
printf 'SKIP %-44s (native mode: non-host arch %s)\n' "$name" "$machine"; skip=$((skip+1)); continue
126121
fi
@@ -146,8 +141,8 @@ for fx in "${@:-$FIXROOT/*/*}"; do
146141
runner="$QEMU_DIR/$qbin"
147142
fi
148143

149-
#Reconstruct a scratch sysroot : copy captured facts, then materialise the
150-
#/ boot images as sparse files of their true size(header prefix preserved).
144+
# Reconstruct a scratch sysroot: copy captured facts, then materialise the
145+
# /boot images as sparse files of their true size (header prefix preserved).
151146
sc=$(mktemp -d)
152147
cp -a "$d/sysroot" "$sc/r"
153148
while read -r sz path; do
@@ -156,34 +151,34 @@ for fx in "${@:-$FIXROOT/*/*}"; do
156151
truncate -s "$sz" "$sc/r$path" 2>/dev/null
157152
done < "$d/sizes.txt"
158153

159-
#Release handling : QEMU_UNAME sets the top - level process's uname, but is
160-
#NOT honored after qemu's self-re-exec for foreign-arch component children
161-
# — so KASLD_UNAME_RELEASE(read by kasld_uname(), propagated via the
162-
#environment) is what actually gives every process the fixture's release
163-
#for / boot path construction.Both are set; the latter is the load - bearing
164-
#one.
165-
#
166-
#KASLD_EXEC_WRAPPER lets the orchestrator's component children execve
167-
#through the host - arch qemu wrapper instead of trying to execve a guest -
168-
#arch ELF directly(which the host kernel refuses with ENOEXEC unless
169-
#binfmt_misc is registered).When $runner is non - empty(foreign - arch
170-
#fixture) we point KASLD_EXEC_WRAPPER at it; for native - arch fixtures
171-
#$runner is empty and KASLD_EXEC_WRAPPER stays unset, so the orchestrator
172-
#takes the production direct - execve path.
154+
# Release handling: QEMU_UNAME sets the top-level process's uname, but is
155+
# NOT honored after qemu's self-re-exec for foreign-arch component children
156+
# — so KASLD_UNAME_RELEASE (read by kasld_uname(), propagated via the
157+
# environment) is what actually gives every process the fixture's release
158+
# for /boot path construction. Both are set; the latter is the load-bearing
159+
# one.
160+
#
161+
# KASLD_EXEC_WRAPPER lets the orchestrator's component children execve
162+
# through the host-arch qemu wrapper instead of trying to execve a guest-
163+
# arch ELF directly (which the host kernel refuses with ENOEXEC unless
164+
# binfmt_misc is registered). When $runner is non-empty (foreign-arch
165+
# fixture) we point KASLD_EXEC_WRAPPER at it; for native-arch fixtures
166+
# $runner is empty and KASLD_EXEC_WRAPPER stays unset, so the orchestrator
167+
# takes the production direct-execve path.
173168
QEMU_UNAME="$release" KASLD_UNAME_RELEASE="$release" KASLD_SYSROOT="$sc/r" \
174169
KASLD_COMPONENT_DIR="$comps" KASLD_EXEC_WRAPPER="$runner" \
175170
$runner "$kasld" -v > "$sc/replay.txt" 2>/dev/null
176171
rc=$?
177172

178-
#Smoke verdict : the run must complete without an emulation crash.kasld
179-
#exits 0 with results, 1 with no tagged results(a valid empty run);
180-
#anything killed by a signal exits >= 128. A crash on any arch's calling
181-
#convention is the failure this harness exists to catch.
182-
#
183-
#With KASLD_EXEC_WRAPPER pointed at the host qemu binary, foreign - arch
184-
#component children do exec successfully under nested qemu - user — so
185-
#both x86(native) and foreign - arch fixtures should produce results and
186-
#render a summary.
173+
# Smoke verdict: the run must complete without an emulation crash. kasld
174+
# exits 0 with results, 1 with no tagged results (a valid empty run);
175+
# anything killed by a signal exits >= 128. A crash on any arch's calling
176+
# convention is the failure this harness exists to catch.
177+
#
178+
# With KASLD_EXEC_WRAPPER pointed at the host qemu binary, foreign-arch
179+
# component children do exec successfully under nested qemu-user — so
180+
# both x86 (native) and foreign-arch fixtures should produce results and
181+
# render a summary.
187182
has_summary=$(grep -cE '^(========| KASLR analysis:|Virtual memory layout)' \
188183
"$sc/replay.txt" 2>/dev/null || true)
189184
n_results=$(grep -cE '^[VPD] ' "$sc/replay.txt" 2>/dev/null || true)

0 commit comments

Comments
 (0)