Files
RedBear-OS/local/scripts/test-phase3-runtime.sh
T
vasilito 6dab9b2953 tests: migrate remaining QEMU runtime proofs to qemu-login-expect.py
Convert the remaining expect-based test scripts (phase1-6 runtime, usb,
wifi, bluetooth, dbus, greeter, live-iso, posix) to the stdlib python
harness, completing the migration started in 9ec00d4c81. Each script now
prefers booting the live ISO when present (falling back to harddrive.img
with snapshot=on), and retries up to 5 times when QEMU exits early or is
killed (rc 3 / 137) — the host-contention failure mode recorded in the
2026-07-20 runtime-proof status.

qemu-login-expect.py: treat an incomplete step sequence as a failure even
when a pass marker was seen partway through — partial sequences must not
count as a pass.
2026-07-20 09:01:14 +09:00

176 lines
5.7 KiB
Bash

#!/usr/bin/env bash
# Phase 3 desktop-session preflight — automated runtime validation harness.
# Validates compositor binary, D-Bus session, seatd, and WAYLAND_DISPLAY.
# Does NOT validate real KWin behavior (KWin recipe is a stub pending Qt6Quick/QML).
#
# Modes:
# --guest Run inside a Red Bear OS guest
# --qemu [CONFIG] Boot CONFIG in QEMU and run the same checks automatically
#
# Exit codes:
# 0 — all checks passed
# 1 — one or more checks failed
# 2 — QEMU boot or login failure
set -euo pipefail
find_uefi_firmware() {
local candidates=(
"/usr/share/ovmf/x64/OVMF.4m.fd"
"/usr/share/OVMF/x64/OVMF.4m.fd"
"/usr/share/ovmf/x64/OVMF_CODE.4m.fd"
"/usr/share/OVMF/x64/OVMF_CODE.4m.fd"
"/usr/share/qemu/edk2-x86_64-code.fd"
)
local path
for path in "${candidates[@]}"; do
if [[ -f "$path" ]]; then
printf '%s\n' "$path"
return 0
fi
done
return 1
}
run_guest_checks() {
echo "=== Red Bear OS Phase 3 Desktop Session Preflight ==="
echo
local failures=0
local expected_bins=(
"redbear-phase3-kwin-check"
)
local bin
for bin in "${expected_bins[@]}"; do
if ! command -v "$bin" >/dev/null 2>&1; then
echo " FAIL $bin: required Phase 3 check binary is not installed"
failures=$((failures + 1))
fi
done
if [[ "$failures" -eq 0 ]]; then
echo " Running redbear-phase3-kwin-check..."
if redbear-phase3-kwin-check --json >/dev/null 2>&1; then
echo " PASS redbear-phase3-kwin-check: desktop session preflight passed"
else
echo " FAIL redbear-phase3-kwin-check: desktop session preflight failed"
failures=$((failures + 1))
fi
fi
echo
echo "=== Phase 3 Desktop Session Preflight Complete ==="
if [[ "$failures" -gt 0 ]]; then
echo " $failures check(s) FAILED"
return 1
fi
echo " All checks PASSED"
return 0
}
run_qemu_checks() {
local config="${1:-redbear-full}"
local firmware
firmware="$(find_uefi_firmware)" || {
echo "ERROR: no usable x86_64 UEFI firmware found" >&2
exit 2
}
local arch image iso extra
arch="${ARCH:-$(uname -m)}"
image="build/$arch/$config/harddrive.img"
iso="build/$arch/$config.iso"
extra="build/$arch/$config/extra.img"
boot_media=""
if [[ -f "$iso" ]]; then
boot_media="iso"
elif [[ -f "$image" ]]; then
boot_media="harddrive"
else
echo "ERROR: no bootable image found ($iso or $image)" >&2
echo "Build it first with: ./local/scripts/build-redbear.sh $config" >&2
exit 2
fi
if [[ "$boot_media" == "iso" ]]; then
boot_args=(-cdrom "$iso")
else
boot_args=(-drive file="$image",format=raw,if=none,id=drv0,snapshot=on -device nvme,drive=drv0,serial=NVME_SERIAL)
fi
if [[ ! -f "$extra" ]]; then
truncate -s 1g "$extra"
fi
attempt=1
while true; do
rc=0
python3 local/scripts/qemu-login-expect.py \
--timeout 300 \
--log "build/$arch/$config/phase3-check.log" \
--step "expect:login:" \
--step "send:root" \
--step "expect:assword:" \
--step "send:password" \
--step "expect:Type 'help' for available commands." \
--step "send:echo __READY__" \
--step "expect:__READY__" \
--step "send:command -v redbear-phase3-kwin-check >/dev/null 2>&1 && echo __PHASE3_BIN_OK__ || echo __PHASE3_BIN_FAIL__" \
--step "expect:__PHASE3_BIN_OK__" \
--step "send:redbear-phase3-kwin-check --json >/dev/null 2>&1 && echo __PHASE3_OK__ || echo __PHASE3_FAIL__" \
--step "expect:__PHASE3_OK__" \
--step "send:echo __PHASE3_RUNTIME_DONE__" \
--step "expect:__PHASE3_RUNTIME_DONE__" \
--step "send:shutdown" \
--pass_marker "__PHASE3_BIN_OK__" \
--pass_marker "__PHASE3_OK__" \
--pass_marker "__PHASE3_RUNTIME_DONE__" \
--fail_marker "__PHASE3_BIN_FAIL__" \
--fail_marker "__PHASE3_FAIL__" \
-- \
qemu-system-x86_64 -name "Red Bear OS x86_64" -device qemu-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 -display none -vga none "${boot_args[@]}" -drive file="$extra",format=raw,if=none,id=drv1,snapshot=on -device nvme,drive=drv1,serial=NVME_EXTRA -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/5)"
sleep 2
continue
fi
exit "$rc"
done
pkill -f "qemu-system-x86_64.*$config" 2>/dev/null || true
echo "Phase 3 desktop session preflight completed via guest runtime check"
exit 0
}
usage() {
cat <<'USAGE'
Usage:
./local/scripts/test-phase3-runtime.sh --guest
./local/scripts/test-phase3-runtime.sh --qemu [redbear-full]
This script validates Phase 3 desktop session preflight by running the
canonical Phase 3 check binary and treating its exit code as authoritative.
Required binary (must be in PATH inside the guest):
redbear-phase3-kwin-check — desktop session preflight
USAGE
}
case "${1:-}" in
--guest)
run_guest_checks
;;
--qemu)
run_qemu_checks "${2:-redbear-full}"
;;
*)
usage
exit 1
;;
esac