Alexander Hansen | 97e7e51 | 2024-08-02 16:44:41 +0200 | [diff] [blame] | 1 | #!/usr/bin/sh |
| 2 | |
| 3 | set -eux |
| 4 | |
| 5 | SOCAT="$1" |
| 6 | SERVER="$2" |
| 7 | |
| 8 | # Meet DBus bus and path name constraints, append own PID for parallel runs |
| 9 | TEST_NAME="$(basename "$0" | tr '-' '_')"_${$} |
| 10 | TEST_DIR="$(mktemp --tmpdir --directory "${TEST_NAME}.XXXXXX")" |
| 11 | PTYS_PID="" |
| 12 | SERVER_PID="" |
| 13 | SUN_PID="" |
| 14 | |
| 15 | cd "$TEST_DIR" |
| 16 | |
| 17 | cleanup() |
| 18 | { |
| 19 | [ -z "$SUN_PID" ] || kill "$SUN_PID" |
| 20 | [ -z "$SERVER_PID" ] || kill "$SERVER_PID" |
| 21 | [ -z "$PTYS_PID" ] || kill "$PTYS_PID" |
| 22 | wait |
| 23 | cd - |
| 24 | rm -rf "$TEST_DIR" |
| 25 | } |
| 26 | |
| 27 | trap cleanup EXIT |
| 28 | |
| 29 | TEST_CONF="${TEST_NAME}.conf" |
| 30 | |
| 31 | TEST_A_NAME="${TEST_NAME}_a" |
| 32 | TEST_A_LOG="${TEST_A_NAME}.log" |
| 33 | |
| 34 | TEST_B_NAME="${TEST_NAME}_b" |
| 35 | TEST_B_LOG="${TEST_B_NAME}.log" |
| 36 | |
| 37 | cat <<EOF > "$TEST_CONF" |
| 38 | active-console = $TEST_A_NAME |
| 39 | [$TEST_A_NAME] |
| 40 | logfile = $TEST_A_LOG |
| 41 | console-id = $TEST_A_NAME |
| 42 | [$TEST_B_NAME] |
| 43 | logfile = $TEST_B_LOG |
| 44 | console-id = $TEST_B_NAME |
| 45 | EOF |
| 46 | |
| 47 | "$SOCAT" -u PTY,raw,echo=0,link=remote PTY,raw,echo=0,wait-slave,link=local & |
| 48 | PTYS_PID="$!" |
| 49 | while ! [ -e remote ] || ! [ -e local ]; do sleep 1; done |
| 50 | |
| 51 | "$SERVER" --config "$TEST_CONF" "$(realpath local)" & |
| 52 | SERVER_PID="$!" |
| 53 | while ! busctl status --user xyz.openbmc_project.Console."${TEST_A_NAME}"; do sleep 1; done |
| 54 | |
| 55 | echo log-for-console-a > remote |
| 56 | |
| 57 | sleep 1 |
| 58 | |
| 59 | grep -LF log-for-console-a "$TEST_A_LOG" |
| 60 | ! grep -F log-for-console-a "$TEST_B_LOG" || exit 1 |
| 61 | |
| 62 | # change the active console |
| 63 | socat -u "ABSTRACT:obmc-console.${TEST_B_NAME}" SYSTEM:'cat > /dev/null' & |
| 64 | SUN_PID="$!" |
| 65 | |
| 66 | sleep 1 |
| 67 | |
| 68 | echo log-for-console-b > remote |
| 69 | |
| 70 | sleep 1 |
| 71 | |
| 72 | grep -LF log-for-console-b "$TEST_B_LOG" |
| 73 | ! grep -F log-for-console-b "$TEST_A_LOG" || exit 1 |