aboutsummaryrefslogtreecommitdiffstats
path: root/tests/run_test.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run_test.sh')
-rwxr-xr-xtests/run_test.sh94
1 files changed, 60 insertions, 34 deletions
diff --git a/tests/run_test.sh b/tests/run_test.sh
index 8a87824..ef359ef 100755
--- a/tests/run_test.sh
+++ b/tests/run_test.sh
@@ -5,7 +5,8 @@
# Usage: tests/run_test.sh <config_dir> <expected_policy>
#
# config_dir — directory containing server_lds.conf,
-# server_register.conf, client_find_servers.conf
+# server_register.conf, server_register_client.conf,
+# client.conf
# expected_policy — security-policy string that must appear in
# the client's endpoint listing (e.g.
# "Basic256Sha256", "Aes128_Sha256_RsaOaep",
@@ -35,6 +36,24 @@ cleanup() {
}
trap cleanup EXIT
+# ── helpers ────────────────────────────────────────────────────
+wait_for_port() {
+ local port="$1" pid="$2" label="$3" i=0
+ while [ $i -lt 50 ]; do
+ if ! kill -0 "$pid" 2>/dev/null; then
+ echo "FAIL: $label exited prematurely"
+ exit 1
+ fi
+ if ss -tlnp 2>/dev/null | grep -q ":${port} "; then
+ return 0
+ fi
+ sleep 0.1
+ i=$((i + 1))
+ done
+ echo "FAIL: $label did not listen on port $port within 5 s"
+ exit 1
+}
+
# ── port check ─────────────────────────────────────────────────
for port in $LDS_PORT $SR_PORT; do
if ss -tlnp 2>/dev/null | grep -q ":${port} "; then
@@ -46,29 +65,14 @@ done
# ── start LDS ──────────────────────────────────────────────────
build/ServerLDS "$CONFIG_DIR/server_lds.conf" >/dev/null 2>&1 &
LDS_PID=$!
-sleep 2
-if ! kill -0 "$LDS_PID" 2>/dev/null; then
- echo "FAIL: ServerLDS exited prematurely"
- exit 1
-fi
+wait_for_port "$LDS_PORT" "$LDS_PID" "ServerLDS"
# ── start ServerRegister ───────────────────────────────────────
-build/ServerRegister "$CONFIG_DIR/server_register.conf" >/dev/null 2>&1 &
+build/ServerRegister "$CONFIG_DIR/server_register.conf" "$CONFIG_DIR/server_register_client.conf" "opc.tcp://localhost:$LDS_PORT" >/dev/null 2>&1 &
SR_PID=$!
-sleep 3
-if ! kill -0 "$SR_PID" 2>/dev/null; then
- echo "FAIL: ServerRegister exited prematurely"
- exit 1
-fi
+wait_for_port "$SR_PORT" "$SR_PID" "ServerRegister"
-# ── run client ─────────────────────────────────────────────────
-TMPFILE=$(mktemp)
-# UA_Log_Stdout writes to stdout; capture both stdout and stderr.
-build/ClientFindServers "$CONFIG_DIR/client_find_servers.conf" >"$TMPFILE" 2>&1
-CLIENT_RC=$?
-CLIENT_OUTPUT=$(<"$TMPFILE")
-
-# ── validation checks ─────────────────────────────────────────
+# ── validation helper ─────────────────────────────────────────
check() {
local label="$1" result="$2"
if [ "$result" -eq 0 ]; then
@@ -79,27 +83,49 @@ check() {
fi
}
-# 1. Exit code
-[ "$CLIENT_RC" -eq 0 ]
-check "client exit code is 0 (got $CLIENT_RC)" $?
+# ── FindServers ───────────────────────────────────────────────
+TMPFILE=$(mktemp)
+build/Client "$CONFIG_DIR/client.conf" find-servers "opc.tcp://localhost:$LDS_PORT" >"$TMPFILE" 2>&1
+FS_RC=$?
+FS_OUTPUT=$(<"$TMPFILE")
+
+[ "$FS_RC" -eq 0 ]
+check "find-servers exit code is 0 (got $FS_RC)" $?
+
+echo "$FS_OUTPUT" | grep -q "urn:bobink.ServerRegister"
+check "find-servers contains urn:bobink.ServerRegister" $?
+
+# ── GetEndpoints ──────────────────────────────────────────────
+build/Client "$CONFIG_DIR/client.conf" get-endpoints "opc.tcp://localhost:$SR_PORT" >"$TMPFILE" 2>&1
+GE_RC=$?
+GE_OUTPUT=$(<"$TMPFILE")
+
+[ "$GE_RC" -eq 0 ]
+check "get-endpoints exit code is 0 (got $GE_RC)" $?
+
+echo "$GE_OUTPUT" | grep -q "$EXPECTED_POLICY"
+check "get-endpoints contains $EXPECTED_POLICY" $?
-# 2. FindServers returned the registered server
-echo "$CLIENT_OUTPUT" | grep -q "urn:bobink.ServerRegister"
-check "FindServers contains urn:bobink.ServerRegister" $?
+# ── ReadTime ──────────────────────────────────────────────────
+build/Client "$CONFIG_DIR/client.conf" read-time "opc.tcp://localhost:$SR_PORT" >"$TMPFILE" 2>&1
+RT_RC=$?
+RT_OUTPUT=$(<"$TMPFILE")
-# 3. Client read the current time
-echo "$CLIENT_OUTPUT" | grep -q "date is:"
-check "client read current time" $?
+[ "$RT_RC" -eq 0 ]
+check "read-time exit code is 0 (got $RT_RC)" $?
-# 4. Endpoint lists expected security policy
-echo "$CLIENT_OUTPUT" | grep -q "$EXPECTED_POLICY"
-check "endpoint contains $EXPECTED_POLICY" $?
+echo "$RT_OUTPUT" | grep -q "date is:"
+check "read-time output contains 'date is:'" $?
# ── result ─────────────────────────────────────────────────────
if [ "$FAILURES" -ne 0 ]; then
echo ""
- echo "--- client output ---"
- echo "$CLIENT_OUTPUT"
+ echo "--- find-servers output ---"
+ echo "$FS_OUTPUT"
+ echo "--- get-endpoints output ---"
+ echo "$GE_OUTPUT"
+ echo "--- read-time output ---"
+ echo "$RT_OUTPUT"
echo "--- end ---"
exit 1
fi