#!/usr/bin/env bash # # scripts/test-fault.sh — fault-diagnostics verification. # # Real hardware has no serial console, so a kernel crash previously left # only a frozen screen ("unresponsive"). This test proves the fault-dump # path: every CPU exception now prints a white-on-red band to the # framebuffer *and* a parseable serial line (vector, error, RIP, CR2, # task) before halting — so the next real-hardware failure identifies # itself. The `fault` command deliberately writes to an unmapped # address; the machine must halt with a full dump, not triple-fault. # # Usage: ./scripts/test-fault.sh # Env: OVMF, QEMU (same defaults as other test scripts) # 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-fault-qpid SOCK=/tmp/rsdos-fault-qmon.sock LOG=/tmp/rsdos-fault-serial.log QLOG=/tmp/rsdos-fault-qemu.log trap 'kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true' EXIT fail() { echo "FAIL: $1" [ -f "$LOG" ] && tail -40 "$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 } 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/6 boot QEMU (headless, + dedicated CRASHLOG stick)" kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true sleep 1 rm -f "$SOCK" "$LOG" # A second FAT32 stick labeled CRASHLOG: crash reports must land here # (label-selected by the kernel), not on the boot device. CRASH_IMG=/tmp/rsdos-crash.img "$SCRIPT_DIR/mkdisk.sh" --fresh --label CRASHLOG --no-seed "$CRASH_IMG" >/dev/null "$QEMU" -bios "$OVMF" \ -drive file=fat:rw:"$ESP_DIR",format=raw \ -drive file="$CRASH_IMG",format=raw,if=none,id=crash \ -device ide-hd,drive=crash,bus=ide.2 \ -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/6 boot diagnostics present" grep -aq "gop: fb base=" "$LOG" || fail "fb geometry diagnostic missing" grep -aq "gop: mode .* selected" "$LOG" || fail "mode-selection diagnostic missing" grep -aq "CRASHLOG" "$LOG" || fail "CRASHLOG stick not mounted" echo "==> 5/6 inject a page fault (fault command)" python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ "clear" \ "fault" sleep 2 # The dump must appear on serial: vector 14, the CR2 we wrote, RIP, and # the shell task identity — then the machine halts (never triple-faults). grep -aq "!!! page fault vec=14 .*rip=" "$LOG" || fail "page-fault dump line missing" grep -aq "cr2=0x400000000000" "$LOG" || fail "CR2 not reported (faulting address)" grep -aq "task=0 \"shell\"" "$LOG" || fail "faulting task not identified" grep -aq "!!! halting" "$LOG" || fail "no halt message" echo "==> 6/6 crash.log persisted on the CRASHLOG stick" grep -aq "crashlog: vol .* (CRASHLOG)" "$LOG" || fail "crashlog did not target the CRASHLOG stick" grep -aq "crashlog: wrote" "$LOG" || fail "crashlog write did not complete" mdir -i "$CRASH_IMG" "::" 2>/dev/null | grep -aqi "crash" \ || fail "crash.log missing on the CRASHLOG stick" # The boot ESP must NOT receive the crash log. if [ -f "$ESP_DIR/crash.log" ]; then fail "crash.log landed on the boot ESP instead of the CRASHLOG stick" fi # The screen dump itself is exercised in-kernel (dump_lines); the serial # path sharing the same format line is verified above. echo "" echo "PASS — fault dump + crash.log on the CRASHLOG stick" echo " every CPU exception halts with a diagnosable dump; the report" echo " survives reboot on the dedicated CRASHLOG volume"