1#!/usr/bin/sh 2 3set -eux 4 5SOCAT="$1" 6SERVER="$2" 7CLIENT="$3" 8 9# Meet DBus bus and path name constraints, append own PID for parallel runs 10TEST_NAME="$(basename "$0" | tr '-' '_')"_${$} 11TEST_DIR="$(mktemp --tmpdir --directory "${TEST_NAME}.XXXXXX")" 12PTYS_PID="" 13SERVER_PID="" 14CLIENT_PID="" 15 16cd "$TEST_DIR" 17 18cleanup() 19{ 20 [ -z "$CLIENT_PID" ] || kill "$CLIENT_PID" 21 [ -z "$SERVER_PID" ] || kill "$SERVER_PID" 22 [ -z "$PTYS_PID" ] || kill "$PTYS_PID" 23 wait 24 cd - 25 rm -rf "$TEST_DIR" 26} 27 28trap cleanup EXIT 29 30TEST_CONF="${TEST_NAME}.conf" 31TEST_LOG="${TEST_NAME}.log" 32 33cat <<EOF > "$TEST_CONF" 34active-console = $TEST_NAME 35[$TEST_NAME] 36console-id = $TEST_NAME 37logfile = $TEST_LOG 38EOF 39 40"$SOCAT" -u PTY,raw,echo=0,link=remote PTY,raw,echo=0,wait-slave,link=local & 41PTYS_PID="$!" 42while ! [ -e remote ] || ! [ -e local ]; do sleep 1; done 43 44"$SERVER" --config "$TEST_CONF" "$(realpath local)" & 45SERVER_PID="$!" 46while ! busctl status --user xyz.openbmc_project.Console."${TEST_NAME}"; do sleep 1; done 47 48$SOCAT EXEC:"$CLIENT -i $TEST_NAME" EXEC:'grep -m1 -qF client-reads-this' & 49CLIENT_PID="$!" 50 51sleep 1 52 53echo client-reads-this > remote 54 55sleep 1 56 57# If we can signal the process, the test has failed. 58# The 'grep -m1' should have ended the process when the message was read. 59kill -0 "$CLIENT_PID" && exit 1 60CLIENT_PID="" 61