summaryrefslogtreecommitdiffstats
path: root/scripts/test-mouse.sh
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-08-01 19:52:05 +0200
committersalmonik <salmonik@tuta.io>2026-08-01 19:52:05 +0200
commit819778f292ee4e1294603b98662e083e49e23463 (patch)
tree8df31b678432d2a89cac8e0d50f271a75a3882b5 /scripts/test-mouse.sh
parentrsnix v0.4.0: GUI input foundation — PS/2 mouse + scheduler message queues (diff)
downloadrs-dos-819778f292ee4e1294603b98662e083e49e23463.tar.gz
rs-dos-819778f292ee4e1294603b98662e083e49e23463.zip
rsnix v0.5.0: graphics layer + cursor compositor
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 <id>' 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.
Diffstat (limited to 'scripts/test-mouse.sh')
-rwxr-xr-xscripts/test-mouse.sh125
1 files changed, 81 insertions, 44 deletions
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 @@
1#!/usr/bin/env bash 1#!/usr/bin/env bash
2# 2#
3# scripts/test-mouse.sh — automated PS/2 mouse round trip. 3# scripts/test-mouse.sh — automated mouse round trip (cursor model).
4# 4#
5# Builds the kernel, boots QEMU headless, injects mouse movement and 5# Since v0.5.0 the cursor task owns the PS/2 ring: mouse input shows up
6# button presses through the monitor's `mouse_move` / `mouse_button` 6# as *cursor position + buttons* on the screen, not as an event drain.
7# commands, and verifies the guest decoded them via IRQ12 → ring → 7# This script boots QEMU headless, injects movement/buttons via the
8# packet decoder. Covers both surfaces: 8# monitor, and verifies:
9# - `cat /dev/mouse` (VFS snapshot of pending events) 9# - the `cursor` command reports a position that moves with `mouse_move`
10# - `mouse` (live streaming command, stopped by ^C) 10# - button presses ride along (L while held)
11# - `/dev/mouse` is a position device (one snapshot line)
12# - the `mouse` watch command prints live changes and stops on ^C
13# - a `mouse <id>` forward routes real events to a task's queue
11# 14#
12# Usage: 15# Usage: ./scripts/test-mouse.sh
13# ./scripts/test-mouse.sh 16# Env: OVMF, QEMU (same defaults as other test scripts)
14#
15# Environment:
16# OVMF firmware (default: /usr/share/edk2/x64/OVMF.4m.fd)
17# QEMU qemu binary (default: qemu-system-x86_64)
18# 17#
19set -euo pipefail 18set -euo pipefail
20 19
@@ -30,16 +29,14 @@ SOCK=/tmp/rsdos-mouse-qmon.sock
30LOG=/tmp/rsdos-mouse-serial.log 29LOG=/tmp/rsdos-mouse-serial.log
31QLOG=/tmp/rsdos-mouse-qemu.log 30QLOG=/tmp/rsdos-mouse-qemu.log
32 31
33# Never leave a QEMU behind.
34trap 'kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true' EXIT 32trap 'kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true' EXIT
35 33
36fail() { 34fail() {
37 echo "FAIL: $1" 35 echo "FAIL: $1"
38 [ -f "$LOG" ] && tail -20 "$LOG" 36 [ -f "$LOG" ] && tail -30 "$LOG"
39 exit 1 37 exit 1
40} 38}
41 39
42# wait_log FILE PATTERN TIMEOUT-SECONDS
43wait_log() { 40wait_log() {
44 local i=0 41 local i=0
45 while [ "$i" -lt $((${3:-60} * 10)) ]; do 42 while [ "$i" -lt $((${3:-60} * 10)) ]; do
@@ -50,7 +47,6 @@ wait_log() {
50 return 1 47 return 1
51} 48}
52 49
53# wait_qemu_exit TIMEOUT-SECONDS
54wait_qemu_exit() { 50wait_qemu_exit() {
55 local i=0 51 local i=0
56 while [ "$i" -lt $((${1:-30} * 10)) ]; do 52 while [ "$i" -lt $((${1:-30} * 10)) ]; do
@@ -61,7 +57,6 @@ wait_qemu_exit() {
61 return 1 57 return 1
62} 58}
63 59
64# qemu_hmp — send one raw HMP command to the monitor socket.
65qemu_hmp() { 60qemu_hmp() {
66 python3 - "$SOCK" "$1" <<'EOF' 61 python3 - "$SOCK" "$1" <<'EOF'
67import socket, sys, time 62import socket, sys, time
@@ -72,14 +67,21 @@ time.sleep(0.4)
72EOF 67EOF
73} 68}
74 69
75echo "==> 1/5 build kernel (debug)" 70# cursor_state — run `cursor`, return "x y buttons" of the LAST occurrence.
71cursor_state() {
72 python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "cursor"
73 sleep 0.5
74 sed -n 's/.*cursor: x=\([0-9]*\) y=\([0-9]*\) buttons=\([A-Za-z-]*\).*/\1 \2 \3/p' "$LOG" | tail -1
75}
76
77echo "==> 1/6 build kernel (debug)"
76cargo build --package rsdos --target x86_64-unknown-uefi 78cargo build --package rsdos --target x86_64-unknown-uefi
77 79
78echo "==> 2/5 deploy to ESP" 80echo "==> 2/6 deploy to ESP"
79mkdir -p "$ESP_DIR/EFI/BOOT" 81mkdir -p "$ESP_DIR/EFI/BOOT"
80cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI" 82cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI"
81 83
82echo "==> 3/5 boot QEMU (headless)" 84echo "==> 3/6 boot QEMU (headless)"
83kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true 85kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true
84sleep 1 86sleep 1
85rm -f "$SOCK" "$LOG" 87rm -f "$SOCK" "$LOG"
@@ -93,38 +95,73 @@ echo $! >"$QPID"
93 95
94wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell" 96wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell"
95grep -aq "ps2: mouse ready" "$LOG" || fail "mouse driver did not come up at boot" 97grep -aq "ps2: mouse ready" "$LOG" || fail "mouse driver did not come up at boot"
98grep -aq "cursor: task " "$LOG" || fail "cursor task did not spawn"
96 99
97# Seed a move *before* any consumer runs, so `cat /dev/mouse` has a 100echo "==> 4/6 cursor position tracks injected movement"
98# queued event to drain (exercises the VFS snapshot path). 101INIT=$(cursor_state)
99qemu_hmp "mouse_move 8 4" 102[ -n "$INIT" ] || fail "no initial cursor position"
100 103IX=$(echo "$INIT" | awk '{print $1}')
101echo "==> 4/5 drive the shell (cat /dev/mouse, mouse stream, poweroff)" 104IY=$(echo "$INIT" | awk '{print $2}')
102python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ 105IB=$(echo "$INIT" | awk '{print $3}')
103 "cat /dev/mouse" \ 106echo " initial: x=$IX y=$IY buttons=$IB"
104 "mouse" 107[ "$IB" = "---" ] || fail "expected no buttons at boot, got $IB"
105 108
106# While the `mouse` stream is live: a move, a left-press, a move with the
107# button held, then release — the button state must ride along on the
108# movement packet.
109qemu_hmp "mouse_move 20 7" 109qemu_hmp "mouse_move 20 7"
110S1=$(cursor_state)
111X1=$(echo "$S1" | awk '{print $1}')
112Y1=$(echo "$S1" | awk '{print $2}')
113[ "$X1" -eq $((IX + 20)) ] || fail "x did not move +20 (was $IX, now $X1)"
114[ "$Y1" -eq $((IY + 7)) ] || fail "y did not move +7 (was $IY, now $Y1)"
115
116echo "==> 5/6 buttons ride along; /dev/mouse is a position device"
110qemu_hmp "mouse_button 1" 117qemu_hmp "mouse_button 1"
118S2=$(cursor_state)
119B2=$(echo "$S2" | awk '{print $3}')
120[ "$B2" = "L--" ] || fail "left press not seen (got $B2)"
121
111qemu_hmp "mouse_move -5 -3" 122qemu_hmp "mouse_move -5 -3"
123S3=$(cursor_state)
124X3=$(echo "$S3" | awk '{print $1}')
125Y3=$(echo "$S3" | awk '{print $2}')
126B3=$(echo "$S3" | awk '{print $3}')
127[ "$X3" -eq $((X1 - 5)) ] || fail "held move x wrong ($X1 -5 = $((X1 - 5)), got $X3)"
128[ "$Y3" -eq $((Y1 - 3)) ] || fail "held move y wrong ($Y1 -3 = $((Y1 - 3)), got $Y3)"
129[ "$B3" = "L--" ] || fail "button state dropped during held move (got $B3)"
130
112qemu_hmp "mouse_button 0" 131qemu_hmp "mouse_button 0"
113qemu_hmp "sendkey ctrl-c" 132S4=$(cursor_state)
133B4=$(echo "$S4" | awk '{print $3}')
134[ "$B4" = "---" ] || fail "release not seen (got $B4)"
135
136python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "cat /dev/mouse"
137sleep 0.5
138grep -aq "x=$X3 y=$Y3 buttons=---" "$LOG" || fail "/dev/mouse does not report position snapshot (x=$X3 y=$Y3)"
139grep -aq "mouse: no events" "$LOG" && fail "/dev/mouse is still an event drain"
114 140
141echo "==> 6/6 live watch + forwarding + poweroff"
115python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ 142python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \
116 "poweroff" 143 "msgrecv" \
144 "mouse 3"
117 145
118echo "==> 5/5 wait for shutdown + verify" 146# Live watch running: a move must appear as a changed line.
119wait_qemu_exit 30 || fail "QEMU did not exit after poweroff" 147qemu_hmp "mouse_move 3 2"
148# Forwarding live: the same move must reach the msgrecv task (spawned as
149# task 3; task 2 is the cursor task itself).
150sleep 1
151qemu_hmp "sendkey ctrl-c"
152
153grep -aq "mouse: routing events to task 3" "$LOG" || fail "mouse 3 did not arm routing"
154grep -aq "msgrecv\[3\]: Mouse(+" "$LOG" || fail "task 3 queue did not receive the routed Mouse event"
155# Watch line: x/y/buttons format (any occurrence after watching started).
156grep -aq "mouse: x=$((X3 + 3)) y=$((Y3 + 2)) buttons=---" "$LOG" || fail "watch did not print the moved cursor (x=$((X3+3)) y=$((Y3+2)))"
157grep -aq "mouse: stopped" "$LOG" || fail "^C did not stop the mouse watch"
120 158
121grep -aq "ps2: mouse ready (IRQ12, stream mode)" "$LOG" || fail "no mouse-ready boot line" 159python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "poweroff"
122grep -aq "dx=+8 dy=+4 buttons=---" "$LOG" || fail "/dev/mouse did not drain the queued move (dx=+8 dy=+4)" 160
123grep -aq "dx=+20 dy=+7 buttons=---" "$LOG" || fail "mouse stream missed mouse_move 20 7" 161echo "==> done: wait for shutdown + verify"
124grep -aq "dx=+0 dy=+0 buttons=L--" "$LOG" || fail "left-button press did not decode" 162wait_qemu_exit 30 || fail "QEMU did not exit after poweroff"
125grep -aq "dx=-5 dy=-3 buttons=L--" "$LOG" || fail "held-button movement wrong (dx=-5 dy=-3 L)"
126grep -aq "mouse: stopped" "$LOG" || fail "^C did not stop the mouse stream"
127 163
128echo "" 164echo ""
129echo "PASS — PS/2 mouse round trip OK (IRQ12, /dev/mouse, live stream, buttons)" 165echo "PASS — mouse round trip OK (cursor task, /dev/mouse, watch, forward)"
130echo " events: 8,4 · 20,7 · L-press · -5,-3 held · release" 166echo " moves: +20,+7 · -5,-3 held · +3,+2 watch"
167echo " path: IRQ12 → ring → cursor task → overlay + queue"