#!/usr/bin/env bash # # scripts/test-gfx.sh — automated graphics-layer verification. # # The cursor overlay compositor is the core of the GUI path: the shadow # holds true content, the display gets shadow pushes with the cursor # painted on top at every push, and the cursor never enters the shadow. # This test boots QEMU headless and runs `gfx check` — an in-kernel # pixel self-test that reads back shadow *and* display pixels — plus the # `gfx` demo scene. Cursor *movement* against injected mouse input is # covered by test-mouse.sh; here we prove the compositor math. # # Usage: ./scripts/test-gfx.sh # Env: OVMF, QEMU (same defaults as other test scripts) # set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" cd "$PROJECT_DIR" OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" QEMU="${QEMU:-qemu-system-x86_64}" ESP_DIR="$PROJECT_DIR/esp" QPID=/tmp/rsdos-gfx-qpid SOCK=/tmp/rsdos-gfx-qmon.sock LOG=/tmp/rsdos-gfx-serial.log QLOG=/tmp/rsdos-gfx-qemu.log trap 'kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true' EXIT fail() { echo "FAIL: $1" [ -f "$LOG" ] && tail -40 "$LOG" exit 1 } wait_log() { local i=0 while [ "$i" -lt $((${3:-60} * 10)) ]; do grep -q "$2" "$1" 2>/dev/null && return 0 sleep 0.1 i=$((i + 1)) done return 1 } wait_qemu_exit() { local i=0 while [ "$i" -lt $((${1:-30} * 10)) ]; do kill -0 "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || return 0 sleep 0.1 i=$((i + 1)) done return 1 } qemu_hmp() { python3 - "$SOCK" "$1" <<'EOF' import socket, sys, time s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.connect(sys.argv[1]) s.sendall((sys.argv[2] + "\n").encode()) time.sleep(0.4) EOF } echo "==> 1/5 build kernel (debug)" cargo build --package rsdos --target x86_64-unknown-uefi echo "==> 2/5 deploy to ESP" mkdir -p "$ESP_DIR/EFI/BOOT" cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI" echo "==> 3/5 boot QEMU (headless)" kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true sleep 1 rm -f "$SOCK" "$LOG" "$QEMU" -bios "$OVMF" \ -drive file=fat:rw:"$ESP_DIR",format=raw \ -serial file:"$LOG" \ -monitor unix:"$SOCK",server,nowait \ -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \ >"$QLOG" 2>&1 & echo $! >"$QPID" wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell" wait_log "$LOG" "cursor: task " 10 || fail "cursor task did not spawn" echo "==> 4/5 in-kernel pixel self-test (gfx check)" python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ "clear" \ "gfx check" sleep 1.5 # Every sub-check must have printed OK. grep -aq "fill_rect/shadow: OK" "$LOG" || fail "shadow writeback failed" grep -aq "display push: OK" "$LOG" || fail "shadow→display push failed" grep -aq "cursor overlay: OK" "$LOG" || fail "cursor not composited on display" grep -aq "cursor not in shadow: OK" "$LOG" || fail "cursor leaked into the shadow" grep -aq "gfx check: PASS" "$LOG" || fail "gfx check did not PASS" grep -aq "gfx check: FAIL" "$LOG" && fail "gfx check reported FAIL" echo "==> 5/5 demo scene + poweroff" python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ "gfx" \ "poweroff" wait_qemu_exit 30 || fail "QEMU did not exit after poweroff" grep -aq "gfx: drew status bar" "$LOG" || fail "gfx demo did not draw" echo "" echo "PASS — graphics layer OK (shadow, display push, cursor overlay)" echo " compositor: shadow=content, display=push+cursor, cursor never in shadow"