sots-engine/tests/mars_stream/build_and_run.sh

53 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# Self-contained build + test for src/mars/stream and src/mars/rng (plain g++, no CMake).
#
# tests/mars_stream/build_and_run.sh [BUILD_DIR]
#
# Environment (all optional):
# SOTS_SAVES_DIR directory with the owner's *.sav files -> real-save test runs
# (skipped cleanly when unset; saves never enter the repo)
# SOTS_SAVE_READER path to the reference save_reader.py -> oracle dump comparison
# PYTHON interpreter for the oracle script (default: python3)
set -euo pipefail
here="$(cd "$(dirname "$0")" && pwd)"
root="$(cd "$here/../.." && pwd)"
out="${1:-$root/build-mars-stream}"
mkdir -p "$out"
CXX="${CXX:-g++}"
CC="${CC:-gcc}"
CXXFLAGS="-std=c++17 -O2 -Wall -Wextra -Wpedantic -I$root/src"
MINIZ_DEFS="-DMINIZ_NO_STDIO -DMINIZ_NO_ARCHIVE_APIS -DMINIZ_NO_TIME"
echo "== build ($out)"
$CC -O2 -w $MINIZ_DEFS -c "$root/third_party/miniz/miniz.c" -o "$out/miniz.o"
objs=()
for src in gzip reader writer dump save; do
$CXX $CXXFLAGS $MINIZ_DEFS -c "$root/src/mars/stream/$src.cpp" -o "$out/stream_$src.o"
objs+=("$out/stream_$src.o")
done
$CXX $CXXFLAGS -c "$root/src/mars/rng/mt19937.cpp" -o "$out/rng_mt19937.o"
$CXX $CXXFLAGS -o "$out/sots_savedump" "$root/src/mars/stream/savedump_main.cpp" "${objs[@]}" "$out/miniz.o"
$CXX $CXXFLAGS -o "$out/test_rng" "$here/test_rng.cpp" "$out/rng_mt19937.o"
$CXX $CXXFLAGS -o "$out/test_stream" "$here/test_stream.cpp" "${objs[@]}" "$out/miniz.o"
$CXX $CXXFLAGS -o "$out/test_save" "$here/test_save.cpp" "${objs[@]}" "$out/miniz.o" "$out/rng_mt19937.o"
echo "== test_rng"
"$out/test_rng"
echo "== test_stream"
"$out/test_stream"
echo "== test_save"
if [ -n "${SOTS_SAVES_DIR:-}" ]; then
mkdir -p "$out/dumps"
SOTS_DUMP_DIR="$out/dumps" "$out/test_save"
if [ -n "${SOTS_SAVE_READER:-}" ]; then
echo "== oracle comparison"
${PYTHON:-python3} "$here/oracle/compare.py" --reader "$SOTS_SAVE_READER" --saves "$SOTS_SAVES_DIR" \
--dumps "$out/dumps" --python "${PYTHON:-python3}"
else
echo "oracle comparison skipped (SOTS_SAVE_READER not set)"
fi
else
"$out/test_save"
fi
echo "== all ok"