diff options
Diffstat (limited to 'scripts/test-mouse.sh')
| -rwxr-xr-x | scripts/test-mouse.sh | 125 |
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 | # |
| 19 | set -euo pipefail | 18 | set -euo pipefail |
| 20 | 19 | ||
| @@ -30,16 +29,14 @@ SOCK=/tmp/rsdos-mouse-qmon.sock | |||
| 30 | LOG=/tmp/rsdos-mouse-serial.log | 29 | LOG=/tmp/rsdos-mouse-serial.log |
| 31 | QLOG=/tmp/rsdos-mouse-qemu.log | 30 | QLOG=/tmp/rsdos-mouse-qemu.log |
| 32 | 31 | ||
| 33 | # Never leave a QEMU behind. | ||
| 34 | trap 'kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true' EXIT | 32 | trap 'kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true' EXIT |
| 35 | 33 | ||
| 36 | fail() { | 34 | fail() { |
| 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 | ||
| 43 | wait_log() { | 40 | wait_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 | ||
| 54 | wait_qemu_exit() { | 50 | wait_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. | ||
| 65 | qemu_hmp() { | 60 | qemu_hmp() { |
| 66 | python3 - "$SOCK" "$1" <<'EOF' | 61 | python3 - "$SOCK" "$1" <<'EOF' |
| 67 | import socket, sys, time | 62 | import socket, sys, time |
| @@ -72,14 +67,21 @@ time.sleep(0.4) | |||
| 72 | EOF | 67 | EOF |
| 73 | } | 68 | } |
| 74 | 69 | ||
| 75 | echo "==> 1/5 build kernel (debug)" | 70 | # cursor_state — run `cursor`, return "x y buttons" of the LAST occurrence. |
| 71 | cursor_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 | |||
| 77 | echo "==> 1/6 build kernel (debug)" | ||
| 76 | cargo build --package rsdos --target x86_64-unknown-uefi | 78 | cargo build --package rsdos --target x86_64-unknown-uefi |
| 77 | 79 | ||
| 78 | echo "==> 2/5 deploy to ESP" | 80 | echo "==> 2/6 deploy to ESP" |
| 79 | mkdir -p "$ESP_DIR/EFI/BOOT" | 81 | mkdir -p "$ESP_DIR/EFI/BOOT" |
| 80 | cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI" | 82 | cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI" |
| 81 | 83 | ||
| 82 | echo "==> 3/5 boot QEMU (headless)" | 84 | echo "==> 3/6 boot QEMU (headless)" |
| 83 | kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true | 85 | kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true |
| 84 | sleep 1 | 86 | sleep 1 |
| 85 | rm -f "$SOCK" "$LOG" | 87 | rm -f "$SOCK" "$LOG" |
| @@ -93,38 +95,73 @@ echo $! >"$QPID" | |||
| 93 | 95 | ||
| 94 | wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell" | 96 | wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell" |
| 95 | grep -aq "ps2: mouse ready" "$LOG" || fail "mouse driver did not come up at boot" | 97 | grep -aq "ps2: mouse ready" "$LOG" || fail "mouse driver did not come up at boot" |
| 98 | grep -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 | 100 | echo "==> 4/6 cursor position tracks injected movement" |
| 98 | # queued event to drain (exercises the VFS snapshot path). | 101 | INIT=$(cursor_state) |
| 99 | qemu_hmp "mouse_move 8 4" | 102 | [ -n "$INIT" ] || fail "no initial cursor position" |
| 100 | 103 | IX=$(echo "$INIT" | awk '{print $1}') | |
| 101 | echo "==> 4/5 drive the shell (cat /dev/mouse, mouse stream, poweroff)" | 104 | IY=$(echo "$INIT" | awk '{print $2}') |
| 102 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ | 105 | IB=$(echo "$INIT" | awk '{print $3}') |
| 103 | "cat /dev/mouse" \ | 106 | echo " 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. | ||
| 109 | qemu_hmp "mouse_move 20 7" | 109 | qemu_hmp "mouse_move 20 7" |
| 110 | S1=$(cursor_state) | ||
| 111 | X1=$(echo "$S1" | awk '{print $1}') | ||
| 112 | Y1=$(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 | |||
| 116 | echo "==> 5/6 buttons ride along; /dev/mouse is a position device" | ||
| 110 | qemu_hmp "mouse_button 1" | 117 | qemu_hmp "mouse_button 1" |
| 118 | S2=$(cursor_state) | ||
| 119 | B2=$(echo "$S2" | awk '{print $3}') | ||
| 120 | [ "$B2" = "L--" ] || fail "left press not seen (got $B2)" | ||
| 121 | |||
| 111 | qemu_hmp "mouse_move -5 -3" | 122 | qemu_hmp "mouse_move -5 -3" |
| 123 | S3=$(cursor_state) | ||
| 124 | X3=$(echo "$S3" | awk '{print $1}') | ||
| 125 | Y3=$(echo "$S3" | awk '{print $2}') | ||
| 126 | B3=$(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 | |||
| 112 | qemu_hmp "mouse_button 0" | 131 | qemu_hmp "mouse_button 0" |
| 113 | qemu_hmp "sendkey ctrl-c" | 132 | S4=$(cursor_state) |
| 133 | B4=$(echo "$S4" | awk '{print $3}') | ||
| 134 | [ "$B4" = "---" ] || fail "release not seen (got $B4)" | ||
| 135 | |||
| 136 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "cat /dev/mouse" | ||
| 137 | sleep 0.5 | ||
| 138 | grep -aq "x=$X3 y=$Y3 buttons=---" "$LOG" || fail "/dev/mouse does not report position snapshot (x=$X3 y=$Y3)" | ||
| 139 | grep -aq "mouse: no events" "$LOG" && fail "/dev/mouse is still an event drain" | ||
| 114 | 140 | ||
| 141 | echo "==> 6/6 live watch + forwarding + poweroff" | ||
| 115 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ | 142 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ |
| 116 | "poweroff" | 143 | "msgrecv" \ |
| 144 | "mouse 3" | ||
| 117 | 145 | ||
| 118 | echo "==> 5/5 wait for shutdown + verify" | 146 | # Live watch running: a move must appear as a changed line. |
| 119 | wait_qemu_exit 30 || fail "QEMU did not exit after poweroff" | 147 | qemu_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). | ||
| 150 | sleep 1 | ||
| 151 | qemu_hmp "sendkey ctrl-c" | ||
| 152 | |||
| 153 | grep -aq "mouse: routing events to task 3" "$LOG" || fail "mouse 3 did not arm routing" | ||
| 154 | grep -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). | ||
| 156 | 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)))" | ||
| 157 | grep -aq "mouse: stopped" "$LOG" || fail "^C did not stop the mouse watch" | ||
| 120 | 158 | ||
| 121 | grep -aq "ps2: mouse ready (IRQ12, stream mode)" "$LOG" || fail "no mouse-ready boot line" | 159 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "poweroff" |
| 122 | grep -aq "dx=+8 dy=+4 buttons=---" "$LOG" || fail "/dev/mouse did not drain the queued move (dx=+8 dy=+4)" | 160 | |
| 123 | grep -aq "dx=+20 dy=+7 buttons=---" "$LOG" || fail "mouse stream missed mouse_move 20 7" | 161 | echo "==> done: wait for shutdown + verify" |
| 124 | grep -aq "dx=+0 dy=+0 buttons=L--" "$LOG" || fail "left-button press did not decode" | 162 | wait_qemu_exit 30 || fail "QEMU did not exit after poweroff" |
| 125 | grep -aq "dx=-5 dy=-3 buttons=L--" "$LOG" || fail "held-button movement wrong (dx=-5 dy=-3 L)" | ||
| 126 | grep -aq "mouse: stopped" "$LOG" || fail "^C did not stop the mouse stream" | ||
| 127 | 163 | ||
| 128 | echo "" | 164 | echo "" |
| 129 | echo "PASS — PS/2 mouse round trip OK (IRQ12, /dev/mouse, live stream, buttons)" | 165 | echo "PASS — mouse round trip OK (cursor task, /dev/mouse, watch, forward)" |
| 130 | echo " events: 8,4 · 20,7 · L-press · -5,-3 held · release" | 166 | echo " moves: +20,+7 · -5,-3 held · +3,+2 watch" |
| 167 | echo " path: IRQ12 → ring → cursor task → overlay + queue" | ||
