Artifact 8ef0bb871a524c7231c8418c6874f97e281c0673facd4ef4ba5d6176376d4da3:
- File
test/budget.sh
— part of check-in
[1165d70f02]
at
2026-11-15 16:50:31
on branch trunk
— Phase 8b: the hook dispatcher runs what is linked into an event's slot
A harness is told once to call suit-run hook EVENT. After that, which programs run for the event is decided by what suit has linked into slots/hook/EVENT: one program, or a folder of programs run one after another in byte order of name. An outfit names them with slot hook/EVENT = PATH or slot hook/EVENT/NAME = PATH. Asking for both forms of the same event is an error at plan time that names both outfits.
The dispatcher lives in suit-run, the small program, because some harnesses run a hook on every tool call. With no slot for the event it exits 0 at once, having read nothing. Otherwise standard input is read once into an unlinked temporary file, at most 16 MiB, and every program gets the same bytes from the start. A program that exits 2 stops the rest and the dispatcher exits 2. Otherwise all run and the result is the first non-zero status; a signal counts as 128 plus its number, and a program that cannot be run as 126. The dispatcher has no timeout of its own and prints nothing on success.
suit hook EVENT calls the same code. suit hooks lists what would run and changes nothing.
The speed budget has a second measurement: suit-run hook with no slot, 0.15 to 0.29 ms over an empty program against the 1 ms limit. The no-change run is unchanged and still passes. Stripped suit-run grew from 35064 to 35512 bytes.
1355 unit checks, 598 shell cases (was 479), 669 store cases, 756 placement cases (was 745) and 378 project cases, under clang, under gcc 16, with no user name set, and under a strict umask, in one run of make gate (35 minutes). 100% coverage in all 25 source files. No suite has fewer cases than at the last check-in. (user: dmestas, size: 2734) [annotate] [blame] [check-ins using]
#!/bin/sh # The speed test: suit-run, the program a timer starts every minute, may cost at # most 1 ms and 1 MiB more than an empty program built the same way (build/empty, # next to the binary). The hook dispatcher on an event with no slot # (`suit-run hook NOSUCHEVENT`) has the same 1 ms limit. The bench runs once on a quiet machine and again under # CPU load from loadgen, whose workers carry their own deadline. # # Each of the two measurements is taken three times, all three are printed, and # it passes if the best of the three is within budget. A machine kept busy by # other work (a load average above about 100) adds noise to a 1 ms difference # that the test cannot tell from suit's own cost; the budget is not loosened. # SUIT names the binary (default build/suit); suit-run is beside it. SUIT=${SUIT:-build/suit} case $SUIT in /*) ;; *) SUIT=$PWD/$SUIT ;; esac LOADGEN=${LOADGEN:-$HOME/.claude/bin/loadgen} RUNS=3 ROUNDS=600 LOAD_WORKERS=8 # Three loaded runs of about 20 seconds each, with room to spare. LOAD_SECONDS=100 mkdir -p build/tmp T=$(mktemp -d "$PWD/build/tmp/budget.XXXXXX") || exit 1 trap 'rm -rf "$T"' EXIT INT TERM # The stamp `suit apply` writes over a real-sized wardrobe: the fixture's store # plus 100 more files in it, all watched, with the links placed in a scratch HOME. export HOME="$T/hm" SUIT_HOME="$T/home" mkdir -p "$HOME" "$SUIT_HOME/store" cp -R test/fixtures/wear "$SUIT_HOME/store/mine" mkdir -p "$SUIT_HOME/store/mine/bulk" i=0 while [ $i -lt 100 ]; do echo "file $i" > "$SUIT_HOME/store/mine/bulk/f$i" i=$((i + 1)) done "$SUIT" apply >/dev/null || { echo "budget: apply of the scratch wardrobe failed"; exit 1; } echo "budget: the stamp watches $(wc -l < "$SUIT_HOME/stamp" | tr -d ' ') paths" "$SUIT" compare || { echo "budget: scratch stamp does not read back as unchanged"; exit 1; } # best_of LABEL: run the bench RUNS times, print every run, succeed if one passed. best_of() { ok=1 n=1 while [ $n -le $RUNS ]; do echo "-- $1, run $n of $RUNS" if "$SUIT" bench -n "$ROUNDS"; then ok=0; fi n=$((n + 1)) done return $ok } failed=0 echo "== quiet (load average: $(uptime | sed 's/.*load averages*: //'))" best_of quiet || { echo "budget: no quiet run was within budget"; failed=1; } [ -x "$LOADGEN" ] || { echo "budget: $LOADGEN not found"; exit 1; } echo "== under load: loadgen $LOAD_SECONDS $LOAD_WORKERS" "$LOADGEN" "$LOAD_SECONDS" "$LOAD_WORKERS" & load=$! sleep 2 echo "load average: $(uptime | sed 's/.*load averages*: //')" best_of loaded || { echo "budget: no loaded run was within budget"; failed=1; } wait "$load" if [ "$failed" -eq 0 ]; then echo "budget: pass"; else echo "budget: FAIL"; fi [ "$failed" -eq 0 ]