joeylib2/scripts/verify-sdl3-input.sh

86 lines
3.4 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
# tests/gate/keysRow.c, as the DVX gates do. Then the named keys a second
# physical key gives: the keypad's 8, 2, 4, and 6 as the arrows, its Enter
# as Return, and the right Ctrl and Alt as Ctrl and Alt, each held alone,
# and Up and the keypad's 8 held together with either let go first, which
# must leave Up down -- read off KEYS's cells (scripts/lib/keysGate.sh,
# tests/gate/keysCells.c).
#
# Usage: scripts/verify-sdl3-input.sh
# Requires: Xvfb, xdotool, ImageMagick; build/sdl3/bin/KEYS
# (make sdl3).
set -euo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
source "$repo/scripts/lib/keysGate.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 ! "$(joeyTool keysRow)" "$work/keys.png" "$target" --size 320x200 --at 0,198 --scale 1; then
echo "verify-sdl3-input: FAIL" >&2
exit 1
fi
# X's names for the keys (scripts/lib/keysGate.sh's).
declare -A xKey=([up]=Up [kp8]=KP_Up [kp2]=KP_Down [kp4]=KP_Left [kp6]=KP_Right [kpenter]=KP_Enter [rctrl]=Control_R [ralt]=Alt_R)
KEYS_LABEL=verify-sdl3-input
keysPress() {
DISPLAY=":$displayNum" xdotool keydown "${xKey[$1]}"
}
keysRelease() {
DISPLAY=":$displayNum" xdotool keyup "${xKey[$1]}"
}
keysRead() {
DISPLAY=":$displayNum" import -window "$win" "$work/cells.png"
"$(joeyTool keysCells)" "$work/cells.png"
}
keysRunSteps kp8 kp2 kp4 kp6 kpenter rctrl ralt
if [ -n "$KEYS_FAILS" ]; then
echo "verify-sdl3-input: FAIL - $KEYS_FAILS" >&2
exit 1
fi
echo "verify-sdl3-input: PASS (typed \"$target\", all ${#target} chars arrived via jlInputGetChar; $KEYS_STEPS named-key steps: the keypad's arrows and Enter, right Ctrl and Alt, Up held with its second key)"