summaryrefslogtreecommitdiffstats
path: root/scripts/tests/test-mouse.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xscripts/tests/test-mouse.sh83
1 files changed, 83 insertions, 0 deletions
diff --git a/scripts/tests/test-mouse.sh b/scripts/tests/test-mouse.sh
new file mode 100755
index 0000000..bb835be
--- /dev/null
+++ b/scripts/tests/test-mouse.sh
@@ -0,0 +1,83 @@
1#!/usr/bin/env bash
2#
3# scripts/tests/test-mouse.sh — automated PS/2 mouse round-trip test.
4#
5# Boots QEMU headless, injects mouse movement via the QEMU monitor,
6# verifies the on-screen cursor tracks it, and tests the mouse stream
7# routing command.
8#
9# Usage: ./scripts/tests/test-mouse.sh
10# Env: SYSTEM_IMG, OVMF, QEMU (see scripts/lib.sh)
11#
12set -euo pipefail
13TNAME="mouse"
14# shellcheck source=../lib.sh
15source "$(dirname "$0")/../lib.sh"
16
17# cursor_state — one-shot `cursor` command, parsed to "x y buttons".
18cursor_state() {
19 sendkeys "cursor"
20 sleep 0.5
21 sed -n 's/.*cursor: x=\([0-9]*\) y=\([0-9]*\) buttons=\([A-Za-z-]*\).*/\1 \2 \3/p' "$LOG" | tail -1
22}
23
24echo "==> 1/6 build (kernel + bins)"
25build_all
26
27echo "==> 2/6 stage system image"
28stage_image --force
29
30echo "==> 3/6 boot QEMU (headless)"
31test_boot
32grep -aq "ps2: mouse ready" "$LOG" || fail "mouse driver did not come up at boot"
33wait_log "$LOG" "cursor: task " 10 || fail "cursor task did not spawn"
34
35echo "==> 4/6 cursor position tracks injected movement"
36INIT=$(cursor_state)
37[ -n "$INIT" ] || fail "no initial cursor position"
38IX=$(echo "$INIT" | awk '{print $1}')
39IY=$(echo "$INIT" | awk '{print $2}')
40IB=$(echo "$INIT" | awk '{print $3}')
41echo " initial: x=$IX y=$IY buttons=$IB"
42[ "$IB" = "---" ] || fail "expected no buttons at boot, got $IB"
43
44qemu_hmp "mouse_move 20 7"
45S1=$(cursor_state)
46X1=$(echo "$S1" | awk '{print $1}')
47Y1=$(echo "$S1" | awk '{print $2}')
48[ "$X1" -eq $((IX + 20)) ] || fail "x did not move +20 (was $IX, now $X1)"
49[ "$Y1" -eq $((IY + 7)) ] || fail "y did not move +7 (was $IY, now $Y1)"
50echo " moved: x=$X1 y=$Y1 (delta +20,+7)"
51
52echo "==> 5/6 left button edge detection"
53qemu_hmp "mouse_button 1"
54S2=$(cursor_state)
55IB2=$(echo "$S2" | awk '{print $3}')
56[ "$IB2" = "L--" ] || fail "expected L--, got $IB2"
57
58qemu_hmp "mouse_button 0"
59S3=$(cursor_state)
60IB3=$(echo "$S3" | awk '{print $3}')
61[ "$IB3" = "---" ] || fail "expected --- after release, got $IB3"
62echo " button: $IB2 → $IB3"
63
64echo "==> 6/6 mouse stream routing to msgrecv's task"
65# The spawned task id shifts with the task table (wm-input took slot 3) —
66# parse it rather than hardcoding.
67sendkeys "msgrecv"
68sleep 1
69MID="$(sed -n 's/.*msgrecv: task \([0-9][0-9]*\) listening.*/\1/p' "$LOG" | tail -1)"
70[ -n "$MID" ] || fail "msgrecv did not spawn"
71echo " msgrecv task id: $MID"
72sendkeys "mouse $MID"
73qemu_hmp "mouse_move 20 7"
74qemu_hmp "mouse_button 1"
75sleep 0.5
76qemu_hmp "mouse_button 0"
77sleep 0.5
78sendkeys "ctrl-c"
79sleep 0.5
80grep -aq "Mouse(+20,+7" "$LOG" || fail "routed mouse move not logged"
81
82echo ""
83echo "PASS — mouse round trip"