Blob: scripts/check-c1.exp
Raw · Blame
#!/usr/bin/expect -f
if {$argc != 2} {
puts stderr "usage: check-c1.exp RUNNER enabled|disabled"
exit 2
}
set runner [file normalize [lindex $argv 0]]
set policy [lindex $argv 1]
set timeout 45
proc fail {message} {
puts stderr "C1 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 to meet you! v0.1.0" "the cheesed startup banner"
await_exact "cheesed: C1 bootstrap complete; cheesed is PID 1" "PID 1 confirmation"
if {$policy eq "enabled"} {
await_exact "cheesed: enabled optional services: mouse_optional" "enabled-service policy"
} elseif {$policy eq "disabled"} {
await_exact "cheesed: enabled optional services: (none)" "disabled-service policy"
} else {
fail "unknown policy $policy"
}
await_exact "cheesed: generated OpenRC runlevels at /run/openrc/runlevels/generations/1" "the generated runlevel"
await_exact "cheesed: OpenRC sysinit transition complete" "the sysinit transition"
await_exact "cheesed: OpenRC boot transition complete" "the boot transition"
await_exact "Marking the MOUSE base ready" "the required service"
if {$policy eq "enabled"} {
await_exact "Starting mouse_optional" "the optional service after its dependency"
}
await_exact "cheesed: OpenRC default transition complete" "the default transition"
await_exact "MOUSE 0.1.0 (x86_64)" "the MOUSE login banner"
await_exact "mouse:~# " "the tcsh prompt"
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 -f /run/mouse-ready.started'; echo READY_\$status\r"
await_exact "READY_0\r" "the required service marker"
await_exact "mouse:~# " "the prompt after the required service check"
send -- "sh -c 'test -L /etc/runlevels'; echo RUNLEVELS_\$status\r"
await_exact "RUNLEVELS_0\r" "the immutable runlevel link"
await_exact "mouse:~# " "the prompt after the runlevel-link check"
send -- "sh -c 'test ! -e /sbin/rc-update'; echo NO_RC_UPDATE_\$status\r"
await_exact "NO_RC_UPDATE_0\r" "the absence of rc-update"
await_exact "mouse:~# " "the prompt after the rc-update check"
if {$policy eq "enabled"} {
send -- "sh -c 'test -f /run/mouse-optional.started'; echo OPTIONAL_\$status\r"
await_exact "OPTIONAL_0\r" "the optional service marker"
await_exact "mouse:~# " "the prompt after the optional marker check"
send -- "service mouse_optional status\r"
await_exact "status: started" "supervise-daemon service status"
await_exact "mouse:~# " "the prompt after service status"
send -- "sh -c 'old_child=`cat /run/openrc/options/mouse_optional/child_pid`; kill -TERM \"\$old_child\"; sleep 3; new_child=`cat /run/openrc/options/mouse_optional/child_pid`; test \"\$old_child\" != \"\$new_child\"'; echo RESPAWN_\$status\r"
await_exact "RESPAWN_0\r" "supervise-daemon replacing a terminated child"
await_exact "mouse:~# " "the prompt after the respawn check"
send -- "sh -c 'test `cat /run/openrc/options/mouse_optional/start_count` = 1'; echo COUNT_\$status\r"
await_exact "COUNT_0\r" "the recorded supervisor restart count"
await_exact "mouse:~# " "the prompt after the restart-count check"
send -- "set before=\"`cksum /etc/rc.conf`\"; service mouse_optional stop\r"
await_exact "Stopping mouse_optional" "the runtime service stop"
await_exact "mouse:~# " "the prompt after stopping the service"
send -- "service mouse_optional start\r"
await_exact "Starting mouse_optional" "the runtime service start"
await_exact "mouse:~# " "the prompt after starting the service"
send -- "set after=\"`cksum /etc/rc.conf`\"; sh -c 'test \"\$1\" = \"\$2\"' sh \"\$before\" \"\$after\"; echo POLICY_\$status\r"
await_exact "POLICY_0\r" "runtime service control preserving boot policy"
await_exact "mouse:~# " "the prompt after the policy check"
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"
} else {
send -- "sh -c 'test ! -e /run/mouse-optional.started'; echo OPTIONAL_DISABLED_\$status\r"
await_exact "OPTIONAL_DISABLED_0\r" "the disabled optional service"
await_exact "mouse:~# " "the prompt after the disabled service check"
send -- "service mouse_optional status\r"
await_exact "status: stopped" "the disabled service status"
await_exact "mouse:~# " "the prompt after disabled service status"
send -- "kill -INT 1\r"
await_exact "cheesed: received reboot request" "the reboot request"
await_exact "cheesed: OpenRC shutdown transition complete" "the shutdown transition"
await_clean_exit "reboot"
}
puts "C1 QEMU integration check passed for $policy policy"