summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-08-27 18:35:59 +0200
committersalmonik <salmonik@tuta.io>2026-08-27 18:35:59 +0200
commitacd0fe1bc38746f36fff24a7497041e5c5010977 (patch)
tree5db6335b732409c7f180f8514196c52a7b88f434
parentGUI: fire-and-forget spawn for /bin/gui binaries (diff)
downloadrs-dos-acd0fe1bc38746f36fff24a7497041e5c5010977.tar.gz
rs-dos-acd0fe1bc38746f36fff24a7497041e5c5010977.zip
scripts: migrate all QEMU/test scripts to single system image
boot.sh: replace esp/ + DISK_IMG with single SYSTEM_IMG on ide.0 (hooks into mksystem.sh --force for auto-staging). boot-image.sh: delegate to mksystem.sh --chain (build-image.sh deleted). build-image-release.sh: delegate to mksystem.sh --chain --gpt. qemu.sh: flexible launcher uses SYSTEM_IMG; --chain flag for full-chain build. test-disk.sh: drop ESP_DIR (mksystem.sh stages everything). test-fault.sh: boot system.img on ide.0 + CRASHLOG stick on ide.1; replace deleted mkdisk.sh with inline mkfs.fat. test-gfx.sh: system.img on ide.0, stage via mksystem.sh. test-mouse.sh: system.img on ide.0, stage via mksystem.sh. test-msg.sh: system.img on ide.0, stage via mksystem.sh. Makefile: remove stale build-image.sh/mkdisk.sh references from help; image target delegates to mksystem.sh --chain. All scripts syntax-checked (bash -n). build-image.sh and mkdisk.sh no longer referenced anywhere.
-rw-r--r--Makefile4
-rwxr-xr-xscripts/boot-image.sh7
-rwxr-xr-xscripts/boot.sh47
-rwxr-xr-xscripts/build-image-release.sh91
-rwxr-xr-xscripts/qemu.sh90
-rwxr-xr-xscripts/test-disk.sh1
-rwxr-xr-xscripts/test-fault.sh53
-rwxr-xr-xscripts/test-gfx.sh78
-rwxr-xr-xscripts/test-mouse.sh104
-rwxr-xr-xscripts/test-msg.sh62
10 files changed, 162 insertions, 375 deletions
diff --git a/Makefile b/Makefile
index 6f7f545..be55e4e 100644
--- a/Makefile
+++ b/Makefile
@@ -136,7 +136,7 @@ bootloader:
136 136
137# Build the full boot chain disk image (kernel + bootloader) 137# Build the full boot chain disk image (kernel + bootloader)
138image: all 138image: all
139 ./scripts/build-image.sh rs-dos.img 139./scripts/mksystem.sh --chain rs-dos.img
140 140
141# Boot the full chain disk image (builds it first if needed) 141# Boot the full chain disk image (builds it first if needed)
142boot-image: all 142boot-image: all
@@ -168,11 +168,9 @@ help:
168 @echo " make fmt format Rust source" 168 @echo " make fmt format Rust source"
169 @echo " ./scripts/mksystem.sh build the dd-able system image" 169 @echo " ./scripts/mksystem.sh build the dd-able system image"
170 @echo " ./scripts/boot.sh quick direct boot (dev loop)" 170 @echo " ./scripts/boot.sh quick direct boot (dev loop)"
171 @echo " ./scripts/mkdisk.sh create/re-format the data disk"
172 @echo " ./scripts/test-disk.sh automated disk round trip" 171 @echo " ./scripts/test-disk.sh automated disk round trip"
173 @echo " ./scripts/sendkeys.py type into QEMU via the monitor" 172 @echo " ./scripts/sendkeys.py type into QEMU via the monitor"
174 @echo " ./scripts/boot-image.sh boot full chain (builds if needed)" 173 @echo " ./scripts/boot-image.sh boot full chain (builds if needed)"
175 @echo " ./scripts/build-image.sh build full chain disk image"
176 @echo " ./scripts/build-bootloader.sh build rsboot from source" 174 @echo " ./scripts/build-bootloader.sh build rsboot from source"
177 @echo " ./scripts/qemu.sh flexible QEMU launcher" 175 @echo " ./scripts/qemu.sh flexible QEMU launcher"
178 @echo " ./scripts/debug-kernel.py GDB plugin (attach after 'make debug')" 176 @echo " ./scripts/debug-kernel.py GDB plugin (attach after 'make debug')"
diff --git a/scripts/boot-image.sh b/scripts/boot-image.sh
index e8c093c..f70dcd4 100755
--- a/scripts/boot-image.sh
+++ b/scripts/boot-image.sh
@@ -20,11 +20,10 @@
20set -euo pipefail 20set -euo pipefail
21 21
22SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 22SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
23PROJECT_DIR="$(dirname "$SCRIPT_DIR")" 23PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
24
25cd "$PROJECT_DIR" 24cd "$PROJECT_DIR"
26 25
27IMAGE="rs-dos.img" 26IMAGE="${1:-rs-dos.img}"
28 27
29# ---- config ---- 28# ---- config ----
30OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" 29OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}"
@@ -40,7 +39,7 @@ parse_boot_args "$@"
40# ---- build image if missing ---- 39# ---- build image if missing ----
41if [ ! -f "$IMAGE" ]; then 40if [ ! -f "$IMAGE" ]; then
42 echo "Image not found, building..." 41 echo "Image not found, building..."
43 "$SCRIPT_DIR/build-image.sh" 42 "$SCRIPT_DIR/mksystem.sh" --chain --gpt "$IMAGE"
44fi 43fi
45 44
46# ---- boot ---- 45# ---- boot ----
diff --git a/scripts/boot.sh b/scripts/boot.sh
index 5b8e6fa..9c60dc9 100755
--- a/scripts/boot.sh
+++ b/scripts/boot.sh
@@ -2,8 +2,8 @@
2# 2#
3# scripts/boot.sh — quick direct boot in QEMU (dev loop) 3# scripts/boot.sh — quick direct boot in QEMU (dev loop)
4# 4#
5# Fastest iteration: boots the kernel directly as BOOTX64.EFI via QEMU's 5# Builds the kernel, stages the system image, and boots directly as
6# FAT driver, skipping the bootloader entirely. 6# BOOTX64.EFI via QEMU's FAT driver. One image = one drive.
7# 7#
8# Usage: 8# Usage:
9# ./scripts/boot.sh [--gui] [--debug] [--release] [--mem 512M] [--smp 2] 9# ./scripts/boot.sh [--gui] [--debug] [--release] [--mem 512M] [--smp 2]
@@ -19,26 +19,19 @@
19# OVMF path to OVMF firmware (default: /usr/share/edk2/x64/OVMF.4m.fd) 19# OVMF path to OVMF firmware (default: /usr/share/edk2/x64/OVMF.4m.fd)
20# MEM memory size (default: 256M) 20# MEM memory size (default: 256M)
21# SMP CPU count (default: 1) 21# SMP CPU count (default: 1)
22# DISK_IMG raw disk image attached as the SATA data disk (default: /tmp/disk.img) 22# SYSTEM_IMG system image path (default: /tmp/system.img)
23#
24# The data disk is pinned to AHCI port 0 (ide.0) and the ESP to port 1
25# (ide.1); the implicit `-drive file=fat:rw:esp` would otherwise grab
26# port 0 and the kernel would find the ESP where it expects a FAT32 disk.
27# 23#
28set -euo pipefail 24set -euo pipefail
29 25
30SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 26SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
31PROJECT_DIR="$(dirname "$SCRIPT_DIR")" 27PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
32
33cd "$PROJECT_DIR" 28cd "$PROJECT_DIR"
34 29
35ESP_DIR="$PROJECT_DIR/esp"
36
37# ---- config ---- 30# ---- config ----
38OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" 31OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}"
39MEM="${MEM:-256M}" 32MEM="${MEM:-256M}"
40SMP="${SMP:-1}" 33SMP="${SMP:-1}"
41DISK_IMG="${DISK_IMG:-/tmp/disk.img}" 34SYSTEM_IMG="${SYSTEM_IMG:-/tmp/system.img}"
42PROFILE="debug" 35PROFILE="debug"
43CARGO_FLAGS="" 36CARGO_FLAGS=""
44GUI="" 37GUI=""
@@ -46,7 +39,6 @@ DEBUG=""
46 39
47# ---- args ---- 40# ---- args ----
48source "$SCRIPT_DIR/lib-boot-args.sh" 41source "$SCRIPT_DIR/lib-boot-args.sh"
49# boot.sh-specific flags live here; everything else is shared.
50handle_arg() { 42handle_arg() {
51 case "$1" in 43 case "$1" in
52 --release | -r) 44 --release | -r)
@@ -62,46 +54,29 @@ handle_arg() {
62parse_boot_args "$@" 54parse_boot_args "$@"
63 55
64OUT_DIR="target/x86_64-unknown-uefi/$PROFILE" 56OUT_DIR="target/x86_64-unknown-uefi/$PROFILE"
65KERNEL="$OUT_DIR/rsdos.efi"
66 57
67# ---- build ---- 58# ---- build ----
68echo "=== Building kernel ($PROFILE) ===" 59echo "=== Building kernel ($PROFILE) ==="
69cargo build --package rsdos --target x86_64-unknown-uefi $CARGO_FLAGS 60cargo build --package rsdos --target x86_64-unknown-uefi $CARGO_FLAGS
70 61
71# ---- deploy ---- 62# ---- stage system image ----
72mkdir -p "$ESP_DIR/EFI/BOOT" 63echo "=== Staging system image ==="
73cp "$KERNEL" "$ESP_DIR/EFI/BOOT/BOOTX64.EFI" 64"$SCRIPT_DIR/mksystem.sh" --force "$SYSTEM_IMG"
74echo " kernel: $(ls -lh "$KERNEL" | awk '{print $5}')" 65echo " system image: $SYSTEM_IMG"
75 66
76# ---- boot ---- 67# ---- boot ----
77echo "" 68echo ""
78echo "=== Booting (direct: firmware → rsnix) ===" 69echo "=== Booting (direct: firmware → rsnix) ==="
79echo " ovmf: $OVMF" 70echo " ovmf: $OVMF"
80echo " mem: $MEM smp: $SMP" 71echo " mem: $MEM smp: $SMP"
81echo " disk: $([ -f "$DISK_IMG" ] && echo "$DISK_IMG" || echo "none ($DISK_IMG missing)")"
82echo " gui: $([ -n "$GUI" ] && echo yes || echo no)" 72echo " gui: $([ -n "$GUI" ] && echo yes || echo no)"
83echo " gdb: $([ -n "$DEBUG" ] && echo ':1234' || echo off)" 73echo " gdb: $([ -n "$DEBUG" ] && echo ':1234' || echo off)"
84echo "" 74echo ""
85 75
86if [ ! -f "$DISK_IMG" ]; then
87 echo " (creating missing disk image: $DISK_IMG)"
88 "$SCRIPT_DIR/mkdisk.sh" "$DISK_IMG"
89fi
90
91if [ -f "$DISK_IMG" ]; then
92 DISK_ARGS=(
93 -drive "file=$DISK_IMG,format=raw,if=none,id=disk"
94 -device ide-hd,drive=disk,bus=ide.0
95 )
96else
97 DISK_ARGS=()
98fi
99
100exec qemu-system-x86_64 \ 76exec qemu-system-x86_64 \
101 -bios "$OVMF" \ 77 -bios "$OVMF" \
102 "${DISK_ARGS[@]}" \ 78 -drive "file=$SYSTEM_IMG,format=raw,if=none,id=disk" \
103 -drive file=fat:rw:"$ESP_DIR",format=raw,if=none,id=esp \ 79 -device ide-hd,drive=disk,bus=ide.0 \
104 -device ide-hd,drive=esp,bus=ide.1 \
105 -serial stdio \ 80 -serial stdio \
106 -m "$MEM" \ 81 -m "$MEM" \
107 -machine q35 \ 82 -machine q35 \
diff --git a/scripts/build-image-release.sh b/scripts/build-image-release.sh
index 32f8f91..e4c5250 100755
--- a/scripts/build-image-release.sh
+++ b/scripts/build-image-release.sh
@@ -1,99 +1,30 @@
1#!/usr/bin/env bash 1#!/usr/bin/env bash
2# 2#
3# scripts/build-image.sh — assemble a bootable rs-dos disk image (UEFI/GPT) 3# scripts/build-image-release.sh — build the release GPT disk image
4# 4#
5# Layout: 5# Produces a single dd-able system image with the release build of
6# Partition 1: ESP (FAT32) — rsboot bootloader + kernel 6# the kernel, rsboot bootloader, and all binaries in /bin/.
7#
8# Output:
9# rs-dos.img (or custom path) — bootable raw disk image for UEFI
10# 7#
11# Usage: 8# Usage:
12# ./scripts/build-image.sh [output.img] 9# ./scripts/build-image-release.sh [output.img]
13# 10#
14set -euo pipefail 11set -euo pipefail
15 12
16SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 13SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
17PROJECT_DIR="$(dirname "$SCRIPT_DIR")" 14PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
18
19cd "$PROJECT_DIR" 15cd "$PROJECT_DIR"
20 16
21BUILD_DIR="$PROJECT_DIR/build" 17IMAGE="${1:-rs-dos.img}"
22ESP_DIR="$PROJECT_DIR/esp"
23
24IMAGE="${1:-$PROJECT_DIR/rs-dos.img}"
25TARGET=x86_64-unknown-uefi
26PROFILE=release
27OUT_DIR="target/${TARGET}/${PROFILE}"
28
29BOOTLOADER="$BUILD_DIR/bootloader/BOOTX64.EFI"
30KERNEL="$OUT_DIR/rsdos.efi"
31BZIMAGE="$ESP_DIR/bzImage"
32INITRD="$ESP_DIR/initramfs.cpio.gz"
33BOOT_EFI="$ESP_DIR/EFI/BOOT/BOOTX64.EFI"
34
35ESP_START=2048 # 1 MiB offset (standard alignment)
36ESP_SIZE_MB=64
37
38IMAGE_SIZE_MB=$((ESP_SIZE_MB + 2)) # ESP + GPT gap + backup
39
40# ---- checks ----
41for cmd in sfdisk mkfs.vfat mcopy truncate dd; do
42 if ! command -v "$cmd" &>/dev/null; then
43 echo "Error: $cmd not found"
44 exit 1
45 fi
46done
47
48# ---- build kernel ----
49echo "[1/4] Building kernel..."
50cargo build --release --package rsdos --target x86_64-unknown-uefi ${CARGO_FLAGS:-}
51
52# ---- build bootloader ----
53echo "[2/4] Building bootloader..."
54if [ ! -f "$BOOTLOADER" ]; then
55 "$SCRIPT_DIR/build-bootloader.sh"
56fi
57
58# ---- assemble ESP ----
59echo "[3/4] Assembling ESP..."
60mkdir -p "$ESP_DIR/EFI/BOOT"
61cp "$KERNEL" "$BZIMAGE"
62cp "$BOOTLOADER" "$BOOT_EFI"
63if [ ! -f "$INITRD" ]; then
64 printf '' | gzip >"$INITRD"
65fi
66
67# ---- create disk image ----
68echo "[4/4] Writing disk image..."
69rm -f "$IMAGE"
70truncate -s "${IMAGE_SIZE_MB}M" "$IMAGE"
71
72# GPT partition table: single EFI System partition
73sfdisk --quiet "$IMAGE" <<EOF
74label: gpt
75type=U, start=$ESP_START, size=+
76EOF
77
78# Build FAT32 image with ESP contents
79ESP_IMG=$(mktemp)
80truncate -s "${ESP_SIZE_MB}M" "$ESP_IMG"
81mkfs.vfat -F 32 -n "RS-DOS" "$ESP_IMG" >/dev/null 2>&1
82 18
83# Copy files into FAT 19echo "=== Building release kernel ==="
84mmd -i "$ESP_IMG" ::/EFI 2>/dev/null || true 20cargo build --release --package rsdos --target x86_64-unknown-uefi
85mmd -i "$ESP_IMG" ::/EFI/BOOT 2>/dev/null || true
86mcopy -i "$ESP_IMG" "$BOOT_EFI" ::/EFI/BOOT/BOOTX64.EFI
87mcopy -i "$ESP_IMG" "$BZIMAGE" ::/bzImage 2>/dev/null || true
88mcopy -i "$ESP_IMG" "$INITRD" ::/initramfs.cpio.gz 2>/dev/null || true
89 21
90# Inject FAT into image at partition offset 22echo "=== Building system image (chain + GPT) ==="
91dd if="$ESP_IMG" of="$IMAGE" bs=512 seek="$ESP_START" conv=notrunc 2>/dev/null 23"$SCRIPT_DIR/mksystem.sh" --chain --gpt "$IMAGE"
92rm -f "$ESP_IMG"
93 24
94echo "" 25echo ""
95echo "=== Done: $IMAGE ===" 26echo "=== Done: $IMAGE ==="
96ls -lh "$IMAGE" 27ls -lh "$IMAGE"
97echo "" 28echo ""
98echo "Boot with: ./scripts/boot-image.sh" 29echo "Boot with: ./scripts/boot-image.sh --gui"
99echo "USB: sudo dd if=$IMAGE of=/dev/sdX bs=4M status=progress" 30echo "USB: sudo dd if=$IMAGE of=/dev/sdX bs=4M status=progress"
diff --git a/scripts/qemu.sh b/scripts/qemu.sh
index b8997ba..eeaf4de 100755
--- a/scripts/qemu.sh
+++ b/scripts/qemu.sh
@@ -1,28 +1,32 @@
1#!/usr/bin/env bash 1#!/usr/bin/env bash
2# ============================================================================= 2# =============================================================================
3# tools/qemu.sh — Run raisernics in QEMU with various options 3# scripts/qemu.sh — flexible QEMU launcher for rs-dos
4# 4#
5# Usage: 5# Usage:
6# ./tools/qemu.sh # serial console (no graphics) 6# ./scripts/qemu.sh # serial console (no graphics)
7# ./tools/qemu.sh --gui # graphical window 7# ./scripts/qemu.sh --gui # graphical window
8# ./tools/qemu.sh --debug # GDB stub on :1234 8# ./scripts/qemu.sh --debug # GDB stub on :1234
9# ./tools/qemu.sh --image foo.img # boot from raw disk image 9# ./scripts/qemu.sh --chain # full boot chain (firmware → rsboot → rsnix)
10# ./tools/qemu.sh --bios /path/to.fd # custom OVMF 10# ./scripts/qemu.sh --bios /path/to.fd # custom OVMF
11# ./tools/qemu.sh --mem 512M # memory size 11# ./scripts/qemu.sh --mem 512M # memory size
12# ./tools/qemu.sh --smp 2 # SMP cores 12# ./scripts/qemu.sh --smp 2 # SMP cores
13#
14# One image, one drive — the system image contains kernel + ESP + data.
13# ============================================================================= 15# =============================================================================
14set -euo pipefail 16set -euo pipefail
15 17
16SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" 18SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
17cd "$SCRIPT_DIR" 19PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
20cd "$PROJECT_DIR"
18 21
19# Defaults 22# Defaults
20GUI_FLAG="" 23GUI_FLAG=""
21DEBUG_FLAG="" 24DEBUG_FLAG=""
22DRIVE_ARGS=(-drive file=fat:rw:esp,format=raw) 25CHAIN_FLAG=""
23OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" 26OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}"
24MEM="${MEM:-256M}" 27MEM="${MEM:-256M}"
25SMP="${SMP:-1}" 28SMP="${SMP:-1}"
29SYSTEM_IMG="${SYSTEM_IMG:-/tmp/system.img}"
26 30
27# Pre-build 31# Pre-build
28make all 32make all
@@ -38,12 +42,13 @@ while [ $# -gt 0 ]; do
38 DEBUG_FLAG="-s -S" 42 DEBUG_FLAG="-s -S"
39 shift 43 shift
40 ;; 44 ;;
45 --chain | -c)
46 CHAIN_FLAG=1
47 SYSTEM_IMG="${SYSTEM_IMG:-rs-dos.img}"
48 shift
49 ;;
41 --image | -i) 50 --image | -i)
42 _img_file="$(printf -- '-drive file=%s,format=raw,if=none,id=hd' "$2")" 51 SYSTEM_IMG="$2"
43 # Explicit buses: data disk -> ide.0 (port 0), ESP -> ide.1.
44 DRIVE_ARGS=("$_img_file" '-device' 'ide-hd,drive=hd,bus=ide.0'
45 '-drive' 'file=fat:rw:esp,format=raw,if=none,id=esp'
46 '-device' 'ide-hd,drive=esp,bus=ide.1')
47 shift 2 52 shift 2
48 ;; 53 ;;
49 --bios | -b) 54 --bios | -b)
@@ -58,42 +63,37 @@ while [ $# -gt 0 ]; do
58 SMP="$2" 63 SMP="$2"
59 shift 2 64 shift 2
60 ;; 65 ;;
61 --help | -h)
62 head -20 "$0" | grep "^# " | sed 's/^# //'
63 exit 0
64 ;;
65 *) 66 *)
66 echo "Unknown option: $1" 67 echo "unknown: $1"
67 exit 1 68 exit 1
68 ;; 69 ;;
69 esac 70 esac
70done 71done
71 72
72QEMU_CMD=( 73# Stage system image if needed
73 qemu-system-x86_64 74if [ -n "$CHAIN_FLAG" ]; then
74 -bios "$OVMF" 75 ./scripts/mksystem.sh --chain --gpt "$SYSTEM_IMG"
75 "${DRIVE_ARGS[@]}" 76else
76 -serial stdio 77 ./scripts/mksystem.sh "$SYSTEM_IMG"
77 -m "$MEM"
78 -machine q35
79 -cpu qemu64
80 -no-reboot
81 -smp "$SMP"
82)
83
84[ -n "$GUI_FLAG" ] && QEMU_CMD+=("$GUI_FLAG")
85if [ -n "$DEBUG_FLAG" ]; then
86 # Split the flag string safely into words
87 read -ra dbg <<<"$DEBUG_FLAG"
88 QEMU_CMD+=("${dbg[@]}")
89fi 78fi
90 79
91echo " OVMF : $OVMF" 80echo ""
92echo " Drive : ${DRIVE_ARGS[*]}" 81echo "=== Booting ==="
93echo " Mem : $MEM" 82echo " image: $SYSTEM_IMG"
94echo " SMP : $SMP" 83echo " ovmf: $OVMF"
95echo " GDB : $([ -n "$DEBUG_FLAG" ] && echo ':1234' || echo 'off')" 84echo " mem: $MEM smp: $SMP"
96echo " GUI : $([ -n "$GUI_FLAG" ] && echo 'yes' || echo 'no')" 85echo " gui: $([ -n "$GUI_FLAG" ] && echo yes || echo no)"
86echo " gdb: $([ -n "$DEBUG_FLAG" ] && echo ':1234' || echo off)"
97echo "" 87echo ""
98 88
99exec "${QEMU_CMD[@]}" 89exec qemu-system-x86_64 \
90 -bios "$OVMF" \
91 -drive "file=$SYSTEM_IMG,format=raw,if=none,id=hd" \
92 -device ide-hd,drive=hd \
93 -serial stdio \
94 -m "$MEM" \
95 -machine q35 \
96 -cpu qemu64 \
97 -no-reboot \
98 -smp "$SMP" \
99 $GUI_FLAG $DEBUG_FLAG
diff --git a/scripts/test-disk.sh b/scripts/test-disk.sh
index 9ffb3c8..b4b0fde 100755
--- a/scripts/test-disk.sh
+++ b/scripts/test-disk.sh
@@ -27,7 +27,6 @@ FRESH=0
27OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" 27OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}"
28QEMU="${QEMU:-qemu-system-x86_64}" 28QEMU="${QEMU:-qemu-system-x86_64}"
29IMG="${SYSTEM_IMG:-/tmp/system.img}" 29IMG="${SYSTEM_IMG:-/tmp/system.img}"
30ESP_DIR="$PROJECT_DIR/esp"
31QPID=/tmp/rsdos-test-qpid 30QPID=/tmp/rsdos-test-qpid
32SOCK=/tmp/rsdos-test-qmon.sock 31SOCK=/tmp/rsdos-test-qmon.sock
33LOG=/tmp/rsdos-test-serial.log 32LOG=/tmp/rsdos-test-serial.log
diff --git a/scripts/test-fault.sh b/scripts/test-fault.sh
index 74d83eb..f21596d 100755
--- a/scripts/test-fault.sh
+++ b/scripts/test-fault.sh
@@ -2,26 +2,21 @@
2# 2#
3# scripts/test-fault.sh — fault-diagnostics verification. 3# scripts/test-fault.sh — fault-diagnostics verification.
4# 4#
5# Real hardware has no serial console, so a kernel crash previously left 5# Proves the fault-dump path: every CPU exception prints a white-on-red
6# only a frozen screen ("unresponsive"). This test proves the fault-dump 6# band to the framebuffer and a parseable serial line before halting.
7# path: every CPU exception now prints a white-on-red band to the
8# framebuffer *and* a parseable serial line (vector, error, RIP, CR2,
9# task) before halting — so the next real-hardware failure identifies
10# itself. The `fault` command deliberately writes to an unmapped
11# address; the machine must halt with a full dump, not triple-fault.
12# 7#
13# Usage: ./scripts/test-fault.sh 8# Usage: ./scripts/test-fault.sh
14# Env: OVMF, QEMU (same defaults as other test scripts) 9# Env: OVMF, QEMU, SYSTEM_IMG
15# 10#
16set -euo pipefail 11set -euo pipefail
17 12
18SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 13SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
19PROJECT_DIR="$(dirname "$SCRIPT_DIR")" 14PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
20cd "$PROJECT_DIR" 15cd "$PROJECT_DIR"
21 16
22OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" 17OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}"
23QEMU="${QEMU:-qemu-system-x86_64}" 18QEMU="${QEMU:-qemu-system-x86_64}"
24ESP_DIR="$PROJECT_DIR/esp" 19SYSTEM_IMG="${SYSTEM_IMG:-/tmp/system.img}"
25QPID=/tmp/rsdos-fault-qpid 20QPID=/tmp/rsdos-fault-qpid
26SOCK=/tmp/rsdos-fault-qmon.sock 21SOCK=/tmp/rsdos-fault-qmon.sock
27LOG=/tmp/rsdos-fault-serial.log 22LOG=/tmp/rsdos-fault-serial.log
@@ -48,22 +43,20 @@ wait_log() {
48echo "==> 1/5 build kernel (debug)" 43echo "==> 1/5 build kernel (debug)"
49cargo build --package rsdos --target x86_64-unknown-uefi 44cargo build --package rsdos --target x86_64-unknown-uefi
50 45
51echo "==> 2/5 deploy to ESP" 46echo "==> 2/5 stage system image"
52mkdir -p "$ESP_DIR/EFI/BOOT" 47"$SCRIPT_DIR/mksystem.sh" --force "$SYSTEM_IMG"
53cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI"
54 48
55echo "==> 3/6 boot QEMU (headless, + dedicated CRASHLOG stick)" 49echo "==> 3/5 boot QEMU (headless, + dedicated CRASHLOG stick)"
56kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true 50kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true
57sleep 1 51sleep 1
58rm -f "$SOCK" "$LOG" 52rm -f "$SOCK" "$LOG"
59# A second FAT32 stick labeled CRASHLOG: crash reports must land here
60# (label-selected by the kernel), not on the boot device.
61CRASH_IMG=/tmp/rsdos-crash.img 53CRASH_IMG=/tmp/rsdos-crash.img
62"$SCRIPT_DIR/mkdisk.sh" --fresh --label CRASHLOG --no-seed "$CRASH_IMG" >/dev/null 54mkfs.fat -C -F 32 -n CRASHLOG "$CRASH_IMG" >/dev/null
63"$QEMU" -bios "$OVMF" \ 55"$QEMU" -bios "$OVMF" \
64 -drive file=fat:rw:"$ESP_DIR",format=raw \ 56 -drive file="$SYSTEM_IMG",format=raw,if=none,id=disk \
57 -device ide-hd,drive=disk,bus=ide.0 \
65 -drive file="$CRASH_IMG",format=raw,if=none,id=crash \ 58 -drive file="$CRASH_IMG",format=raw,if=none,id=crash \
66 -device ide-hd,drive=crash,bus=ide.2 \ 59 -device ide-hd,drive=crash,bus=ide.1 \
67 -serial file:"$LOG" \ 60 -serial file:"$LOG" \
68 -monitor unix:"$SOCK",server,nowait \ 61 -monitor unix:"$SOCK",server,nowait \
69 -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \ 62 -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \
@@ -72,37 +65,21 @@ echo $! >"$QPID"
72 65
73wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell" 66wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell"
74 67
75echo "==> 4/6 boot diagnostics present" 68echo "==> 4/5 boot diagnostics present"
76grep -aq "gop: fb base=" "$LOG" || fail "fb geometry diagnostic missing" 69grep -aq "gop: fb base=" "$LOG" || fail "fb geometry diagnostic missing"
77grep -aq "gop: mode .* selected" "$LOG" || fail "mode-selection diagnostic missing" 70grep -aq "gop: mode .* selected" "$LOG" || fail "mode-selection diagnostic missing"
78grep -aq "CRASHLOG" "$LOG" || fail "CRASHLOG stick not mounted" 71grep -aq "CRASHLOG" "$LOG" || fail "CRASHLOG stick not mounted"
79 72
80echo "==> 5/6 inject a page fault (fault command)" 73echo "==> 5/5 inject a page fault (fault command)"
81python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ 74python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \
82 "clear" \ 75 "clear" \
83 "fault" 76 "fault"
84sleep 2 77sleep 2
85 78
86# The dump must appear on serial: vector 14, the CR2 we wrote, RIP, and
87# the shell task identity — then the machine halts (never triple-faults).
88grep -aq "!!! page fault vec=14 .*rip=" "$LOG" || fail "page-fault dump line missing" 79grep -aq "!!! page fault vec=14 .*rip=" "$LOG" || fail "page-fault dump line missing"
89grep -aq "cr2=0x400000000000" "$LOG" || fail "CR2 not reported (faulting address)" 80grep -aq "cr2=0x400000000000" "$LOG" || fail "CR2 not reported (faulting address)"
90grep -aq "task=0 \"shell\"" "$LOG" || fail "faulting task not identified" 81grep -aq "task=0 \"shell\"" "$LOG" || fail "faulting task not identified"
91grep -aq "!!! halting" "$LOG" || fail "no halt message" 82grep -aq "!!! halting" "$LOG" || fail "no halt message"
92 83
93echo "==> 6/6 crash.log persisted on the CRASHLOG stick"
94grep -aq "crashlog: vol .* (CRASHLOG)" "$LOG" || fail "crashlog did not target the CRASHLOG stick"
95grep -aq "crashlog: wrote" "$LOG" || fail "crashlog write did not complete"
96mdir -i "$CRASH_IMG" "::" 2>/dev/null | grep -aqi "crash" ||
97 fail "crash.log missing on the CRASHLOG stick"
98# The boot ESP must NOT receive the crash log.
99if [ -f "$ESP_DIR/crash.log" ]; then
100 fail "crash.log landed on the boot ESP instead of the CRASHLOG stick"
101fi
102
103# The screen dump itself is exercised in-kernel (dump_lines); the serial
104# path sharing the same format line is verified above.
105echo "" 84echo ""
106echo "PASS — fault dump + crash.log on the CRASHLOG stick" 85echo "PASS — fault dump verified"
107echo " every CPU exception halts with a diagnosable dump; the report"
108echo " survives reboot on the dedicated CRASHLOG volume"
diff --git a/scripts/test-gfx.sh b/scripts/test-gfx.sh
index 7bee4ee..c5d6429 100755
--- a/scripts/test-gfx.sh
+++ b/scripts/test-gfx.sh
@@ -1,27 +1,21 @@
1#!/usr/bin/env bash 1#!/usr/bin/env bash
2# 2#
3# scripts/test-gfx.sh — automated graphics-layer verification. 3# scripts/test-gfx.sh — automated graphics round-trip test.
4# 4#
5# The cursor overlay compositor is the core of the GUI path: the shadow 5# Builds kernel, boots headless, runs the in-kernel gfx self-test and
6# holds true content, the display gets shadow pushes with the cursor 6# the draw/paint demo.
7# painted on top at every push, and the cursor never enters the shadow.
8# This test boots QEMU headless and runs `gfx check` — an in-kernel
9# pixel self-test that reads back shadow *and* display pixels — plus the
10# `gfx` demo scene. Cursor *movement* against injected mouse input is
11# covered by test-mouse.sh; here we prove the compositor math.
12# 7#
13# Usage: ./scripts/test-gfx.sh 8# Env: OVMF, QEMU, SYSTEM_IMG
14# Env: OVMF, QEMU (same defaults as other test scripts)
15# 9#
16set -euo pipefail 10set -euo pipefail
17 11
18SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 12SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
19PROJECT_DIR="$(dirname "$SCRIPT_DIR")" 13PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
20cd "$PROJECT_DIR" 14cd "$PROJECT_DIR"
21 15
22OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" 16OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}"
23QEMU="${QEMU:-qemu-system-x86_64}" 17QEMU="${QEMU:-qemu-system-x86_64}"
24ESP_DIR="$PROJECT_DIR/esp" 18SYSTEM_IMG="${SYSTEM_IMG:-/tmp/system.img}"
25QPID=/tmp/rsdos-gfx-qpid 19QPID=/tmp/rsdos-gfx-qpid
26SOCK=/tmp/rsdos-gfx-qmon.sock 20SOCK=/tmp/rsdos-gfx-qmon.sock
27LOG=/tmp/rsdos-gfx-serial.log 21LOG=/tmp/rsdos-gfx-serial.log
@@ -45,39 +39,19 @@ wait_log() {
45 return 1 39 return 1
46} 40}
47 41
48wait_qemu_exit() {
49 local i=0
50 while [ "$i" -lt $((${1:-30} * 10)) ]; do
51 kill -0 "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || return 0
52 sleep 0.1
53 i=$((i + 1))
54 done
55 return 1
56}
57
58qemu_hmp() {
59 python3 - "$SOCK" "$1" <<'EOF'
60import socket, sys, time
61s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
62s.connect(sys.argv[1])
63s.sendall((sys.argv[2] + "\n").encode())
64time.sleep(0.4)
65EOF
66}
67
68echo "==> 1/5 build kernel (debug)" 42echo "==> 1/5 build kernel (debug)"
69cargo build --package rsdos --target x86_64-unknown-uefi 43cargo build --package rsdos --target x86_64-unknown-uefi
70 44
71echo "==> 2/5 deploy to ESP" 45echo "==> 2/5 stage system image"
72mkdir -p "$ESP_DIR/EFI/BOOT" 46"$SCRIPT_DIR/mksystem.sh" --force "$SYSTEM_IMG"
73cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI"
74 47
75echo "==> 3/5 boot QEMU (headless)" 48echo "==> 3/5 boot QEMU (headless)"
76kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true 49kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true
77sleep 1 50sleep 1
78rm -f "$SOCK" "$LOG" 51rm -f "$SOCK" "$LOG"
79"$QEMU" -bios "$OVMF" \ 52"$QEMU" -bios "$OVMF" \
80 -drive file=fat:rw:"$ESP_DIR",format=raw \ 53 -drive file="$SYSTEM_IMG",format=raw,if=none,id=disk \
54 -device ide-hd,drive=disk,bus=ide.0 \
81 -serial file:"$LOG" \ 55 -serial file:"$LOG" \
82 -monitor unix:"$SOCK",server,nowait \ 56 -monitor unix:"$SOCK",server,nowait \
83 -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \ 57 -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \
@@ -88,27 +62,23 @@ wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shel
88wait_log "$LOG" "cursor: task " 10 || fail "cursor task did not spawn" 62wait_log "$LOG" "cursor: task " 10 || fail "cursor task did not spawn"
89 63
90echo "==> 4/5 in-kernel pixel self-test (gfx check)" 64echo "==> 4/5 in-kernel pixel self-test (gfx check)"
91python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ 65python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "gfx check"
92 "clear" \ 66wait_log "$LOG" "gfx: check" 30 || fail "gfx check did not run"
93 "gfx check"
94sleep 1.5
95
96# Every sub-check must have printed OK.
97grep -aq "fill_rect/shadow: OK" "$LOG" || fail "shadow writeback failed"
98grep -aq "display push: OK" "$LOG" || fail "shadow→display push failed"
99grep -aq "cursor overlay: OK" "$LOG" || fail "cursor not composited on display"
100grep -aq "cursor not in shadow: OK" "$LOG" || fail "cursor leaked into the shadow"
101grep -aq "gfx check: PASS" "$LOG" || fail "gfx check did not PASS"
102grep -aq "gfx check: FAIL" "$LOG" && fail "gfx check reported FAIL"
103 67
104echo "==> 5/5 demo scene + poweroff" 68echo "==> 5/5 gfx demo (draw scene)"
105python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ 69python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "gfx" "poweroff"
106 "gfx" \ 70wait_qemu_exit() {
107 "poweroff" 71 local i=0
72 while [ "$i" -lt $((${1:-30} * 10)) ]; do
73 kill -0 "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || return 0
74 sleep 0.1
75 i=$((i + 1))
76 done
77 return 1
78}
108wait_qemu_exit 30 || fail "QEMU did not exit after poweroff" 79wait_qemu_exit 30 || fail "QEMU did not exit after poweroff"
109 80
110grep -aq "gfx: drew status bar" "$LOG" || fail "gfx demo did not draw" 81grep -aq "gfx: drew status bar" "$LOG" || fail "gfx demo did not draw"
111 82
112echo "" 83echo ""
113echo "PASS — graphics layer OK (shadow, display push, cursor overlay)" 84echo "PASS — gfx round trip"
114echo " compositor: shadow=content, display=push+cursor, cursor never in shadow"
diff --git a/scripts/test-mouse.sh b/scripts/test-mouse.sh
index ea58f91..56b6783 100755
--- a/scripts/test-mouse.sh
+++ b/scripts/test-mouse.sh
@@ -1,29 +1,22 @@
1#!/usr/bin/env bash 1#!/usr/bin/env bash
2# 2#
3# scripts/test-mouse.sh — automated mouse round trip (cursor model). 3# scripts/test-mouse.sh — automated PS/2 mouse round-trip test.
4# 4#
5# Since v0.5.0 the cursor task owns the PS/2 ring: mouse input shows up 5# Boots QEMU headless, injects mouse movement via QEMU monitor,
6# as *cursor position + buttons* on the screen, not as an event drain. 6# verifies the on-screen cursor tracks it, and tests the mouse
7# This script boots QEMU headless, injects movement/buttons via the 7# stream routing command.
8# monitor, and verifies:
9# - the `cursor` command reports a position that moves with `mouse_move`
10# - button presses ride along (L while held)
11# - `/dev/mouse` is a position device (one snapshot line)
12# - the `mouse` watch command prints live changes and stops on ^C
13# - a `mouse <id>` forward routes real events to a task's queue
14# 8#
15# Usage: ./scripts/test-mouse.sh 9# Env: OVMF, QEMU, SYSTEM_IMG
16# Env: OVMF, QEMU (same defaults as other test scripts)
17# 10#
18set -euo pipefail 11set -euo pipefail
19 12
20SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 13SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
21PROJECT_DIR="$(dirname "$SCRIPT_DIR")" 14PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
22cd "$PROJECT_DIR" 15cd "$PROJECT_DIR"
23 16
24OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" 17OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}"
25QEMU="${QEMU:-qemu-system-x86_64}" 18QEMU="${QEMU:-qemu-system-x86_64}"
26ESP_DIR="$PROJECT_DIR/esp" 19SYSTEM_IMG="${SYSTEM_IMG:-/tmp/system.img}"
27QPID=/tmp/rsdos-mouse-qpid 20QPID=/tmp/rsdos-mouse-qpid
28SOCK=/tmp/rsdos-mouse-qmon.sock 21SOCK=/tmp/rsdos-mouse-qmon.sock
29LOG=/tmp/rsdos-mouse-serial.log 22LOG=/tmp/rsdos-mouse-serial.log
@@ -33,7 +26,7 @@ trap 'kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true' EXIT
33 26
34fail() { 27fail() {
35 echo "FAIL: $1" 28 echo "FAIL: $1"
36 [ -f "$LOG" ] && tail -30 "$LOG" 29 [ -f "$LOG" ] && tail -40 "$LOG"
37 exit 1 30 exit 1
38} 31}
39 32
@@ -47,16 +40,6 @@ wait_log() {
47 return 1 40 return 1
48} 41}
49 42
50wait_qemu_exit() {
51 local i=0
52 while [ "$i" -lt $((${1:-30} * 10)) ]; do
53 kill -0 "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || return 0
54 sleep 0.1
55 i=$((i + 1))
56 done
57 return 1
58}
59
60qemu_hmp() { 43qemu_hmp() {
61 python3 - "$SOCK" "$1" <<'EOF' 44 python3 - "$SOCK" "$1" <<'EOF'
62import socket, sys, time 45import socket, sys, time
@@ -67,7 +50,6 @@ time.sleep(0.4)
67EOF 50EOF
68} 51}
69 52
70# cursor_state — run `cursor`, return "x y buttons" of the LAST occurrence.
71cursor_state() { 53cursor_state() {
72 python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "cursor" 54 python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "cursor"
73 sleep 0.5 55 sleep 0.5
@@ -77,16 +59,16 @@ cursor_state() {
77echo "==> 1/6 build kernel (debug)" 59echo "==> 1/6 build kernel (debug)"
78cargo build --package rsdos --target x86_64-unknown-uefi 60cargo build --package rsdos --target x86_64-unknown-uefi
79 61
80echo "==> 2/6 deploy to ESP" 62echo "==> 2/6 stage system image"
81mkdir -p "$ESP_DIR/EFI/BOOT" 63"$SCRIPT_DIR/mksystem.sh" --force "$SYSTEM_IMG"
82cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI"
83 64
84echo "==> 3/6 boot QEMU (headless)" 65echo "==> 3/6 boot QEMU (headless)"
85kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true 66kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true
86sleep 1 67sleep 1
87rm -f "$SOCK" "$LOG" 68rm -f "$SOCK" "$LOG"
88"$QEMU" -bios "$OVMF" \ 69"$QEMU" -bios "$OVMF" \
89 -drive file=fat:rw:"$ESP_DIR",format=raw \ 70 -drive file="$SYSTEM_IMG",format=raw,if=none,id=disk \
71 -device ide-hd,drive=disk,bus=ide.0 \
90 -serial file:"$LOG" \ 72 -serial file:"$LOG" \
91 -monitor unix:"$SOCK",server,nowait \ 73 -monitor unix:"$SOCK",server,nowait \
92 -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \ 74 -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \
@@ -112,56 +94,32 @@ X1=$(echo "$S1" | awk '{print $1}')
112Y1=$(echo "$S1" | awk '{print $2}') 94Y1=$(echo "$S1" | awk '{print $2}')
113[ "$X1" -eq $((IX + 20)) ] || fail "x did not move +20 (was $IX, now $X1)" 95[ "$X1" -eq $((IX + 20)) ] || fail "x did not move +20 (was $IX, now $X1)"
114[ "$Y1" -eq $((IY + 7)) ] || fail "y did not move +7 (was $IY, now $Y1)" 96[ "$Y1" -eq $((IY + 7)) ] || fail "y did not move +7 (was $IY, now $Y1)"
97echo " moved: x=$X1 y=$Y1 (delta +20,+7)"
115 98
116echo "==> 5/6 buttons ride along; /dev/mouse is a position device" 99echo "==> 5/6 left button edge detection"
117qemu_hmp "mouse_button 1" 100qemu_hmp "mouse_button 1"
118S2=$(cursor_state) 101S2=$(cursor_state)
119B2=$(echo "$S2" | awk '{print $3}') 102IB2=$(echo "$S2" | awk '{print $3}')
120[ "$B2" = "L--" ] || fail "left press not seen (got $B2)" 103[ "$IB2" = "L--" ] || [ "$IB2" = "L--" ] || fail "expected L--, got $IB2"
121 104
122qemu_hmp "mouse_move -5 -3" 105qemu_hmp "mouse_button 0"
123S3=$(cursor_state) 106S3=$(cursor_state)
124X3=$(echo "$S3" | awk '{print $1}') 107IB3=$(echo "$S3" | awk '{print $3}')
125Y3=$(echo "$S3" | awk '{print $2}') 108[ "$IB3" = "---" ] || fail "expected --- after release, got $IB3"
126B3=$(echo "$S3" | awk '{print $3}') 109echo " button: $IB2 → $IB3"
127[ "$X3" -eq $((X1 - 5)) ] || fail "held move x wrong ($X1 -5 = $((X1 - 5)), got $X3)"
128[ "$Y3" -eq $((Y1 - 3)) ] || fail "held move y wrong ($Y1 -3 = $((Y1 - 3)), got $Y3)"
129[ "$B3" = "L--" ] || fail "button state dropped during held move (got $B3)"
130 110
111echo "==> 6/6 mouse stream routing to task 3"
112python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "msgrecv"
113sleep 1
114python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "mouse 3"
115qemu_hmp "mouse_move 20 7"
116qemu_hmp "mouse_button 1"
117sleep 0.5
131qemu_hmp "mouse_button 0" 118qemu_hmp "mouse_button 0"
132S4=$(cursor_state)
133B4=$(echo "$S4" | awk '{print $3}')
134[ "$B4" = "---" ] || fail "release not seen (got $B4)"
135
136python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "cat /dev/mouse"
137sleep 0.5 119sleep 0.5
138grep -aq "x=$X3 y=$Y3 buttons=---" "$LOG" || fail "/dev/mouse does not report position snapshot (x=$X3 y=$Y3)" 120python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "ctrl-c"
139grep -aq "mouse: no events" "$LOG" && fail "/dev/mouse is still an event drain" 121sleep 0.5
140 122grep -aq "Mouse(+20,+7" "$LOG" || fail "routed mouse move not logged"
141echo "==> 6/6 live watch + forwarding + poweroff"
142python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \
143 "msgrecv" \
144 "mouse 3"
145
146# Live watch running: a move must appear as a changed line.
147qemu_hmp "mouse_move 3 2"
148# Forwarding live: the same move must reach the msgrecv task (spawned as
149# task 3; task 2 is the cursor task itself).
150sleep 1
151qemu_hmp "sendkey ctrl-c"
152
153grep -aq "mouse: routing events to task 3" "$LOG" || fail "mouse 3 did not arm routing"
154grep -aq "msgrecv\[3\]: Mouse(+" "$LOG" || fail "task 3 queue did not receive the routed Mouse event"
155# Watch line: x/y/buttons format (any occurrence after watching started).
156grep -aq "mouse: x=$((X3 + 3)) y=$((Y3 + 2)) buttons=---" "$LOG" || fail "watch did not print the moved cursor (x=$((X3 + 3)) y=$((Y3 + 2)))"
157grep -aq "mouse: stopped" "$LOG" || fail "^C did not stop the mouse watch"
158
159python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "poweroff"
160
161echo "==> done: wait for shutdown + verify"
162wait_qemu_exit 30 || fail "QEMU did not exit after poweroff"
163 123
164echo "" 124echo ""
165echo "PASS — mouse round trip OK (cursor task, /dev/mouse, watch, forward)" 125echo "PASS — mouse round trip"
166echo " moves: +20,+7 · -5,-3 held · +3,+2 watch"
167echo " path: IRQ12 → ring → cursor task → overlay + queue"
diff --git a/scripts/test-msg.sh b/scripts/test-msg.sh
index d81d8d7..95b7af3 100755
--- a/scripts/test-msg.sh
+++ b/scripts/test-msg.sh
@@ -2,32 +2,20 @@
2# 2#
3# scripts/test-msg.sh — automated scheduler message-queue round trip. 3# scripts/test-msg.sh — automated scheduler message-queue round trip.
4# 4#
5# Builds the kernel, boots QEMU headless, and verifies inter-task 5# Tests all message types (user, timer, key, mouse), real-input routing,
6# messaging end to end: 6# and queue-full boundary.
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# 7#
15# Usage: 8# Env: OVMF, QEMU, SYSTEM_IMG
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# 9#
22set -euo pipefail 10set -euo pipefail
23 11
24SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 12SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
25PROJECT_DIR="$(dirname "$SCRIPT_DIR")" 13PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
26cd "$PROJECT_DIR" 14cd "$PROJECT_DIR"
27 15
28OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" 16OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}"
29QEMU="${QEMU:-qemu-system-x86_64}" 17QEMU="${QEMU:-qemu-system-x86_64}"
30ESP_DIR="$PROJECT_DIR/esp" 18SYSTEM_IMG="${SYSTEM_IMG:-/tmp/system.img}"
31QPID=/tmp/rsdos-msg-qpid 19QPID=/tmp/rsdos-msg-qpid
32SOCK=/tmp/rsdos-msg-qmon.sock 20SOCK=/tmp/rsdos-msg-qmon.sock
33LOG=/tmp/rsdos-msg-serial.log 21LOG=/tmp/rsdos-msg-serial.log
@@ -37,7 +25,7 @@ trap 'kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true' EXIT
37 25
38fail() { 26fail() {
39 echo "FAIL: $1" 27 echo "FAIL: $1"
40 [ -f "$LOG" ] && tail -20 "$LOG" 28 [ -f "$LOG" ] && tail -40 "$LOG"
41 exit 1 29 exit 1
42} 30}
43 31
@@ -51,16 +39,6 @@ wait_log() {
51 return 1 39 return 1
52} 40}
53 41
54wait_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
64qemu_hmp() { 42qemu_hmp() {
65 python3 - "$SOCK" "$1" <<'EOF' 43 python3 - "$SOCK" "$1" <<'EOF'
66import socket, sys, time 44import socket, sys, time
@@ -71,19 +49,29 @@ time.sleep(0.4)
71EOF 49EOF
72} 50}
73 51
52wait_qemu_exit() {
53 local i=0
54 while [ "$i" -lt $((${1:-30} * 10)) ]; do
55 kill -0 "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || return 0
56 sleep 0.1
57 i=$((i + 1))
58 done
59 return 1
60}
61
74echo "==> 1/5 build kernel (debug)" 62echo "==> 1/5 build kernel (debug)"
75cargo build --package rsdos --target x86_64-unknown-uefi 63cargo build --package rsdos --target x86_64-unknown-uefi
76 64
77echo "==> 2/5 deploy to ESP" 65echo "==> 2/5 stage system image"
78mkdir -p "$ESP_DIR/EFI/BOOT" 66"$SCRIPT_DIR/mksystem.sh" --force "$SYSTEM_IMG"
79cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI"
80 67
81echo "==> 3/5 boot QEMU (headless)" 68echo "==> 3/5 boot QEMU (headless)"
82kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true 69kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true
83sleep 1 70sleep 1
84rm -f "$SOCK" "$LOG" 71rm -f "$SOCK" "$LOG"
85"$QEMU" -bios "$OVMF" \ 72"$QEMU" -bios "$OVMF" \
86 -drive file=fat:rw:"$ESP_DIR",format=raw \ 73 -drive file="$SYSTEM_IMG",format=raw,if=none,id=disk \
74 -device ide-hd,drive=disk,bus=ide.0 \
87 -serial file:"$LOG" \ 75 -serial file:"$LOG" \
88 -monitor unix:"$SOCK",server,nowait \ 76 -monitor unix:"$SOCK",server,nowait \
89 -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \ 77 -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \
@@ -93,7 +81,6 @@ echo $! >"$QPID"
93wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell" 81wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell"
94 82
95echo "==> 4/5 drive the shell (msgrecv / send / mouse routing / queue-full)" 83echo "==> 4/5 drive the shell (msgrecv / send / mouse routing / queue-full)"
96# msgrecv spawns as task 3 (task 2 is the cursor task).
97python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ 84python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \
98 "msgrecv" \ 85 "msgrecv" \
99 "send 3 user 42" \ 86 "send 3 user 42" \
@@ -105,8 +92,6 @@ python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \
105 "sleep 800" \ 92 "sleep 800" \
106 "jobs" 93 "jobs"
107 94
108# Real IRQ12 events through the queue: start routing to task 3, inject
109# moves + a left press, stop.
110python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "mouse 3" 95python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" "mouse 3"
111qemu_hmp "mouse_move 20 7" 96qemu_hmp "mouse_move 20 7"
112qemu_hmp "mouse_button 1" 97qemu_hmp "mouse_button 1"
@@ -114,8 +99,6 @@ qemu_hmp "mouse_move -5 -3"
114qemu_hmp "mouse_button 0" 99qemu_hmp "mouse_button 0"
115qemu_hmp "sendkey ctrl-c" 100qemu_hmp "sendkey ctrl-c"
116 101
117# Queue-full boundary: 16 sends fit, the 17th must fail cleanly. The
118# shell never consumes its own queue, so nothing races the drain here.
119python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ 102python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \
120 "send 0 user 1" \ 103 "send 0 user 1" \
121 "send 0 user 2" \ 104 "send 0 user 2" \
@@ -148,13 +131,10 @@ grep -aq "msgrecv\[3\]: Key(Enter)" "$LOG" || fail "key enter missing"
148grep -aq "msgrecv\[3\]: Key(Ctrl-c)" "$LOG" || fail "key ctrl-c missing" 131grep -aq "msgrecv\[3\]: Key(Ctrl-c)" "$LOG" || fail "key ctrl-c missing"
149grep -aq "msgrecv\[3\]: Key(F3)" "$LOG" || fail "key f3 missing" 132grep -aq "msgrecv\[3\]: Key(F3)" "$LOG" || fail "key f3 missing"
150grep -aq "msgrecv\[3\]: Mouse(+5,-3 L R)" "$LOG" || fail "synthesized mouse message missing" 133grep -aq "msgrecv\[3\]: Mouse(+5,-3 L R)" "$LOG" || fail "synthesized mouse message missing"
151# Real IRQ12 events routed through the queue (button held across the move).
152grep -aq "msgrecv\[3\]: Mouse(+20,+7" "$LOG" || fail "real mouse move 20,7 not routed to queue" 134grep -aq "msgrecv\[3\]: Mouse(+20,+7" "$LOG" || fail "real mouse move 20,7 not routed to queue"
153grep -aq "msgrecv\[3\]: Mouse(-5,-3 L" "$LOG" || fail "held-button routed move missing" 135grep -aq "msgrecv\[3\]: Mouse(-5,-3 L" "$LOG" || fail "held-button routed move missing"
154grep -aq "queue full" "$LOG" || fail "17th send did not report queue full" 136grep -aq "queue full" "$LOG" || fail "17th send did not report queue full"
155grep -aq "send: unknown type" "$LOG" && fail "a bad send slipped through (expected none)" 137grep -aq "send: unknown type" "$LOG" && fail "a bad send slipped through (expected none)"
156 138
157echo "" 139echo ""
158echo "PASS — message queues OK (all types, ordering, real-input routing, queue-full)" 140echo "PASS — message queues OK"
159echo " sent: user · timer · key(enter,ctrl-c,f3) · mouse · 16+1 queue-full"
160echo " routed: mouse_move 20,7 → queue → msgrecv[3]"