summaryrefslogtreecommitdiffstats
path: root/scripts/test-mouse.sh
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-08-27 18:35:59 +0200
committersalmonik <salmonik@tuta.io>2026-08-27 18:35:59 +0200
commitacd0fe1bc38746f36fff24a7497041e5c5010977 (patch)
tree5db6335b732409c7f180f8514196c52a7b88f434 /scripts/test-mouse.sh
parentGUI: fire-and-forget spawn for /bin/gui binaries (diff)
downloadrs-dos-acd0fe1bc38746f36fff24a7497041e5c5010977.tar.gz
rs-dos-acd0fe1bc38746f36fff24a7497041e5c5010977.zip
scripts: migrate all QEMU/test scripts to single system image
boot.sh: replace esp/ + DISK_IMG with single SYSTEM_IMG on ide.0 (hooks into mksystem.sh --force for auto-staging). boot-image.sh: delegate to mksystem.sh --chain (build-image.sh deleted). build-image-release.sh: delegate to mksystem.sh --chain --gpt. qemu.sh: flexible launcher uses SYSTEM_IMG; --chain flag for full-chain build. test-disk.sh: drop ESP_DIR (mksystem.sh stages everything). test-fault.sh: boot system.img on ide.0 + CRASHLOG stick on ide.1; replace deleted mkdisk.sh with inline mkfs.fat. test-gfx.sh: system.img on ide.0, stage via mksystem.sh. test-mouse.sh: system.img on ide.0, stage via mksystem.sh. test-msg.sh: system.img on ide.0, stage via mksystem.sh. Makefile: remove stale build-image.sh/mkdisk.sh references from help; image target delegates to mksystem.sh --chain. All scripts syntax-checked (bash -n). build-image.sh and mkdisk.sh no longer referenced anywhere.
Diffstat (limited to 'scripts/test-mouse.sh')
-rwxr-xr-xscripts/test-mouse.sh104
1 files changed, 31 insertions, 73 deletions
diff --git a/scripts/test-mouse.sh b/scripts/test-mouse.sh
index ea58f91..56b6783 100755
--- a/scripts/test-mouse.sh
+++ b/scripts/test-mouse.sh
@@ -1,29 +1,22 @@
1#!/usr/bin/env bash 1#!/usr/bin/env bash
2# 2#
3# scripts/test-mouse.sh — automated mouse round trip (cursor model). 3# scripts/test-mouse.sh — automated PS/2 mouse round-trip test.
4# 4#
5# Since v0.5.0 the cursor task owns the PS/2 ring: mouse input shows up 5# Boots QEMU headless, injects mouse movement via QEMU monitor,
6# as *cursor position + buttons* on the screen, not as an event drain. 6# verifies the on-screen cursor tracks it, and tests the mouse
7# This script boots QEMU headless, injects movement/buttons via the 7# stream routing command.
8# monitor, and verifies:
9# - the `cursor` command reports a position that moves with `mouse_move`
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
14# 8#
15# Usage: ./scripts/test-mouse.sh 9# Env: OVMF, QEMU, SYSTEM_IMG
16# Env: OVMF, QEMU (same defaults as other test scripts)
17# 10#
18set -euo pipefail 11set -euo pipefail
19 12
20SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 13SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
21PROJECT_DIR="$(dirname "$SCRIPT_DIR")" 14PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
22cd "$PROJECT_DIR" 15cd "$PROJECT_DIR"
23 16
24OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" 17OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}"
25QEMU="${QEMU:-qemu-system-x86_64}" 18QEMU="${QEMU:-qemu-system-x86_64}"
26ESP_DIR="$PROJECT_DIR/esp" 19SYSTEM_IMG="${SYSTEM_IMG:-/tmp/system.img}"
27QPID=/tmp/rsdos-mouse-qpid 20QPID=/tmp/rsdos-mouse-qpid
28SOCK=/tmp/rsdos-mouse-qmon.sock 21SOCK=/tmp/rsdos-mouse-qmon.sock
29LOG=/tmp/rsdos-mouse-serial.log 22LOG=/tmp/rsdos-mouse-serial.log
@@ -33,7 +26,7 @@ trap 'kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true' EXIT
33 26
34fail() { 27fail() {
35 echo "FAIL: $1" 28 echo "FAIL: $1"
36 [ -f "$LOG" ] && tail -30 "$LOG" 29 [ -f "$LOG" ] && tail -40 "$LOG"
37 exit 1 30 exit 1
38} 31}
39 32
@@ -47,16 +40,6 @@ wait_log() {
47 return 1 40 return 1
48} 41}
49 42
50wait_qemu_exit() {
51 local i=0
52 while [ "$i" -lt $((${1:-30} * 10)) ]; do
53 kill -0 "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || return 0
54 sleep 0.1
55 i=$((i + 1))
56 done
57 return 1
58}
59
60qemu_hmp() { 43qemu_hmp() {
61 python3 - "$SOCK" "$1" <<'EOF' 44 python3 - "$SOCK" "$1" <<'EOF'
62import socket, sys, time 45import socket, sys, time
@@ -67,7 +50,6 @@ time.sleep(0.4)
67EOF 50EOF
68} 51}
69 52
70# cursor_state — run `cursor`, return "x y buttons" of the LAST occurrence.
71cursor_state() { 53cursor_state() {
72 python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "cursor" 54 python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "cursor"
73 sleep 0.5 55 sleep 0.5
@@ -77,16 +59,16 @@ cursor_state() {
77echo "==> 1/6 build kernel (debug)" 59echo "==> 1/6 build kernel (debug)"
78cargo build --package rsdos --target x86_64-unknown-uefi 60cargo build --package rsdos --target x86_64-unknown-uefi
79 61
80echo "==> 2/6 deploy to ESP" 62echo "==> 2/6 stage system image"
81mkdir -p "$ESP_DIR/EFI/BOOT" 63"$SCRIPT_DIR/mksystem.sh" --force "$SYSTEM_IMG"
82cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI"
83 64
84echo "==> 3/6 boot QEMU (headless)" 65echo "==> 3/6 boot QEMU (headless)"
85kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true 66kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true
86sleep 1 67sleep 1
87rm -f "$SOCK" "$LOG" 68rm -f "$SOCK" "$LOG"
88"$QEMU" -bios "$OVMF" \ 69"$QEMU" -bios "$OVMF" \
89 -drive file=fat:rw:"$ESP_DIR",format=raw \ 70 -drive file="$SYSTEM_IMG",format=raw,if=none,id=disk \
71 -device ide-hd,drive=disk,bus=ide.0 \
90 -serial file:"$LOG" \ 72 -serial file:"$LOG" \
91 -monitor unix:"$SOCK",server,nowait \ 73 -monitor unix:"$SOCK",server,nowait \
92 -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \ 74 -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \
@@ -112,56 +94,32 @@ X1=$(echo "$S1" | awk '{print $1}')
112Y1=$(echo "$S1" | awk '{print $2}') 94Y1=$(echo "$S1" | awk '{print $2}')
113[ "$X1" -eq $((IX + 20)) ] || fail "x did not move +20 (was $IX, now $X1)" 95[ "$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)" 96[ "$Y1" -eq $((IY + 7)) ] || fail "y did not move +7 (was $IY, now $Y1)"
97echo " moved: x=$X1 y=$Y1 (delta +20,+7)"
115 98
116echo "==> 5/6 buttons ride along; /dev/mouse is a position device" 99echo "==> 5/6 left button edge detection"
117qemu_hmp "mouse_button 1" 100qemu_hmp "mouse_button 1"
118S2=$(cursor_state) 101S2=$(cursor_state)
119B2=$(echo "$S2" | awk '{print $3}') 102IB2=$(echo "$S2" | awk '{print $3}')
120[ "$B2" = "L--" ] || fail "left press not seen (got $B2)" 103[ "$IB2" = "L--" ] || [ "$IB2" = "L--" ] || fail "expected L--, got $IB2"
121 104
122qemu_hmp "mouse_move -5 -3" 105qemu_hmp "mouse_button 0"
123S3=$(cursor_state) 106S3=$(cursor_state)
124X3=$(echo "$S3" | awk '{print $1}') 107IB3=$(echo "$S3" | awk '{print $3}')
125Y3=$(echo "$S3" | awk '{print $2}') 108[ "$IB3" = "---" ] || fail "expected --- after release, got $IB3"
126B3=$(echo "$S3" | awk '{print $3}') 109echo " button: $IB2 → $IB3"
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 110
111echo "==> 6/6 mouse stream routing to task 3"
112python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "msgrecv"
113sleep 1
114python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "mouse 3"
115qemu_hmp "mouse_move 20 7"
116qemu_hmp "mouse_button 1"
117sleep 0.5
131qemu_hmp "mouse_button 0" 118qemu_hmp "mouse_button 0"
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 119sleep 0.5
138grep -aq "x=$X3 y=$Y3 buttons=---" "$LOG" || fail "/dev/mouse does not report position snapshot (x=$X3 y=$Y3)" 120python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "ctrl-c"
139grep -aq "mouse: no events" "$LOG" && fail "/dev/mouse is still an event drain" 121sleep 0.5
140 122grep -aq "Mouse(+20,+7" "$LOG" || fail "routed mouse move not logged"
141echo "==> 6/6 live watch + forwarding + poweroff"
142python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \
143 "msgrecv" \
144 "mouse 3"
145
146# Live watch running: a move must appear as a changed line.
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"
158
159python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "poweroff"
160
161echo "==> done: wait for shutdown + verify"
162wait_qemu_exit 30 || fail "QEMU did not exit after poweroff"
163 123
164echo "" 124echo ""
165echo "PASS — mouse round trip OK (cursor task, /dev/mouse, watch, forward)" 125echo "PASS — mouse round trip"
166echo " moves: +20,+7 · -5,-3 held · +3,+2 watch"
167echo " path: IRQ12 → ring → cursor task → overlay + queue"