interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / scripts / bench / own30b-quiet-run-selftest.sh

181 lines · 9287 bytes Raw Blame History
1#!/usr/bin/env bash
2# Self-test for scripts/bench/own30b-quiet-run.sh (#625). Bash + jq only.
3# Fakes quietlock, nvidia-smi, ss and flock on PATH; the "server" is a
4# command that sleeps or exits. Covers: normal completion, child failure,
5# SIGINT, SIGTERM, repeat invocations, contended refusal, recorded override,
6# a declared server PID, a foreign process seen only after the run, a quiet
7# flag already held, and that /tmp/aien-gb10.lock is never touched.
8# With QUIETLOCK_REAL=/path/to/quietlock the hold and interrupt cases run
9# again against the real binary in a private QUIETLOCK_DIR.
10#
11# bash scripts/bench/own30b-quiet-run-selftest.sh (exit 0 = all checks passed)
12set -uo pipefail
13
14HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
15RUN="$HERE/own30b-quiet-run.sh"
16T=$(mktemp -d "${TMPDIR:-/tmp}/own30b-quiet-run-selftest.XXXXXX")
17if [ "${QR_SELFTEST_KEEP:-0}" = 1 ]; then echo "keeping $T"; else trap 'rm -rf "$T"' EXIT; fi
18PASS=0; FAIL=0
19check() { # check <name> <command...>
20 local name=$1; shift
21 if "$@" >/dev/null 2>&1; then PASS=$((PASS + 1)); echo "ok $name"
22 else FAIL=$((FAIL + 1)); echo "FAIL $name"; fi
23}
24jqt() { jq -e "$@"; }
25
26BIN="$T/bin"; QD="$T/ql"; mkdir -p "$BIN" "$QD"
27cat >"$BIN/quietlock" <<'FAKE'
28#!/usr/bin/env bash
29# Fake quietlock: a flag file, acquire/release lines in a log, and TERM
30# forwarded to the held command (the real one forwards to its process group).
31D=${FAKE_QL_DIR:?}
32case "$1" in
33 check) [ ! -e "$D/held" ] || { echo "quietlock: QUIETLOCK_REFUSED fake" >&2; exit 75; }; exit 0 ;;
34 hold)
35 shift; owner="" minutes=""
36 while [ "$1" != -- ]; do case "$1" in --owner) owner=$2 ;; --minutes) minutes=$2 ;; esac; shift 2; done
37 shift
38 [ ! -e "$D/held" ] || { echo "quietlock: QUIETLOCK_REFUSED fake" >&2; exit 75; }
39 : >"$D/held"; echo "acquire $owner $minutes" >>"$D/log"
40 "$@" & c=$!
41 trap 'echo "forward TERM" >>"$D/log"; kill -TERM $c 2>/dev/null' TERM
42 while :; do wait $c; rc=$?; kill -0 $c 2>/dev/null || break; done
43 rm -f "$D/held"; echo "release $rc" >>"$D/log"; exit $rc ;;
44 *) exit 2 ;;
45esac
46FAKE
47cat >"$BIN/nvidia-smi" <<'FAKE'
48#!/usr/bin/env bash
49[ ! -e "${FAKE_SMI_DIR:?}/broken" ] || exit 9
50case "$1" in
51 --query-gpu=*) echo "NVIDIA GB10, 0 %, [N/A], [N/A]" ;;
52 --query-compute-apps=*) cat "$FAKE_SMI_DIR/apps" 2>/dev/null; true ;;
53esac
54FAKE
55cat >"$BIN/ss" <<'FAKE'
56#!/usr/bin/env bash
57echo 'LISTEN 0 128 127.0.0.1:18091 0.0.0.0:* users:(("aien-serve-http",pid=4242,fd=13))'
58echo 'LISTEN 0 128 127.0.0.1:18080 0.0.0.0:* users:(("cortex-rs",pid=5060,fd=12))'
59FAKE
60cat >"$BIN/flock" <<'FAKE'
61#!/usr/bin/env bash
62echo "flock $*" >>"${FAKE_FLOCK_LOG:?}"; exit 1
63FAKE
64chmod +x "$BIN"/*
65export PATH="$BIN:$PATH" FAKE_QL_DIR="$QD" FAKE_SMI_DIR="$T/smi" FAKE_FLOCK_LOG="$T/flock.log"
66mkdir -p "$FAKE_SMI_DIR"
67reset() { rm -f "$QD/held" "$QD/log" "$FAKE_SMI_DIR/apps" "$FAKE_SMI_DIR/broken"; }
68qr() { # qr <out> [runner args...] -- cmd... (exit status in $RC)
69 local out=$1; shift
70 "$RUN" --owner selftest --minutes 2 --out "$T/$out" "$@" 2>"$T/$out.err"; RC=$?
71}
72M() { echo "$T/$1/manifest.json"; }
73not_held() { [ ! -e "$QD/held" ]; }
74log_has() { grep -qx "$1" "$QD/log"; }
75
76# 1. idle GPU, normal completion
77reset; qr ok1 --server-bin "$BIN/ss" --model "$BIN" --omega-pin abc123 -- true
78check "normal: exit 0" test "$RC" -eq 0
79check "normal: hold acquired with owner and bound" log_has "acquire selftest 2"
80check "normal: hold released" log_has "release 0"
81check "normal: no flag left" not_held
82check "normal: manifest comparable" jqt '.schema == "own30b-quiet-run/v1" and .comparable and .outcome == "completed" and .exit_status == 0' "$(M ok1)"
83check "normal: identity recorded" jqt '(.identity.repo_head | length) >= 7 and (.identity.server_bin.sha256 | length) == 64 and .identity.model.kib >= 0 and .identity.omega_pin == "abc123"' "$(M ok1)"
84check "normal: GPU line kept raw (N/A memory)" jqt '.preflight.gpu == "NVIDIA GB10, 0 %, [N/A], [N/A]" and .postflight.available' "$(M ok1)"
85check "normal: only AIEN listeners recorded" jqt '.preflight.aien_listeners | length == 1 and (.[0] | test("aien-serve-http"))' "$(M ok1)"
86check "normal: command recorded" jqt '.command == ["true"]' "$(M ok1)"
87
88# 2. child failure
89reset; qr fail1 -- sh -c 'exit 7'
90check "child failure: exit status passed through" test "$RC" -eq 7
91check "child failure: hold released" log_has "release 7"
92check "child failure: no flag left" not_held
93check "child failure: outcome" jqt '.outcome == "exit 7" and .exit_status == 7' "$(M fail1)"
94
95# 3. repeat invocations, and a reused output directory
96reset; qr rep1 -- true; r1=$RC; qr rep2 -- true; r2=$RC
97check "repeat: both runs succeed" test "$r1$r2" = 00
98check "repeat: two acquire/release pairs" test "$(grep -c '^acquire ' "$QD/log")$(grep -c '^release 0' "$QD/log")" = 22
99qr rep1 -- true
100check "NEGATIVE: reused --out refused" test "$RC" -eq 2
101
102# 4/5. interrupts: the held command is stopped and the flag released
103interrupt() { # interrupt <out> <signal> <expected exit>
104 reset; rm -f "$T/$1.child"
105 # Job control on: a background job of a non-interactive shell starts with
106 # SIGINT ignored, which a terminal-run (foreground) runner never has.
107 set -m
108 "$RUN" --owner selftest --minutes 2 --out "$T/$1" -- sh -c 'echo $$ >"$0"; exec sleep 30' "$T/$1.child" 2>"$T/$1.err" &
109 local rp=$! i
110 set +m
111 for i in $(seq 1 100); do [ -s "$T/$1.child" ] && break; sleep 0.1; done
112 kill "-$2" "$rp"; wait "$rp"; RC=$?
113 check "$2: runner exits $3" test "$RC" -eq "$3"
114 check "$2: no flag left" not_held
115 check "$2: held command stopped" bash -c "! kill -0 \$(cat '$T/$1.child')"
116 check "$2: manifest says interrupted, not comparable" jqt --arg s "SIG$2" '.outcome == "interrupted: \($s)" and (.comparable | not)' "$(M "$1")"
117}
118interrupt int1 INT 130
119check "INT: passed on as TERM" log_has "forward TERM"
120interrupt term1 TERM 143
121
122# 6. contended: refused, nothing run, no hold taken
123reset; printf '999, ./max-model, 70000 MiB\n' >"$FAKE_SMI_DIR/apps"
124qr busy1 -- touch "$T/busy1.ran"
125check "contended: exit 3" test "$RC" -eq 3
126check "contended: command not run" test ! -e "$T/busy1.ran"
127check "contended: no hold taken" test ! -e "$QD/log"
128check "contended: reason names the process" jqt '(.comparable | not) and (.not_comparable_reasons[0] | test("999 ./max-model")) and .override == null' "$(M busy1)"
129
130# 7. contended with override: runs, recorded, not comparable
131qr busy2 --allow-contended "MAX model shares the GPU on purpose" -- touch "$T/busy2.ran"
132check "override: runs" test "$RC" -eq 0 -a -e "$T/busy2.ran"
133check "override: reason recorded, not comparable" jqt '(.comparable | not) and .override.reason == "MAX model shares the GPU on purpose" and (.not_comparable_reasons | any(startswith("override:")))' "$(M busy2)"
134
135# 8. the declared server is allowed on the GPU
136reset; printf '4242, ./aien-serve-http, 81717 MiB\n' >"$FAKE_SMI_DIR/apps"
137qr srv1 --server-pid 4242 -- true
138check "server pid: comparable" jqt '.comparable and .server_pids == [4242] and (.preflight.compute_apps | length) == 1 and (.preflight.foreign | length) == 0' "$(M srv1)"
139
140# 9. a foreign process that appears during the run
141reset; qr post1 -- sh -c "printf '777, ./repro2, 9 MiB\n' >'$FAKE_SMI_DIR/apps'"
142check "postflight: run completes" test "$RC" -eq 0
143check "postflight: foreign process marks not comparable" jqt '(.comparable | not) and (.not_comparable_reasons[0] | test("^postflight: .*777"))' "$(M post1)"
144
145# 10. nvidia-smi unavailable never counts as idle
146reset; : >"$FAKE_SMI_DIR/broken"
147qr nosmi -- touch "$T/nosmi.ran"
148check "no nvidia-smi: refused" test "$RC" -eq 3 -a ! -e "$T/nosmi.ran"
149check "no nvidia-smi: recorded" jqt '(.preflight.available | not) and (.not_comparable_reasons[0] | test("unavailable"))' "$(M nosmi)"
150
151# 11. quiet flag already held by someone else
152reset; : >"$QD/held"
153qr held1 -- touch "$T/held1.ran"
154check "quiet held: exit 75, command not run" test "$RC" -eq 75 -a ! -e "$T/held1.ran"
155check "quiet held: other holder's flag untouched" test -e "$QD/held"
156
157# 12. usage errors
158reset
159check "NEGATIVE: --minutes 21 refused" bash -c "! '$RUN' --owner x --minutes 21 --out '$T/u1' -- true"
160check "NEGATIVE: missing --owner refused" bash -c "! '$RUN' --out '$T/u2' -- true"
161check "NEGATIVE: no command refused" bash -c "! '$RUN' --owner x --out '$T/u3' --"
162
163# 13. the GPU lock is never taken from outside the server
164check "never runs flock" test ! -e "$FAKE_FLOCK_LOG"
165check "script does not open the GPU lock" bash -c "! grep -v '^#' '$RUN' | grep -q 'aien-gb10.lock'"
166
167# 14. optional: the real quietlock in a private state dir
168if [ -n "${QUIETLOCK_REAL:-}" ]; then
169 export OWN30B_QR_QUIETLOCK="$QUIETLOCK_REAL" QUIETLOCK_DIR="$T/realq"; mkdir -p "$QUIETLOCK_DIR"
170 reset; qr real1 -- true
171 check "real quietlock: normal run releases" test "$RC" -eq 0 -a ! -e "$QUIETLOCK_DIR/.spark-quiet"
172 qr real2 -- sh -c 'exit 5'
173 check "real quietlock: child failure releases" test "$RC" -eq 5 -a ! -e "$QUIETLOCK_DIR/.spark-quiet"
174 interrupt realint INT 130
175 check "real quietlock: INT releases" test ! -e "$QUIETLOCK_DIR/.spark-quiet"
176 interrupt realterm TERM 143
177 check "real quietlock: TERM releases" test ! -e "$QUIETLOCK_DIR/.spark-quiet"
178fi
179
180echo "own30b-quiet-run-selftest: $PASS passed, $FAIL failed"
181[ "$FAIL" -eq 0 ]