59 lines
1.9 KiB
Bash
Executable file
59 lines
1.9 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-win32-serial.sh - both-directions RS-232 gate for the Win32 port.
|
|
#
|
|
# Runs SERTEST.EXE (examples/sertest: banner, then echo) under Wine with
|
|
# COM1 joined to the host peer (scripts/lib/serialLoopPeer.py) through a
|
|
# pseudo-terminal: the peer makes the pty pair, and the Wine prefix's COM1 is
|
|
# mapped to the guest end (wineComPort), so the program's CreateFile("COM1")
|
|
# opens it. The peer waits for the banner, sends a probe and expects it
|
|
# echoed: the chain is JoeyLib's Win32 serial HAL -> the Win32 comms calls
|
|
# -> Wine -> the pty -> the host.
|
|
#
|
|
# Usage: scripts/verify-win32-serial.sh
|
|
# Requires: Wine, python3; build/win32/bin/SERTEST.EXE (make win32).
|
|
set -uo pipefail
|
|
|
|
repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
|
source "$repo/scripts/lib/joeyEnv.sh"
|
|
source "$repo/scripts/lib/wineGate.sh"
|
|
wineNeed
|
|
|
|
program=$(joeyExampleProgram sertest win32)
|
|
[ -f "$program" ] || { echo "verify-win32-serial: build SERTEST.EXE first (make win32)" >&2; exit 2; }
|
|
wall=40
|
|
ptyWaitTries=40
|
|
|
|
work=$(mktemp -d -t joeylib-win32-serial.XXXXXX)
|
|
peerPid=""
|
|
cleanup() {
|
|
joeyStop "$peerPid"
|
|
wineStop
|
|
rm -rf "$work"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
wineStart "$work"
|
|
python3 "$repo/scripts/lib/serialLoopPeer.py" pty "$work/pty.path" "$wall" > "$work/peer.log" 2>&1 &
|
|
peerPid=$!
|
|
for ((tries = 0; tries < ptyWaitTries; tries++)); do
|
|
[ -s "$work/pty.path" ] && break
|
|
sleep 0.25
|
|
done
|
|
[ -s "$work/pty.path" ] || { echo "verify-win32-serial: FAIL - the peer made no pty" >&2; exit 1; }
|
|
wineComPort 1 "$(cat "$work/pty.path")"
|
|
|
|
wineRun "$program"
|
|
wait "$peerPid"
|
|
peerStatus=$?
|
|
peerPid=""
|
|
cat "$work/peer.log"
|
|
if [ "$peerStatus" -eq 0 ]; then
|
|
echo "verify-win32-serial: PASS (banner out, probe echoed through COM1)"
|
|
else
|
|
echo "verify-win32-serial: FAIL" >&2
|
|
exit 1
|
|
fi
|