From 9b9758e5ee2564b04685eadf2b9ce23dd1060b86 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 1 Aug 2026 19:34:40 +0200 Subject: rsnix v0.4.0: GUI input foundation — PS/2 mouse + scheduler message queues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mouse (IRQ12, stream mode): ByteRing generalized for both PS/2 devices, ISR routes data-port bytes by the controller's aux bit; mouse_init with bounded-ACK handshake (boots without a mouse); packet decoder with bit-3 resync, screen-relative deltas, buttons. Exposed as /dev/mouse, the `mouse` stream command, and `make test-mouse`. Message queues (ADR 0003's GUI-era primitive): every task gets a static 16-slot TaskMsg ring; send/recv/recv_blocking with direct wake + tick scan safety net for the lost-wakeup race; `msgrecv`/`send` commands, `mouse ` routes real IRQ12 events into a task's queue, jobs shows q=. `make test-msg` + `make test-disk` regression pass. --- scripts/test-msg.sh | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100755 scripts/test-msg.sh (limited to 'scripts/test-msg.sh') 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 @@ +#!/usr/bin/env bash +# +# scripts/test-msg.sh — automated scheduler message-queue round trip. +# +# Builds the kernel, boots QEMU headless, and verifies inter-task +# messaging end to end: +# - `msgrecv` spawns a task that blocks on recv_blocking +# - `send ` delivers every message type in order +# - `mouse ` routes *real* IRQ12 mouse events into the queue +# (the window-manager input path) +# - queue-full is a clean error (16-cap; tested against the shell's +# own never-consumed queue) +# - jobs shows q=0 after everything drains, task back to blocked +# +# Usage: +# ./scripts/test-msg.sh +# +# Environment: +# OVMF firmware (default: /usr/share/edk2/x64/OVMF.4m.fd) +# QEMU qemu binary (default: qemu-system-x86_64) +# +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +PROJECT_DIR="$(dirname "$SCRIPT_DIR")" +cd "$PROJECT_DIR" + +OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" +QEMU="${QEMU:-qemu-system-x86_64}" +ESP_DIR="$PROJECT_DIR/esp" +QPID=/tmp/rsdos-msg-qpid +SOCK=/tmp/rsdos-msg-qmon.sock +LOG=/tmp/rsdos-msg-serial.log +QLOG=/tmp/rsdos-msg-qemu.log + +trap 'kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true' EXIT + +fail() { + echo "FAIL: $1" + [ -f "$LOG" ] && tail -20 "$LOG" + exit 1 +} + +wait_log() { + local i=0 + while [ "$i" -lt $((${3:-60} * 10)) ]; do + grep -q "$2" "$1" 2>/dev/null && return 0 + sleep 0.1 + i=$((i + 1)) + done + return 1 +} + +wait_qemu_exit() { + local i=0 + while [ "$i" -lt $((${1:-30} * 10)) ]; do + kill -0 "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || return 0 + sleep 0.1 + i=$((i + 1)) + done + return 1 +} + +qemu_hmp() { + python3 - "$SOCK" "$1" <<'EOF' +import socket, sys, time +s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) +s.connect(sys.argv[1]) +s.sendall((sys.argv[2] + "\n").encode()) +time.sleep(0.4) +EOF +} + +echo "==> 1/5 build kernel (debug)" +cargo build --package rsdos --target x86_64-unknown-uefi + +echo "==> 2/5 deploy to ESP" +mkdir -p "$ESP_DIR/EFI/BOOT" +cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI" + +echo "==> 3/5 boot QEMU (headless)" +kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true +sleep 1 +rm -f "$SOCK" "$LOG" +"$QEMU" -bios "$OVMF" \ + -drive file=fat:rw:"$ESP_DIR",format=raw \ + -serial file:"$LOG" \ + -monitor unix:"$SOCK",server,nowait \ + -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \ + >"$QLOG" 2>&1 & +echo $! >"$QPID" + +wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell" + +echo "==> 4/5 drive the shell (msgrecv / send / mouse routing / queue-full)" +python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ + "msgrecv" \ + "send 2 user 42" \ + "send 2 timer" \ + "send 2 key enter" \ + "send 2 key ctrl-c" \ + "send 2 key f3" \ + "send 2 mouse 5 -3 3" \ + "sleep 800" \ + "jobs" + +# Real IRQ12 events through the queue: start routing to task 2, inject +# moves + a left press, stop. +python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "mouse 2" +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 boundary: 16 sends fit, the 17th must fail cleanly. The +# shell never consumes its own queue, so nothing races the drain here. +python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ + "send 0 user 1" \ + "send 0 user 2" \ + "send 0 user 3" \ + "send 0 user 4" \ + "send 0 user 5" \ + "send 0 user 6" \ + "send 0 user 7" \ + "send 0 user 8" \ + "send 0 user 9" \ + "send 0 user 10" \ + "send 0 user 11" \ + "send 0 user 12" \ + "send 0 user 13" \ + "send 0 user 14" \ + "send 0 user 15" \ + "send 0 user 16" \ + "send 0 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 2 listening" "$LOG" || fail "msgrecv did not spawn" +grep -aq "msgrecv\[2\]: User(42)" "$LOG" || fail "user message missing" +grep -aq "msgrecv\[2\]: Timer" "$LOG" || fail "timer message missing" +grep -aq "msgrecv\[2\]: Key(Enter)" "$LOG" || fail "key enter missing" +grep -aq "msgrecv\[2\]: Key(Ctrl-c)" "$LOG" || fail "key ctrl-c missing" +grep -aq "msgrecv\[2\]: Key(F3)" "$LOG" || fail "key f3 missing" +grep -aq "msgrecv\[2\]: Mouse(+5,-3 L R)" "$LOG" || fail "synthesized mouse message missing" +# Real IRQ12 events routed through the queue (button held across the move). +grep -aq "msgrecv\[2\]: Mouse(+20,+7" "$LOG" || fail "real mouse move 20,7 not routed to queue" +grep -aq "msgrecv\[2\]: 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 (all types, ordering, real-input routing, queue-full)" +echo " sent: user · timer · key(enter,ctrl-c,f3) · mouse · 16+1 queue-full" +echo " routed: mouse_move 20,7 → queue → msgrecv[2]" -- cgit v1.2.3