diff options
| author | salmonik <salmonik@tuta.io> | 2026-08-27 18:35:59 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-08-27 18:35:59 +0200 |
| commit | acd0fe1bc38746f36fff24a7497041e5c5010977 (patch) | |
| tree | 5db6335b732409c7f180f8514196c52a7b88f434 /scripts/test-mouse.sh | |
| parent | GUI: fire-and-forget spawn for /bin/gui binaries (diff) | |
| download | rs-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-x | scripts/test-mouse.sh | 104 |
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 | # |
| 18 | set -euo pipefail | 11 | set -euo pipefail |
| 19 | 12 | ||
| 20 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | 13 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 21 | PROJECT_DIR="$(dirname "$SCRIPT_DIR")" | 14 | PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 22 | cd "$PROJECT_DIR" | 15 | cd "$PROJECT_DIR" |
| 23 | 16 | ||
| 24 | OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" | 17 | OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" |
| 25 | QEMU="${QEMU:-qemu-system-x86_64}" | 18 | QEMU="${QEMU:-qemu-system-x86_64}" |
| 26 | ESP_DIR="$PROJECT_DIR/esp" | 19 | SYSTEM_IMG="${SYSTEM_IMG:-/tmp/system.img}" |
| 27 | QPID=/tmp/rsdos-mouse-qpid | 20 | QPID=/tmp/rsdos-mouse-qpid |
| 28 | SOCK=/tmp/rsdos-mouse-qmon.sock | 21 | SOCK=/tmp/rsdos-mouse-qmon.sock |
| 29 | LOG=/tmp/rsdos-mouse-serial.log | 22 | LOG=/tmp/rsdos-mouse-serial.log |
| @@ -33,7 +26,7 @@ trap 'kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true' EXIT | |||
| 33 | 26 | ||
| 34 | fail() { | 27 | fail() { |
| 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 | ||
| 50 | wait_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 | |||
| 60 | qemu_hmp() { | 43 | qemu_hmp() { |
| 61 | python3 - "$SOCK" "$1" <<'EOF' | 44 | python3 - "$SOCK" "$1" <<'EOF' |
| 62 | import socket, sys, time | 45 | import socket, sys, time |
| @@ -67,7 +50,6 @@ time.sleep(0.4) | |||
| 67 | EOF | 50 | EOF |
| 68 | } | 51 | } |
| 69 | 52 | ||
| 70 | # cursor_state — run `cursor`, return "x y buttons" of the LAST occurrence. | ||
| 71 | cursor_state() { | 53 | cursor_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() { | |||
| 77 | echo "==> 1/6 build kernel (debug)" | 59 | echo "==> 1/6 build kernel (debug)" |
| 78 | cargo build --package rsdos --target x86_64-unknown-uefi | 60 | cargo build --package rsdos --target x86_64-unknown-uefi |
| 79 | 61 | ||
| 80 | echo "==> 2/6 deploy to ESP" | 62 | echo "==> 2/6 stage system image" |
| 81 | mkdir -p "$ESP_DIR/EFI/BOOT" | 63 | "$SCRIPT_DIR/mksystem.sh" --force "$SYSTEM_IMG" |
| 82 | cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI" | ||
| 83 | 64 | ||
| 84 | echo "==> 3/6 boot QEMU (headless)" | 65 | echo "==> 3/6 boot QEMU (headless)" |
| 85 | kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true | 66 | kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true |
| 86 | sleep 1 | 67 | sleep 1 |
| 87 | rm -f "$SOCK" "$LOG" | 68 | rm -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}') | |||
| 112 | Y1=$(echo "$S1" | awk '{print $2}') | 94 | Y1=$(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)" |
| 97 | echo " moved: x=$X1 y=$Y1 (delta +20,+7)" | ||
| 115 | 98 | ||
| 116 | echo "==> 5/6 buttons ride along; /dev/mouse is a position device" | 99 | echo "==> 5/6 left button edge detection" |
| 117 | qemu_hmp "mouse_button 1" | 100 | qemu_hmp "mouse_button 1" |
| 118 | S2=$(cursor_state) | 101 | S2=$(cursor_state) |
| 119 | B2=$(echo "$S2" | awk '{print $3}') | 102 | IB2=$(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 | ||
| 122 | qemu_hmp "mouse_move -5 -3" | 105 | qemu_hmp "mouse_button 0" |
| 123 | S3=$(cursor_state) | 106 | S3=$(cursor_state) |
| 124 | X3=$(echo "$S3" | awk '{print $1}') | 107 | IB3=$(echo "$S3" | awk '{print $3}') |
| 125 | Y3=$(echo "$S3" | awk '{print $2}') | 108 | [ "$IB3" = "---" ] || fail "expected --- after release, got $IB3" |
| 126 | B3=$(echo "$S3" | awk '{print $3}') | 109 | echo " 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 | ||
| 111 | echo "==> 6/6 mouse stream routing to task 3" | ||
| 112 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "msgrecv" | ||
| 113 | sleep 1 | ||
| 114 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "mouse 3" | ||
| 115 | qemu_hmp "mouse_move 20 7" | ||
| 116 | qemu_hmp "mouse_button 1" | ||
| 117 | sleep 0.5 | ||
| 131 | qemu_hmp "mouse_button 0" | 118 | qemu_hmp "mouse_button 0" |
| 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 | 119 | sleep 0.5 |
| 138 | grep -aq "x=$X3 y=$Y3 buttons=---" "$LOG" || fail "/dev/mouse does not report position snapshot (x=$X3 y=$Y3)" | 120 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "ctrl-c" |
| 139 | grep -aq "mouse: no events" "$LOG" && fail "/dev/mouse is still an event drain" | 121 | sleep 0.5 |
| 140 | 122 | grep -aq "Mouse(+20,+7" "$LOG" || fail "routed mouse move not logged" | |
| 141 | echo "==> 6/6 live watch + forwarding + poweroff" | ||
| 142 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ | ||
| 143 | "msgrecv" \ | ||
| 144 | "mouse 3" | ||
| 145 | |||
| 146 | # Live watch running: a move must appear as a changed line. | ||
| 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" | ||
| 158 | |||
| 159 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "poweroff" | ||
| 160 | |||
| 161 | echo "==> done: wait for shutdown + verify" | ||
| 162 | wait_qemu_exit 30 || fail "QEMU did not exit after poweroff" | ||
| 163 | 123 | ||
| 164 | echo "" | 124 | echo "" |
| 165 | echo "PASS — mouse round trip OK (cursor task, /dev/mouse, watch, forward)" | 125 | echo "PASS — mouse round trip" |
| 166 | echo " moves: +20,+7 · -5,-3 held · +3,+2 watch" | ||
| 167 | echo " path: IRQ12 → ring → cursor task → overlay + queue" | ||
