joeylib2/scripts/verify-psp-save.sh

51 lines
1.9 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-psp-save.sh - Save gate for the PSP port: a save outlives the
# program, beside it on the memory stick.
#
# SAVE (examples/save) counts its launches in SAVES/runs.dat. It is run twice
# under PPSSPPHeadless (scripts/lib/pspGate.sh) from the same folder on a
# private memory stick, PSP/GAME/SAVE, with every memory access checked as a
# PSP checks it; the PSP starts a program with its own folder as the current
# directory, so SAVES/ must appear there, and after the second run the count
# must be 2.
#
# Usage: scripts/verify-psp-save.sh
# Requires: PPSSPPHeadless; build/psp/bin/SAVE (make psp).
set -euo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
source "$repo/scripts/lib/pspGate.sh"
pspNeed
program=$(joeyExampleProgram save psp)
[ -f "$program" ] || { echo "verify-psp-save: build SAVE first (make psp)" >&2; exit 2; }
dir=$(dirname "$program")
# Real seconds a run is given: SAVE saves at once, then waits for Escape.
runSeconds=3
work=$(mktemp -d -t joeylib-psp-save.XXXXXX)
cleanup() {
pspStop
rm -rf "$work"
}
trap cleanup EXIT
folder=$(pspStage "$work" "$dir")
for run in 1 2; do
pspRun "$work" "$folder" "$runSeconds"
pspWait
pspStrictCheck "$work" "$dir" || { echo "verify-psp-save: FAIL - a bad memory access in run $run" >&2; exit 1; }
done
[ -f "$folder/SAVES/runs.dat" ] || { echo "verify-psp-save: FAIL - no SAVES/runs.dat beside the program" >&2; exit 1; }
count=$(joeyLe16 "$folder/SAVES/runs.dat")
if [ "$count" = 2 ]; then
echo "verify-psp-save: PASS (the second run counted 2, in SAVES/ beside the program on the memory stick)"
else
echo "verify-psp-save: FAIL - the second run counted $count, not 2" >&2
exit 1
fi