joeylib2/scripts/verify-win16-save.sh

65 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License.
# See LICENSE.md for license information.
# SPDX-License-Identifier: MIT
#
# verify-win16-save.sh - Save gate for the Win16 port: a save outlives the
# program, beside it.
#
# SAVE.EXE (examples/save) counts its launches in SAVES\RUNS.DAT. Windows
# 3.11 under DOSBox (scripts/lib/win16Gate.sh) is booted twice with it as
# the shell, its scratch folder as drive D:. Windows starts it from
# C:\WINDOWS, so the port's own move into the program's folder is what puts
# SAVES there. Each run is stopped once it has counted itself (SAVE waits
# for ESC); the first must count 1 and the second 2.
#
# Usage: scripts/verify-win16-save.sh
# Requires: Windows on DOSBox (install.sh install emulator:win16);
# build/win16/bin/SAVE.EXE (make win16).
set -uo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
source "$repo/scripts/lib/win16Gate.sh"
label=verify-win16-save
win16Need
program=$(joeyExampleProgram save win16)
[ -f "$program" ] || { echo "$label: build SAVE.EXE first (make win16)" >&2; exit 2; }
runSeconds=60
work=$(mktemp -d -t joeylib-win16-save.XXXXXX)
cleanup() {
win16Stop
rm -rf "$work"
}
trap cleanup EXIT
# savedCount -- the launch count in SAVES\RUNS.DAT, or nothing yet.
savedCount() {
local saved
saved=$(find "$work/program" -maxdepth 2 -ipath "*/saves/runs.dat" -print -quit)
[ -s "$saved" ] || return 0
joeyLe16 "$saved"
}
mkdir -p "$work/program"
cp "$program" "$work/program/SAVE.EXE"
win16Stage "$work" "$work/program" SAVE.EXE
for run in 1 2; do
win16Start "$work"
count=""
for ((waited = 0; waited < runSeconds; waited++)); do
count=$(savedCount)
[ "$count" = "$run" ] && break
joeyAlive "$WIN16_GUARD" || break
sleep 1
done
win16Stop
if [ "$count" != "$run" ]; then
echo "$label: FAIL - run $run counted '${count:-nothing}', not $run, in SAVES beside the program" >&2
exit 1
fi
done
echo "$label: PASS (the second run counted 2, in SAVES beside the program)"