test: console socket read
Change-Id: Ic7c2035640db4e403afe9db01a33ccb532d195d6
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/test/meson.build b/test/meson.build
index e890313..7c92ff8 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -35,13 +35,19 @@
socat = find_program('socat', native: true)
-meson.override_find_program('test-console-logs-to-file', files('test-console-logs-to-file'))
-test('test-console-logs-to-file',
- find_program('test-console-logs-to-file'),
- args: [ socat.full_path(), server.full_path() ],
- depends: [ server ],
- suite: 'itests'
-)
+server_tests = [
+ 'test-console-logs-to-file',
+ 'test-console-socket-read',
+]
+
+foreach st : server_tests
+ test(st,
+ find_program(st),
+ args: [ socat.full_path(), server.full_path() ],
+ depends: [ server ],
+ suite: 'itests'
+ )
+endforeach
client_tests = [
'test-console-client-can-read',
diff --git a/test/test-console-socket-read b/test/test-console-socket-read
new file mode 100755
index 0000000..a1119eb
--- /dev/null
+++ b/test/test-console-socket-read
@@ -0,0 +1,58 @@
+#!/usr/bin/sh
+
+set -eux
+
+SOCAT="$1"
+SERVER="$2"
+
+# Meet DBus bus and path name constraints, append own PID for parallel runs
+TEST_NAME="$(basename "$0" | tr '-' '_')"_${$}
+TEST_DIR="$(mktemp --tmpdir --directory "${TEST_NAME}.XXXXXX")"
+
+PTYS_PID=""
+SUN_PID=""
+SERVER_PID=""
+
+cd "$TEST_DIR"
+
+cleanup()
+{
+ [ -z "$SUN_PID" ] || kill "$SUN_PID"
+ [ -z "$SERVER_PID" ] || kill "$SERVER_PID"
+ [ -z "$PTYS_PID" ] || kill "$PTYS_PID"
+ wait
+ cd -
+ rm -rf "$TEST_DIR"
+}
+
+trap cleanup EXIT
+
+TEST_CONF="${TEST_NAME}.conf"
+TEST_LOG="${TEST_NAME}.log"
+
+cat <<EOF > "$TEST_CONF"
+active-console = $TEST_NAME
+[$TEST_NAME]
+console-id = $TEST_NAME
+logfile = $TEST_LOG
+EOF
+
+"$SOCAT" PTY,raw,echo=0,link=remote PTY,raw,echo=0,wait-slave,link=local &
+PTYS_PID="$!"
+while ! [ -e remote ] || ! [ -e local ]; do sleep 1; done
+
+"$SERVER" --config "$TEST_CONF" "$(realpath local)" &
+SERVER_PID="$!"
+while ! busctl status --user xyz.openbmc_project.Console."${TEST_NAME}"; do sleep 1; done
+
+"$SOCAT" -u "ABSTRACT:obmc-console.${TEST_NAME}" EXEC:'grep -m1 -qF socket-read' &
+SUN_PID="$!"
+
+sleep 1
+
+echo "socket-read" > remote
+
+sleep 1
+
+kill -0 "$SUN_PID" && exit 1
+SUN_PID=""