Blob: scripts/check-c0.exp
Raw · Blame
#!/usr/bin/expect -f
if {$argc != 1} {
puts stderr "usage: check-c0.exp RUNNER"
exit 2
}
set runner [file normalize [lindex $argv 0]]
set timeout 30
proc fail {message} {
puts stderr "C0 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_regexp {pattern description} {
expect {
-re $pattern {
return
}
timeout {
fail "timed out waiting for $description"
}
eof {
fail "QEMU exited while waiting for $description"
}
}
}
proc boot_mouse {runner} {
global spawn_id
spawn -noecho $runner
await_exact "Cheesed to meet you! v0.1.0" "the cheesed startup banner"
await_exact "cheesed: C0 bootstrap complete; cheesed is PID 1" "PID 1 confirmation"
await_exact "MOUSE 0.1.0 (x86_64)" "the MOUSE login banner"
await_exact "mouse:~# " "the tcsh prompt"
}
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"
}
}
}
boot_mouse $runner
send -- "hostname\r"
await_exact "mouse\r" "the configured hostname"
await_exact "mouse:~# " "the prompt after hostname"
send -- "cat /proc/1/comm\r"
await_exact "cheesed\r" "cheesed in /proc/1"
await_exact "mouse:~# " "the prompt after the PID 1 check"
send -- "sh -c 'test -c /dev/null'; echo DEV_STATUS_\$status\r"
await_exact "DEV_STATUS_0\r" "a mounted devtmpfs"
await_exact "mouse:~# " "the prompt after the devtmpfs check"
send -- "clear; echo CLEAR_STATUS_\$status\r"
await_exact "CLEAR_STATUS_0\r" "a successful clear command"
await_exact "mouse:~# " "the prompt after clear"
send -- "sleep 1 &\r"
await_regexp {\[1\] [0-9]+} "a background tcsh job"
await_exact "mouse:~# " "the prompt after starting a background job"
send -- "jobs\r"
await_exact "Running" "tcsh job control"
await_exact "mouse:~# " "the prompt after jobs"
send -- {sh -c 'i=0; while [ "$i" -lt 8 ]; do (sleep 1) & i=$((i + 1)); done'}
send -- "\r"
await_exact "mouse:~# " "the prompt after starting orphan probes"
await_exact "cheesed: reaped orphan PID " "PID 1 orphan reaping"
send -- "sleep 2\r"
await_exact "mouse:~# " "all orphan probes to exit"
send -- {sh -c 'if grep -l ") Z " /proc/[0-9]*/stat >/dev/null; then hostname; else cat /proc/1/comm; fi'}
send -- "\r"
await_exact "cheesed\r" "a zombie-free process table"
await_exact "mouse:~# " "the prompt after the zombie check"
send -- "kill -TERM 1\r"
await_exact "cheesed: received poweroff request" "the poweroff request"
await_clean_exit "poweroff"
boot_mouse $runner
send -- "kill -INT 1\r"
await_exact "cheesed: received reboot request" "the reboot request"
await_clean_exit "reboot"
puts "C0 QEMU integration checks passed"