#!/usr/bin/env bash # Real socket test; never use on a host with an active MARS broker. set -euo pipefail cd "$(dirname "$0")/.." [[ $EUID == 0 ]] || { echo 'Use sudo make check-ncp-ip-integration on an isolated test host'; exit 1; } [[ ! -S /run/mars-pcap/transport.sock ]] || { echo 'Existing MARS broker; test aborted'; exit 1; } work=$(mktemp -d); config=$work/ip.json; touch "$config"; chmod 600 "$config"; printf '{"enabled":true,"address":"127.0.0.1","slp":true}' > "$config" unset MARS_NDS_LAB MARS_NDS_LAB_CONFIG MARS_NDS_LAB_DB MARS_NDS_DISCOVERY_TREE MARS_TEST_NDS_DISCOVERY MARS_TEST_INVALID_NDS if [[ ${1:-} == --nds || ${1:-} == --invalid-nds ]]; then printf '{"tree":"MARS_TREE","organization":"HOME","units":["USERS"]}' > "$work/tree.json" export MARS_NDS_LAB=1 MARS_NDS_LAB_DB="$work/directory.sqlite3" MARS_NDS_DISCOVERY_TREE=MARS_TREE MARS_TEST_NDS_DISCOVERY=1 MARS_NDS_LAB_CONFIG=$(python3 nds/tools/snapshot.py "$work/tree.json" "$MARS_NDS_LAB_DB"); export MARS_NDS_LAB_CONFIG if [[ ${1:-} == --invalid-nds ]]; then unset MARS_TEST_NDS_DISCOVERY; export MARS_TEST_INVALID_NDS=1; rm -f "$MARS_NDS_LAB_DB"; fi fi ./build/mars-pcapd --offline-test --test-ip-config "$config" & pid=$! trap 'kill "$pid" 2>/dev/null || true; wait "$pid" 2>/dev/null || true; rm -rf -- "$work"' EXIT for i in $(seq 1 50); do [[ -S /run/mars-pcap/transport.sock ]] && break; sleep .1; done ./build/test-ncp-ip