diff options
| author | salmonik <salmonik@tuta.io> | 2026-08-01 01:56:12 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-08-01 01:56:12 +0200 |
| commit | 4ea992c71dd0cdcffe0f74216e748256bd700a31 (patch) | |
| tree | 2992b0063f08fbf79586d35ad481539fd7ee9af4 /scripts/test-disk.sh | |
| parent | ahci: skip ATAPI ports and fast-fail on device abort (diff) | |
| download | rs-dos-4ea992c71dd0cdcffe0f74216e748256bd700a31.tar.gz rs-dos-4ea992c71dd0cdcffe0f74216e748256bd700a31.zip | |
scripts: automate the data-disk workflow (mkdisk / sendkeys / test-disk)
- 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
Diffstat (limited to '')
| -rwxr-xr-x | scripts/test-disk.sh | 111 |
1 files changed, 111 insertions, 0 deletions
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 @@ | |||
| 1 | #!/usr/bin/env bash | ||
| 2 | # | ||
| 3 | # scripts/test-disk.sh — full automated data-disk round trip. | ||
| 4 | # | ||
| 5 | # Builds the kernel, ensures the FAT32 image exists (with --fresh it is | ||
| 6 | # re-formatted and re-seeded), boots QEMU headless, drives the shell via | ||
| 7 | # the monitor, then verifies the results with mtools and fsck. | ||
| 8 | # | ||
| 9 | # Usage: | ||
| 10 | # ./scripts/test-disk.sh # reuse existing image | ||
| 11 | # ./scripts/test-disk.sh --fresh # re-format the image first | ||
| 12 | # | ||
| 13 | # Environment: | ||
| 14 | # DISK_IMG data disk path (default: /tmp/disk.img) | ||
| 15 | # OVMF firmware (default: /usr/share/edk2/x64/OVMF.4m.fd) | ||
| 16 | # QEMU qemu binary (default: qemu-system-x86_64) | ||
| 17 | # | ||
| 18 | set -euo pipefail | ||
| 19 | |||
| 20 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| 21 | PROJECT_DIR="$(dirname "$SCRIPT_DIR")" | ||
| 22 | cd "$PROJECT_DIR" | ||
| 23 | |||
| 24 | FRESH=0 | ||
| 25 | [ "${1:-}" = "--fresh" ] && FRESH=1 | ||
| 26 | |||
| 27 | OVMF="${OVMF:-/usr/share/edk2/x64/OVMF.4m.fd}" | ||
| 28 | QEMU="${QEMU:-qemu-system-x86_64}" | ||
| 29 | IMG="${DISK_IMG:-/tmp/disk.img}" | ||
| 30 | ESP_DIR="$PROJECT_DIR/esp" | ||
| 31 | QPID=/tmp/rsdos-test-qpid | ||
| 32 | SOCK=/tmp/rsdos-test-qmon.sock | ||
| 33 | LOG=/tmp/rsdos-test-serial.log | ||
| 34 | STAMP="$(date +%s)" | ||
| 35 | |||
| 36 | fail() { | ||
| 37 | echo "FAIL: $1" | ||
| 38 | [ -f "$LOG" ] && tail -20 "$LOG" | ||
| 39 | exit 1 | ||
| 40 | } | ||
| 41 | |||
| 42 | # wait_log FILE PATTERN TIMEOUT-SECONDS — poll a file for a regex. | ||
| 43 | wait_log() { | ||
| 44 | local i=0 | ||
| 45 | while [ "$i" -lt $(( ${3:-60} * 10 )) ]; do | ||
| 46 | grep -q "$2" "$1" 2>/dev/null && return 0 | ||
| 47 | sleep 0.1 | ||
| 48 | i=$((i + 1)) | ||
| 49 | done | ||
| 50 | return 1 | ||
| 51 | } | ||
| 52 | |||
| 53 | # wait_qemu_exit TIMEOUT-SECONDS — poll until the pid is gone. | ||
| 54 | wait_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 | |||
| 64 | echo "==> 1/6 build kernel (debug)" | ||
| 65 | cargo build --package rsdos --target x86_64-unknown-uefi | ||
| 66 | |||
| 67 | echo "==> 2/6 deploy to ESP + ensure disk image" | ||
| 68 | mkdir -p "$ESP_DIR/EFI/BOOT" | ||
| 69 | cp target/x86_64-unknown-uefi/debug/rsdos.efi "$ESP_DIR/EFI/BOOT/BOOTX64.EFI" | ||
| 70 | "$SCRIPT_DIR/mkdisk.sh" $([ "$FRESH" -eq 1 ] && echo --fresh) "$IMG" | ||
| 71 | |||
| 72 | echo "==> 3/6 boot QEMU (headless)" | ||
| 73 | kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true | ||
| 74 | sleep 1 | ||
| 75 | rm -f "$SOCK" "$LOG" | ||
| 76 | "$QEMU" -bios "$OVMF" \ | ||
| 77 | -drive file="$IMG",format=raw,if=none,id=disk \ | ||
| 78 | -device ide-hd,drive=disk,bus=ide.0 \ | ||
| 79 | -drive file=fat:rw:"$ESP_DIR",format=raw,if=none,id=esp \ | ||
| 80 | -device ide-hd,drive=esp,bus=ide.1 \ | ||
| 81 | -serial file:"$LOG" \ | ||
| 82 | -monitor unix:"$SOCK",server,nowait \ | ||
| 83 | -m 256M -machine q35 -cpu qemu64 -no-reboot -display none & | ||
| 84 | echo $! > "$QPID" | ||
| 85 | |||
| 86 | wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell" | ||
| 87 | sleep 1 | ||
| 88 | |||
| 89 | echo "==> 4/6 drive the shell (ls / mkdir / echo > / cat / poweroff)" | ||
| 90 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ | ||
| 91 | "ls /disk" \ | ||
| 92 | "mkdir /disk/sub" \ | ||
| 93 | "echo disk-test-$STAMP > /disk/sub/hello.txt" \ | ||
| 94 | "cat /disk/sub/hello.txt" \ | ||
| 95 | "poweroff" | ||
| 96 | |||
| 97 | echo "==> 5/6 wait for shutdown" | ||
| 98 | wait_qemu_exit 30 || fail "QEMU did not exit after poweroff" | ||
| 99 | |||
| 100 | echo "==> 6/6 verify" | ||
| 101 | grep -a "disk-test-$STAMP" "$LOG" >/dev/null || fail "cat output missing from serial log" | ||
| 102 | if ! fsck.fat -n "$IMG" >/tmp/rsdos-fsck.out 2>&1; then | ||
| 103 | fail "fsck.fat reports problems: $(cat /tmp/rsdos-fsck.out | tail -3)" | ||
| 104 | fi | ||
| 105 | MT="$(mtype -i "$IMG" "::/sub/hello.txt" 2>/dev/null || true)" | ||
| 106 | [ "$MT" = "disk-test-$STAMP" ] || fail "mtype mismatch: got '$MT'" | ||
| 107 | |||
| 108 | echo "" | ||
| 109 | echo "PASS — disk round trip OK (fsck clean, file survived poweroff)" | ||
| 110 | echo " image: $IMG" | ||
| 111 | echo " written: /disk/sub/hello.txt = \"disk-test-$STAMP\"" | ||
