diff options
Diffstat (limited to 'scripts/test-msg.sh')
| -rwxr-xr-x | scripts/test-msg.sh | 62 |
1 files changed, 21 insertions, 41 deletions
diff --git a/scripts/test-msg.sh b/scripts/test-msg.sh index d81d8d7..95b7af3 100755 --- a/scripts/test-msg.sh +++ b/scripts/test-msg.sh | |||
| @@ -2,32 +2,20 @@ | |||
| 2 | # | 2 | # |
| 3 | # scripts/test-msg.sh — automated scheduler message-queue round trip. | 3 | # scripts/test-msg.sh — automated scheduler message-queue round trip. |
| 4 | # | 4 | # |
| 5 | # Builds the kernel, boots QEMU headless, and verifies inter-task | 5 | # Tests all message types (user, timer, key, mouse), real-input routing, |
| 6 | # messaging end to end: | 6 | # and queue-full boundary. |
| 7 | # - `msgrecv` spawns a task that blocks on recv_blocking | ||
| 8 | # - `send <id> <type>` delivers every message type in order | ||
| 9 | # - `mouse <id>` routes *real* IRQ12 mouse events into the queue | ||
| 10 | # (the window-manager input path) | ||
| 11 | # - queue-full is a clean error (16-cap; tested against the shell's | ||
| 12 | # own never-consumed queue) | ||
| 13 | # - jobs shows q=0 after everything drains, task back to blocked | ||
| 14 | # | 7 | # |
| 15 | # Usage: | 8 | # Env: OVMF, QEMU, SYSTEM_IMG |
| 16 | # ./scripts/test-msg.sh | ||
| 17 | # | ||
| 18 | # Environment: | ||
| 19 | # OVMF firmware (default: /usr/share/edk2/x64/OVMF.4m.fd) | ||
| 20 | # QEMU qemu binary (default: qemu-system-x86_64) | ||
| 21 | # | 9 | # |
| 22 | set -euo pipefail | 10 | set -euo pipefail |
| 23 | 11 | ||
| 24 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | 12 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 25 | PROJECT_DIR="$(dirname "$SCRIPT_DIR")" | 13 | PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 26 | cd "$PROJECT_DIR" | 14 | cd "$PROJECT_DIR" |
| 27 | 15 | ||
| 28 | OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" | 16 | OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" |
| 29 | QEMU="${QEMU:-qemu-system-x86_64}" | 17 | QEMU="${QEMU:-qemu-system-x86_64}" |
| 30 | ESP_DIR="$PROJECT_DIR/esp" | 18 | SYSTEM_IMG="${SYSTEM_IMG:-/tmp/system.img}" |
| 31 | QPID=/tmp/rsdos-msg-qpid | 19 | QPID=/tmp/rsdos-msg-qpid |
| 32 | SOCK=/tmp/rsdos-msg-qmon.sock | 20 | SOCK=/tmp/rsdos-msg-qmon.sock |
| 33 | LOG=/tmp/rsdos-msg-serial.log | 21 | LOG=/tmp/rsdos-msg-serial.log |
| @@ -37,7 +25,7 @@ trap 'kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true' EXIT | |||
| 37 | 25 | ||
| 38 | fail() { | 26 | fail() { |
| 39 | echo "FAIL: $1" | 27 | echo "FAIL: $1" |
| 40 | [ -f "$LOG" ] && tail -20 "$LOG" | 28 | [ -f "$LOG" ] && tail -40 "$LOG" |
| 41 | exit 1 | 29 | exit 1 |
| 42 | } | 30 | } |
| 43 | 31 | ||
| @@ -51,16 +39,6 @@ wait_log() { | |||
| 51 | return 1 | 39 | return 1 |
| 52 | } | 40 | } |
| 53 | 41 | ||
| 54 | wait_qemu_exit() { | ||
| 55 | local i=0 | ||
| 56 | while [ "$i" -lt $((${1:-30} * 10)) ]; do | ||
| 57 | kill -0 "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || return 0 | ||
| 58 | sleep 0.1 | ||
| 59 | i=$((i + 1)) | ||
| 60 | done | ||
| 61 | return 1 | ||
| 62 | } | ||
| 63 | |||
| 64 | qemu_hmp() { | 42 | qemu_hmp() { |
| 65 | python3 - "$SOCK" "$1" <<'EOF' | 43 | python3 - "$SOCK" "$1" <<'EOF' |
| 66 | import socket, sys, time | 44 | import socket, sys, time |
| @@ -71,19 +49,29 @@ time.sleep(0.4) | |||
| 71 | EOF | 49 | EOF |
| 72 | } | 50 | } |
| 73 | 51 | ||
| 52 | wait_qemu_exit() { | ||
| 53 | local i=0 | ||
| 54 | while [ "$i" -lt $((${1:-30} * 10)) ]; do | ||
| 55 | kill -0 "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || return 0 | ||
| 56 | sleep 0.1 | ||
| 57 | i=$((i + 1)) | ||
| 58 | done | ||
| 59 | return 1 | ||
| 60 | } | ||
| 61 | |||
| 74 | echo "==> 1/5 build kernel (debug)" | 62 | echo "==> 1/5 build kernel (debug)" |
| 75 | cargo build --package rsdos --target x86_64-unknown-uefi | 63 | cargo build --package rsdos --target x86_64-unknown-uefi |
| 76 | 64 | ||
| 77 | echo "==> 2/5 deploy to ESP" | 65 | echo "==> 2/5 stage system image" |
| 78 | mkdir -p "$ESP_DIR/EFI/BOOT" | 66 | "$SCRIPT_DIR/mksystem.sh" --force "$SYSTEM_IMG" |
| 79 | cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI" | ||
| 80 | 67 | ||
| 81 | echo "==> 3/5 boot QEMU (headless)" | 68 | echo "==> 3/5 boot QEMU (headless)" |
| 82 | kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true | 69 | kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true |
| 83 | sleep 1 | 70 | sleep 1 |
| 84 | rm -f "$SOCK" "$LOG" | 71 | rm -f "$SOCK" "$LOG" |
| 85 | "$QEMU" -bios "$OVMF" \ | 72 | "$QEMU" -bios "$OVMF" \ |
| 86 | -drive file=fat:rw:"$ESP_DIR",format=raw \ | 73 | -drive file="$SYSTEM_IMG",format=raw,if=none,id=disk \ |
| 74 | -device ide-hd,drive=disk,bus=ide.0 \ | ||
| 87 | -serial file:"$LOG" \ | 75 | -serial file:"$LOG" \ |
| 88 | -monitor unix:"$SOCK",server,nowait \ | 76 | -monitor unix:"$SOCK",server,nowait \ |
| 89 | -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \ | 77 | -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \ |
| @@ -93,7 +81,6 @@ echo $! >"$QPID" | |||
| 93 | wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell" | 81 | wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell" |
| 94 | 82 | ||
| 95 | echo "==> 4/5 drive the shell (msgrecv / send / mouse routing / queue-full)" | 83 | echo "==> 4/5 drive the shell (msgrecv / send / mouse routing / queue-full)" |
| 96 | # msgrecv spawns as task 3 (task 2 is the cursor task). | ||
| 97 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ | 84 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ |
| 98 | "msgrecv" \ | 85 | "msgrecv" \ |
| 99 | "send 3 user 42" \ | 86 | "send 3 user 42" \ |
| @@ -105,8 +92,6 @@ python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ | |||
| 105 | "sleep 800" \ | 92 | "sleep 800" \ |
| 106 | "jobs" | 93 | "jobs" |
| 107 | 94 | ||
| 108 | # Real IRQ12 events through the queue: start routing to task 3, inject | ||
| 109 | # moves + a left press, stop. | ||
| 110 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "mouse 3" | 95 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "mouse 3" |
| 111 | qemu_hmp "mouse_move 20 7" | 96 | qemu_hmp "mouse_move 20 7" |
| 112 | qemu_hmp "mouse_button 1" | 97 | qemu_hmp "mouse_button 1" |
| @@ -114,8 +99,6 @@ qemu_hmp "mouse_move -5 -3" | |||
| 114 | qemu_hmp "mouse_button 0" | 99 | qemu_hmp "mouse_button 0" |
| 115 | qemu_hmp "sendkey ctrl-c" | 100 | qemu_hmp "sendkey ctrl-c" |
| 116 | 101 | ||
| 117 | # Queue-full boundary: 16 sends fit, the 17th must fail cleanly. The | ||
| 118 | # shell never consumes its own queue, so nothing races the drain here. | ||
| 119 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ | 102 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ |
| 120 | "send 0 user 1" \ | 103 | "send 0 user 1" \ |
| 121 | "send 0 user 2" \ | 104 | "send 0 user 2" \ |
| @@ -148,13 +131,10 @@ grep -aq "msgrecv\[3\]: Key(Enter)" "$LOG" || fail "key enter missing" | |||
| 148 | grep -aq "msgrecv\[3\]: Key(Ctrl-c)" "$LOG" || fail "key ctrl-c missing" | 131 | grep -aq "msgrecv\[3\]: Key(Ctrl-c)" "$LOG" || fail "key ctrl-c missing" |
| 149 | grep -aq "msgrecv\[3\]: Key(F3)" "$LOG" || fail "key f3 missing" | 132 | grep -aq "msgrecv\[3\]: Key(F3)" "$LOG" || fail "key f3 missing" |
| 150 | grep -aq "msgrecv\[3\]: Mouse(+5,-3 L R)" "$LOG" || fail "synthesized mouse message missing" | 133 | grep -aq "msgrecv\[3\]: Mouse(+5,-3 L R)" "$LOG" || fail "synthesized mouse message missing" |
| 151 | # Real IRQ12 events routed through the queue (button held across the move). | ||
| 152 | grep -aq "msgrecv\[3\]: Mouse(+20,+7" "$LOG" || fail "real mouse move 20,7 not routed to queue" | 134 | grep -aq "msgrecv\[3\]: Mouse(+20,+7" "$LOG" || fail "real mouse move 20,7 not routed to queue" |
| 153 | grep -aq "msgrecv\[3\]: Mouse(-5,-3 L" "$LOG" || fail "held-button routed move missing" | 135 | grep -aq "msgrecv\[3\]: Mouse(-5,-3 L" "$LOG" || fail "held-button routed move missing" |
| 154 | grep -aq "queue full" "$LOG" || fail "17th send did not report queue full" | 136 | grep -aq "queue full" "$LOG" || fail "17th send did not report queue full" |
| 155 | grep -aq "send: unknown type" "$LOG" && fail "a bad send slipped through (expected none)" | 137 | grep -aq "send: unknown type" "$LOG" && fail "a bad send slipped through (expected none)" |
| 156 | 138 | ||
| 157 | echo "" | 139 | echo "" |
| 158 | echo "PASS — message queues OK (all types, ordering, real-input routing, queue-full)" | 140 | echo "PASS — message queues OK" |
| 159 | echo " sent: user · timer · key(enter,ctrl-c,f3) · mouse · 16+1 queue-full" | ||
| 160 | echo " routed: mouse_move 20,7 → queue → msgrecv[3]" | ||
