1*c7602e0aSAlexander Hansen#!/usr/bin/sh
2*c7602e0aSAlexander Hansen
3*c7602e0aSAlexander Hansenset -eux
4*c7602e0aSAlexander Hansen
5*c7602e0aSAlexander HansenSOCAT="$1"
6*c7602e0aSAlexander HansenSERVER="$2"
7*c7602e0aSAlexander Hansen
8*c7602e0aSAlexander Hansen# Meet DBus bus and path name constraints, append own PID for parallel runs
9*c7602e0aSAlexander HansenTEST_NAME="$(basename "$0" | tr '-' '_')"_${$}
10*c7602e0aSAlexander HansenTEST_DIR="$(mktemp --tmpdir --directory "${TEST_NAME}.XXXXXX")"
11*c7602e0aSAlexander Hansen
12*c7602e0aSAlexander HansenPTY_PID=""
13*c7602e0aSAlexander HansenSERVER_PID=""
14*c7602e0aSAlexander Hansen
15*c7602e0aSAlexander Hansencd "$TEST_DIR"
16*c7602e0aSAlexander Hansen
17*c7602e0aSAlexander Hansencleanup()
18*c7602e0aSAlexander Hansen{
19*c7602e0aSAlexander Hansen  [ -z "$SERVER_PID" ] || kill "$SERVER_PID" || true
20*c7602e0aSAlexander Hansen  [ -z "$PTY_PID" ] || kill "$PTY_PID"
21*c7602e0aSAlexander Hansen
22*c7602e0aSAlexander Hansen  wait
23*c7602e0aSAlexander Hansen  cd -
24*c7602e0aSAlexander Hansen  rm -rf "$TEST_DIR"
25*c7602e0aSAlexander Hansen}
26*c7602e0aSAlexander Hansen
27*c7602e0aSAlexander Hansentrap cleanup EXIT
28*c7602e0aSAlexander Hansen
29*c7602e0aSAlexander HansenTEST_CONF="${TEST_NAME}.conf"
30*c7602e0aSAlexander HansenTEST_LOG="${TEST_NAME}.log"
31*c7602e0aSAlexander Hansen
32*c7602e0aSAlexander Hansencat <<EOF > "$TEST_CONF"
33*c7602e0aSAlexander Hansenactive-console = $TEST_NAME
34*c7602e0aSAlexander Hansen[$TEST_NAME]
35*c7602e0aSAlexander Hansenconsole-id = $TEST_NAME
36*c7602e0aSAlexander Hansenlogfile = $TEST_LOG
37*c7602e0aSAlexander HansenEOF
38*c7602e0aSAlexander Hansen
39*c7602e0aSAlexander Hansen"$SOCAT" PTY,raw,echo=0,link=local EXEC:'grep -m1 -qF socket-write' &
40*c7602e0aSAlexander HansenPTY_PID="$!"
41*c7602e0aSAlexander Hansenwhile ! [ -e local ]; do sleep 1; done
42*c7602e0aSAlexander Hansen
43*c7602e0aSAlexander Hansen"$SERVER" --config "$TEST_CONF" "$(realpath local)" &
44*c7602e0aSAlexander HansenSERVER_PID="$!"
45*c7602e0aSAlexander Hansenwhile ! busctl status --user xyz.openbmc_project.Console."${TEST_NAME}"; do sleep 1; done
46*c7602e0aSAlexander Hansen
47*c7602e0aSAlexander Hansensleep 1
48*c7602e0aSAlexander Hansen
49*c7602e0aSAlexander Hansenecho socket-write | socat -u - "ABSTRACT:obmc-console.${TEST_NAME}"
50*c7602e0aSAlexander Hansen
51*c7602e0aSAlexander Hansensleep 1
52*c7602e0aSAlexander Hansen
53*c7602e0aSAlexander Hansenkill -0 "$PTY_PID" && exit 1
54*c7602e0aSAlexander HansenPTY_PID=""
55