#!/bin/bash # SPDX-License-Identifier: MIT # Milestone 6's sweep: each title of a list on the board and on the detectors (PicoDrive, # BlastEm: libretro cores run as closed boxes), the same frames and the same presses, so # scripts/triage_sweep.py can set each board frame beside the detectors' closest ones. # # OUT=reference/sweep/NAME LIST=tests/smoke_sweep.txt JOBS=8 scripts/sweep.sh # # The protocol (docs/worklog.md, Sessions 12-15): FRAMES frames (1,200), pad 1 Start held # 6 frames at first picture + 550 and + 850 (counted from each emulator's own first picture: # the boots differ most between them), the board's composite every 100 frames, the # detectors' every second frame. The region picks the console: USA and World on `genesis`, # Europe on `megadrive` (50 Hz), Japan on `megadrive-japan`. # # Found through the environment, never a machine path here: # SEGA32X_BIOS_DIR the user's 32X_G/M/S_BIOS.BIN (copied for the detectors into a # temporary folder outside the repository) # NO_INTRO_DIR the cartridges: "$NO_INTRO_DIR/Sega - 32X/NAME.zip" # PY the board's interpreter (default .venv-pypy/bin/python); DPY the # detectors' frontend's (default .venv/bin/python, CPython for ctypes) # PICODRIVE_CORE default reference/build/picodrive/picodrive_libretro.so # BLASTEM_CORE a BlastEm libretro build; unset: no BlastEm column # DETECTOR_DIR a previous sweep's OUT whose detector frames are reused (the detectors # do not change between board revisions); a title's are copied from # there when present, else run # JOBS titles at once (default 8); FRAMES (default 1200) set -u ROOT=$(cd "$(dirname "$0")/.." && pwd) cd "$ROOT" || exit 1 OUT=${OUT:?OUT: where the sweep writes}; LIST=${LIST:-tests/smoke_sweep.txt} : "${SEGA32X_BIOS_DIR:?the user\'s 32X boot ROMs}" "${NO_INTRO_DIR:?the No-Intro set}" PY=${PY:-$ROOT/.venv-pypy/bin/python}; DPY=${DPY:-$ROOT/.venv/bin/python} PICO=${PICODRIVE_CORE:-$ROOT/reference/build/picodrive/picodrive_libretro.so} BLAST=${BLASTEM_CORE:-}; JOBS=${JOBS:-8}; FRAMES=${FRAMES:-1200} export OUT LIST PY DPY PICO BLAST FRAMES ROOT PYPY_GC_NURSERY=1M PYTHONPATH="$ROOT/src" export DETECTOR_DIR=${DETECTOR_DIR:-} CARTS="$NO_INTRO_DIR/Sega - 32X" one() { name=$1 slug=$(printf '%s' "$name" | tr -c 'A-Za-z0-9' '_') case "$name" in *USA*|*World*) machine=genesis ;; *Europe*) machine=megadrive ;; *Japan*) machine=megadrive-japan ;; *) machine=genesis ;; esac press=(--press-from-picture 550:start:6 --press-from-picture 850:start:6) rom=$OUT/roms/$slug.bin [ -f "$rom" ] || "$PY" -c "import sys; from megadrive_python.cartridge import load_image; open(sys.argv[2], 'wb').write(load_image(sys.argv[1]))" "$CARTS/$name.zip" "$rom" for det in pico blastem; do core=$PICO; bios=$BIOS_COPIES/pico if [ $det = blastem ]; then core=$BLAST; bios=$BIOS_COPIES/blastem; fi [ -n "$core" ] || continue if [ -n "$DETECTOR_DIR" ] && [ -f "$DETECTOR_DIR/$det/$slug/f$(printf %05d "$FRAMES").png" ]; then mkdir -p "$OUT/$det/$slug" && cp -p "$DETECTOR_DIR/$det/$slug"/f*.png "$OUT/$det/$slug/" cp -p "$DETECTOR_DIR/logs/$slug-$det.log" "$OUT/logs/" 2>/dev/null continue fi s=$(date +%s) nice "$DPY" scripts/libretro_frames.py "$core" "$rom" "$OUT/$det/$slug" --frames "$(seq -s, 2 2 "$FRAMES")" --bios-dir "$bios" "${press[@]}" > "$OUT/logs/$slug-$det.log" 2>&1 echo "EXIT $? $(( $(date +%s) - s )) s" >> "$OUT/logs/$slug-$det.log" done s=$(date +%s) nice "$PY" scripts/run_32x.py "$CARTS/$name.zip" --machine $machine --bios-dir "$SEGA32X_BIOS_DIR" --frames "$FRAMES" --out "$OUT/board/$slug" --png-every 100 --report-every 50 "${press[@]}" > "$OUT/logs/$slug-board.log" 2>&1 echo "EXIT $? $(( $(date +%s) - s )) s" >> "$OUT/logs/$slug-board.log" } export -f one # The detectors want only the three boot ROMs in their system folder, BlastEm under # lower-case extensions: copies in a temporary folder outside the repository, so nothing # under reference/ holds Sega's ROMs (fetch_references.py --verify). BIOS_COPIES=$(mktemp -d "${TMPDIR:-/tmp}/sega32x-sweep-bios.XXXXXX") export BIOS_COPIES mkdir -p "$OUT/board" "$OUT/pico" "$OUT/blastem" "$OUT/logs" "$OUT/roms" "$BIOS_COPIES/pico" "$BIOS_COPIES/blastem" for kind in G M S; do cp -p "$SEGA32X_BIOS_DIR/32X_${kind}_BIOS.BIN" "$BIOS_COPIES/pico/" cp -p "$SEGA32X_BIOS_DIR/32X_${kind}_BIOS.BIN" "$BIOS_COPIES/blastem/32X_${kind}_BIOS.bin" done git rev-parse --short HEAD > "$OUT/at.txt"; cp "$LIST" "$OUT/list.txt"; uptime > "$OUT/load-start.txt" grep -v '^#' "$LIST" | grep . | tr '\n' '\0' | xargs -0 -P "$JOBS" -I{} bash -c 'one "$1"' _ {} uptime > "$OUT/load-end.txt"; echo ALLDONE > "$OUT/done.txt"