xref: /openbmc/obmc-console/test/test-console-logs-to-file-no-sections (revision 366651d9ef0e03f97b1e1d2b6188f2b452044d1c)
16498f9faSAlexander Hansen#!/usr/bin/sh
26498f9faSAlexander Hansen
36498f9faSAlexander Hansenset -eux
46498f9faSAlexander Hansen
56498f9faSAlexander HansenSOCAT="$1"
66498f9faSAlexander HansenSERVER="$2"
76498f9faSAlexander Hansen
86498f9faSAlexander Hansen# Meet DBus bus and path name constraints, append own PID for parallel runs
96498f9faSAlexander HansenTEST_NAME="$(basename "$0" | tr '-' '_')"_${$}
106498f9faSAlexander HansenTEST_DIR="$(mktemp --tmpdir --directory "${TEST_NAME}.XXXXXX")"
116498f9faSAlexander HansenPTYS_PID=""
126498f9faSAlexander HansenSERVER_PID=""
136498f9faSAlexander Hansen
146498f9faSAlexander Hansencd "$TEST_DIR"
156498f9faSAlexander Hansen
166498f9faSAlexander Hansencleanup()
176498f9faSAlexander Hansen{
186498f9faSAlexander Hansen  [ -z "$SERVER_PID" ] || kill -s INT "$SERVER_PID"
196498f9faSAlexander Hansen  [ -z "$PTYS_PID" ] || kill "$PTYS_PID"
206498f9faSAlexander Hansen  wait
216498f9faSAlexander Hansen  cd -
226498f9faSAlexander Hansen  rm -rf "$TEST_DIR"
236498f9faSAlexander Hansen}
246498f9faSAlexander Hansen
256498f9faSAlexander Hansentrap cleanup EXIT
266498f9faSAlexander Hansen
276498f9faSAlexander HansenTEST_CONF="${TEST_NAME}.conf"
286498f9faSAlexander HansenTEST_LOG="${TEST_NAME}.log"
29*366651d9SMarshall ZhanBLOCK_SIZE=1024
30*366651d9SMarshall ZhanLOG_MAX_SIZE=$((5 * $BLOCK_SIZE))
316498f9faSAlexander Hansen
326498f9faSAlexander Hansencat <<EOF > "$TEST_CONF"
336498f9faSAlexander Hansenlogfile = $TEST_LOG
346498f9faSAlexander Hansenconsole-id = $TEST_NAME
35*366651d9SMarshall Zhanlogsize = $LOG_MAX_SIZE
366498f9faSAlexander HansenEOF
376498f9faSAlexander Hansen
38*366651d9SMarshall Zhandd if=/dev/zero bs=$BLOCK_SIZE count=$(($LOG_MAX_SIZE / $BLOCK_SIZE)) >> "$TEST_LOG"
39*366651d9SMarshall Zhan
406498f9faSAlexander Hansen"$SOCAT" -u PTY,raw,echo=0,link=remote PTY,raw,echo=0,wait-slave,link=local &
416498f9faSAlexander HansenPTYS_PID="$!"
426498f9faSAlexander Hansenwhile ! [ -e remote ] || ! [ -e local ]; do sleep 1; done
436498f9faSAlexander Hansen
446498f9faSAlexander Hansen"$SERVER" --config "$TEST_CONF" "$(realpath local)" &
456498f9faSAlexander HansenSERVER_PID="$!"
466498f9faSAlexander Hansenwhile ! busctl status --user xyz.openbmc_project.Console."${TEST_NAME}"; do sleep 1; done
476498f9faSAlexander Hansen
486498f9faSAlexander Hansenecho console-should-log-to-file-legacy-syntax > remote
496498f9faSAlexander Hansensleep 1
506498f9faSAlexander Hansengrep -LF console-should-log-to-file-legacy-syntax "$TEST_LOG"
51*366651d9SMarshall Zhan
52*366651d9SMarshall Zhan[ -e "$TEST_LOG" ] && [ $(stat -c%s "$TEST_LOG") -le $LOG_MAX_SIZE ]
53