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-mouse.sh | 125 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 81 insertions(+), 44 deletions(-) (limited to 'scripts/test-mouse.sh') 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" -- cgit v1.2.3