joeylib2/scripts/verify-dos-serial.sh
2026-09-28 21:03:46 -05:00

60 lines
2 KiB
Bash
Executable file

#!/usr/bin/env bash
# verify-dos-serial.sh - both-directions RS-232 gate for the DOS port.
#
# Runs SERTEST.EXE (examples/sertest: banner, then echo) in DOSBox Staging
# with COM1 as a nullmodem connecting to the host peer
# (scripts/lib/serialLoopPeer.py), which waits for the banner, sends a probe
# and expects it echoed. That exercises the chain: DJGPP -> DPMI -> JoeyLib's
# interrupt-driven 8250/16550 HAL -> DOSBox's UART -> host.
#
# Usage: scripts/verify-dos-serial.sh
# Env: DOS_SERIAL_PORT TCP port the peer listens on (default 6802)
# Requires: DOSBox Staging, Xvfb; build/dos/bin/SERTEST.EXE (make dos).
set -uo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
joeyNeed DOSBOX dosbox
exe="$repo/build/dos/bin/SERTEST.EXE"
port="${DOS_SERIAL_PORT:-6802}"
wall=38
runSeconds=40 # SERTEST echoes forever: DOSBox ends by timeout
[ -f "$exe" ] || { echo "verify-dos-serial: build SERTEST.EXE first (make dos)" >&2; exit 2; }
work=$(mktemp -d -t joeylib-dos-serial.XXXXXX)
cleanup() {
joeyStop "${peerPid:-}"
joeyStop "${xvfbPid:-}"
rm -rf "$work"
}
trap cleanup EXIT
mkdir -p "$work/c" "$work/xdg"
cp "$exe" "$work/c/SERTEST.EXE"
python3 "$repo/scripts/lib/serialLoopPeer.py" tcp-server "$port" "$wall" > "$work/peer.log" 2>&1 &
peerPid=$!
sleep 1
display=":$((RANDOM % 400 + 1300))"
Xvfb "$display" -screen 0 800x600x24 -nolisten tcp >/dev/null 2>&1 &
xvfbPid=$!
sleep 1
# Foreground under timeout -s KILL, so nothing can outlive the gate.
XDG_CONFIG_HOME="$work/xdg" DISPLAY="$display" SDL_AUDIODRIVER=dummy \
timeout -s KILL "$runSeconds" "$DOSBOX" "${JOEY_DOSBOX_ISOLATE[@]}" \
--set "serial1=nullmodem server:127.0.0.1 port:$port transparent:1" \
-c "MOUNT C $work/c" -c "C:" -c "SERTEST.EXE" -c "exit" > "$work/dosbox.log" 2>&1
wait "$peerPid"
rc=$?
peerPid=""
cat "$work/peer.log"
if [ "$rc" -eq 0 ]; then
echo "verify-dos-serial: PASS (banner out, probe echoed through COM1)"
else
echo "verify-dos-serial: FAIL" >&2
fi
exit "$rc"