aboutsummaryrefslogtreecommitdiffstats
path: root/tests/run_test.sh
blob: 85eb291d41768190b144d51ab671c82a57733a64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
# ---------------------------------------------------------------
# Integration-test helper for OPC UA discovery.
#
# Usage:  tests/run_test.sh <config_dir> <expected_policy>
#
#   config_dir       — directory containing server_lds.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",
#                      or "None")
#
# Exit: 0 when all checks pass, 1 on any failure.
# ---------------------------------------------------------------
set -uo pipefail
# NOTE: we intentionally omit "set -e" so that every check runs
# even if the client itself returns non-zero.

source "$(dirname "$0")/test_helpers.sh"

CONFIG_DIR="${1:?Usage: $0 <config_dir> <expected_policy>}"
EXPECTED_POLICY="${2:?Usage: $0 <config_dir> <expected_policy>}"

LDS_PORT=14840
SR_PORT=14841
LDS_PID=""
SR_PID=""
TMPFILE=""

# ── cleanup ────────────────────────────────────────────────────
cleanup() {
  [ -n "$LDS_PID" ] && kill "$LDS_PID" 2>/dev/null && wait "$LDS_PID" 2>/dev/null
  [ -n "$SR_PID" ] && kill "$SR_PID" 2>/dev/null && wait "$SR_PID" 2>/dev/null
  [ -n "$TMPFILE" ] && rm -f "$TMPFILE"
}
trap cleanup EXIT

assert_ports_free "$LDS_PORT" "$SR_PORT"

# ── start LDS ──────────────────────────────────────────────────
build/bobink_opcua_discovery_server "$CONFIG_DIR/server_lds.conf" >/dev/null 2>&1 &
LDS_PID=$!
wait_for_port "$LDS_PORT" "$LDS_PID" "bobink_opcua_discovery_server"

# ── start ServerRegister ───────────────────────────────────────
build/bobink_opcua_server "$CONFIG_DIR/server_register.conf" "$CONFIG_DIR/server_register_client.conf" "opc.tcp://localhost:$LDS_PORT" >/dev/null 2>&1 &
SR_PID=$!
wait_for_port "$SR_PORT" "$SR_PID" "bobink_opcua_server"

# ── FindServers ───────────────────────────────────────────────
TMPFILE=$(mktemp)
build/bobink_opcua_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:localhost:bobink:ServerRegister"
check "find-servers contains urn:localhost:bobink:ServerRegister" $?

# ── GetEndpoints ──────────────────────────────────────────────
build/bobink_opcua_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" $?

# ── ReadTime ──────────────────────────────────────────────────
build/bobink_opcua_client "$CONFIG_DIR/client.conf" read-time "opc.tcp://localhost:$SR_PORT" >"$TMPFILE" 2>&1
RT_RC=$?
RT_OUTPUT=$(<"$TMPFILE")

[ "$RT_RC" -eq 0 ]
check "read-time exit code is 0 (got $RT_RC)" $?

echo "$RT_OUTPUT" | grep -q "date is:"
check "read-time output contains 'date is:'" $?

# ── result ─────────────────────────────────────────────────────
if [ "$FAILURES" -ne 0 ]; then
  echo ""
  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
exit 0