summaryrefslogtreecommitdiffstats
path: root/scripts/tests
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-01 15:53:29 +0100
committersalmonik <salmonik@tuta.io>2026-11-01 15:53:29 +0100
commit7958276c9f0d230053520ba20f2a00f5ecda18e4 (patch)
tree596f5f71ad597ed951bae98de818cb37f171a18d /scripts/tests
parentfs: /bin alias for the system volume (diff)
downloadrs-dos-7958276c9f0d230053520ba20f2a00f5ecda18e4.tar.gz
rs-dos-7958276c9f0d230053520ba20f2a00f5ecda18e4.zip
scripts: rebuild the dev loop around build.sh/run.sh
`make` did not parse at all (missing separator at line 139), so every make target was dead. The folder also carried three overlapping launchers (boot.sh, qemu.sh, boot-image.sh) plus a fourth partial one in the Makefile, `cargo build --package rsdos` copy-pasted eight times, the QEMU invocation copy-pasted per script, and the test helpers (fail/wait_log/wait_qemu_exit/qemu_hmp) duplicated in five tests. New layout: - scripts/lib.sh: single config (image, OVMF, mem/smp), the one cargo invocation (build_all), the one QEMU shape (qemu_args), and the test harness (test_boot, wait_log, wait_qemu_exit, qemu_hmp, sendkeys) - scripts/build.sh: kernel + every bins/* in one pass - scripts/mksystem.sh: freshness-aware image build that now stages every bins/*.efi into /bin/cli|gui (they were never copied before) - scripts/run.sh: build + stage + boot in one command; --headless, --debug (GDB stub), --monitor (HMP socket), --fresh, --mem/--smp/ --bios/--image; on Wayland it auto-selects XWayland plus grab-on-hover so the mouse can be captured (Ctrl+Alt+G toggles) - scripts/tests/: the five automated tests on the shared harness - deleted: boot.sh, qemu.sh, boot-image.sh, lib-boot-args.sh, build-image-release.sh, build-bootloader.sh (rsboot chain dropped) The Makefile is now a thin wrapper: make run, make test, make system, make inspect, make help. Two-command flow: ./scripts/build.sh then ./scripts/run.sh (run.sh alone also works). Stale test assumptions fixed so the suite is green again: test-gfx waited for "gfx: check" while the shell prints "gfx check: PASS"; test-mouse/test-msg hardcoded msgrecv = task 3 (wm-input took slot 3 — ids are parsed from the log now); the queue-full probe targeted task 0, whose exec pump drains its own queue as completion codes (moved to the cursor task, which never recvs). Verified in QEMU: make test -> test-disk, test-gfx, test-mouse, test-msg, test-fault all PASS.
Diffstat (limited to '')
-rwxr-xr-xscripts/tests/sendkeys.py (renamed from scripts/sendkeys.py)12
-rwxr-xr-xscripts/tests/test-disk.sh67
-rwxr-xr-xscripts/tests/test-fault.sh47
-rwxr-xr-xscripts/tests/test-focus.py (renamed from scripts/test-focus.py)7
-rwxr-xr-xscripts/tests/test-gfx.sh37
-rwxr-xr-xscripts/tests/test-mouse.sh83
-rwxr-xr-xscripts/tests/test-msg.sh98
7 files changed, 343 insertions, 8 deletions
diff --git a/scripts/sendkeys.py b/scripts/tests/sendkeys.py
index a67903d..9300242 100755
--- a/scripts/sendkeys.py
+++ b/scripts/tests/sendkeys.py
@@ -5,18 +5,20 @@ Each positional argument is one line: it is typed character by character
5(US layout) followed by Enter. Use it to drive the rs-dos shell from a 5(US layout) followed by Enter. Use it to drive the rs-dos shell from a
6test script without a display. 6test script without a display.
7 7
8Usage: 8Used by scripts/tests/test-*.sh, and manually against an interactive
9 sendkeys.py "ls /disk" "echo hi WRITING /disk/a.txt" "poweroff" 9session started with `./scripts/run.sh --monitor`:
10 sendkeys.py --sock /tmp/qmon.sock "date"
11 10
12Environment: QMON_SOCK (default: /tmp/qmon.sock) 11 ./scripts/tests/sendkeys.py "ls /disk" "date" "poweroff"
12 ./scripts/tests/sendkeys.py --sock /tmp/rsdos-monitor.sock "date"
13
14Environment: QMON_SOCK (default: /tmp/rsdos-monitor.sock)
13""" 15"""
14import os 16import os
15import socket 17import socket
16import sys 18import sys
17import time 19import time
18 20
19SOCK = os.environ.get("QMON_SOCK", "/tmp/qmon.sock") 21SOCK = os.environ.get("QMON_SOCK", "/tmp/rsdos-monitor.sock")
20 22
21# Unshifted punctuation needs QEMU's *named* keys — bare '-'/'.'/'/' are 23# Unshifted punctuation needs QEMU's *named* keys — bare '-'/'.'/'/' are
22# not valid sendkey names (and '-' is the modifier separator). 24# not valid sendkey names (and '-' is the modifier separator).
diff --git a/scripts/tests/test-disk.sh b/scripts/tests/test-disk.sh
new file mode 100755
index 0000000..3836b6d
--- /dev/null
+++ b/scripts/tests/test-disk.sh
@@ -0,0 +1,67 @@
1#!/usr/bin/env bash
2#
3# scripts/tests/test-disk.sh — full automated data-disk round trip.
4#
5# Builds, stages the system image, boots QEMU headless, drives the shell
6# via the monitor (ls / mkdir / echo WRITING / cat / poweroff), then
7# verifies the results with mtools and fsck.
8#
9# Usage:
10# ./scripts/tests/test-disk.sh reuse the existing image
11# ./scripts/tests/test-disk.sh --fresh reformat + reseed first
12#
13# Env: SYSTEM_IMG, OVMF, QEMU (see scripts/lib.sh)
14#
15set -euo pipefail
16TNAME="disk"
17# shellcheck source=../lib.sh
18source "$(dirname "$0")/../lib.sh"
19
20FRESH=0
21[ "${1:-}" = "--fresh" ] && FRESH=1
22STAMP="$(date +%s)"
23
24echo "==> 1/6 build (kernel + bins)"
25build_all
26
27echo "==> 2/6 stage system image"
28if [ "$FRESH" -eq 1 ]; then stage_image --force; else stage_image; fi
29
30echo "==> 3/6 boot QEMU (headless)"
31test_boot
32sleep 1
33
34# Volumes mount under /disk/<UID>/ where UID = "LABEL-SERIAL" (e.g.
35# RSDOS-5BD1E55F). Discover it from the boot log so the test works on
36# any image without knowing the serial in advance.
37VOL_UID="$(grep -a 'fat: mounted' "$LOG" | sed -n 's/.*at \/disk\/\([^ )]*\).*/\1/p' | head -1)"
38[ -n "$VOL_UID" ] || fail "no FAT32 volume was mounted (look for 'fat: mounted' in the log)"
39echo " mounted volume UID: $VOL_UID"
40
41echo "==> 4/6 drive the shell (ls / mkdir / echo WRITING / cat / poweroff)"
42# The filename is deliberately >13 chars so the FAT LFN path gets
43# multi-entry entries (they're stored last-first on disk).
44TESTFILE="disk-test-$STAMP.txt"
45sendkeys \
46 "ls /disk" \
47 "mkdir /disk/$VOL_UID/sub" \
48 "echo disk-test-$STAMP WRITING /disk/$VOL_UID/sub/$TESTFILE" \
49 "cat /disk/$VOL_UID/sub/$TESTFILE" \
50 "poweroff"
51
52echo "==> 5/6 wait for shutdown"
53wait_qemu_exit 30 || fail "QEMU did not exit after poweroff"
54
55echo "==> 6/6 verify"
56grep -a "disk-test-$STAMP" "$LOG" >/dev/null || fail "cat output missing from serial log"
57if ! fsck.fat -n "$SYSTEM_IMG" >/tmp/rsdos-fsck.out 2>&1; then
58 fail "fsck.fat reports problems: $(tail -3 /tmp/rsdos-fsck.out)"
59fi
60MT="$(mtype -i "$SYSTEM_IMG" "::/sub/$TESTFILE" 2>/dev/null || true)"
61[ "$MT" = "disk-test-$STAMP" ] || fail "mtype mismatch: got '$MT'"
62
63echo ""
64echo "PASS — disk round trip OK (fsck clean, file survived poweroff)"
65echo " image: $SYSTEM_IMG"
66echo " volume: /disk/$VOL_UID"
67echo " written: /disk/$VOL_UID/sub/$TESTFILE = \"disk-test-$STAMP\""
diff --git a/scripts/tests/test-fault.sh b/scripts/tests/test-fault.sh
new file mode 100755
index 0000000..0c39cde
--- /dev/null
+++ b/scripts/tests/test-fault.sh
@@ -0,0 +1,47 @@
1#!/usr/bin/env bash
2#
3# scripts/tests/test-fault.sh — fault-diagnostics verification.
4#
5# Proves the fault-dump path: every CPU exception prints a white-on-red
6# band to the framebuffer and a parseable serial line before halting.
7# Boots with a dedicated CRASHLOG FAT stick on ide.1 so the crash band
8# has somewhere to write.
9#
10# Usage: ./scripts/tests/test-fault.sh
11# Env: SYSTEM_IMG, OVMF, QEMU (see scripts/lib.sh)
12#
13set -euo pipefail
14TNAME="fault"
15# shellcheck source=../lib.sh
16source "$(dirname "$0")/../lib.sh"
17
18echo "==> 1/5 build (kernel + bins)"
19build_all
20
21echo "==> 2/5 stage system image"
22stage_image --force
23
24echo "==> 3/5 boot QEMU (headless, + dedicated CRASHLOG stick)"
25CRASH_IMG=/tmp/rsdos-crash.img
26rm -f "$CRASH_IMG"
27mkfs.fat -C -F 32 -n CRASHLOG "$CRASH_IMG" 65536 >/dev/null
28test_boot \
29 -drive "file=$CRASH_IMG,format=raw,if=none,id=crash" \
30 -device ide-hd,drive=crash,bus=ide.1
31
32echo "==> 4/5 boot diagnostics present"
33grep -aq "gop: fb base=" "$LOG" || fail "fb geometry diagnostic missing"
34grep -aq "gop: mode .* selected" "$LOG" || fail "mode-selection diagnostic missing"
35grep -aq "CRASHLOG" "$LOG" || fail "CRASHLOG stick not mounted"
36
37echo "==> 5/5 inject a page fault (fault command)"
38sendkeys "clear" "fault"
39sleep 2
40
41grep -aq "!!! page fault vec=14 .*rip=" "$LOG" || fail "page-fault dump line missing"
42grep -aq "cr2=0x400000000000" "$LOG" || fail "CR2 not reported (faulting address)"
43grep -aq "task=0 \"shell\"" "$LOG" || fail "faulting task not identified"
44grep -aq "!!! halting" "$LOG" || fail "no halt message"
45
46echo ""
47echo "PASS — fault dump verified"
diff --git a/scripts/test-focus.py b/scripts/tests/test-focus.py
index e1bbe2d..cfa317a 100755
--- a/scripts/test-focus.py
+++ b/scripts/tests/test-focus.py
@@ -2,16 +2,17 @@
2"""Drive the focus-routing gate: 3 windows, type markers, verify routing. 2"""Drive the focus-routing gate: 3 windows, type markers, verify routing.
3 3
4Connects to the QEMU monitor once and keeps the socket open (the per-call 4Connects to the QEMU monitor once and keeps the socket open (the per-call
5scripts/sendkeys.py pattern loses the socket when the monitor resets). 5sendkeys.py pattern loses the socket when the monitor resets).
6 6
7Usage: python3 scripts/test-focus.py /tmp/qmon.sock 7Usage: start the guest with `./scripts/run.sh --monitor`, then
8 python3 scripts/tests/test-focus.py [/tmp/rsdos-monitor.sock]
8""" 9"""
9import socket 10import socket
10import sys 11import sys
11import time 12import time
12 13
13sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) 14sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
14sock.connect(sys.argv[1] if len(sys.argv) > 1 else "/tmp/sysboot-mon.sock") 15sock.connect(sys.argv[1] if len(sys.argv) > 1 else "/tmp/rsdos-monitor.sock")
15 16
16 17
17def sk(k, d=0.35): 18def sk(k, d=0.35):
diff --git a/scripts/tests/test-gfx.sh b/scripts/tests/test-gfx.sh
new file mode 100755
index 0000000..613318f
--- /dev/null
+++ b/scripts/tests/test-gfx.sh
@@ -0,0 +1,37 @@
1#!/usr/bin/env bash
2#
3# scripts/tests/test-gfx.sh — automated graphics round-trip test.
4#
5# Builds, boots headless, runs the in-kernel gfx self-test and the
6# status-bar demo, then powers off.
7#
8# Usage: ./scripts/tests/test-gfx.sh
9# Env: SYSTEM_IMG, OVMF, QEMU (see scripts/lib.sh)
10#
11set -euo pipefail
12TNAME="gfx"
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
24wait_log "$LOG" "cursor: task " 10 || fail "cursor task did not spawn"
25
26echo "==> 4/5 in-kernel pixel self-test (gfx check)"
27sendkeys "gfx check"
28wait_log "$LOG" "gfx check: PASS" 30 || fail "gfx check did not run"
29
30echo "==> 5/5 gfx demo (draw scene)"
31sendkeys "gfx" "poweroff"
32wait_qemu_exit 30 || fail "QEMU did not exit after poweroff"
33
34grep -aq "gfx: drew status bar" "$LOG" || fail "gfx demo did not draw"
35
36echo ""
37echo "PASS — gfx round trip"
diff --git a/scripts/tests/test-mouse.sh b/scripts/tests/test-mouse.sh
new file mode 100755
index 0000000..bb835be
--- /dev/null
+++ b/scripts/tests/test-mouse.sh
@@ -0,0 +1,83 @@
1#!/usr/bin/env bash
2#
3# scripts/tests/test-mouse.sh — automated PS/2 mouse round-trip test.
4#
5# Boots QEMU headless, injects mouse movement via the QEMU monitor,
6# verifies the on-screen cursor tracks it, and tests the mouse stream
7# routing command.
8#
9# Usage: ./scripts/tests/test-mouse.sh
10# Env: SYSTEM_IMG, OVMF, QEMU (see scripts/lib.sh)
11#
12set -euo pipefail
13TNAME="mouse"
14# shellcheck source=../lib.sh
15source "$(dirname "$0")/../lib.sh"
16
17# cursor_state — one-shot `cursor` command, parsed to "x y buttons".
18cursor_state() {
19 sendkeys "cursor"
20 sleep 0.5
21 sed -n 's/.*cursor: x=\([0-9]*\) y=\([0-9]*\) buttons=\([A-Za-z-]*\).*/\1 \2 \3/p' "$LOG" | tail -1
22}
23
24echo "==> 1/6 build (kernel + bins)"
25build_all
26
27echo "==> 2/6 stage system image"
28stage_image --force
29
30echo "==> 3/6 boot QEMU (headless)"
31test_boot
32grep -aq "ps2: mouse ready" "$LOG" || fail "mouse driver did not come up at boot"
33wait_log "$LOG" "cursor: task " 10 || fail "cursor task did not spawn"
34
35echo "==> 4/6 cursor position tracks injected movement"
36INIT=$(cursor_state)
37[ -n "$INIT" ] || fail "no initial cursor position"
38IX=$(echo "$INIT" | awk '{print $1}')
39IY=$(echo "$INIT" | awk '{print $2}')
40IB=$(echo "$INIT" | awk '{print $3}')
41echo " initial: x=$IX y=$IY buttons=$IB"
42[ "$IB" = "---" ] || fail "expected no buttons at boot, got $IB"
43
44qemu_hmp "mouse_move 20 7"
45S1=$(cursor_state)
46X1=$(echo "$S1" | awk '{print $1}')
47Y1=$(echo "$S1" | awk '{print $2}')
48[ "$X1" -eq $((IX + 20)) ] || fail "x did not move +20 (was $IX, now $X1)"
49[ "$Y1" -eq $((IY + 7)) ] || fail "y did not move +7 (was $IY, now $Y1)"
50echo " moved: x=$X1 y=$Y1 (delta +20,+7)"
51
52echo "==> 5/6 left button edge detection"
53qemu_hmp "mouse_button 1"
54S2=$(cursor_state)
55IB2=$(echo "$S2" | awk '{print $3}')
56[ "$IB2" = "L--" ] || fail "expected L--, got $IB2"
57
58qemu_hmp "mouse_button 0"
59S3=$(cursor_state)
60IB3=$(echo "$S3" | awk '{print $3}')
61[ "$IB3" = "---" ] || fail "expected --- after release, got $IB3"
62echo " button: $IB2 → $IB3"
63
64echo "==> 6/6 mouse stream routing to msgrecv's task"
65# The spawned task id shifts with the task table (wm-input took slot 3) —
66# parse it rather than hardcoding.
67sendkeys "msgrecv"
68sleep 1
69MID="$(sed -n 's/.*msgrecv: task \([0-9][0-9]*\) listening.*/\1/p' "$LOG" | tail -1)"
70[ -n "$MID" ] || fail "msgrecv did not spawn"
71echo " msgrecv task id: $MID"
72sendkeys "mouse $MID"
73qemu_hmp "mouse_move 20 7"
74qemu_hmp "mouse_button 1"
75sleep 0.5
76qemu_hmp "mouse_button 0"
77sleep 0.5
78sendkeys "ctrl-c"
79sleep 0.5
80grep -aq "Mouse(+20,+7" "$LOG" || fail "routed mouse move not logged"
81
82echo ""
83echo "PASS — mouse round trip"
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"