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/omega-gpu-driver/blob/main/tests/window_sim.sh # omega-gpu-driver aien-dev/omega-gpu-driver 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 `omega-gpu-driver / tests / window_sim.sh` 462 lines ยท 24613 bytes Raw Blame History 1 #!/bin/sh 2 # tests/window_sim.sh -- run the real window scripts (window/*.sh, copied unchanged) against a simulated Spark 3 # under /tmp: fake sysfs, /etc, /dev/vfio, /proc and shims for sudo, systemctl, modprobe, sysctl, lsmod, 4 # nvidia-smi, pgrep, curl, tee (sysfs side effects), stat, fuser, modinfo, lsinitramfs and spark-window. The 5 # "35B" is a sleep process the fake start script launches. A reboot is simulated by the harness: /tmp emptied, 6 # 35B gone, sysctls reset, nvidia loaded unless the hold-back file says otherwise, then the boot unit if enabled. 7 # Test-only shell (no product code); evidence label: EXERCISED (host simulator). Nothing here touches the GPU, 8 # the real /sys, /etc, sudo or the live 35B: window/common.sh refuses unless every acting command is a shim. 9 # sh tests/window_sim.sh all scenarios 10 # SIMDIR=/tmp/x sh tests/window_sim.sh keep the simulated machines in /tmp/x 11 set -eu 12 R=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) 13 BASE=${SIMDIR:-$(mktemp -d /tmp/owndriver-window-sim.XXXXXX)} 14 case $BASE in /tmp/*) ;; *) echo "SIMDIR must be under /tmp"; exit 2 ;; esac 15 BDF=000f:01:00.0 16 pass=0 17 fail=0 18 19 # --- the simulated machine ------------------------------------------------------------------------------ 20 mkroot() { 21 S=$BASE/$1 22 rm -rf "$S" 23 mkdir -p "$S/bin" "$S/st/modes" "$S/repo" "$S/tmp" "$S/home/handoffs/OwnDriver/window" "$S/q36/bin-`19173f9e`" \ 24 "$S/etc/sudoers.d" "$S/etc/udev/rules.d" "$S/etc/security/limits.d" "$S/etc/modprobe.d" "$S/etc/systemd/system" \ 25 "$S/sys/bus/pci/devices/$BDF/power" "$S/sys/bus/pci/drivers/nvidia" "$S/sys/bus/pci/drivers/vfio-pci" \ 26 "$S/sys/kernel/iommu_groups/20/devices" "$S/dev/vfio" "$S/proc" "$S/build" 27 touch "$S/.owndriver-window-sim" 28 cp -r "$R/window" "$R/tools" "$S/repo/" 29 mkdir -p "$S/repo/build" 30 ln -s "$R/build/omc" "$S/repo/build/omc" 31 D=$S/sys/bus/pci/devices/$BDF 32 echo 0x10de > "$D/vendor"; echo 0x2e12 > "$D/device"; echo "flr bus" > "$D/reset_method" 33 : > "$D/driver_override"; echo auto > "$D/power/control"; echo active > "$D/power/runtime_status" 34 ln -s ../../../../kernel/iommu_groups/20 "$D/iommu_group" 35 touch "$S/sys/kernel/iommu_groups/20/devices/$BDF" "$S/sys/bus/pci/drivers_probe" \ 36 "$S/sys/bus/pci/drivers/vfio-pci/unbind" "$S/sys/bus/pci/drivers/nvidia/unbind" 37 echo "drakestapleton ALL=(root) NOPASSWD: /usr/local/sbin/aien-run-exec" > "$S/etc/sudoers.d/aien-local-ci" 38 echo "options nvidia NVreg_Example=1" > "$S/etc/modprobe.d/nvidia.conf" 39 echo simkey > "$S/q36/KEY" 40 echo 0 > "$S/st/sysctl.kernel.panic"; echo 0 > "$S/st/sysctl.kernel.panic_on_oops" 41 echo 0 > "$S/st/boots"; : > "$S/st/events" 42 printf 'window: sim\nreset: approved\nreboot: approved\n' > "$S/home/handoffs/OwnDriver/window/APPROVED" 43 case $1 in identity_*) echo "stage: W0" >> "$S/home/handoffs/OwnDriver/window/APPROVED" ;; esac 44 shims "$S" 45 cat > "$S/q36/start-35b-batch.sh" <<'EOF' 46 #!/bin/sh 47 # fake start-35b-batch.sh: a sleep stands in for aien-serve-http; its launch record goes to $ROOT/proc/. 48 S=${OWNDRIVER_WINDOW_ROOT:?} 49 [ -e "$S/st/start_fail" ] && { echo "start failed"; exit 1; } 50 nohup sleep 100000 >/dev/null 2>&1 & 51 p=$! 52 mkdir -p "$S/proc/$p" 53 printf '%s\0' ./aien-serve-http --engine omega --model-dir /home/drakestapleton/models/qwen3.6-35b-a3b-fp8-`95a723d0` --port 18091 \ 54 --max-context 49152 --max-tokens-cap 16384 --thinking off --batch-slots 8 > "$S/proc/$p/cmdline" 55 printf 'Q36_BATCH_BIN=%s\0AIEN_Q36_STROKE=%s\0AIEN_SERVE_GPU_LOCK=%s\0AIEN_COORD_KEY=%s\0HOME=x\0' \ 56 "${Q36_BATCH_BIN:-}" "${AIEN_Q36_STROKE:-}" "${AIEN_SERVE_GPU_LOCK:-}" "${AIEN_COORD_KEY:-}" > "$S/proc/$p/environ" 57 ln -s "$S/q36/${Q36_BATCH_BIN:-bin-`99230310`}" "$S/proc/$p/cwd" 58 echo aien-serve-http > "$S/proc/$p/comm" 59 echo "$p" > "$S/st/35b" 60 echo "start35b $p" >> "$S/st/events" 61 echo "pid $p" 62 EOF 63 chmod +x "$S/q36/start-35b-batch.sh" 64 cat > "$S/build/w0" <<'EOF' 65 #!/bin/sh 66 # fake build/w0: refuses unless the device is on vfio-pci, powered on and active, as the real one needs. 67 S=${OWNDRIVER_WINDOW_ROOT:?} 68 D=$S/sys/bus/pci/devices/000f:01:00.0 69 echo "w0 $*" >> "$S/st/events" 70 [ "$(basename "$(readlink "$D/driver")")" = vfio-pci ] || { echo "w0: not on vfio-pci"; exit 3; } 71 [ "$(cat "$D/power/control")" = on ] && [ "$(cat "$D/power/runtime_status")" = active ] || { echo "w0: device not powered"; exit 4; } 72 [ -e "$S/st/w0_leak" ] && echo 'SUBSYSTEM=="vfio", MODE="0666"' > "$S/etc/udev/rules.d/99-vfio.rules" 73 if [ -e "$S/st/w0_crash" ]; then 74 echo crash >> "$S/st/events"; touch "$S/st/reboot" 75 pkill -KILL -f "$S/repo/window/d2-run.sh" 76 exit 9 77 fi 78 echo "BOOT_0 0x1b000000 BOOT_42 0x1b000000 (simulated)" 79 exit "$(cat "$S/st/w0_rc" 2>/dev/null || echo 0)" 80 EOF 81 chmod +x "$S/build/w0" 82 boot_power_on "$S" 0 83 start35b "$S" 84 } 85 86 start35b() { OWNDRIVER_WINDOW_ROOT=$1 Q36_BATCH_BIN=bin-`19173f9e` AIEN_Q36_STROKE=1 AIEN_SERVE_GPU_LOCK=/tmp/aien-serve-18091.lock AIEN_COORD_KEY=simkey "$1/q36/start-35b-batch.sh" >/dev/null; } 87 88 bind_nvidia() { 89 S=$1; D=$S/sys/bus/pci/devices/$BDF 90 rm -f "$D/driver"; ln -s ../../drivers/nvidia "$D/driver" 91 } 92 93 # Power-on state; $2=1 runs the boot unit afterwards. 94 boot_power_on() { 95 S=$1 96 n=$(($(cat "$S/st/boots") + 1)); echo $n > "$S/st/boots" 97 echo "boot $n" >> "$S/st/events" 98 if [ -s "$S/st/35b" ]; then kill "$(cat "$S/st/35b")" 2>/dev/null || true; rm -f "$S/st/35b"; fi 99 rm -rf "$S/tmp" && mkdir -p "$S/tmp" 100 if [ -e "$S/st/lock_after_reboot" ] && [ "$2" = 1 ]; then 101 rm -f "$S/st/lock_after_reboot" 102 (flock -x 9; sleep 20) 9>>"$S/tmp/aien-gb10.lock" & 103 echo $! > "$S/st/lockholder"; sleep 0.3 104 echo "boot: another GPU job took the chip lock" >> "$S/st/events" 105 fi 106 D=$S/sys/bus/pci/devices/$BDF 107 rm -f "$D/driver" "$S/st/modules" "$S/st/persistenced" "$S/st/nvidia_broken" "$S/dev/vfio/vfio" "$S/dev/vfio/20" 108 : > "$D/driver_override"; echo auto > "$D/power/control" 109 if [ -e "$S/st/pm_suspended" ]; then echo suspended > "$D/power/runtime_status"; else echo active > "$D/power/runtime_status"; fi 110 echo 0 > "$S/st/sysctl.kernel.panic"; echo 0 > "$S/st/sysctl.kernel.panic_on_oops" 111 bad=$(cat "$S/st/nvidia_bad_boots" 2>/dev/null || echo 0) 112 if grep -q 'install nvidia /bin/false' "$S"/etc/modprobe.d/* 2>/dev/null; then 113 echo "boot: nvidia held back" >> "$S/st/events" 114 elif [ "$bad" -gt 0 ] && [ "$2" = 1 ]; then 115 echo $((bad - 1)) > "$S/st/nvidia_bad_boots"; touch "$S/st/nvidia_broken" 116 echo "boot: nvidia failed to load (this boot)" >> "$S/st/events" 117 else 118 printf 'nvidia_uvm\nnvidia_drm\nnvidia_modeset\nnvidia\n' > "$S/st/modules" 119 bind_nvidia "$S"; touch "$S/st/persistenced" 120 fi 121 if [ "$2" = 1 ] && [ -e "$S/st/unit-enabled" ] && [ -e "$S/etc/systemd/system/aien-owndriver-window.service" ]; then 122 u=$S/etc/systemd/system/aien-owndriver-window.service 123 if ! grep -Fxq "WorkingDirectory=$S/repo" "$u" || ! grep -Fxq 'ExecStart=/bin/sh ./window/d2-boot.sh' "$u"; then 124 echo "invalid unit target" >> "$S/st/events" 125 return 1 126 fi 127 [ ! -e "$S/st/add_ogd_after_boot" ] || touch "$S/build/ogd" 128 [ ! -e "$S/st/alter_w0_after_boot" ] || echo '# changed' >> "$S/build/w0" 129 echo "unit runs" >> "$S/st/events" 130 (cd "$S/repo" && OWNDRIVER_WINDOW_ROOT=$S PATH="$S/bin:$PATH" sh "$S/repo/window/d2-boot.sh") > "$S/st/unit-$n.out" 2>&1 || 131 echo "unit exit $?" >> "$S/st/events" 132 fi 133 } 134 135 # Run a window command, then follow every reboot it asks for (at most 8 boots). 136 run_window() { 137 S=$1; shift 138 (cd "$S/repo" && OWNDRIVER_WINDOW_ROOT=$S PATH="$S/bin:$PATH" "$@") > "$S/st/cmd.out" 2>&1 && echo "cmd exit 0" >> "$S/st/events" || 139 echo "cmd exit $?" >> "$S/st/events" 140 while [ -e "$S/st/reboot" ]; do 141 rm -f "$S/st/reboot" 142 [ "$(cat "$S/st/boots")" -lt 9 ] || { echo "boot loop" >> "$S/st/events"; return; } 143 boot_power_on "$S" 1 144 done 145 } 146 147 shims() { 148 S=$1; B=$S/bin 149 w() { printf '#!/bin/sh\nS=%s\nD=$S/sys/bus/pci/devices/%s\n%s\n' "$S" "$BDF" "$2" > "$B/$1"; chmod +x "$B/$1"; } 150 w ss '[ ! -e "$S/st/ss_fail" ] || exit 1 151 [ ! -e "$S/st/unrecognized" ] || echo "LISTEN 0 1 127.0.0.1:18091" 152 exit 0' 153 w sudo '[ "$1" = -n ] && shift 154 exec "$@"' 155 w systemctl 'echo "systemctl $*" >> $S/st/events 156 case $1 in 157 daemon-reload) ;; 158 enable) [ -e $S/st/fail_enable ] && exit 1; [ -e $S/etc/systemd/system/$2 ] && touch $S/st/unit-enabled ;; 159 disable) rm -f $S/st/unit-enabled ;; 160 is-active) [ "$2" = --quiet ] && shift; [ -e $S/st/persistenced ] || { [ "$2" = --quiet ] || echo inactive; exit 3; }; echo active ;; 161 start) [ -s $S/st/modules ] && touch $S/st/persistenced ;; 162 reboot) touch $S/st/reboot ;; 163 *) exit 1 ;; 164 esac' 165 w modprobe 'echo "modprobe $*" >> $S/st/events 166 for m in "$@"; do case $m in 167 vfio-pci) grep -qx vfio_pci $S/st/modules 2>/dev/null || echo vfio_pci >> $S/st/modules; : > $S/dev/vfio/vfio; echo root:root:666 > $S/st/modes/vfio ;; 168 nvidia*) grep -q "install nvidia /bin/false" $S/etc/modprobe.d/* 2>/dev/null && exit 1 169 [ -e $S/st/nvidia_broken ] && exit 1 170 for n in nvidia nvidia_modeset nvidia_drm nvidia_uvm; do grep -qx $n $S/st/modules 2>/dev/null || echo $n >> $S/st/modules; done 171 [ -e $D/driver ] || [ -n "$(cat $D/driver_override)" ] || { ln -s ../../drivers/nvidia $D/driver; } ;; 172 *) exit 1 ;; 173 esac; done' 174 w lsmod 'echo "Module Size Used by" 175 [ -s $S/st/modules ] && while read -r m; do echo "$m 16384 0"; done < $S/st/modules 176 exit 0' 177 w sysctl 'case $1 in 178 -n) cat $S/st/sysctl.$2 ;; 179 -q) shift; if [ "$1" = -p ]; then while IFS== read -r k v; do echo "$v" > $S/st/sysctl.$k; done < "$2"; else for a; do echo "${a#*=}" > $S/st/sysctl.${a%%=*}; done; fi 180 echo "sysctl $*" >> $S/st/events ;; 181 *) exit 1 ;; 182 esac' 183 w nvidia-smi 'up() { [ -s $S/st/35b ] && kill -0 "$(cat $S/st/35b)" 2>/dev/null; } 184 case $1 in 185 -L) grep -qx nvidia $S/st/modules 2>/dev/null && [ "$(basename "$(readlink $D/driver)")" = nvidia ] && echo "GPU 0: NVIDIA GB10 (UUID: GPU-sim)" || { echo "No devices were found"; exit 6; } ;; 186 --query-compute-apps=pid) up && cat $S/st/35b; exit 0 ;; 187 --query-compute-apps=process_name,used_memory) up && echo "aien-serve-http, 43520 MiB"; exit 0 ;; 188 *) exit 1 ;; 189 esac' 190 w pgrep '[ -s $S/st/35b ] && kill -0 "$(cat $S/st/35b)" 2>/dev/null && cat $S/st/35b && exit 0 191 exit 1' 192 w curl 'up() { [ -s $S/st/35b ] && kill -0 "$(cat $S/st/35b)" 2>/dev/null && [ ! -e $S/st/serve_dead ]; } 193 up || exit 7 194 case "$*" in 195 */v1/models*) echo "{\"data\":[{\"id\":\"qwen3.6-35b-a3b\"}]}" ;; 196 */v1/chat/completions*) echo "{\"choices\":[{\"message\":{\"content\":\"ready\"}}]}" ;; 197 *) exit 22 ;; 198 esac' 199 w tee '/usr/bin/tee "$@" || exit $? 200 for a; do t=$a; done 201 case $t in 202 $S/sys/bus/pci/drivers_probe) 203 if [ ! -e $D/driver ]; then 204 o=$(cat $D/driver_override) 205 if [ "$o" = vfio-pci ] && grep -qx vfio_pci $S/st/modules; then ln -s ../../drivers/vfio-pci $D/driver; : > $S/dev/vfio/20; cat $S/st/vfio_mode 2>/dev/null > $S/st/modes/20 || echo root:root:600 > $S/st/modes/20; echo "bind vfio-pci" >> $S/st/events 206 elif [ -z "$o" ] && grep -qx nvidia $S/st/modules 2>/dev/null; then ln -s ../../drivers/nvidia $D/driver; echo "bind nvidia" >> $S/st/events; fi 207 fi ;; 208 $S/sys/bus/pci/drivers/vfio-pci/unbind) rm -f $D/driver $S/dev/vfio/20; echo "unbind vfio-pci (FLR)" >> $S/st/events ;; 209 $D/power/control) [ "$(cat $D/power/control)" = on ] && [ ! -e $S/st/pm_stuck ] && echo active > $D/power/runtime_status ;; 210 esac 211 exit 0' 212 w stat 'for a; do f=$a; done 213 case $f in $S/dev/vfio/*) cat $S/st/modes/$(basename $f) ;; *) exec /usr/bin/stat "$@" ;; esac' 214 w fuser 'echo " 1755 $(cat $S/st/35b 2>/dev/null)"' 215 w modinfo 'case "$*" in 216 "-n vfio-pci") echo /lib/modules/sim/vfio-pci.ko ;; 217 nvgrace-gpu-vfio-pci) for a in 31C2 2941 2348 2345 2342; do echo "alias: pci:v000010DEd0000${a}sv*sd*bc*sc*i*"; done ;; 218 *) exit 1 ;; 219 esac' 220 w lsinitramfs '[ ! -e "$S/st/initramfs_fail" ] || exit 1 221 echo usr/lib/modules/sim/kernel/drivers/vfio/pci/vfio-pci.ko' 222 w spark-window 'echo free' 223 } 224 225 # --- assertions ---------------------------------------------------------------------------------------- 226 ok() { pass=$((pass + 1)); echo " ok $1"; } 227 bad() { fail=$((fail + 1)); echo " FAIL $1"; FAILED_IN="$FAILED_IN $CASE"; } 228 check() { if eval "$2"; then ok "$1"; else bad "$1"; fi; } 229 L() { echo "$S/home/handoffs/OwnDriver/window"; } 230 alive35b() { [ -s "$S/st/35b" ] && kill -0 "$(cat "$S/st/35b")" 2>/dev/null; } 231 restored() { 232 check "35B running again" alive35b 233 check "35B restarted with the recorded env (key compared)" "tr '\\0' '\\n' < $S/proc/\$(cat $S/st/35b)/environ | grep -qx AIEN_COORD_KEY=simkey && tr '\\0' '\\n' < $S/proc/\$(cat $S/st/35b)/environ | grep -qx Q36_BATCH_BIN=bin-`19173f9e`" 234 check "nvidia bound, 4 modules" "[ \$(basename \$(readlink $S/sys/bus/pci/devices/$BDF/driver)) = nvidia ] && [ \$(grep -c nvidia $S/st/modules) = 4 ]" 235 check "hold-back file and unit gone" "[ ! -e $S/etc/modprobe.d/zz-aien-owndriver-window.conf ] && [ ! -e $S/etc/systemd/system/aien-owndriver-window.service ] && [ ! -e $S/st/unit-enabled ]" 236 check "sysctl back to 0/0" "[ \$(cat $S/st/sysctl.kernel.panic) = 0 ] && [ \$(cat $S/st/sysctl.kernel.panic_on_oops) = 0 ]" 237 check "state, approval, restore-path cleared" "[ ! -e $(L)/state ] && [ ! -e $(L)/APPROVED ] && [ ! -e $(L)/restore-path ]" 238 check "driver_override empty" "[ -z \"\$(tr -d '\\n' < $S/sys/bus/pci/devices/$BDF/driver_override)\" ]" 239 check "BOARD says WINDOW CLOSED" "grep -q 'WINDOW CLOSED' $S/home/handoffs/BOARD.md" 240 check "power/control back to auto" "[ \$(cat $S/sys/bus/pci/devices/$BDF/power/control) = auto ]" 241 } 242 untouched() { 243 check "35B never stopped" "alive35b && ! grep -q 'boot 2' $S/st/events" 244 check "no window file written" "[ ! -e $S/etc/modprobe.d/zz-aien-owndriver-window.conf ] && [ ! -e $S/etc/systemd/system/aien-owndriver-window.service ] && [ ! -e $(L)/state ]" 245 } 246 boots() { check "boots after power-on: $1" "[ \$(cat $S/st/boots) = $(($1 + 1)) ]"; } 247 248 FAILED_IN= 249 CASE=w0; echo "case $CASE: W0 read-only"; mkroot $CASE 250 run_window "$S" sh window/d2-pre.sh 251 check "W0 exit 0" "grep -qx 'cmd exit 0' $S/st/events"; untouched 252 check "baseline written" "[ -s $(L)/priv-baseline ]" 253 254 # mkfw S: a build/fw in fwprep's manifest format (fw_file names the real firmware sha256). 255 mkfw() { 256 mkdir -p "$1/build/fw" 257 { 258 echo "fwmanifest 1" 259 echo "fw_file bytes=`75012080` sha256=`32cb7cf3e77f97e92f6e92135939ccb3ba382748144569c0dfccf3338d43d963`" 260 for o in fmc.img fmc.hash fmc.pubkey fmc.sig bl.img; do 261 echo "sim $o" > "$1/build/fw/$o" 262 echo "out $o bytes=$(wc -c < "$1/build/fw/$o") sha256=$(sha256sum "$1/build/fw/$o" | cut -c1-64)" 263 done 264 echo end 265 } > "$1/build/fw/fw.manifest.tmp" 266 mv "$1/build/fw/fw.manifest.tmp" "$1/build/fw/fw.manifest" 267 } 268 CASE=fwgood; echo "case $CASE: W0 with a matching build/fw"; mkroot $CASE 269 mkfw "$S" 270 run_window "$S" sh window/d2-pre.sh 271 check "W0 exit 0" "grep -qx 'cmd exit 0' $S/st/events"; untouched 272 check "build/fw checked" "grep -q 'build/fw matches fw.manifest' $(L)/*-pre.log" 273 274 CASE=fwbad; echo "case $CASE: W0 with a build/fw file that differs from fw.manifest"; mkroot $CASE 275 mkfw "$S"; echo tampered > "$S/build/fw/bl.img" 276 run_window "$S" sh window/d2-pre.sh 277 check "W0 refused" "grep -qx 'cmd exit 1' $S/st/events"; untouched 278 check "names the mismatch" "grep -q 'build/fw files do not match' $(L)/*-pre.log" 279 280 CASE=d2; echo "case $CASE: full D2 window, reboot restore path"; mkroot $CASE 281 run_window "$S" sh window/d2-pre.sh --go D2 282 boots 2; restored 283 check "W2 bound vfio-pci, then W7 unbound it (FLR)" "grep -q 'bind vfio-pci' $S/st/events && grep -q 'unbind vfio-pci' $S/st/events" 284 check "w0 ran on the device" "grep -q '^w0 000f:01:00.0 20' $S/st/events" 285 check "W4/W5 logged NOT_RUN (no build/ogd)" "grep -q \"W-boot NOT_RUN\" $(L)/*-run.log && grep -q \"W-hello NOT_RUN\" $(L)/*-run.log" 286 check "panic sysctls were 10/1 during W2" "grep -q 'sysctl kernel.panic=10 kernel.panic_on_oops=1' $S/st/events" 287 288 CASE=identity_up; echo "case $CASE"; mkroot "$CASE" 289 run_window "$S" sh window/d2-pre.sh --go W0 290 boots 2; restored 291 check "identity ran exactly once" "test \$(grep -c '^w0 ' $S/st/events) = 1" 292 check "cleared identity receipts" "[ ! -e $(L)/identity-service ] && [ ! -e $(L)/identity-executable.sha256 ]" 293 294 stop_sim_service() { kill "$(cat "$S/st/35b")"; rm -f "$S/st/35b"; } 295 CASE=identity_down; echo "case $CASE"; mkroot "$CASE"; stop_sim_service 296 run_window "$S" sh window/d2-pre.sh --go W0 297 boots 2 298 check "previously idle port kept idle" "! alive35b && test \$(grep -c '^start35b ' $S/st/events) = 1 && grep -q 'WINDOW CLOSED' $S/home/handoffs/BOARD.md" 299 300 CASE=identity_foreign_service; echo "case $CASE"; mkroot "$CASE" 301 printf '%s\0' test-foreign-argument >> "$S/proc/$(cat "$S/st/35b")/cmdline" 302 run_window "$S" sh window/d2-pre.sh --go W0 303 boots 0; untouched 304 check "foreign command line kept out of logs" "! grep -rqs test-foreign-argument $(L) && grep -q 'another launch recipe' $(L)/*-pre.log" 305 306 CASE=identity_downgrade; echo "case $CASE"; mkroot "$CASE" 307 run_window "$S" sh window/d2-pre.sh --go D2 308 boots 0; untouched 309 check "identity authorization refuses broader stage" "grep -q 'approval does not name this stage' $(L)/*-pre.log" 310 311 for refusal in initramfs_fail ss_fail unrecognized ogd; do 312 CASE=identity_$refusal; echo "case $CASE"; mkroot "$CASE"; stop_sim_service 313 if [ "$refusal" = ogd ]; then touch "$S/build/ogd"; else touch "$S/st/$refusal"; fi 314 run_window "$S" sh window/d2-pre.sh --go W0 315 boots 0 316 check "failed before arming the window" "grep -q 'cmd exit 1' $S/st/events && [ ! -e $(L)/state ] && [ ! -e $S/st/unit-enabled ]" 317 done 318 319 for mutation in add_ogd_after_boot alter_w0_after_boot; do 320 CASE=identity_$mutation; echo "case $CASE"; mkroot "$CASE"; touch "$S/st/$mutation" 321 run_window "$S" sh window/d2-pre.sh --go W0 322 boots 2; restored 323 check "post-boot mutation refused before binding" "! grep -q '^bind vfio-pci' $S/st/events && ! grep -q '^w0 ' $S/st/events" 324 done 325 326 CASE=identity_restore_failure; echo "case $CASE"; mkroot "$CASE"; echo 1 > "$S/st/nvidia_bad_boots" 327 run_window "$S" sh window/d2-pre.sh --go W0 328 boots 2 329 check "failed restore requests attended recovery" "grep -q 'Attended recovery required' $(L)/*-restore.log && test \"\$(cat $(L)/state)\" = 'restore W0'" 330 331 CASE=rebind; echo "case $CASE: D2 window, RESTORE_PATH=rebind"; mkroot $CASE 332 run_window "$S" env RESTORE_PATH=rebind sh window/d2-pre.sh --go D2 333 boots 1; restored 334 335 CASE=noappr; echo "case $CASE: no approval file"; mkroot $CASE 336 rm "$(L)/APPROVED" 337 run_window "$S" sh window/d2-pre.sh --go D2 338 check "refused" "grep -q 'cmd exit 1' $S/st/events"; untouched 339 340 CASE=noreset; echo "case $CASE: approval without 'reset: approved'"; mkroot $CASE 341 printf 'window: sim\nreboot: approved\n' > "$(L)/APPROVED" 342 run_window "$S" sh window/d2-pre.sh --go D2 343 check "refused" "grep -q 'cmd exit 1' $S/st/events"; untouched 344 345 CASE=locked; echo "case $CASE: chip lock held by another GPU job"; mkroot $CASE 346 (flock -x 9; sleep 30) 9>>"$S/tmp/aien-gb10.lock" & 347 lockpid=$!; sleep 0.3 348 run_window "$S" sh window/d2-pre.sh --go D2 349 kill $lockpid 2>/dev/null || true 350 check "refused" "grep -q 'cmd exit 1' $S/st/events"; untouched 351 352 CASE=snapdiff; echo "case $CASE: live 35B started differently from the restore recipe"; mkroot $CASE 353 printf 'Q36_BATCH_BIN=bin-`99230310`\0AIEN_COORD_KEY=simkey\0' > "$S/proc/$(cat "$S/st/35b")/environ" 354 run_window "$S" sh window/d2-pre.sh --go D2 355 check "refused" "grep -q 'cmd exit 1' $S/st/events"; untouched 356 357 CASE=w1abort; echo "case $CASE: W1 fails after stopping the 35B (systemctl enable fails)"; mkroot $CASE 358 touch "$S/st/fail_enable" 359 run_window "$S" sh window/d2-pre.sh --go D2 360 boots 0; restored 361 check "W1 exit nonzero" "grep -q 'cmd exit 1' $S/st/events" 362 363 CASE=pm; echo "case $CASE: runtime PM stays suspended after power/control=on"; mkroot $CASE 364 touch "$S/st/pm_suspended" "$S/st/pm_stuck" 365 run_window "$S" sh window/d2-pre.sh --go D2 366 rm -f "$S/st/pm_suspended" "$S/st/pm_stuck" 367 check "w0 never ran (no BAR access while suspended)" "! grep -q '^w0 ' $S/st/events" 368 check "W3 refused on runtime_status" "grep -q 'runtime_status=suspended, not active' $(L)/*-run.log" 369 boots 2; restored 370 371 CASE=w0fail; echo "case $CASE: w0 fails"; mkroot $CASE 372 echo 3 > "$S/st/w0_rc" 373 run_window "$S" sh window/d2-pre.sh --go D2 374 boots 2; restored 375 check "release logged rc=1" "grep -q 'W7 release (rc=1)' $(L)/*-run.log" 376 377 CASE=crash; echo "case $CASE: crash during W3 (no trap runs)"; mkroot $CASE 378 touch "$S/st/w0_crash" 379 run_window "$S" sh window/d2-pre.sh --go D2 380 boots 2; restored 381 382 CASE=fallback; echo "case $CASE: nvidia fails to come back once: one reboot fallback"; mkroot $CASE 383 echo 1 > "$S/st/nvidia_bad_boots" 384 run_window "$S" sh window/d2-pre.sh --go D2 385 boots 3; restored 386 check "fallback used once" "grep -q 'reboot fallback' $S/home/handoffs/BOARD.md" 387 388 CASE=fallback2; echo "case $CASE: nvidia never comes back: stop after one fallback"; mkroot $CASE 389 echo 99 > "$S/st/nvidia_bad_boots" 390 run_window "$S" sh window/d2-pre.sh --go D2 391 boots 3 392 check "BOARD says restore FAILED" "grep -q 'restore FAILED after the reboot fallback' $S/home/handoffs/BOARD.md" 393 check "no reboot loop" "! grep -q 'boot loop' $S/st/events" 394 check "unit and state kept for the next (manual) boot" "[ -e $S/etc/systemd/system/aien-owndriver-window.service ] && [ \$(cat $(L)/state) = restore ]" 395 396 CASE=leak; echo "case $CASE: a privilege file appears during the window"; mkroot $CASE 397 touch "$S/st/w0_leak" 398 run_window "$S" sh window/d2-pre.sh --go D2 399 check "BOARD says PRIVILEGE PERSISTED" "grep -q 'PRIVILEGE PERSISTED' $S/home/handoffs/BOARD.md" 400 check "no WINDOW CLOSED" "! grep -q 'WINDOW CLOSED' $S/home/handoffs/BOARD.md" 401 402 CASE=vfiomode; echo "case $CASE: /dev/vfio/20 comes up world-writable"; mkroot $CASE 403 echo root:root:666 > "$S/st/vfio_mode" 404 run_window "$S" sh window/d2-pre.sh --go D2 405 check "w0 never ran" "! grep -q '^w0 ' $S/st/events" 406 check "W2 refused on the mode" "grep -q 'is root:root:666, expected root:root:600' $(L)/*-run.log" 407 boots 2; restored 408 409 CASE=lockboot; echo "case $CASE: another GPU job takes the chip lock right after the W1 reboot"; mkroot $CASE 410 touch "$S/st/lock_after_reboot" 411 run_window "$S" sh window/d2-pre.sh --go D2 412 kill "$(cat "$S/st/lockholder")" 2>/dev/null || true 413 check "w0 never ran" "! grep -q '^w0 ' $S/st/events" 414 check "W2 refused on the lock" "grep -q 'is held: something started a GPU job' $(L)/*-run.log" 415 boots 2; restored 416 417 CASE=d3noogd; echo "case $CASE: D3 without build/ogd"; mkroot $CASE 418 D3_CMD="make chip-gates" run_window "$S" sh window/d2-pre.sh --go D3 419 check "refused" "grep -q 'cmd exit 1' $S/st/events"; untouched 420 421 for capability in model suffix failed; do 422 CASE=d3$capability; echo "case $CASE: D3 requires successful exact exec capability"; mkroot "$CASE" 423 before=$(cat "$S/st/35b") 424 case $capability in model) advertised='model\nmodel-trace'; queryrc=0 ;; suffix) advertised=exec-extra; queryrc=0 ;; failed) advertised=exec; queryrc=1 ;; esac 425 printf '#!/bin/sh\n[ "$1" = modes ] || exit 95\nprintf "%%b\\n" "%s"\nexit %s\n' "$advertised" "$queryrc" > "$S/build/ogd" 426 chmod +x "$S/build/ogd" 427 D3_CMD="make chip-gates" run_window "$S" sh window/d2-pre.sh --go D3 428 check "D3 capability refused before disruption" "grep -q 'cmd exit 1' $S/st/events && grep -q \"successful exact 'exec' mode\" $(L)/*-pre.log" 429 untouched; boots 0 430 check "original server retained" "[ '$before' = \"\$(cat $S/st/35b)\" ] && kill -0 '$before'" 431 check "no VFIO binding" "! grep -q 'bind vfio-pci' $S/st/events" 432 check "no D3 command or restore-path persisted" "[ ! -e $(L)/d3-cmd ] && [ ! -e $(L)/restore-path ]" 433 done 434 435 CASE=d3exec; echo "case $CASE: successful exact exec capability reaches D3"; mkroot "$CASE" 436 cat > "$S/build/ogd" <<'EOF' 437 #!/bin/sh 438 case $1 in 439 modes) echo exec ;; 440 exec) echo "ogd exec" >> "${OWNDRIVER_WINDOW_ROOT:?}/st/events" ;; 441 *) exit 95 ;; 442 esac 443 EOF 444 chmod +x "$S/build/ogd" 445 D3_CMD="make chip-gates" run_window "$S" sh window/d2-pre.sh --go D3 446 check "D3 exec ran in isolated simulator" "grep -q '^ogd exec$' $S/st/events" 447 boots 2; restored 448 449 CASE=stale; echo "case $CASE: boot unit left over with no state"; mkroot $CASE 450 sed "s|@CHECKOUT@|$S/repo|g" "$R/window/aien-owndriver-window.service" > "$S/etc/systemd/system/aien-owndriver-window.service"; touch "$S/st/unit-enabled" 451 boot_power_on "$S" 1 452 check "unit removed itself" "[ ! -e $S/etc/systemd/system/aien-owndriver-window.service ] && [ ! -e $S/st/unit-enabled ]" 453 check "no driver change" "! grep -q 'bind vfio-pci' $S/st/events" 454 455 for s in "$BASE"/*/st/35b; do [ -s "$s" ] && kill "$(cat "$s")" 2>/dev/null || true; done 456 [ -n "${SIMDIR:-}" ] || rm -rf "$BASE" 457 if [ "$fail" -eq 0 ]; then 458 echo "window_sim: PASS ($pass checks, $(grep -c '^CASE=' "$0") scenarios)" 459 else 460 echo "window_sim: FAIL ($fail of $((pass + fail)) checks; in:$FAILED_IN)" 461 exit 1 462 fi