43 lines
1.6 KiB
Bash
Executable file
43 lines
1.6 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-web-save.sh - Save gate for the web port: a save outlives the page.
|
|
#
|
|
# A web program's SAVES/ is kept in the browser's IndexedDB (the SDL3
|
|
# backend mounts IDBFS there and writes it back every two seconds). SAVE
|
|
# (examples/save) counts its launches in SAVES/runs.dat, so its page is
|
|
# opened in headless Chromium, given time to write, opened again
|
|
# (reloaded), and given time again: the count it then holds must be 2 --
|
|
# the first launch's 1 came back from IndexedDB and the second launch added
|
|
# one.
|
|
#
|
|
# Usage: scripts/verify-web-save.sh
|
|
# Requires: Chromium, emsdk's node; build/web/bin/SAVE (make web).
|
|
set -euo pipefail
|
|
|
|
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
|
source "$repo/scripts/lib/joeyEnv.sh"
|
|
source "$repo/scripts/lib/webGate.sh"
|
|
webNeed
|
|
|
|
dir=$repo/build/web/bin/SAVE
|
|
[ -f "$dir/SAVE.html" ] || { echo "verify-web-save: build SAVE first (make web)" >&2; exit 2; }
|
|
|
|
work=$(mktemp -d -t joeylib-web-save.XXXXXX)
|
|
cleanup() {
|
|
webStop
|
|
rm -rf "$work"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
webServe "$dir"
|
|
webDrive "SAVE.html" --step wait:4 --step reload --step wait:4 --file "/SAVES/runs.dat:$work/runs.dat"
|
|
count=$(python3 -c "import struct, sys; print(struct.unpack('<H', open(sys.argv[1], 'rb').read(2))[0])" "$work/runs.dat")
|
|
if [ "$count" = 2 ]; then
|
|
echo "verify-web-save: PASS (the second launch counted 2: the first launch's save came back from IndexedDB)"
|
|
else
|
|
echo "verify-web-save: FAIL - the second launch counted $count, not 2" >&2
|
|
exit 1
|
|
fi
|