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