xref: /openbmc/obmc-console/test/test-console-logs-to-file (revision 366651d9ef0e03f97b1e1d2b6188f2b452044d1c)
129a8f989SAndrew Jeffery#!/usr/bin/sh
229a8f989SAndrew Jeffery
329a8f989SAndrew Jefferyset -eux
429a8f989SAndrew Jeffery
529a8f989SAndrew JefferySOCAT="$1"
629a8f989SAndrew JefferySERVER="$2"
729a8f989SAndrew Jeffery
829a8f989SAndrew Jeffery# Meet DBus bus and path name constraints, append own PID for parallel runs
929a8f989SAndrew JefferyTEST_NAME="$(basename "$0" | tr '-' '_')"_${$}
1029a8f989SAndrew JefferyTEST_DIR="$(mktemp --tmpdir --directory "${TEST_NAME}.XXXXXX")"
1129a8f989SAndrew JefferyPTYS_PID=""
1229a8f989SAndrew JefferySERVER_PID=""
1329a8f989SAndrew Jeffery
1429a8f989SAndrew Jefferycd "$TEST_DIR"
1529a8f989SAndrew Jeffery
1629a8f989SAndrew Jefferycleanup()
1729a8f989SAndrew Jeffery{
1829a8f989SAndrew Jeffery  [ -z "$SERVER_PID" ] || kill -s INT "$SERVER_PID"
1929a8f989SAndrew Jeffery  [ -z "$PTYS_PID" ] || kill "$PTYS_PID"
2029a8f989SAndrew Jeffery  wait
2129a8f989SAndrew Jeffery  cd -
2229a8f989SAndrew Jeffery  rm -rf "$TEST_DIR"
2329a8f989SAndrew Jeffery}
2429a8f989SAndrew Jeffery
2529a8f989SAndrew Jefferytrap cleanup EXIT
2629a8f989SAndrew Jeffery
2729a8f989SAndrew JefferyTEST_CONF="${TEST_NAME}.conf"
2829a8f989SAndrew JefferyTEST_LOG="${TEST_NAME}.log"
29*366651d9SMarshall ZhanBLOCK_SIZE=1024
30*366651d9SMarshall ZhanLOG_MAX_SIZE=$((5 * $BLOCK_SIZE))
3129a8f989SAndrew Jeffery
3229a8f989SAndrew Jefferycat <<EOF > "$TEST_CONF"
3329a8f989SAndrew Jefferyactive-console = $TEST_NAME
34*366651d9SMarshall Zhanlogsize = $LOG_MAX_SIZE
3529a8f989SAndrew Jeffery[$TEST_NAME]
3629a8f989SAndrew Jefferylogfile = $TEST_LOG
3729a8f989SAndrew Jefferyconsole-id = $TEST_NAME
3829a8f989SAndrew JefferyEOF
3929a8f989SAndrew Jeffery
40*366651d9SMarshall Zhandd if=/dev/zero bs=$BLOCK_SIZE count=$(($LOG_MAX_SIZE / $BLOCK_SIZE)) >> "$TEST_LOG"
41*366651d9SMarshall Zhan
4229a8f989SAndrew Jeffery"$SOCAT" -u PTY,raw,echo=0,link=remote PTY,raw,echo=0,wait-slave,link=local &
4329a8f989SAndrew JefferyPTYS_PID="$!"
4429a8f989SAndrew Jefferywhile ! [ -e remote ] || ! [ -e local ]; do sleep 1; done
4529a8f989SAndrew Jeffery
4629a8f989SAndrew Jeffery"$SERVER" --config "$TEST_CONF" "$(realpath local)" &
4729a8f989SAndrew JefferySERVER_PID="$!"
4829a8f989SAndrew Jefferywhile ! busctl status --user xyz.openbmc_project.Console."${TEST_NAME}"; do sleep 1; done
4929a8f989SAndrew Jeffery
5029a8f989SAndrew Jefferyecho console-should-log-to-file > remote
5129a8f989SAndrew Jefferysleep 1
5229a8f989SAndrew Jefferygrep -LF console-should-log-to-file "$TEST_LOG"
53*366651d9SMarshall Zhan
54*366651d9SMarshall Zhan[ -e "$TEST_LOG" ] && [ $(stat -c%s "$TEST_LOG") -le $LOG_MAX_SIZE ]
55