summaryrefslogtreecommitdiffstats
path: root/scripts/tests/test-msg.sh
blob: 7786beba21806165b0960a9af8c4db249e113205 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
#
# scripts/tests/test-msg.sh — automated scheduler message-queue round trip.
#
# Tests all message types (user, timer, key, mouse), real-input routing,
# and the queue-full boundary.
#
# Usage: ./scripts/tests/test-msg.sh
# Env:   SYSTEM_IMG, OVMF, QEMU (see scripts/lib.sh)
#
set -euo pipefail
TNAME="msg"
# shellcheck source=../lib.sh
source "$(dirname "$0")/../lib.sh"

echo "==> 1/5 build (kernel + bins)"
build_all

echo "==> 2/5 stage system image"
stage_image --force

echo "==> 3/5 boot QEMU (headless)"
test_boot

echo "==> 4/5 drive the shell (msgrecv / send / mouse routing / queue-full)"
# msgrecv's task id is assigned at spawn time and shifts when the task
# table grows (the Windowed GUI added wm-input at slot 3) — read it from
# the log instead of hardcoding.
sendkeys "msgrecv"
sleep 1
MID="$(sed -n 's/.*msgrecv: task \([0-9][0-9]*\) listening.*/\1/p' "$LOG" | tail -1)"
[ -n "$MID" ] || fail "msgrecv did not spawn (no 'msgrecv: task N listening' in the log)"
echo "  msgrecv task id: $MID"

sendkeys \
	"send $MID user 42" \
	"send $MID timer" \
	"send $MID key enter" \
	"send $MID key ctrl-c" \
	"send $MID key f3" \
	"send $MID mouse 5 -3 3" \
	"sleep 800" \
	"jobs"

sendkeys "mouse $MID"
qemu_hmp "mouse_move 20 7"
qemu_hmp "mouse_button 1"
qemu_hmp "mouse_move -5 -3"
qemu_hmp "mouse_button 0"
qemu_hmp "sendkey ctrl-c"

# Queue-full probe: overflow a queue that nobody drains.  The shell used
# to be that task, but its exec pump now consumes its own User messages
# as completion codes (q=0 at the prompt), and msgrecv consumes on wake —
# the cursor task never calls recv, so its 16-slot ring fills for real.
CID="$(awk '$2 == "cursor" { print $1 }' "$LOG" | tail -1)"
[ -n "$CID" ] || fail "no cursor task in jobs output (cannot probe queue-full)"
echo "  queue-full target: task $CID (cursor, never recv'd)"

sendkeys \
	"send $CID user 1" \
	"send $CID user 2" \
	"send $CID user 3" \
	"send $CID user 4" \
	"send $CID user 5" \
	"send $CID user 6" \
	"send $CID user 7" \
	"send $CID user 8" \
	"send $CID user 9" \
	"send $CID user 10" \
	"send $CID user 11" \
	"send $CID user 12" \
	"send $CID user 13" \
	"send $CID user 14" \
	"send $CID user 15" \
	"send $CID user 16" \
	"send $CID user 17" \
	"sleep 800" \
	"jobs" \
	"poweroff"

echo "==> 5/5 wait for shutdown + verify"
wait_qemu_exit 30 || fail "QEMU did not exit after poweroff"

grep -aq "msgrecv: task $MID listening" "$LOG" || fail "msgrecv did not spawn"
grep -aq "msgrecv\[$MID\]: User(42)" "$LOG" || fail "user message missing"
grep -aq "msgrecv\[$MID\]: Timer" "$LOG" || fail "timer message missing"
grep -aq "msgrecv\[$MID\]: Key(Enter)" "$LOG" || fail "key enter missing"
grep -aq "msgrecv\[$MID\]: Key(Ctrl-c)" "$LOG" || fail "key ctrl-c missing"
grep -aq "msgrecv\[$MID\]: Key(F3)" "$LOG" || fail "key f3 missing"
grep -aq "msgrecv\[$MID\]: Mouse(+5,-3 L R)" "$LOG" || fail "synthesized mouse message missing"
grep -aq "msgrecv\[$MID\]: Mouse(+20,+7" "$LOG" || fail "real mouse move 20,7 not routed to queue"
grep -aq "msgrecv\[$MID\]: Mouse(-5,-3 L" "$LOG" || fail "held-button routed move missing"
grep -aq "queue full" "$LOG" || fail "17th send did not report queue full"
grep -aq "send: unknown type" "$LOG" && fail "a bad send slipped through (expected none)"

echo ""
echo "PASS — message queues OK"