diff options
Diffstat (limited to '')
| -rwxr-xr-x | scripts/tests/test-mouse.sh | 83 |
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 | # | ||
| 12 | set -euo pipefail | ||
| 13 | TNAME="mouse" | ||
| 14 | # shellcheck source=../lib.sh | ||
| 15 | source "$(dirname "$0")/../lib.sh" | ||
| 16 | |||
| 17 | # cursor_state — one-shot `cursor` command, parsed to "x y buttons". | ||
| 18 | cursor_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 | |||
| 24 | echo "==> 1/6 build (kernel + bins)" | ||
| 25 | build_all | ||
| 26 | |||
| 27 | echo "==> 2/6 stage system image" | ||
| 28 | stage_image --force | ||
| 29 | |||
| 30 | echo "==> 3/6 boot QEMU (headless)" | ||
| 31 | test_boot | ||
| 32 | grep -aq "ps2: mouse ready" "$LOG" || fail "mouse driver did not come up at boot" | ||
| 33 | wait_log "$LOG" "cursor: task " 10 || fail "cursor task did not spawn" | ||
| 34 | |||
| 35 | echo "==> 4/6 cursor position tracks injected movement" | ||
| 36 | INIT=$(cursor_state) | ||
| 37 | [ -n "$INIT" ] || fail "no initial cursor position" | ||
| 38 | IX=$(echo "$INIT" | awk '{print $1}') | ||
| 39 | IY=$(echo "$INIT" | awk '{print $2}') | ||
| 40 | IB=$(echo "$INIT" | awk '{print $3}') | ||
| 41 | echo " initial: x=$IX y=$IY buttons=$IB" | ||
| 42 | [ "$IB" = "---" ] || fail "expected no buttons at boot, got $IB" | ||
| 43 | |||
| 44 | qemu_hmp "mouse_move 20 7" | ||
| 45 | S1=$(cursor_state) | ||
| 46 | X1=$(echo "$S1" | awk '{print $1}') | ||
| 47 | Y1=$(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)" | ||
| 50 | echo " moved: x=$X1 y=$Y1 (delta +20,+7)" | ||
| 51 | |||
| 52 | echo "==> 5/6 left button edge detection" | ||
| 53 | qemu_hmp "mouse_button 1" | ||
| 54 | S2=$(cursor_state) | ||
| 55 | IB2=$(echo "$S2" | awk '{print $3}') | ||
| 56 | [ "$IB2" = "L--" ] || fail "expected L--, got $IB2" | ||
| 57 | |||
| 58 | qemu_hmp "mouse_button 0" | ||
| 59 | S3=$(cursor_state) | ||
| 60 | IB3=$(echo "$S3" | awk '{print $3}') | ||
| 61 | [ "$IB3" = "---" ] || fail "expected --- after release, got $IB3" | ||
| 62 | echo " button: $IB2 → $IB3" | ||
| 63 | |||
| 64 | echo "==> 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. | ||
| 67 | sendkeys "msgrecv" | ||
| 68 | sleep 1 | ||
| 69 | MID="$(sed -n 's/.*msgrecv: task \([0-9][0-9]*\) listening.*/\1/p' "$LOG" | tail -1)" | ||
| 70 | [ -n "$MID" ] || fail "msgrecv did not spawn" | ||
| 71 | echo " msgrecv task id: $MID" | ||
| 72 | sendkeys "mouse $MID" | ||
| 73 | qemu_hmp "mouse_move 20 7" | ||
| 74 | qemu_hmp "mouse_button 1" | ||
| 75 | sleep 0.5 | ||
| 76 | qemu_hmp "mouse_button 0" | ||
| 77 | sleep 0.5 | ||
| 78 | sendkeys "ctrl-c" | ||
| 79 | sleep 0.5 | ||
| 80 | grep -aq "Mouse(+20,+7" "$LOG" || fail "routed mouse move not logged" | ||
| 81 | |||
| 82 | echo "" | ||
| 83 | echo "PASS — mouse round trip" | ||
