summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/test-fault.sh90
1 files changed, 90 insertions, 0 deletions
diff --git a/scripts/test-fault.sh b/scripts/test-fault.sh
new file mode 100755
index 0000000..49ba791
--- /dev/null
+++ b/scripts/test-fault.sh
@@ -0,0 +1,90 @@
1#!/usr/bin/env bash
2#
3# scripts/test-fault.sh — fault-diagnostics verification.
4#
5# Real hardware has no serial console, so a kernel crash previously left
6# only a frozen screen ("unresponsive"). This test proves the fault-dump
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#
13# Usage: ./scripts/test-fault.sh
14# Env: OVMF, QEMU (same defaults as other test scripts)
15#
16set -euo pipefail
17
18SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
19PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
20cd "$PROJECT_DIR"
21
22OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}"
23QEMU="${QEMU:-qemu-system-x86_64}"
24ESP_DIR="$PROJECT_DIR/esp"
25QPID=/tmp/rsdos-fault-qpid
26SOCK=/tmp/rsdos-fault-qmon.sock
27LOG=/tmp/rsdos-fault-serial.log
28QLOG=/tmp/rsdos-fault-qemu.log
29
30trap 'kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true' EXIT
31
32fail() {
33 echo "FAIL: $1"
34 [ -f "$LOG" ] && tail -40 "$LOG"
35 exit 1
36}
37
38wait_log() {
39 local i=0
40 while [ "$i" -lt $((${3:-60} * 10)) ]; do
41 grep -q "$2" "$1" 2>/dev/null && return 0
42 sleep 0.1
43 i=$((i + 1))
44 done
45 return 1
46}
47
48echo "==> 1/5 build kernel (debug)"
49cargo build --package rsdos --target x86_64-unknown-uefi
50
51echo "==> 2/5 deploy to ESP"
52mkdir -p "$ESP_DIR/EFI/BOOT"
53cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI"
54
55echo "==> 3/5 boot QEMU (headless)"
56kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true
57sleep 1
58rm -f "$SOCK" "$LOG"
59"$QEMU" -bios "$OVMF" \
60 -drive file=fat:rw:"$ESP_DIR",format=raw \
61 -serial file:"$LOG" \
62 -monitor unix:"$SOCK",server,nowait \
63 -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \
64 >"$QLOG" 2>&1 &
65echo $! >"$QPID"
66
67wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell"
68
69echo "==> 4/5 boot diagnostics present"
70grep -aq "gop: fb base=" "$LOG" || fail "fb geometry diagnostic missing"
71grep -aq "gop: mode .* selected" "$LOG" || fail "mode-selection diagnostic missing"
72
73echo "==> 5/5 inject a page fault (fault command)"
74python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \
75 "clear" \
76 "fault"
77sleep 2
78
79# The dump must appear on serial: vector 14, the CR2 we wrote, RIP, and
80# the shell task identity — then the machine halts (never triple-faults).
81grep -aq "!!! page fault vec=14 .*rip=" "$LOG" || fail "page-fault dump line missing"
82grep -aq "cr2=0x400000000000" "$LOG" || fail "CR2 not reported (faulting address)"
83grep -aq "task=0 \"shell\"" "$LOG" || fail "faulting task not identified"
84grep -aq "!!! halting" "$LOG" || fail "no halt message"
85
86# The screen dump itself is exercised in-kernel (dump_lines); the serial
87# path sharing the same format line is verified above.
88echo ""
89echo "PASS — fault dump works (vec, err, rip, cr2, task → screen + serial)"
90echo " every CPU exception now halts with a diagnosable dump, not a freeze"