diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-01 15:53:29 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-01 15:53:29 +0100 |
| commit | 7958276c9f0d230053520ba20f2a00f5ecda18e4 (patch) | |
| tree | 596f5f71ad597ed951bae98de818cb37f171a18d /scripts/test-disk.sh | |
| parent | fs: /bin alias for the system volume (diff) | |
| download | rs-dos-7958276c9f0d230053520ba20f2a00f5ecda18e4.tar.gz rs-dos-7958276c9f0d230053520ba20f2a00f5ecda18e4.zip | |
scripts: rebuild the dev loop around build.sh/run.sh
`make` did not parse at all (missing separator at line 139), so every
make target was dead. The folder also carried three overlapping
launchers (boot.sh, qemu.sh, boot-image.sh) plus a fourth partial one
in the Makefile, `cargo build --package rsdos` copy-pasted eight times,
the QEMU invocation copy-pasted per script, and the test helpers
(fail/wait_log/wait_qemu_exit/qemu_hmp) duplicated in five tests.
New layout:
- scripts/lib.sh: single config (image, OVMF, mem/smp), the one cargo
invocation (build_all), the one QEMU shape (qemu_args), and the test
harness (test_boot, wait_log, wait_qemu_exit, qemu_hmp, sendkeys)
- scripts/build.sh: kernel + every bins/* in one pass
- scripts/mksystem.sh: freshness-aware image build that now stages
every bins/*.efi into /bin/cli|gui (they were never copied before)
- scripts/run.sh: build + stage + boot in one command; --headless,
--debug (GDB stub), --monitor (HMP socket), --fresh, --mem/--smp/
--bios/--image; on Wayland it auto-selects XWayland plus
grab-on-hover so the mouse can be captured (Ctrl+Alt+G toggles)
- scripts/tests/: the five automated tests on the shared harness
- deleted: boot.sh, qemu.sh, boot-image.sh, lib-boot-args.sh,
build-image-release.sh, build-bootloader.sh (rsboot chain dropped)
The Makefile is now a thin wrapper: make run, make test, make system,
make inspect, make help. Two-command flow: ./scripts/build.sh then
./scripts/run.sh (run.sh alone also works).
Stale test assumptions fixed so the suite is green again: test-gfx
waited for "gfx: check" while the shell prints "gfx check: PASS";
test-mouse/test-msg hardcoded msgrecv = task 3 (wm-input took slot 3 —
ids are parsed from the log now); the queue-full probe targeted task 0,
whose exec pump drains its own queue as completion codes (moved to the
cursor task, which never recvs).
Verified in QEMU: make test -> test-disk, test-gfx, test-mouse,
test-msg, test-fault all PASS.
Diffstat (limited to '')
| -rwxr-xr-x | scripts/test-disk.sh | 131 |
1 files changed, 0 insertions, 131 deletions
diff --git a/scripts/test-disk.sh b/scripts/test-disk.sh deleted file mode 100755 index 881b475..0000000 --- a/scripts/test-disk.sh +++ /dev/null | |||
| @@ -1,131 +0,0 @@ | |||
| 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="${SYSTEM_IMG:-/tmp/system.img}" | ||
| 30 | QPID=/tmp/rsdos-test-qpid | ||
| 31 | SOCK=/tmp/rsdos-test-qmon.sock | ||
| 32 | LOG=/tmp/rsdos-test-serial.log | ||
| 33 | QLOG=/tmp/rsdos-test-qemu.log | ||
| 34 | STAMP="$(date +%s)" | ||
| 35 | |||
| 36 | # Never leave a QEMU behind (an orphan holding our stdout would hang any | ||
| 37 | # caller that pipes our output). | ||
| 38 | trap 'kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true' EXIT | ||
| 39 | |||
| 40 | fail() { | ||
| 41 | echo "FAIL: $1" | ||
| 42 | [ -f "$LOG" ] && tail -20 "$LOG" | ||
| 43 | exit 1 | ||
| 44 | } | ||
| 45 | |||
| 46 | # wait_log FILE PATTERN TIMEOUT-SECONDS — poll a file for a regex. | ||
| 47 | wait_log() { | ||
| 48 | local i=0 | ||
| 49 | while [ "$i" -lt $((${3:-60} * 10)) ]; do | ||
| 50 | grep -q "$2" "$1" 2>/dev/null && return 0 | ||
| 51 | sleep 0.1 | ||
| 52 | i=$((i + 1)) | ||
| 53 | done | ||
| 54 | return 1 | ||
| 55 | } | ||
| 56 | |||
| 57 | # wait_qemu_exit TIMEOUT-SECONDS — poll until the pid is gone. | ||
| 58 | wait_qemu_exit() { | ||
| 59 | local i=0 | ||
| 60 | while [ "$i" -lt $((${1:-30} * 10)) ]; do | ||
| 61 | kill -0 "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || return 0 | ||
| 62 | sleep 0.1 | ||
| 63 | i=$((i + 1)) | ||
| 64 | done | ||
| 65 | return 1 | ||
| 66 | } | ||
| 67 | |||
| 68 | echo "==> 1/6 build kernel (debug)" | ||
| 69 | cargo build --release --package rsdos --target x86_64-unknown-uefi | ||
| 70 | |||
| 71 | echo "==> 2/6 ensure system image" | ||
| 72 | if [ "$FRESH" -eq 1 ]; then | ||
| 73 | "$SCRIPT_DIR/mksystem.sh" --force "$IMG" | ||
| 74 | else | ||
| 75 | "$SCRIPT_DIR/mksystem.sh" "$IMG" | ||
| 76 | fi | ||
| 77 | |||
| 78 | echo "==> 3/6 boot QEMU (headless)" | ||
| 79 | kill "$(cat "$QPID" 2>/dev/null)" 2>/dev/null || true | ||
| 80 | sleep 1 | ||
| 81 | rm -f "$SOCK" "$LOG" | ||
| 82 | # Throwaway OVMF varstore: a stale/poisoned NvVars (e.g. left by the old | ||
| 83 | # vvfat setup) makes the firmware skip the \EFI\BOOT fallback entirely. | ||
| 84 | NV="/tmp/rsdos-test-ovmf-vars.fd" | ||
| 85 | rm -f "$NV" | ||
| 86 | cp /usr/share/edk2/x64/OVMF.4m.fd "$NV" | ||
| 87 | "$QEMU" -bios "$NV" \ | ||
| 88 | -drive file="$IMG",format=raw,if=none,id=disk \ | ||
| 89 | -device ide-hd,drive=disk,bus=ide.0 \ | ||
| 90 | -serial file:"$LOG" \ | ||
| 91 | -monitor unix:"$SOCK",server,nowait \ | ||
| 92 | -m 256M -machine q35 -cpu qemu64 -no-reboot -display none \ | ||
| 93 | >"$QLOG" 2>&1 & | ||
| 94 | |||
| 95 | wait_log "$LOG" "boot: entering shell" 90 || fail "kernel never reached the shell" | ||
| 96 | sleep 1 | ||
| 97 | |||
| 98 | # Volumes mount under /disk/<UID>/ where UID = "LABEL-SERIAL" (e.g. | ||
| 99 | # RSDOS-5BD1E55F). Discover it from the boot log so the test works on | ||
| 100 | # any image without knowing the serial in advance. | ||
| 101 | VOL_UID="$(grep -a 'fat: mounted' "$LOG" | sed -n 's/.*at \/disk\/\([^ )]*\).*/\1/p' | head -1)" | ||
| 102 | [ -n "$VOL_UID" ] || fail "no FAT32 volume was mounted (look for 'fat: mounted' in the log)" | ||
| 103 | echo " mounted volume UID: $VOL_UID" | ||
| 104 | |||
| 105 | echo "==> 4/6 drive the shell (ls / mkdir / echo WRITING / cat / poweroff)" | ||
| 106 | # The filename is deliberately >13 chars so the FAT LFN path gets | ||
| 107 | # multi-entry entries (they're stored last-first on disk). | ||
| 108 | TESTFILE="disk-test-$STAMP.txt" | ||
| 109 | python3 "$SCRIPT_DIR/sendkeys.py" --sock "$SOCK" \ | ||
| 110 | "ls /disk" \ | ||
| 111 | "mkdir /disk/$VOL_UID/sub" \ | ||
| 112 | "echo disk-test-$STAMP WRITING /disk/$VOL_UID/sub/$TESTFILE" \ | ||
| 113 | "cat /disk/$VOL_UID/sub/$TESTFILE" \ | ||
| 114 | "poweroff" | ||
| 115 | |||
| 116 | echo "==> 5/6 wait for shutdown" | ||
| 117 | wait_qemu_exit 30 || fail "QEMU did not exit after poweroff" | ||
| 118 | |||
| 119 | echo "==> 6/6 verify" | ||
| 120 | grep -a "disk-test-$STAMP" "$LOG" >/dev/null || fail "cat output missing from serial log" | ||
| 121 | if ! fsck.fat -n "$IMG" >/tmp/rsdos-fsck.out 2>&1; then | ||
| 122 | fail "fsck.fat reports problems: $(cat /tmp/rsdos-fsck.out | tail -3)" | ||
| 123 | fi | ||
| 124 | MT="$(mtype -i "$IMG" "::/sub/$TESTFILE" 2>/dev/null || true)" | ||
| 125 | [ "$MT" = "disk-test-$STAMP" ] || fail "mtype mismatch: got '$MT'" | ||
| 126 | |||
| 127 | echo "" | ||
| 128 | echo "PASS — disk round trip OK (fsck clean, file survived poweroff)" | ||
| 129 | echo " image: $IMG" | ||
| 130 | echo " volume: /disk/$VOL_UID" | ||
| 131 | echo " written: /disk/$VOL_UID/sub/$TESTFILE = \"disk-test-$STAMP\"" | ||
