diff options
Diffstat (limited to '')
| -rwxr-xr-x | scripts/tests/test-disk.sh | 67 |
1 files changed, 67 insertions, 0 deletions
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 | # | ||
| 15 | set -euo pipefail | ||
| 16 | TNAME="disk" | ||
| 17 | # shellcheck source=../lib.sh | ||
| 18 | source "$(dirname "$0")/../lib.sh" | ||
| 19 | |||
| 20 | FRESH=0 | ||
| 21 | [ "${1:-}" = "--fresh" ] && FRESH=1 | ||
| 22 | STAMP="$(date +%s)" | ||
| 23 | |||
| 24 | echo "==> 1/6 build (kernel + bins)" | ||
| 25 | build_all | ||
| 26 | |||
| 27 | echo "==> 2/6 stage system image" | ||
| 28 | if [ "$FRESH" -eq 1 ]; then stage_image --force; else stage_image; fi | ||
| 29 | |||
| 30 | echo "==> 3/6 boot QEMU (headless)" | ||
| 31 | test_boot | ||
| 32 | sleep 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. | ||
| 37 | VOL_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)" | ||
| 39 | echo " mounted volume UID: $VOL_UID" | ||
| 40 | |||
| 41 | echo "==> 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). | ||
| 44 | TESTFILE="disk-test-$STAMP.txt" | ||
| 45 | sendkeys \ | ||
| 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 | |||
| 52 | echo "==> 5/6 wait for shutdown" | ||
| 53 | wait_qemu_exit 30 || fail "QEMU did not exit after poweroff" | ||
| 54 | |||
| 55 | echo "==> 6/6 verify" | ||
| 56 | grep -a "disk-test-$STAMP" "$LOG" >/dev/null || fail "cat output missing from serial log" | ||
| 57 | if ! fsck.fat -n "$SYSTEM_IMG" >/tmp/rsdos-fsck.out 2>&1; then | ||
| 58 | fail "fsck.fat reports problems: $(tail -3 /tmp/rsdos-fsck.out)" | ||
| 59 | fi | ||
| 60 | MT="$(mtype -i "$SYSTEM_IMG" "::/sub/$TESTFILE" 2>/dev/null || true)" | ||
| 61 | [ "$MT" = "disk-test-$STAMP" ] || fail "mtype mismatch: got '$MT'" | ||
| 62 | |||
| 63 | echo "" | ||
| 64 | echo "PASS — disk round trip OK (fsck clean, file survived poweroff)" | ||
| 65 | echo " image: $SYSTEM_IMG" | ||
| 66 | echo " volume: /disk/$VOL_UID" | ||
| 67 | echo " written: /disk/$VOL_UID/sub/$TESTFILE = \"disk-test-$STAMP\"" | ||
