joeylib2/scripts/verify-win16-serial-fast.sh

70 lines
2.6 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-win16-serial-fast.sh - the Win16 port's serial throughput and loss
# gate. SERFAST (SERTEST at 115200, make/examples.mk) runs on Windows 3.11
# under DOSBox with COM1 a nullmodem to the host peer
# (scripts/lib/serialLoopPeer.py), and the KPCOMM driver every Win16 run gets
# (win16Stage), which takes a COM port past 57600. After the banner and the
# probe's echo the peer streams STREAM_BYTES bytes through SERTEST's echo, a
# window at a time, and every one must come back once and in order, at no
# less than three quarters of what 115200 baud carries. The rate was measured
# once by hand when KPCOMM came in (11485 bytes a second echoed); this keeps
# it, and its loss, under test.
#
# Usage: scripts/verify-win16-serial-fast.sh
# Env: WIN16_SERIAL_PORT the nullmodem's TCP port (default 6805)
# Exit: 0 PASS, 1 FAIL, 2 SKIP
# Requires: Windows on DOSBox (install.sh install emulator:win16), python3;
# the win16 toolchain (it builds SERFAST.EXE, make win16-serfast).
set -uo pipefail
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
source "$repo/scripts/lib/joeyEnv.sh"
source "$repo/scripts/lib/win16Gate.sh"
label=verify-win16-serial-fast
win16Need
make -s -f "$repo/make/win16.mk" win16-serfast || {
echo "$label: FAIL - building SERFAST.EXE failed" >&2
exit 1
}
program=$(find "$repo/build/win16/test" -name SERFAST.EXE | head -1)
[ -f "$program" ] || { echo "$label: FAIL - no SERFAST.EXE after the build" >&2; exit 1; }
port="${WIN16_SERIAL_PORT:-6805}"
baud=115200
streamBytes=16384
# The peer's budget: Windows' boot, the banner and the echo, then the stream.
wall=120
work=$(mktemp -d -t joeylib-win16-serial-fast.XXXXXX)
peerPid=""
cleanup() {
joeyStop "$peerPid"
win16Stop
rm -rf "$work"
}
trap cleanup EXIT
python3 "$repo/scripts/lib/serialLoopPeer.py" tcp-server "$port" "$wall" --stream "$streamBytes" --rate "$baud" > "$work/peer.log" 2>&1 &
peerPid=$!
sleep 1
mkdir -p "$work/program"
cp "$program" "$work/program/SERFAST.EXE"
win16Stage "$work" "$work/program" SERFAST.EXE
# transparent:1 -- the bytes alone, no modem lines in the stream.
WIN16_DOSBOX_ARGS=(--set "serial1=nullmodem server:127.0.0.1 port:$port transparent:1")
win16Start "$work"
wait "$peerPid"
rc=$?
peerPid=""
cat "$work/peer.log"
if [ "$rc" -eq 0 ]; then
echo "$label: PASS ($streamBytes bytes through COM1 at $baud baud and back, none lost)"
else
echo "$label: FAIL" >&2
fi
exit "$rc"