joeylib2/scripts/verify-amiga-fastram.sh

80 lines
2.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-amiga-fastram.sh - a surface in Fast RAM draws and copies as one in
# chip RAM does.
#
# The Amiga puts a surface's planes in chip RAM, where the blitter that does
# its fills and copies can reach them; once chip RAM has run out, a surface
# other than the stage goes in Fast RAM, and its fills and copies run on the
# CPU (src/amiga/hal.c, jlpSurfaceAllocPortData). FASTRAM (tests/amiga/
# fastRam.c; make -f make/amiga.mk build/amiga/test/Fastram) runs under
# FS-UAE on an A500 with 2 MB of Fast RAM: it fills chip RAM with ballast,
# makes a surface, which must land in Fast RAM, and checks that the same
# drawing and copies on it and on a chip surface hash the same.
#
# Usage: scripts/verify-amiga-fastram.sh
# Env: TIMEOUT seconds to wait for the program (default 120)
# Exit: 0 PASS, 1 FAIL, 2 SKIP (FS-UAE or the Kickstart not installed)
set -uo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
joeyNeed FSUAE fsuae
source "$repo/scripts/lib/amigaGate.sh"
amigaMachine
timeout_s=${TIMEOUT:-120}
probe=$repo/build/amiga/test/Fastram
label=verify-amiga-fastram
make -s -f "$repo/make/amiga.mk" "$probe" || {
echo "$label: FAIL - building Fastram failed" >&2
exit 1
}
work=$(mktemp -d -t joeylib-amiga-fastram.XXXXXX)
mkdir -p "$work/s"
cp "$probe" "$work/"
printf 'stack 32768\n:Fastram\n' > "$work/s/startup-sequence"
display=:$((RANDOM % 400 + 1300))
Xvfb "$display" -screen 0 800x600x24 -nolisten tcp > /dev/null 2>&1 &
xvfb_pid=$!
fs_pid=
cleanup() {
[[ -n $fs_pid ]] && joeyStop "$fs_pid"
kill "$xvfb_pid" 2>/dev/null || true
wait 2>/dev/null || true
rm -rf "$work"
}
trap cleanup EXIT
sleep 0.5
DISPLAY=$display "$FSUAE" "${AMIGA_MACHINE_ARGS[@]}" --fast_memory=2048 \
--hard_drive_0="$work" --hard_drive_0_label=JOEYLIB \
--automatic_input_grab=0 \
--fullscreen=0 --fade_out_duration=0 > "$work/fsuae.log" 2>&1 &
fs_pid=$!
log=$work/joeylog.txt
for ((waited = 0; waited < timeout_s; waited++)); do
if grep -q "FASTRAM: done" "$log" 2>/dev/null; then
break
fi
sleep 1
done
if ! grep -q "FASTRAM: done" "$log" 2>/dev/null; then
echo "$label: FAIL - the program did not finish within ${timeout_s}s" >&2
exit 1
fi
grep "FASTRAM:" "$log"
if ! grep -q "FASTRAM: fast surface chip=0" "$log"; then
echo "$label: FAIL - the surface made with chip RAM full did not land outside chip RAM"
exit 1
fi
if ! grep -q "FASTRAM: PASS" "$log"; then
echo "$label: FAIL - $(grep 'FASTRAM: ' "$log" | grep -v 'done\|surface chip' | head -3 | tr '\n' ';')"
exit 1
fi
echo "$label: PASS (a surface in Fast RAM, chip RAM full, draws and copies as a chip one, onto the stage too)"