test: parallelize test/run via xargs -P; 180s per-tool timeout

test/run fans test/wcc/*.c across $(nproc) workers via xargs -0 -n2 -P
$JOBS; each worker writes <prefix>.status and an optional <prefix>.fail
sentinel into a mktemp results dir. The driver collects in glob order so
output stays deterministic across runs.

Wraps every ww/w6c/w6a/w6l/wwdump invocation in 990-995 with
`timeout 180`, bounding orphan compilers under 8-way contention. The
direct runwait(exe) calls for fresh-built test binaries get the same
treatment via a "timeout 180 %s" snprintf hop. Motivation: pid 2101 was
a w6c_ww that ran 42h on /tmp/wcas_asm_1326_15.ww until we killed it
during this session; timeout makes that impossible.

993's /tmp/ww_d_hello.ww is now pid-keyed (snprintf %d getpid); without
it concurrent runs (or future shards of 993 itself) would race on the
staging file.

Wall: 9m59s → 4m31s on 8 cores. Same 132/132 status.
This commit is contained in:
2026-05-21 16:32:27 +09:00
parent 0715ec9662
commit 65a6cac6a0
7 changed files with 104 additions and 76 deletions

View File

@@ -1,56 +1,74 @@
#!/bin/sh
# test/run — driver for `make test`. Plan 9 rc-flavoured but plain sh.
#
# Walks the test/ tree:
# test/wcc/<NNN>_<name>.c → out/bin/test_<name> binary, run it.
# test/lang/<phase>/*.ww → compile/run via $WW, compare stdout/exit
# with header comments (// expected: ...).
# Exit non-zero on first failure.
set -e
# Walks test/wcc/<NNN>_<name>.c → out/bin/test_<name> binary, fans out
# across $JOBS (default $(nproc)) workers via xargs -P. Each worker
# writes its status to a per-job file; the collector enumerates them in
# lexicographic order so output stays deterministic across runs even
# though execution interleaves. Exit non-zero if any worker failed.
BIN=${BIN:-out/bin}
WW=${WW:-$BIN/ww}
fail=0
ran=0
# ---- C-side unit tests --------------------------------------------------
for t in test/wcc/*.c; do
[ -f "$t" ] || continue
# Worker mode: invoked once per test by xargs. Argv: --one <prefix> <test.c>.
# Writes <prefix>.status; touches <prefix>.fail on a non-zero binary exit.
if [ "$1" = "--one" ]; then
prefix=$2
t=$3
name=${t##*/}
name=${name%.c}
# strip leading <NNN>_
short=${name#[0-9][0-9][0-9]_}
bin=$BIN/test_$short
if [ ! -x "$bin" ]; then
echo "SKIP $name (no binary $bin)"
continue
printf 'SKIP %s (no binary %s)\n' "$name" "$bin" > "$prefix.status"
exit 0
fi
if "$bin" >"$BIN/.$short.out" 2>"$BIN/.$short.err"; then
echo "ok $name"
if "$bin" > "$prefix.out" 2> "$prefix.err"; then
printf 'ok %s\n' "$name" > "$prefix.status"
else
rc=$?
echo "FAIL $name (rc=$rc)"
echo "--- stdout ---"
cat "$BIN/.$short.out"
echo "--- stderr ---"
cat "$BIN/.$short.err"
fail=$((fail + 1))
{
printf 'FAIL %s (rc=%d)\n' "$name" "$rc"
echo '--- stdout ---'
cat "$prefix.out"
echo '--- stderr ---'
cat "$prefix.err"
} > "$prefix.status"
: > "$prefix.fail"
fi
exit 0
fi
set -e
RESULTS=$(mktemp -d "${TMPDIR:-/tmp}/wwtest.XXXXXX")
trap 'rm -rf "$RESULTS"' EXIT
JOBS=${JOBS:-$(nproc 2>/dev/null || echo 4)}
# Emit (prefix, testpath) pairs NUL-separated. The prefix carries the
# test's <NNN>_<name> stem so the collector iterates in lexical order,
# yielding deterministic output even though workers interleave.
for t in test/wcc/*.c; do
[ -f "$t" ] || continue
name=${t##*/}; name=${name%.c}
printf '%s/%s\0%s\0' "$RESULTS" "$name" "$t"
done | xargs -0 -n2 -P "$JOBS" "$0" --one || true
fail=0
ran=0
for s in "$RESULTS"/*.status; do
[ -f "$s" ] || continue
cat "$s"
ran=$((ran + 1))
prefix=${s%.status}
[ -f "$prefix.fail" ] && fail=$((fail + 1))
done
# ---- ww source-level tests ----------------------------------------------
# Each test/lang/<phase>/*.ww has a header:
# // expected-exit: 0
# // expected-stdout: hello world
# These run with `ww run`; phases that don't compile yet skip entries
# that begin with `// phase: <N>` if N > current.
if [ -d test/lang ]; then
for f in test/lang/*/*.ww; do
[ -f "$f" ] || continue
# Skip until ww run exists; placeholder for phase 7+
echo "skip $f (ww run not online yet)"
done
fi