From 4ea992c71dd0cdcffe0f74216e748256bd700a31 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 1 Aug 2026 01:56:12 +0200 Subject: scripts: automate the data-disk workflow (mkdisk / sendkeys / test-disk) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - scripts/mkdisk.sh: create the FAT32 disk with mkfs.fat -C (the flag that actually creates the file — plain mkfs.fat fails on a missing path), accept M/G/K sizes, seed seed/ files via mtools; --fresh re-formats, --no-seed skips seeding - scripts/sendkeys.py: type lines into the guest via the QEMU monitor (US layout). Punctuation must use QEMU's named keys (minus, slash, dot, ...) — bare '-', '.', '/' are not valid sendkey names, and '-' is the modifier separator, so they were silently dropped before - scripts/test-disk.sh: full automated round trip — build, deploy, ensure image, boot headless QEMU, drive the shell (ls /disk, mkdir, echo >, cat, poweroff), then verify with fsck.fat (must be clean) and mtype (file content must have survived poweroff) - Makefile: make disk / disk-fresh / inspect / test-disk; run, run-gui and debug now auto-create a missing DISK_IMG; fix the stale comment (mkfs.fat without -C) - scripts/boot.sh: auto-create a missing DISK_IMG via mkdisk.sh - seed/: motd.txt + lines.txt seeded onto fresh images - Verified end to end: ./scripts/test-disk.sh --fresh passes --- scripts/test-disk.sh | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100755 scripts/test-disk.sh (limited to 'scripts/test-disk.sh') diff --git a/scripts/test-disk.sh b/scripts/test-disk.sh new file mode 100755 index 0000000..f7be7c6 --- /dev/null +++ b/scripts/test-disk.sh @@ -0,0 +1,111 @@ +#!/usr/bin/env bash +# +# scripts/test-disk.sh — full automated data-disk round trip. +# +# Builds the kernel, ensures the FAT32 image exists (with --fresh it is +# re-formatted and re-seeded), boots QEMU headless, drives the shell via +# the monitor, then verifies the results with mtools and fsck. +# +# Usage: +# ./scripts/test-disk.sh # reuse existing image +# ./scripts/test-disk.sh --fresh # re-format the image first +# +# Environment: +# DISK_IMG data disk path (default: /tmp/disk.img) +# 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" + +FRESH=0 +[ "${1:-}" = "--fresh" ] && FRESH=1 + +OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" +QEMU="${QEMU:-qemu-system-x86_64}" +IMG="${DISK_IMG:-/tmp/disk.img}" +ESP_DIR="$PROJECT_DIR/esp" +QPID=/tmp/rsdos-test-qpid +SOCK=/tmp/rsdos-test-qmon.sock +LOG=/tmp/rsdos-test-serial.log +STAMP="$(date +%s)" + +fail() { + echo "FAIL: $1" + [ -f "$LOG" ] && tail -20 "$LOG" + exit 1 +} + +# wait_log FILE PATTERN TIMEOUT-SECONDS — poll a file for a regex. +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 TIMEOUT-SECONDS — poll until the pid is gone. +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 +} + +echo "==> 1/6 build kernel (debug)" +cargo build --package rsdos --target x86_64-unknown-uefi + +echo "==> 2/6 deploy to ESP + ensure disk image" +mkdir -p "$ESP_DIR/EFI/BOOT" +cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI" +"$SCRIPT_DIR/mkdisk.sh" $([ "$FRESH" -eq 1 ] && echo --fresh) "$IMG" + +echo "==> 3/6 boot QEMU (headless)" +kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true +sleep 1 +rm -f "$SOCK" "$LOG" +"$QEMU" -bios "$OVMF" \ + -drive file="$IMG",format=raw,if=none,id=disk \ + -device ide-hd,drive=disk,bus=ide.0 \ + -drive file=fat:rw:"$ESP_DIR",format=raw,if=none,id=esp \ + -device ide-hd,drive=esp,bus=ide.1 \ + -serial file:"$LOG" \ + -monitor unix:"$SOCK",server,nowait \ + -m 256M -machine q35 -cpu qemu64 -no-reboot -display none & +echo $! > "$QPID" + +wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell" +sleep 1 + +echo "==> 4/6 drive the shell (ls / mkdir / echo > / cat / poweroff)" +python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ + "ls /disk" \ + "mkdir /disk/sub" \ + "echo disk-test-$STAMP > /disk/sub/hello.txt" \ + "cat /disk/sub/hello.txt" \ + "poweroff" + +echo "==> 5/6 wait for shutdown" +wait_qemu_exit 30 || fail "QEMU did not exit after poweroff" + +echo "==> 6/6 verify" +grep -a "disk-test-$STAMP" "$LOG" >/dev/null || fail "cat output missing from serial log" +if ! fsck.fat -n "$IMG" >/tmp/rsdos-fsck.out 2>&1; then + fail "fsck.fat reports problems: $(cat /tmp/rsdos-fsck.out | tail -3)" +fi +MT="$(mtype -i "$IMG" "::/sub/hello.txt" 2>/dev/null || true)" +[ "$MT" = "disk-test-$STAMP" ] || fail "mtype mismatch: got '$MT'" + +echo "" +echo "PASS — disk round trip OK (fsck clean, file survived poweroff)" +echo " image: $IMG" +echo " written: /disk/sub/hello.txt = \"disk-test-$STAMP\"" -- cgit v1.2.3