joeylib2/scripts/verify-sdl3-input.sh
2026-10-13 14:01:46 -05:00

62 lines
2.3 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-sdl3-input.sh - Headless typed-character acceptance gate for the
# SDL3 port. Runs KEYS on a private Xvfb display through SDL's X11 driver at
# one window pixel per stage pixel (JOEYLIB_SCALE=1, JOEYLIB_ASPECT=square),
# types the RetroNet definition-of-done string with xdotool (real X key
# events through XTEST, shift and all -- SDL ignores the XSendEvent ones
# `xdotool type --window` sends), grabs the window with ImageMagick, and
# decodes the example's verification scanline (row 198) with
# scripts/lib/keysRow.py, as the DVX gates do.
#
# Usage: scripts/verify-sdl3-input.sh
# Requires: Xvfb, xdotool, ImageMagick, python3 + PIL; build/sdl3/bin/KEYS
# (make sdl3).
set -euo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
target="192.168.1.10:6510"
program=$(joeyExampleProgram keys sdl3)
[ -x "$program" ] || { echo "verify-sdl3-input: build KEYS first (make sdl3)" >&2; exit 2; }
work=$(mktemp -d -t joeylib-sdl3-input.XXXXXX)
displayNum=$((RANDOM % 500 + 300))
cleanup() {
joeyStop "${keysPid:-}"
[ -n "${xvfbPid:-}" ] && kill "$xvfbPid" 2>/dev/null
rm -rf "$work"
}
trap cleanup EXIT
Xvfb ":$displayNum" -screen 0 1024x768x24 -nolisten tcp >/dev/null 2>&1 &
xvfbPid=$!
sleep 1
DISPLAY=":$displayNum" SDL_VIDEO_DRIVER=x11 SDL_AUDIO_DRIVER=dummy JOEYLIB_SCALE=1 JOEYLIB_ASPECT=square \
"$program" >"$work/keys.log" 2>&1 &
keysPid=$!
sleep 3
win=$(joeyFindWindow ":$displayNum" "$keysPid") || true
if [ -z "$win" ]; then
echo "verify-sdl3-input: FAIL - KEYS window not found" >&2
exit 1
fi
# No window manager: give the window the keyboard directly.
DISPLAY=":$displayNum" xdotool windowfocus --sync "$win"
DISPLAY=":$displayNum" xdotool type --delay 150 -- "$target"
sleep 2
DISPLAY=":$displayNum" import -window "$win" "$work/keys.png"
# The stage at one pixel a pixel: the row must be exactly at (0,198).
if python3 "$repo/scripts/lib/keysRow.py" "$work/keys.png" "$target" --size 320x200 --at 0,198 --scale 1; then
echo "verify-sdl3-input: PASS (typed \"$target\", all ${#target} chars arrived via jlInputGetChar)"
else
echo "verify-sdl3-input: FAIL" >&2
exit 1
fi