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

58 lines
2 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-tilebank.sh - Tile-bank gate for SDL3: proves the SDL3 build
# loads the DOS bake (its stage is the same chunky 4bpp) exactly and refuses
# a bank baked for any other target.
#
# Runs TILEBANK (examples/tilebank) headless -- SDL's dummy video and audio
# drivers -- from a scratch folder holding it and the DATA/tilebank
# make/sdl3.mk staged from the host gate's fixture (the port makes the
# program's own folder the current directory). Its TILEBANK line in
# joeylog.txt must say PASS with both hashes equal to the host gate's and
# every other target refused (scripts/lib/tileBankGate.sh).
#
# Usage: scripts/verify-sdl3-tilebank.sh
# Env: TILEBANK_DATA_DIR stage this DATA/tilebank instead (negative controls)
# Requires: a host cc; build/sdl3/bin/TILEBANK and its DATA/tilebank (make sdl3).
set -uo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
source "$repo/scripts/lib/tileBankGate.sh"
binDir=$repo/build/sdl3/bin
dataDir=$(tileBankData "$binDir")
wall=60 # hard cap on the program, whatever happens to this script
lineSeconds=30
tileBankNeedBuild "$binDir/TILEBANK" "$dataDir" "make sdl3"
tileBankReference
work=$(mktemp -d -t joeylib-sdl3-tilebank.XXXXXX)
guard=""
# 2>/dev/null: bash reports the SIGKILLed timeout wrapper as "Killed".
cleanup() {
joeyStop "$guard" 2> /dev/null
rm -rf "$work"
}
trap cleanup EXIT
mkdir -p "$work/DATA"
cp "$binDir/TILEBANK" "$work/"
cp -r "$dataDir" "$work/DATA/tilebank"
SDL_VIDEO_DRIVER=dummy SDL_AUDIO_DRIVER=dummy timeout -s KILL "$wall" "$work/TILEBANK" > "$work/run.log" 2>&1 &
guard=$!
log=$(tileBankAwaitLine "$work" "$lineSeconds" "$guard")
joeyStop "$guard" 2> /dev/null
guard=""
if [ -z "$log" ]; then
echo "verify-sdl3-tilebank: FAIL - no TILEBANK line within ${lineSeconds}s" >&2
tail -5 "$work/run.log" >&2
exit 1
fi
tileBankJudge "$log"