aboutsummaryrefslogtreecommitdiffstats
path: root/tests/run_test.sh
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-02-19 00:01:18 +0100
committerThomas Vanbesien <tvanbesi@proton.me>2026-02-19 00:01:18 +0100
commitf3648fefe040152bb1676d651ebf7d836cb8ac9e (patch)
treea656270416167c3a15e61f937c27093a7fb05bf0 /tests/run_test.sh
parent965db7e3243aecb02f7f57b4fe8dabe9ad50a697 (diff)
downloadBobinkCOpcUa-f3648fefe040152bb1676d651ebf7d836cb8ac9e.tar.gz
BobinkCOpcUa-f3648fefe040152bb1676d651ebf7d836cb8ac9e.zip
Refactor: reduce duplication and tighten helpers
- Remove redundant applicationUri log in print_application_description - Use UA_SECURITY_POLICY_NONE_URI macro instead of hardcoded string - Extract _s_register_with_lds / _s_deregister_from_lds helpers - Rename signal handler param 'sign' to 'sig' for consistency - Add INT_MIN/INT_MAX bounds check to config_require_int - Extract shared test helpers into tests/test_helpers.sh
Diffstat (limited to 'tests/run_test.sh')
-rwxr-xr-xtests/run_test.sh40
1 files changed, 3 insertions, 37 deletions
diff --git a/tests/run_test.sh b/tests/run_test.sh
index 6d17958..8f6c21b 100755
--- a/tests/run_test.sh
+++ b/tests/run_test.sh
@@ -18,6 +18,8 @@ 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>}"
@@ -26,7 +28,6 @@ SR_PORT=14841
LDS_PID=""
SR_PID=""
TMPFILE=""
-FAILURES=0
# ── cleanup ────────────────────────────────────────────────────
cleanup() {
@@ -36,31 +37,7 @@ 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
- echo "FAIL: port $port is already in use"
- exit 1
- fi
-done
+assert_ports_free "$LDS_PORT" "$SR_PORT"
# ── start LDS ──────────────────────────────────────────────────
build/bobink_opcua_discovery_server "$CONFIG_DIR/server_lds.conf" >/dev/null 2>&1 &
@@ -72,17 +49,6 @@ build/bobink_opcua_server "$CONFIG_DIR/server_register.conf" "$CONFIG_DIR/server
SR_PID=$!
wait_for_port "$SR_PORT" "$SR_PID" "bobink_opcua_server"
-# ── validation helper ─────────────────────────────────────────
-check() {
- local label="$1" result="$2"
- if [ "$result" -eq 0 ]; then
- echo "PASS: $label"
- else
- echo "FAIL: $label"
- FAILURES=$((FAILURES + 1))
- fi
-}
-
# ── FindServers ───────────────────────────────────────────────
TMPFILE=$(mktemp)
build/client "$CONFIG_DIR/client.conf" find-servers "opc.tcp://localhost:$LDS_PORT" >"$TMPFILE" 2>&1