Blob: scripts/check-c2.exp
Raw · Blame
#!/usr/bin/expect -f
if {$argc != 1} {
puts stderr "usage: check-c2.exp RUNNER"
exit 2
}
set runner [file normalize [lindex $argv 0]]
set timeout 45
proc fail {message} {
puts stderr "C2 check failed: $message"
exit 1
}
proc await_exact {text description} {
expect {
-exact $text {
return
}
timeout {
fail "timed out waiting for $description"
}
eof {
fail "QEMU exited while waiting for $description"
}
}
}
proc await_clean_exit {action} {
expect {
eof {
set result [wait]
set status [lindex $result 3]
if {$status != 0} {
fail "QEMU exited with status $status after $action"
}
}
timeout {
fail "QEMU did not exit after $action"
}
}
}
spawn -noecho $runner
await_exact "cheesed: C1 bootstrap complete; cheesed is PID 1" "PID 1 confirmation"
await_exact "cheesed: enabled optional services: mouse_optional" "enabled-service policy"
await_exact "cheesed: OpenRC default transition complete" "the default transition"
await_exact "mouse:~# " "the tcsh prompt"
send -- "sh -c 'i=0; while \[ \"\$i\" -lt 4 \]; do child=`cat /run/openrc/options/mouse_optional/child_pid`; kill -KILL \"\$child\"; i=\$((i + 1)); sleep 1; done'; echo EXHAUST_\$status\r"
await_exact "EXHAUST_0\r" "four supervised crashes"
await_exact "mouse:~# " "the prompt after exhausting respawns"
send -- "service mouse_optional status; echo FAILED_STATUS_\$status\r"
await_exact "status: failed" "the failed service status"
await_exact "FAILED_STATUS_32\r" "the failed status exit code"
await_exact "mouse:~# " "the prompt after failed status"
send -- "sh -c 'test -e /run/openrc/failed/mouse_optional'; echo FAILED_MARKER_\$status\r"
await_exact "FAILED_MARKER_0\r" "OpenRC's failed-state marker"
await_exact "mouse:~# " "the prompt after the failed marker"
send -- "service mouse_optional restart\r"
await_exact "Starting mouse_optional" "administrative recovery"
await_exact "mouse:~# " "the prompt after administrative recovery"
send -- "service mouse_optional status\r"
await_exact "status: started" "started status after recovery"
await_exact "mouse:~# " "the prompt after recovered status"
send -- "sh -c 'test ! -e /run/openrc/failed/mouse_optional'; echo RECOVERED_\$status\r"
await_exact "RECOVERED_0\r" "the cleared failed state"
await_exact "mouse:~# " "the prompt after the recovery-state check"
send -- "set stubborn=`cat /run/openrc/options/mouse_optional/child_pid`; service mouse_optional stop\r"
await_exact "Stopping mouse_optional" "the forced runtime stop"
await_exact "mouse:~# " "the prompt after the forced runtime stop"
send -- "sh -c 'test -f /run/mouse-c2-daemon.term'; echo TERM_SEEN_\$status\r"
await_exact "TERM_SEEN_0\r" "the daemon observing and ignoring SIGTERM"
await_exact "mouse:~# " "the prompt after the SIGTERM marker check"
send -- "sh -c '! kill -0 \"\$1\" 2>/dev/null' sh \"\$stubborn\"; echo FORCED_GONE_\$status\r"
await_exact "FORCED_GONE_0\r" "supervise-daemon escalating to SIGKILL"
await_exact "mouse:~# " "the prompt after forced termination"
send -- "service mouse_optional start\r"
await_exact "Starting mouse_optional" "the final runtime start"
await_exact "mouse:~# " "the prompt after the final runtime start"
send -- "kill -TERM 1\r"
await_exact "cheesed: received poweroff request" "the poweroff request"
await_exact "cheesed: OpenRC shutdown transition complete" "the shutdown transition"
await_clean_exit "poweroff"
puts "C2 QEMU supervision checks passed"