diff options
Diffstat (limited to 'scripts/test-msg.sh')
| -rwxr-xr-x | scripts/test-msg.sh | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/scripts/test-msg.sh b/scripts/test-msg.sh new file mode 100755 index 0000000..0bd1c81 --- /dev/null +++ b/scripts/test-msg.sh | |||
| @@ -0,0 +1,159 @@ | |||
| 1 | #!/usr/bin/env bash | ||
| 2 | # | ||
| 3 | # scripts/test-msg.sh — automated scheduler message-queue round trip. | ||
| 4 | # | ||
| 5 | # Builds the kernel, boots QEMU headless, and verifies inter-task | ||
| 6 | # messaging end to end: | ||
| 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 | # | ||
| 15 | # Usage: | ||
| 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 | # | ||
| 22 | set -euo pipefail | ||
| 23 | |||
| 24 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| 25 | PROJECT_DIR="$(dirname "$SCRIPT_DIR")" | ||
| 26 | cd "$PROJECT_DIR" | ||
| 27 | |||
| 28 | OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" | ||
| 29 | QEMU="${QEMU:-qemu-system-x86_64}" | ||
| 30 | ESP_DIR="$PROJECT_DIR/esp" | ||
| 31 | QPID=/tmp/rsdos-msg-qpid | ||
| 32 | SOCK=/tmp/rsdos-msg-qmon.sock | ||
| 33 | LOG=/tmp/rsdos-msg-serial.log | ||
| 34 | QLOG=/tmp/rsdos-msg-qemu.log | ||
| 35 | |||
| 36 | trap 'kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true' EXIT | ||
| 37 | |||
| 38 | fail() { | ||
| 39 | echo "FAIL: $1" | ||
| 40 | [ -f "$LOG" ] && tail -20 "$LOG" | ||
| 41 | exit 1 | ||
| 42 | } | ||
| 43 | |||
| 44 | wait_log() { | ||
| 45 | local i=0 | ||
| 46 | while [ "$i" -lt $((${3:-60} * 10)) ]; do | ||
| 47 | grep -q "$2" "$1" 2>/dev/null && return 0 | ||
| 48 | sleep 0.1 | ||
| 49 | i=$((i + 1)) | ||
| 50 | done | ||
| 51 | return 1 | ||
| 52 | } | ||
| 53 | |||
| 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() { | ||
| 65 | python3 - "$SOCK" "$1" <<'EOF' | ||
| 66 | import socket, sys, time | ||
| 67 | s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
| 68 | s.connect(sys.argv[1]) | ||
| 69 | s.sendall((sys.argv[2] + "\n").encode()) | ||
| 70 | time.sleep(0.4) | ||
| 71 | EOF | ||
| 72 | } | ||
| 73 | |||
| 74 | echo "==> 1/5 build kernel (debug)" | ||
| 75 | cargo build --package rsdos --target x86_64-unknown-uefi | ||
| 76 | |||
| 77 | echo "==> 2/5 deploy to ESP" | ||
| 78 | mkdir -p "$ESP_DIR/EFI/BOOT" | ||
| 79 | cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI" | ||
| 80 | |||
| 81 | echo "==> 3/5 boot QEMU (headless)" | ||
| 82 | kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true | ||
| 83 | sleep 1 | ||
| 84 | rm -f "$SOCK" "$LOG" | ||
| 85 | "$QEMU" -bios "$OVMF" \ | ||
| 86 | -drive file=fat:rw:"$ESP_DIR",format=raw \ | ||
| 87 | -serial file:"$LOG" \ | ||
| 88 | -monitor unix:"$SOCK",server,nowait \ | ||
| 89 | -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \ | ||
| 90 | >"$QLOG" 2>&1 & | ||
| 91 | echo $! >"$QPID" | ||
| 92 | |||
| 93 | wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell" | ||
| 94 | |||
| 95 | echo "==> 4/5 drive the shell (msgrecv / send / mouse routing / queue-full)" | ||
| 96 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ | ||
| 97 | "msgrecv" \ | ||
| 98 | "send 2 user 42" \ | ||
| 99 | "send 2 timer" \ | ||
| 100 | "send 2 key enter" \ | ||
| 101 | "send 2 key ctrl-c" \ | ||
| 102 | "send 2 key f3" \ | ||
| 103 | "send 2 mouse 5 -3 3" \ | ||
| 104 | "sleep 800" \ | ||
| 105 | "jobs" | ||
| 106 | |||
| 107 | # Real IRQ12 events through the queue: start routing to task 2, inject | ||
| 108 | # moves + a left press, stop. | ||
| 109 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "mouse 2" | ||
| 110 | qemu_hmp "mouse_move 20 7" | ||
| 111 | qemu_hmp "mouse_button 1" | ||
| 112 | qemu_hmp "mouse_move -5 -3" | ||
| 113 | qemu_hmp "mouse_button 0" | ||
| 114 | qemu_hmp "sendkey ctrl-c" | ||
| 115 | |||
| 116 | # Queue-full boundary: 16 sends fit, the 17th must fail cleanly. The | ||
| 117 | # shell never consumes its own queue, so nothing races the drain here. | ||
| 118 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ | ||
| 119 | "send 0 user 1" \ | ||
| 120 | "send 0 user 2" \ | ||
| 121 | "send 0 user 3" \ | ||
| 122 | "send 0 user 4" \ | ||
| 123 | "send 0 user 5" \ | ||
| 124 | "send 0 user 6" \ | ||
| 125 | "send 0 user 7" \ | ||
| 126 | "send 0 user 8" \ | ||
| 127 | "send 0 user 9" \ | ||
| 128 | "send 0 user 10" \ | ||
| 129 | "send 0 user 11" \ | ||
| 130 | "send 0 user 12" \ | ||
| 131 | "send 0 user 13" \ | ||
| 132 | "send 0 user 14" \ | ||
| 133 | "send 0 user 15" \ | ||
| 134 | "send 0 user 16" \ | ||
| 135 | "send 0 user 17" \ | ||
| 136 | "sleep 800" \ | ||
| 137 | "jobs" \ | ||
| 138 | "poweroff" | ||
| 139 | |||
| 140 | echo "==> 5/5 wait for shutdown + verify" | ||
| 141 | wait_qemu_exit 30 || fail "QEMU did not exit after poweroff" | ||
| 142 | |||
| 143 | grep -aq "msgrecv: task 2 listening" "$LOG" || fail "msgrecv did not spawn" | ||
| 144 | grep -aq "msgrecv\[2\]: User(42)" "$LOG" || fail "user message missing" | ||
| 145 | grep -aq "msgrecv\[2\]: Timer" "$LOG" || fail "timer message missing" | ||
| 146 | grep -aq "msgrecv\[2\]: Key(Enter)" "$LOG" || fail "key enter missing" | ||
| 147 | grep -aq "msgrecv\[2\]: Key(Ctrl-c)" "$LOG" || fail "key ctrl-c missing" | ||
| 148 | grep -aq "msgrecv\[2\]: Key(F3)" "$LOG" || fail "key f3 missing" | ||
| 149 | grep -aq "msgrecv\[2\]: Mouse(+5,-3 L R)" "$LOG" || fail "synthesized mouse message missing" | ||
| 150 | # Real IRQ12 events routed through the queue (button held across the move). | ||
| 151 | grep -aq "msgrecv\[2\]: Mouse(+20,+7" "$LOG" || fail "real mouse move 20,7 not routed to queue" | ||
| 152 | grep -aq "msgrecv\[2\]: Mouse(-5,-3 L" "$LOG" || fail "held-button routed move missing" | ||
| 153 | grep -aq "queue full" "$LOG" || fail "17th send did not report queue full" | ||
| 154 | grep -aq "send: unknown type" "$LOG" && fail "a bad send slipped through (expected none)" | ||
| 155 | |||
| 156 | echo "" | ||
| 157 | echo "PASS — message queues OK (all types, ordering, real-input routing, queue-full)" | ||
| 158 | echo " sent: user · timer · key(enter,ctrl-c,f3) · mouse · 16+1 queue-full" | ||
| 159 | echo " routed: mouse_move 20,7 → queue → msgrecv[2]" | ||
