1#!/usr/bin/sh 2 3set -eux 4 5SOCAT="$1" 6SERVER="$2" 7 8# Meet DBus bus and path name constraints, append own PID for parallel runs 9TEST_NAME="$(basename "$0" | tr '-' '_')"_${$} 10TEST_DIR="$(mktemp --tmpdir --directory "${TEST_NAME}.XXXXXX")" 11PTYS_PID="" 12SERVER_PID="" 13 14cd "$TEST_DIR" 15 16cleanup() 17{ 18 [ -z "$SERVER_PID" ] || kill -s INT "$SERVER_PID" 19 [ -z "$PTYS_PID" ] || kill "$PTYS_PID" 20 wait 21 cd - 22 rm -rf "$TEST_DIR" 23} 24 25trap cleanup EXIT 26 27TEST_CONF="${TEST_NAME}.conf" 28TEST_LOG="${TEST_NAME}.log" 29BLOCK_SIZE=1024 30LOG_MAX_SIZE=$((5 * $BLOCK_SIZE)) 31 32cat <<EOF > "$TEST_CONF" 33logfile = $TEST_LOG 34console-id = $TEST_NAME 35logsize = $LOG_MAX_SIZE 36EOF 37 38dd if=/dev/zero bs=$BLOCK_SIZE count=$(($LOG_MAX_SIZE / $BLOCK_SIZE)) >> "$TEST_LOG" 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 48echo console-should-log-to-file-legacy-syntax > remote 49sleep 1 50grep -LF console-should-log-to-file-legacy-syntax "$TEST_LOG" 51 52[ -e "$TEST_LOG" ] && [ $(stat -c%s "$TEST_LOG") -le $LOG_MAX_SIZE ] 53