From 819778f292ee4e1294603b98662e083e49e23463 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 1 Aug 2026 19:52:05 +0200 Subject: rsnix v0.5.0: graphics layer + cursor compositor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first visible GUI surface: real rect primitives, a single shadow→display push path, and an on-screen mouse cursor that can never race the text surface. gop: - fill_rect + push_rect(x,y,w,h): every raster op rasterises into the RAM shadow, then push_rect copies the rect to the display (write-only, still never read) and composites the cursor on top. blit_glyph and scroll shifts now route through it. - cursor overlay: 12x16 pointer (const-fn built from column lists) drawn white with a black offset outline; position in one AtomicU64 (x:high 32, y:low 32) — unpack masks the low word (a bare 'as usize' cast is a no-op on 64-bit). The cursor never enters the shadow, so erasing is just a shadow push of the old rect. - cursor_redraw after scroll shifts and once at spawn (the vt diff never re-blits idle cells). cursor task (task 2, spawned at boot when a mouse is present): - owns the PS/2 ring; polls every 10 ms, moves the cursor (clamped), tracks buttons, and forwards every event to a task's queue when 'mouse ' armed it (the window-manager input path). - /dev/mouse is now a position device (x/y/buttons snapshot); 'mouse' watches the cursor live (prints on change); 'cursor' prints one-shot state; 'gfx' draws a status-bar demo; 'gfx check' is an in-kernel pixel self-test (shadow readback, display readback, cursor overlay purity) — PASS/FAIL per stage. Tests (headless QEMU + monitor injection): - make test-gfx (new): all four compositor checks PASS. - make test-mouse (rewritten): cursor tracks mouse_move deltas, buttons ride along, /dev/mouse snapshot, live watch, real-event queue routing. - make test-msg: task numbering shifted (cursor is task 2; msgrecv is task 3) — updated, still PASS. - make test-disk regression re-passes. 0 build warnings. --- scripts/test-gfx.sh | 114 +++++++++++++++++++++++++++++++++++++++++++++ scripts/test-mouse.sh | 125 ++++++++++++++++++++++++++++++++------------------ scripts/test-msg.sh | 37 +++++++-------- 3 files changed, 214 insertions(+), 62 deletions(-) create mode 100755 scripts/test-gfx.sh (limited to 'scripts') diff --git a/scripts/test-gfx.sh b/scripts/test-gfx.sh new file mode 100755 index 0000000..a6e4016 --- /dev/null +++ b/scripts/test-gfx.sh @@ -0,0 +1,114 @@ +#!/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" +grep -aq "cursor: task " "$LOG" || 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" diff --git a/scripts/test-mouse.sh b/scripts/test-mouse.sh index ed4df44..e58d474 100755 --- a/scripts/test-mouse.sh +++ b/scripts/test-mouse.sh @@ -1,20 +1,19 @@ #!/usr/bin/env bash # -# scripts/test-mouse.sh — automated PS/2 mouse round trip. +# scripts/test-mouse.sh — automated mouse round trip (cursor model). # -# Builds the kernel, boots QEMU headless, injects mouse movement and -# button presses through the monitor's `mouse_move` / `mouse_button` -# commands, and verifies the guest decoded them via IRQ12 → ring → -# packet decoder. Covers both surfaces: -# - `cat /dev/mouse` (VFS snapshot of pending events) -# - `mouse` (live streaming command, stopped by ^C) +# Since v0.5.0 the cursor task owns the PS/2 ring: mouse input shows up +# as *cursor position + buttons* on the screen, not as an event drain. +# This script boots QEMU headless, injects movement/buttons via the +# monitor, and verifies: +# - the `cursor` command reports a position that moves with `mouse_move` +# - button presses ride along (L while held) +# - `/dev/mouse` is a position device (one snapshot line) +# - the `mouse` watch command prints live changes and stops on ^C +# - a `mouse ` forward routes real events to a task's queue # -# Usage: -# ./scripts/test-mouse.sh -# -# Environment: -# OVMF firmware (default: /usr/share/edk2/x64/OVMF.4m.fd) -# QEMU qemu binary (default: qemu-system-x86_64) +# Usage: ./scripts/test-mouse.sh +# Env: OVMF, QEMU (same defaults as other test scripts) # set -euo pipefail @@ -30,16 +29,14 @@ SOCK=/tmp/rsdos-mouse-qmon.sock LOG=/tmp/rsdos-mouse-serial.log QLOG=/tmp/rsdos-mouse-qemu.log -# Never leave a QEMU behind. trap 'kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true' EXIT fail() { echo "FAIL: $1" - [ -f "$LOG" ] && tail -20 "$LOG" + [ -f "$LOG" ] && tail -30 "$LOG" exit 1 } -# wait_log FILE PATTERN TIMEOUT-SECONDS wait_log() { local i=0 while [ "$i" -lt $((${3:-60} * 10)) ]; do @@ -50,7 +47,6 @@ wait_log() { return 1 } -# wait_qemu_exit TIMEOUT-SECONDS wait_qemu_exit() { local i=0 while [ "$i" -lt $((${1:-30} * 10)) ]; do @@ -61,7 +57,6 @@ wait_qemu_exit() { return 1 } -# qemu_hmp — send one raw HMP command to the monitor socket. qemu_hmp() { python3 - "$SOCK" "$1" <<'EOF' import socket, sys, time @@ -72,14 +67,21 @@ time.sleep(0.4) EOF } -echo "==> 1/5 build kernel (debug)" +# cursor_state — run `cursor`, return "x y buttons" of the LAST occurrence. +cursor_state() { + python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "cursor" + sleep 0.5 + sed -n 's/.*cursor: x=\([0-9]*\) y=\([0-9]*\) buttons=\([A-Za-z-]*\).*/\1 \2 \3/p' "$LOG" | tail -1 +} + +echo "==> 1/6 build kernel (debug)" cargo build --package rsdos --target x86_64-unknown-uefi -echo "==> 2/5 deploy to ESP" +echo "==> 2/6 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)" +echo "==> 3/6 boot QEMU (headless)" kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true sleep 1 rm -f "$SOCK" "$LOG" @@ -93,38 +95,73 @@ echo $! >"$QPID" wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell" grep -aq "ps2: mouse ready" "$LOG" || fail "mouse driver did not come up at boot" +grep -aq "cursor: task " "$LOG" || fail "cursor task did not spawn" -# Seed a move *before* any consumer runs, so `cat /dev/mouse` has a -# queued event to drain (exercises the VFS snapshot path). -qemu_hmp "mouse_move 8 4" - -echo "==> 4/5 drive the shell (cat /dev/mouse, mouse stream, poweroff)" -python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ - "cat /dev/mouse" \ - "mouse" +echo "==> 4/6 cursor position tracks injected movement" +INIT=$(cursor_state) +[ -n "$INIT" ] || fail "no initial cursor position" +IX=$(echo "$INIT" | awk '{print $1}') +IY=$(echo "$INIT" | awk '{print $2}') +IB=$(echo "$INIT" | awk '{print $3}') +echo " initial: x=$IX y=$IY buttons=$IB" +[ "$IB" = "---" ] || fail "expected no buttons at boot, got $IB" -# While the `mouse` stream is live: a move, a left-press, a move with the -# button held, then release — the button state must ride along on the -# movement packet. qemu_hmp "mouse_move 20 7" +S1=$(cursor_state) +X1=$(echo "$S1" | awk '{print $1}') +Y1=$(echo "$S1" | awk '{print $2}') +[ "$X1" -eq $((IX + 20)) ] || fail "x did not move +20 (was $IX, now $X1)" +[ "$Y1" -eq $((IY + 7)) ] || fail "y did not move +7 (was $IY, now $Y1)" + +echo "==> 5/6 buttons ride along; /dev/mouse is a position device" qemu_hmp "mouse_button 1" +S2=$(cursor_state) +B2=$(echo "$S2" | awk '{print $3}') +[ "$B2" = "L--" ] || fail "left press not seen (got $B2)" + qemu_hmp "mouse_move -5 -3" +S3=$(cursor_state) +X3=$(echo "$S3" | awk '{print $1}') +Y3=$(echo "$S3" | awk '{print $2}') +B3=$(echo "$S3" | awk '{print $3}') +[ "$X3" -eq $((X1 - 5)) ] || fail "held move x wrong ($X1 -5 = $((X1 - 5)), got $X3)" +[ "$Y3" -eq $((Y1 - 3)) ] || fail "held move y wrong ($Y1 -3 = $((Y1 - 3)), got $Y3)" +[ "$B3" = "L--" ] || fail "button state dropped during held move (got $B3)" + qemu_hmp "mouse_button 0" -qemu_hmp "sendkey ctrl-c" +S4=$(cursor_state) +B4=$(echo "$S4" | awk '{print $3}') +[ "$B4" = "---" ] || fail "release not seen (got $B4)" + +python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "cat /dev/mouse" +sleep 0.5 +grep -aq "x=$X3 y=$Y3 buttons=---" "$LOG" || fail "/dev/mouse does not report position snapshot (x=$X3 y=$Y3)" +grep -aq "mouse: no events" "$LOG" && fail "/dev/mouse is still an event drain" +echo "==> 6/6 live watch + forwarding + poweroff" python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ - "poweroff" + "msgrecv" \ + "mouse 3" -echo "==> 5/5 wait for shutdown + verify" -wait_qemu_exit 30 || fail "QEMU did not exit after poweroff" +# Live watch running: a move must appear as a changed line. +qemu_hmp "mouse_move 3 2" +# Forwarding live: the same move must reach the msgrecv task (spawned as +# task 3; task 2 is the cursor task itself). +sleep 1 +qemu_hmp "sendkey ctrl-c" + +grep -aq "mouse: routing events to task 3" "$LOG" || fail "mouse 3 did not arm routing" +grep -aq "msgrecv\[3\]: Mouse(+" "$LOG" || fail "task 3 queue did not receive the routed Mouse event" +# Watch line: x/y/buttons format (any occurrence after watching started). +grep -aq "mouse: x=$((X3 + 3)) y=$((Y3 + 2)) buttons=---" "$LOG" || fail "watch did not print the moved cursor (x=$((X3+3)) y=$((Y3+2)))" +grep -aq "mouse: stopped" "$LOG" || fail "^C did not stop the mouse watch" -grep -aq "ps2: mouse ready (IRQ12, stream mode)" "$LOG" || fail "no mouse-ready boot line" -grep -aq "dx=+8 dy=+4 buttons=---" "$LOG" || fail "/dev/mouse did not drain the queued move (dx=+8 dy=+4)" -grep -aq "dx=+20 dy=+7 buttons=---" "$LOG" || fail "mouse stream missed mouse_move 20 7" -grep -aq "dx=+0 dy=+0 buttons=L--" "$LOG" || fail "left-button press did not decode" -grep -aq "dx=-5 dy=-3 buttons=L--" "$LOG" || fail "held-button movement wrong (dx=-5 dy=-3 L)" -grep -aq "mouse: stopped" "$LOG" || fail "^C did not stop the mouse stream" +python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "poweroff" + +echo "==> done: wait for shutdown + verify" +wait_qemu_exit 30 || fail "QEMU did not exit after poweroff" echo "" -echo "PASS — PS/2 mouse round trip OK (IRQ12, /dev/mouse, live stream, buttons)" -echo " events: 8,4 · 20,7 · L-press · -5,-3 held · release" +echo "PASS — mouse round trip OK (cursor task, /dev/mouse, watch, forward)" +echo " moves: +20,+7 · -5,-3 held · +3,+2 watch" +echo " path: IRQ12 → ring → cursor task → overlay + queue" diff --git a/scripts/test-msg.sh b/scripts/test-msg.sh index 0bd1c81..d81d8d7 100755 --- a/scripts/test-msg.sh +++ b/scripts/test-msg.sh @@ -93,20 +93,21 @@ echo $! >"$QPID" wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell" echo "==> 4/5 drive the shell (msgrecv / send / mouse routing / queue-full)" +# msgrecv spawns as task 3 (task 2 is the cursor task). python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ "msgrecv" \ - "send 2 user 42" \ - "send 2 timer" \ - "send 2 key enter" \ - "send 2 key ctrl-c" \ - "send 2 key f3" \ - "send 2 mouse 5 -3 3" \ + "send 3 user 42" \ + "send 3 timer" \ + "send 3 key enter" \ + "send 3 key ctrl-c" \ + "send 3 key f3" \ + "send 3 mouse 5 -3 3" \ "sleep 800" \ "jobs" -# Real IRQ12 events through the queue: start routing to task 2, inject +# Real IRQ12 events through the queue: start routing to task 3, inject # moves + a left press, stop. -python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "mouse 2" +python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "mouse 3" qemu_hmp "mouse_move 20 7" qemu_hmp "mouse_button 1" qemu_hmp "mouse_move -5 -3" @@ -140,20 +141,20 @@ python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ echo "==> 5/5 wait for shutdown + verify" wait_qemu_exit 30 || fail "QEMU did not exit after poweroff" -grep -aq "msgrecv: task 2 listening" "$LOG" || fail "msgrecv did not spawn" -grep -aq "msgrecv\[2\]: User(42)" "$LOG" || fail "user message missing" -grep -aq "msgrecv\[2\]: Timer" "$LOG" || fail "timer message missing" -grep -aq "msgrecv\[2\]: Key(Enter)" "$LOG" || fail "key enter missing" -grep -aq "msgrecv\[2\]: Key(Ctrl-c)" "$LOG" || fail "key ctrl-c missing" -grep -aq "msgrecv\[2\]: Key(F3)" "$LOG" || fail "key f3 missing" -grep -aq "msgrecv\[2\]: Mouse(+5,-3 L R)" "$LOG" || fail "synthesized mouse message missing" +grep -aq "msgrecv: task 3 listening" "$LOG" || fail "msgrecv did not spawn" +grep -aq "msgrecv\[3\]: User(42)" "$LOG" || fail "user message missing" +grep -aq "msgrecv\[3\]: Timer" "$LOG" || fail "timer message missing" +grep -aq "msgrecv\[3\]: Key(Enter)" "$LOG" || fail "key enter missing" +grep -aq "msgrecv\[3\]: Key(Ctrl-c)" "$LOG" || fail "key ctrl-c missing" +grep -aq "msgrecv\[3\]: Key(F3)" "$LOG" || fail "key f3 missing" +grep -aq "msgrecv\[3\]: Mouse(+5,-3 L R)" "$LOG" || fail "synthesized mouse message missing" # Real IRQ12 events routed through the queue (button held across the move). -grep -aq "msgrecv\[2\]: Mouse(+20,+7" "$LOG" || fail "real mouse move 20,7 not routed to queue" -grep -aq "msgrecv\[2\]: Mouse(-5,-3 L" "$LOG" || fail "held-button routed move missing" +grep -aq "msgrecv\[3\]: Mouse(+20,+7" "$LOG" || fail "real mouse move 20,7 not routed to queue" +grep -aq "msgrecv\[3\]: Mouse(-5,-3 L" "$LOG" || fail "held-button routed move missing" grep -aq "queue full" "$LOG" || fail "17th send did not report queue full" grep -aq "send: unknown type" "$LOG" && fail "a bad send slipped through (expected none)" echo "" echo "PASS — message queues OK (all types, ordering, real-input routing, queue-full)" echo " sent: user · timer · key(enter,ctrl-c,f3) · mouse · 16+1 queue-full" -echo " routed: mouse_move 20,7 → queue → msgrecv[2]" +echo " routed: mouse_move 20,7 → queue → msgrecv[3]" -- cgit v1.2.3