tests: replace expect with stdlib python helper for QEMU login proofs

Drop the host expect dependency from the PS/2, timer, IOMMU, and USB
storage (BOT) runtime proofs. local/scripts/qemu-login-expect.py drives
the guest over serial-on-stdio with ordered expect/send steps, per-step
timeouts (matching expect's per-pattern semantics), and pass/fail markers.
It distinguishes premature QEMU death (exit 3) from genuine check failure
(exit 1) so the scripts retry external interruptions without retrying real
failures. Scripts use headless -display none -vga none (fbcond serial
mirror), a 3600s per-step timeout, and a retry loop (max 5 attempts).
This commit is contained in:
2026-07-20 05:38:44 +09:00
parent 569f05debc
commit 9ec00d4c81
5 changed files with 299 additions and 108 deletions
+40 -48
View File
@@ -109,54 +109,46 @@ pkill -f "qemu-system-x86_64.*$config" 2>/dev/null || true
sleep 1
rm -f "$log_file"
expect <<EOF
log_user 1
log_file -noappend $log_file
set timeout 300
spawn qemu-system-x86_64 -name {Red Bear OS x86_64} -device qemu-xhci,id=xhci -smp 4 -m 2048 -bios $firmware -chardev stdio,id=debug,signal=off,mux=on -serial chardev:debug -mon chardev=debug -machine q35 -device ich9-intel-hda -device hda-output -device virtio-net,netdev=net0 -netdev user,id=net0 -object filter-dump,id=f1,netdev=net0,file=build/$arch/$config/network.pcap -nographic -vga none ${boot_args[*]} -drive file=$extra,format=raw,if=none,id=drv1,snapshot=on -device nvme,drive=drv1,serial=NVME_EXTRA -drive file=$usb_img,format=raw,if=none,id=usbdisk,snapshot=on -device usb-storage,bus=xhci.0,drive=usbdisk -enable-kvm -cpu host
expect "USB SCSI driver spawned"
expect "DISK CONTENT: $expected_sector_b64"
expect "login:"
send "root\r"
expect "assword:"
send "password\r"
expect "Type 'help' for available commands."
send "redbear-usb-storage-check\r"
expect {
"[PASS] STORAGE_DISCOVERY:" { }
"[FAIL] STORAGE_DISCOVERY:" {
puts "ERROR: USB storage device discovery failed"
exit 1
}
timeout { exit 1 }
}
expect {
"[PASS] STORAGE_WRITE:" { }
"[FAIL] STORAGE_WRITE:" {
puts "ERROR: USB storage write failed"
exit 1
}
timeout { exit 1 }
}
expect {
"[PASS] STORAGE_READBACK:" { }
"[FAIL] STORAGE_READBACK:" {
puts "ERROR: USB storage readback failed"
exit 1
}
timeout { exit 1 }
}
expect {
"[PASS] STORAGE_RESTORE:" { }
"[FAIL] STORAGE_RESTORE:" {
puts "ERROR: USB storage sector restore failed"
exit 1
}
timeout { exit 1 }
}
send "shutdown\r"
sleep 2
EOF
attempt=1
while true; do
rc=0
python3 local/scripts/qemu-login-expect.py \
--timeout 3600 \
--log "$log_file" \
--step "expect:USB SCSI driver spawned" \
--step "expect:DISK CONTENT: $expected_sector_b64" \
--step "expect:login:" \
--step "send:root" \
--step "expect:assword:" \
--step "send:password" \
--step "expect:Type 'help' for available commands." \
--step "send:redbear-usb-storage-check" \
--step "expect:[PASS] STORAGE_DISCOVERY:" \
--step "expect:[PASS] STORAGE_WRITE:" \
--step "expect:[PASS] STORAGE_READBACK:" \
--step "expect:[PASS] STORAGE_RESTORE:" \
--step "send:shutdown" \
--pass_marker "[PASS] STORAGE_DISCOVERY:" \
--pass_marker "[PASS] STORAGE_WRITE:" \
--pass_marker "[PASS] STORAGE_READBACK:" \
--pass_marker "[PASS] STORAGE_RESTORE:" \
--fail_marker "[FAIL] STORAGE_DISCOVERY:" \
--fail_marker "[FAIL] STORAGE_WRITE:" \
--fail_marker "[FAIL] STORAGE_READBACK:" \
--fail_marker "[FAIL] STORAGE_RESTORE:" \
-- \
qemu-system-x86_64 -name "Red Bear OS x86_64" -device qemu-xhci,id=xhci -smp 4 -m 2048 -bios "$firmware" -chardev stdio,id=debug,signal=off,mux=on -serial chardev:debug -mon chardev=debug -machine q35 -device ich9-intel-hda -device hda-output -device virtio-net,netdev=net0 -netdev user,id=net0 -object filter-dump,id=f1,netdev=net0,file="build/$arch/$config/network.pcap" -display none -vga none "${boot_args[@]}" -drive file="$extra",format=raw,if=none,id=drv1,snapshot=on -device nvme,drive=drv1,serial=NVME_EXTRA -drive file="$usb_img",format=raw,if=none,id=usbdisk,snapshot=on -device usb-storage,bus=xhci.0,drive=usbdisk -enable-kvm -cpu host || rc=$?
if [[ $rc -eq 0 ]]; then
break
fi
if [[ ( $rc -eq 3 || $rc -eq 137 ) && $attempt -lt 5 ]]; then
attempt=$((attempt + 1))
echo "QEMU exited before completing the check; retrying (attempt $attempt/3)"
sleep 2
continue
fi
exit "$rc"
done
pkill -f "qemu-system-x86_64.*$image" 2>/dev/null || true