Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/scripts/bench/own30b-quiet-run-selftest.sh # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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) 12 set -uo pipefail 13 14 HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) 15 RUN="$HERE/own30b-quiet-run.sh" 16 T=$(mktemp -d "${TMPDIR:-/tmp}/own30b-quiet-run-selftest.XXXXXX") 17 if [ "${QR_SELFTEST_KEEP:-0}" = 1 ]; then echo "keeping $T"; else trap 'rm -rf "$T"' EXIT; fi 18 PASS=0; FAIL=0 19 check() { # check 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 } 24 jqt() { jq -e "$@"; } 25 26 BIN="$T/bin"; QD="$T/ql"; mkdir -p "$BIN" "$QD" 27 cat >"$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). 31 D=${FAKE_QL_DIR:?} 32 case "$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 ;; 45 esac 46 FAKE 47 cat >"$BIN/nvidia-smi" <<'FAKE' 48 #!/usr/bin/env bash 49 [ ! -e "${FAKE_SMI_DIR:?}/broken" ] || exit 9 50 case "$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 ;; 53 esac 54 FAKE 55 cat >"$BIN/ss" <<'FAKE' 56 #!/usr/bin/env bash 57 echo 'LISTEN 0 128 127.0.0.1:18091 0.0.0.0:* users:(("aien-serve-http",pid=4242,fd=13))' 58 echo 'LISTEN 0 128 127.0.0.1:18080 0.0.0.0:* users:(("cortex-rs",pid=5060,fd=12))' 59 FAKE 60 cat >"$BIN/flock" <<'FAKE' 61 #!/usr/bin/env bash 62 echo "flock $*" >>"${FAKE_FLOCK_LOG:?}"; exit 1 63 FAKE 64 chmod +x "$BIN"/* 65 export PATH="$BIN:$PATH" FAKE_QL_DIR="$QD" FAKE_SMI_DIR="$T/smi" FAKE_FLOCK_LOG="$T/flock.log" 66 mkdir -p "$FAKE_SMI_DIR" 67 reset() { rm -f "$QD/held" "$QD/log" "$FAKE_SMI_DIR/apps" "$FAKE_SMI_DIR/broken"; } 68 qr() { # qr [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 } 72 M() { echo "$T/$1/manifest.json"; } 73 not_held() { [ ! -e "$QD/held" ]; } 74 log_has() { grep -qx "$1" "$QD/log"; } 75 76 # 1. idle GPU, normal completion 77 reset; qr ok1 --server-bin "$BIN/ss" --model "$BIN" --omega-pin abc123 -- true 78 check "normal: exit 0" test "$RC" -eq 0 79 check "normal: hold acquired with owner and bound" log_has "acquire selftest 2" 80 check "normal: hold released" log_has "release 0" 81 check "normal: no flag left" not_held 82 check "normal: manifest comparable" jqt '.schema == "own30b-quiet-run/v1" and .comparable and .outcome == "completed" and .exit_status == 0' "$(M ok1)" 83 check "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)" 84 check "normal: GPU line kept raw (N/A memory)" jqt '.preflight.gpu == "NVIDIA GB10, 0 %, [N/A], [N/A]" and .postflight.available' "$(M ok1)" 85 check "normal: only AIEN listeners recorded" jqt '.preflight.aien_listeners | length == 1 and (.[0] | test("aien-serve-http"))' "$(M ok1)" 86 check "normal: command recorded" jqt '.command == ["true"]' "$(M ok1)" 87 88 # 2. child failure 89 reset; qr fail1 -- sh -c 'exit 7' 90 check "child failure: exit status passed through" test "$RC" -eq 7 91 check "child failure: hold released" log_has "release 7" 92 check "child failure: no flag left" not_held 93 check "child failure: outcome" jqt '.outcome == "exit 7" and .exit_status == 7' "$(M fail1)" 94 95 # 3. repeat invocations, and a reused output directory 96 reset; qr rep1 -- true; r1=$RC; qr rep2 -- true; r2=$RC 97 check "repeat: both runs succeed" test "$r1$r2" = 00 98 check "repeat: two acquire/release pairs" test "$(grep -c '^acquire ' "$QD/log")$(grep -c '^release 0' "$QD/log")" = 22 99 qr rep1 -- true 100 check "NEGATIVE: reused --out refused" test "$RC" -eq 2 101 102 # 4/5. interrupts: the held command is stopped and the flag released 103 interrupt() { # interrupt 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 } 118 interrupt int1 INT 130 119 check "INT: passed on as TERM" log_has "forward TERM" 120 interrupt term1 TERM 143 121 122 # 6. contended: refused, nothing run, no hold taken 123 reset; printf '999, ./max-model, 70000 MiB\n' >"$FAKE_SMI_DIR/apps" 124 qr busy1 -- touch "$T/busy1.ran" 125 check "contended: exit 3" test "$RC" -eq 3 126 check "contended: command not run" test ! -e "$T/busy1.ran" 127 check "contended: no hold taken" test ! -e "$QD/log" 128 check "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 131 qr busy2 --allow-contended "MAX model shares the GPU on purpose" -- touch "$T/busy2.ran" 132 check "override: runs" test "$RC" -eq 0 -a -e "$T/busy2.ran" 133 check "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 136 reset; printf '4242, ./aien-serve-http, 81717 MiB\n' >"$FAKE_SMI_DIR/apps" 137 qr srv1 --server-pid 4242 -- true 138 check "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 141 reset; qr post1 -- sh -c "printf '777, ./repro2, 9 MiB\n' >'$FAKE_SMI_DIR/apps'" 142 check "postflight: run completes" test "$RC" -eq 0 143 check "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 146 reset; : >"$FAKE_SMI_DIR/broken" 147 qr nosmi -- touch "$T/nosmi.ran" 148 check "no nvidia-smi: refused" test "$RC" -eq 3 -a ! -e "$T/nosmi.ran" 149 check "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 152 reset; : >"$QD/held" 153 qr held1 -- touch "$T/held1.ran" 154 check "quiet held: exit 75, command not run" test "$RC" -eq 75 -a ! -e "$T/held1.ran" 155 check "quiet held: other holder's flag untouched" test -e "$QD/held" 156 157 # 12. usage errors 158 reset 159 check "NEGATIVE: --minutes 21 refused" bash -c "! '$RUN' --owner x --minutes 21 --out '$T/u1' -- true" 160 check "NEGATIVE: missing --owner refused" bash -c "! '$RUN' --out '$T/u2' -- true" 161 check "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 164 check "never runs flock" test ! -e "$FAKE_FLOCK_LOG" 165 check "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 168 if [ -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" 178 fi 179 180 echo "own30b-quiet-run-selftest: $PASS passed, $FAIL failed" 181 [ "$FAIL" -eq 0 ]