joeylib2/scripts/verify-sdl3-save.sh
2026-10-13 14:01:46 -05:00

42 lines
1.8 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-sdl3-save.sh - Save gate for the SDL3 port: a save outlives the
# program, beside it.
#
# SAVE (examples/save) counts its launches in SAVES/runs.dat. It is run twice
# headless (SDL's dummy drivers) from a scratch folder, started from another
# directory each time so the port's own move into the program's folder is
# what puts SAVES/ there; after the second run the count must be 2.
#
# Usage: scripts/verify-sdl3-save.sh
# Requires: build/sdl3/bin/SAVE (make sdl3).
set -euo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
program=$(joeyExampleProgram save sdl3)
[ -x "$program" ] || { echo "verify-sdl3-save: build SAVE first (make sdl3)" >&2; exit 2; }
runSeconds=3
work=$(mktemp -d -t joeylib-sdl3-save.XXXXXX)
trap 'rm -rf "$work"' EXIT
mkdir -p "$work/program" "$work/elsewhere"
cp "$program" "$work/program/SAVE"
for run in 1 2; do
# SAVE waits for ESC; the timeout's SIGTERM, which SDL turns into a quit,
# ends each run once it has saved.
(cd "$work/elsewhere" && SDL_VIDEO_DRIVER=dummy SDL_AUDIO_DRIVER=dummy timeout "$runSeconds" "$work/program/SAVE" > /dev/null 2>&1) || true
done
[ -f "$work/program/SAVES/runs.dat" ] || { echo "verify-sdl3-save: FAIL - no SAVES/runs.dat beside the program" >&2; exit 1; }
count=$(python3 -c "import struct, sys; print(struct.unpack('<H', open(sys.argv[1], 'rb').read(2))[0])" "$work/program/SAVES/runs.dat")
if [ "$count" = 2 ]; then
echo "verify-sdl3-save: PASS (the second run counted 2, in SAVES/ beside the program)"
else
echo "verify-sdl3-save: FAIL - the second run counted $count, not 2" >&2
exit 1
fi