joeylib2/scripts/verify-amiga-serial.sh

72 lines
2.7 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-amiga-serial.sh - both-directions RS-232 gate for the Amiga port.
#
# Boots SerTest (examples/sertest: banner, then echo) off a directory hard
# drive in FS-UAE with the serial port on a TCP socket, and has the host
# peer (tests/gate/serialLoopPeer.c) wait for the banner, send a probe and
# expect it echoed. That exercises the chain: m68k-amigaos-gcc -> AmigaDOS ->
# serial.device -> JoeyLib serial HAL -> Paula's UART -> host.
#
# Kickstart 3.1 has no serial.device in ROM: AmigaOS loads it from DEVS:, so
# the boot drive gets Devs/serial.device from the installer (amigaSerial).
#
# Usage: scripts/verify-amiga-serial.sh
# Env: AMIGA_SERIAL_PORT TCP port FS-UAE listens on (default 6801)
# Requires: fs-uae, Xvfb; build/amiga/bin/SerTest (make amiga); the
# Kickstart and serial.device (install.sh install emulator:amiga).
set -uo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
joeyNeed FSUAE fsuae
source "$repo/scripts/lib/amigaGate.sh"
amigaMachine
joeyNeed AMIGA_SERIAL_DEVICE amigaSerial
bin="$repo/build/amiga/bin/SerTest"
port="${AMIGA_SERIAL_PORT:-6801}"
wall=60
[ -f "$bin" ] || { echo "verify-amiga-serial: build SerTest first (make amiga)" >&2; exit 2; }
work=$(mktemp -d -t joeylib-amiga-serial.XXXXXX)
cleanup() {
joeyStop "${fsuaePid:-}"
joeyStop "${xvfbPid:-}"
rm -rf "$work"
}
trap cleanup EXIT
mkdir -p "$work/hd/s" "$work/hd/Devs" "$work/home"
cp "$bin" "$work/hd/SerTest"
cp "$AMIGA_SERIAL_DEVICE" "$work/hd/Devs/serial.device"
printf 'stack 32768\n:SerTest\n' > "$work/hd/s/startup-sequence"
display=":$((RANDOM % 400 + 1700))"
Xvfb "$display" -screen 0 800x600x24 -nolisten tcp >/dev/null 2>&1 &
xvfbPid=$!
sleep 1
# serial_port tcp://.../wait: FS-UAE listens and holds the emulation until
# the peer connects, so the banner is never sent to nobody.
HOME="$work/home" DISPLAY="$display" SDL_AUDIODRIVER=dummy ALSOFT_DRIVERS=null "$FSUAE" \
"${AMIGA_MACHINE_ARGS[@]}" \
--hard_drive_0="$work/hd" --hard_drive_0_label=JOEYLIB \
--fade_out_duration=0 --joystick_port_0=none --joystick_port_1=none \
--amiga_enable_serial_port=1 --serial_port="tcp://127.0.0.1:$port/wait" \
> "$work/fsuae.log" 2>&1 &
fsuaePid=$!
result=$("$(joeyTool serialLoopPeer)" tcp-client "$port" "$wall")
rc=$?
echo "$result"
if [ "$rc" -eq 0 ]; then
echo "verify-amiga-serial: PASS (banner out, probe echoed through serial.device)"
else
echo "verify-amiga-serial: FAIL" >&2
tail -n 5 "$work/fsuae.log" >&2
fi
exit "$rc"