diff options
Diffstat (limited to 'scripts/tests/test-msg.sh')
| -rwxr-xr-x | scripts/tests/test-msg.sh | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/scripts/tests/test-msg.sh b/scripts/tests/test-msg.sh new file mode 100755 index 0000000..7786beb --- /dev/null +++ b/scripts/tests/test-msg.sh | |||
| @@ -0,0 +1,98 @@ | |||
| 1 | #!/usr/bin/env bash | ||
| 2 | # | ||
| 3 | # scripts/tests/test-msg.sh — automated scheduler message-queue round trip. | ||
| 4 | # | ||
| 5 | # Tests all message types (user, timer, key, mouse), real-input routing, | ||
| 6 | # and the queue-full boundary. | ||
| 7 | # | ||
| 8 | # Usage: ./scripts/tests/test-msg.sh | ||
| 9 | # Env: SYSTEM_IMG, OVMF, QEMU (see scripts/lib.sh) | ||
| 10 | # | ||
| 11 | set -euo pipefail | ||
| 12 | TNAME="msg" | ||
| 13 | # shellcheck source=../lib.sh | ||
| 14 | source "$(dirname "$0")/../lib.sh" | ||
| 15 | |||
| 16 | echo "==> 1/5 build (kernel + bins)" | ||
| 17 | build_all | ||
| 18 | |||
| 19 | echo "==> 2/5 stage system image" | ||
| 20 | stage_image --force | ||
| 21 | |||
| 22 | echo "==> 3/5 boot QEMU (headless)" | ||
| 23 | test_boot | ||
| 24 | |||
| 25 | echo "==> 4/5 drive the shell (msgrecv / send / mouse routing / queue-full)" | ||
| 26 | # msgrecv's task id is assigned at spawn time and shifts when the task | ||
| 27 | # table grows (the Windowed GUI added wm-input at slot 3) — read it from | ||
| 28 | # the log instead of hardcoding. | ||
| 29 | sendkeys "msgrecv" | ||
| 30 | sleep 1 | ||
| 31 | MID="$(sed -n 's/.*msgrecv: task \([0-9][0-9]*\) listening.*/\1/p' "$LOG" | tail -1)" | ||
| 32 | [ -n "$MID" ] || fail "msgrecv did not spawn (no 'msgrecv: task N listening' in the log)" | ||
| 33 | echo " msgrecv task id: $MID" | ||
| 34 | |||
| 35 | sendkeys \ | ||
| 36 | "send $MID user 42" \ | ||
| 37 | "send $MID timer" \ | ||
| 38 | "send $MID key enter" \ | ||
| 39 | "send $MID key ctrl-c" \ | ||
| 40 | "send $MID key f3" \ | ||
| 41 | "send $MID mouse 5 -3 3" \ | ||
| 42 | "sleep 800" \ | ||
| 43 | "jobs" | ||
| 44 | |||
| 45 | sendkeys "mouse $MID" | ||
| 46 | qemu_hmp "mouse_move 20 7" | ||
| 47 | qemu_hmp "mouse_button 1" | ||
| 48 | qemu_hmp "mouse_move -5 -3" | ||
| 49 | qemu_hmp "mouse_button 0" | ||
| 50 | qemu_hmp "sendkey ctrl-c" | ||
| 51 | |||
| 52 | # Queue-full probe: overflow a queue that nobody drains. The shell used | ||
| 53 | # to be that task, but its exec pump now consumes its own User messages | ||
| 54 | # as completion codes (q=0 at the prompt), and msgrecv consumes on wake — | ||
| 55 | # the cursor task never calls recv, so its 16-slot ring fills for real. | ||
| 56 | CID="$(awk '$2 == "cursor" { print $1 }' "$LOG" | tail -1)" | ||
| 57 | [ -n "$CID" ] || fail "no cursor task in jobs output (cannot probe queue-full)" | ||
| 58 | echo " queue-full target: task $CID (cursor, never recv'd)" | ||
| 59 | |||
| 60 | sendkeys \ | ||
| 61 | "send $CID user 1" \ | ||
| 62 | "send $CID user 2" \ | ||
| 63 | "send $CID user 3" \ | ||
| 64 | "send $CID user 4" \ | ||
| 65 | "send $CID user 5" \ | ||
| 66 | "send $CID user 6" \ | ||
| 67 | "send $CID user 7" \ | ||
| 68 | "send $CID user 8" \ | ||
| 69 | "send $CID user 9" \ | ||
| 70 | "send $CID user 10" \ | ||
| 71 | "send $CID user 11" \ | ||
| 72 | "send $CID user 12" \ | ||
| 73 | "send $CID user 13" \ | ||
| 74 | "send $CID user 14" \ | ||
| 75 | "send $CID user 15" \ | ||
| 76 | "send $CID user 16" \ | ||
| 77 | "send $CID user 17" \ | ||
| 78 | "sleep 800" \ | ||
| 79 | "jobs" \ | ||
| 80 | "poweroff" | ||
| 81 | |||
| 82 | echo "==> 5/5 wait for shutdown + verify" | ||
| 83 | wait_qemu_exit 30 || fail "QEMU did not exit after poweroff" | ||
| 84 | |||
| 85 | grep -aq "msgrecv: task $MID listening" "$LOG" || fail "msgrecv did not spawn" | ||
| 86 | grep -aq "msgrecv\[$MID\]: User(42)" "$LOG" || fail "user message missing" | ||
| 87 | grep -aq "msgrecv\[$MID\]: Timer" "$LOG" || fail "timer message missing" | ||
| 88 | grep -aq "msgrecv\[$MID\]: Key(Enter)" "$LOG" || fail "key enter missing" | ||
| 89 | grep -aq "msgrecv\[$MID\]: Key(Ctrl-c)" "$LOG" || fail "key ctrl-c missing" | ||
| 90 | grep -aq "msgrecv\[$MID\]: Key(F3)" "$LOG" || fail "key f3 missing" | ||
| 91 | grep -aq "msgrecv\[$MID\]: Mouse(+5,-3 L R)" "$LOG" || fail "synthesized mouse message missing" | ||
| 92 | grep -aq "msgrecv\[$MID\]: Mouse(+20,+7" "$LOG" || fail "real mouse move 20,7 not routed to queue" | ||
| 93 | grep -aq "msgrecv\[$MID\]: Mouse(-5,-3 L" "$LOG" || fail "held-button routed move missing" | ||
| 94 | grep -aq "queue full" "$LOG" || fail "17th send did not report queue full" | ||
| 95 | grep -aq "send: unknown type" "$LOG" && fail "a bad send slipped through (expected none)" | ||
| 96 | |||
| 97 | echo "" | ||
| 98 | echo "PASS — message queues OK" | ||
