summaryrefslogtreecommitdiffstats
path: root/scripts/tests/test-msg.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/tests/test-msg.sh')
-rwxr-xr-xscripts/tests/test-msg.sh98
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#
11set -euo pipefail
12TNAME="msg"
13# shellcheck source=../lib.sh
14source "$(dirname "$0")/../lib.sh"
15
16echo "==> 1/5 build (kernel + bins)"
17build_all
18
19echo "==> 2/5 stage system image"
20stage_image --force
21
22echo "==> 3/5 boot QEMU (headless)"
23test_boot
24
25echo "==> 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.
29sendkeys "msgrecv"
30sleep 1
31MID="$(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)"
33echo " msgrecv task id: $MID"
34
35sendkeys \
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
45sendkeys "mouse $MID"
46qemu_hmp "mouse_move 20 7"
47qemu_hmp "mouse_button 1"
48qemu_hmp "mouse_move -5 -3"
49qemu_hmp "mouse_button 0"
50qemu_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.
56CID="$(awk '$2 == "cursor" { print $1 }' "$LOG" | tail -1)"
57[ -n "$CID" ] || fail "no cursor task in jobs output (cannot probe queue-full)"
58echo " queue-full target: task $CID (cursor, never recv'd)"
59
60sendkeys \
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
82echo "==> 5/5 wait for shutdown + verify"
83wait_qemu_exit 30 || fail "QEMU did not exit after poweroff"
84
85grep -aq "msgrecv: task $MID listening" "$LOG" || fail "msgrecv did not spawn"
86grep -aq "msgrecv\[$MID\]: User(42)" "$LOG" || fail "user message missing"
87grep -aq "msgrecv\[$MID\]: Timer" "$LOG" || fail "timer message missing"
88grep -aq "msgrecv\[$MID\]: Key(Enter)" "$LOG" || fail "key enter missing"
89grep -aq "msgrecv\[$MID\]: Key(Ctrl-c)" "$LOG" || fail "key ctrl-c missing"
90grep -aq "msgrecv\[$MID\]: Key(F3)" "$LOG" || fail "key f3 missing"
91grep -aq "msgrecv\[$MID\]: Mouse(+5,-3 L R)" "$LOG" || fail "synthesized mouse message missing"
92grep -aq "msgrecv\[$MID\]: Mouse(+20,+7" "$LOG" || fail "real mouse move 20,7 not routed to queue"
93grep -aq "msgrecv\[$MID\]: Mouse(-5,-3 L" "$LOG" || fail "held-button routed move missing"
94grep -aq "queue full" "$LOG" || fail "17th send did not report queue full"
95grep -aq "send: unknown type" "$LOG" && fail "a bad send slipped through (expected none)"
96
97echo ""
98echo "PASS — message queues OK"