#!/usr/bin/env bash # run_chain_e2e.sh — Full-chain E2E orchestrator for the streaming chain # # MARTe2 app (FileReader -> IOGAM -> UDPStreamer) # -> UDPS -> StreamHub -> chain-client (record + zoom/window/trigger) # -> validate_waveform.py -> plots.py -> results.json [-> PDF] # # Per scenario (scenarios.py) it generates input data + both cfgs, runs the # two-process stack, drives the mock client, validates the recorded waveform # against the analytic/fed oracle, renders plots, and aggregates results.json. # Artifacts: Build/x86-linux/E2E/chain/ (report) and /tmp/chain_e2e/ (scratch). # # Usage: ./run_chain_e2e.sh [--skip-build] [--only ] [--pdf-only] [--cpp-coverage] [--stress] # --stress also runs the capacity matrix (stress.py / stress_run.py) and embeds a # Stress Tests section (table + per-axis scaling curves) in the PDF. set -u SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "${SCRIPT_DIR}/../../.." && pwd)" TARGET=x86-linux BUILD_DIR="${REPO_ROOT}/Build/${TARGET}" OUT_DIR="${BUILD_DIR}/E2E/chain" WORK="/tmp/chain_e2e" mkdir -p "${OUT_DIR}" "${WORK}" SKIP_BUILD=0 ONLY="" PDF_ONLY=0 CPP_COV=0 STRESS=0 while [ $# -gt 0 ]; do case "$1" in --skip-build) SKIP_BUILD=1 ;; --only) shift; ONLY="$1" ;; --pdf-only) PDF_ONLY=1 ;; --cpp-coverage) CPP_COV=1 ;; --stress) STRESS=1 ;; --help|-h) echo "Usage: $0 [--skip-build] [--only ] [--pdf-only] [--cpp-coverage] [--stress]"; exit 0 ;; *) echo "unknown arg $1" >&2; exit 2 ;; esac shift done ENV_SCRIPT="${REPO_ROOT}/env.sh" [ -f "${ENV_SCRIPT}" ] || { echo "ERROR: ${ENV_SCRIPT} not found" >&2; exit 1; } : "${LD_LIBRARY_PATH:=}" # env.sh appends to it under our set -u source "${ENV_SCRIPT}" COMP="${MARTe2_Components_DIR}/Build/${TARGET}/Components" export LD_LIBRARY_PATH="\ ${BUILD_DIR}/Components/DataSources/UDPStreamer:\ ${BUILD_DIR}/Components/Interfaces/UDPStream:\ ${MARTe2_DIR}/Build/${TARGET}/Core:\ ${COMP}/DataSources/LinuxTimer:\ ${COMP}/DataSources/FileDataSource:\ ${COMP}/GAMs/IOGAM:\ ${LD_LIBRARY_PATH:-}" MARTE_APP="${MARTe2_DIR}/Build/${TARGET}/App/MARTeApp.ex" STREAMHUB_EX="${BUILD_DIR}/StreamHub/StreamHub.ex" CLIENT="${SCRIPT_DIR}/client/chain-client" PY="python3" SCEN() { ${PY} "${SCRIPT_DIR}/scenarios.py" >/dev/null 2>&1; } # ── PDF-only shortcut (Task 9 fills in the compile) ────────────────────────── if [ "${PDF_ONLY}" -eq 1 ]; then if command -v typst >/dev/null 2>&1 && [ -f "${SCRIPT_DIR}/E2E_Report.typ" ]; then cp "${SCRIPT_DIR}/E2E_Report.typ" "${OUT_DIR}/" 2>/dev/null || true (cd "${OUT_DIR}" && typst compile E2E_Report.typ E2E_Report.pdf) \ && echo "PDF: ${OUT_DIR}/E2E_Report.pdf" else echo "typst or E2E_Report.typ missing — skipping PDF" fi exit 0 fi # ── Build ──────────────────────────────────────────────────────────────────── if [ "${SKIP_BUILD}" -eq 0 ]; then echo "── Building components ──" make -C "${REPO_ROOT}/Source/Components/Interfaces/UDPStream" -f Makefile.gcc TARGET="${TARGET}" 2>&1 | tail -1 make -C "${REPO_ROOT}/Source/Components/DataSources/UDPStreamer" -f Makefile.gcc TARGET="${TARGET}" 2>&1 | tail -1 make -C "${REPO_ROOT}/Source/Applications/StreamHub" -f Makefile.gcc TARGET="${TARGET}" 2>&1 | tail -1 fi if [ ! -x "${CLIENT}" ]; then echo "── Building chain-client ──" (cd "${SCRIPT_DIR}/client" && go build -o chain-client .) || { echo "client build failed"; exit 1; } fi [ -x "${MARTE_APP}" ] || { echo "ERROR: MARTeApp.ex not found at ${MARTE_APP}" >&2; exit 1; } [ -x "${STREAMHUB_EX}" ] || { echo "ERROR: StreamHub.ex not found" >&2; exit 1; } # ── Scenario list (id|ws_port|udp_port0|network|oracle|trig|checks) ────────── LIST="$(${PY} - "${ONLY}" <<'PY' import sys, os sys.path.insert(0, os.path.dirname(os.path.abspath("Test/E2E/chain/scenarios.py"))) sys.path.insert(0, os.path.join(os.getcwd(), "Test/E2E/chain")) import scenarios as S only = sys.argv[1] if len(sys.argv) > 1 else "" for s in S.SCENARIOS: if only and s["id"] != only: continue trig = s.get("trig_signal") or "" checks = ",".join(s.get("client_checks", [])) if not trig: checks = ",".join(c for c in s.get("client_checks", []) if c != "trigger") print("|".join([s["id"], str(s["ws_port"]), str(s["sources"][0]["udp_port"]), s["network"], s["oracle"], trig, checks])) PY )" if [ -z "${LIST}" ]; then echo "no scenarios selected"; exit 1; fi SCEN_IDS="" HUB_PID=""; APP_PID="" cleanup() { [ -n "${APP_PID}" ] && kill "${APP_PID}" 2>/dev/null [ -n "${HUB_PID}" ] && kill "${HUB_PID}" 2>/dev/null wait "${APP_PID}" 2>/dev/null; wait "${HUB_PID}" 2>/dev/null APP_PID=""; HUB_PID="" } trap cleanup EXIT while IFS='|' read -r ID WSPORT UDPPORT NET ORACLE TRIG CHECKS; do [ -z "${ID}" ] && continue SCEN_IDS="${SCEN_IDS} ${ID}" echo "" echo "══ scenario ${ID} (net=${NET} oracle=${ORACLE} ws=${WSPORT}) ══" : > "${WORK}/status_${ID}.txt" # multicast route probe if [ "${NET}" = "multicast" ]; then GRP="$(${PY} -c "import sys;sys.path.insert(0,'${SCRIPT_DIR}');import scenarios as S;print(next(s for s in S.SCENARIOS if s['id']=='${ID}')['sources'][0]['multicast_group'])")" if ! ip route get "${GRP}" >/dev/null 2>&1; then echo " SKIP: no multicast route to ${GRP}" echo "SKIP" > "${WORK}/status_${ID}.txt" continue fi fi INPUT="${WORK}/input_${ID}.bin" MCFG="${WORK}/m_${ID}.cfg" HCFG="${WORK}/h_${ID}.cfg" TAP="" if [ "${ORACLE}" = "fed" ] || [ "${ORACLE}" = "both" ]; then TAP="${WORK}/tap_${ID}.bin" fi ${PY} "${SCRIPT_DIR}/gen_data.py" --scenario "${ID}" --out "${INPUT}" || { echo FAIL > "${WORK}/status_${ID}.txt"; continue; } if [ -n "${TAP}" ]; then ${PY} "${SCRIPT_DIR}/gen_cfg.py" --scenario "${ID}" --input "${INPUT}" --marte-out "${MCFG}" --hub-out "${HCFG}" --tap "${TAP}" else ${PY} "${SCRIPT_DIR}/gen_cfg.py" --scenario "${ID}" --input "${INPUT}" --marte-out "${MCFG}" --hub-out "${HCFG}" fi HUB_LOG="${OUT_DIR}/hub_${ID}.log" APP_LOG="${OUT_DIR}/marte_${ID}.log" rm -f "${WORK}/received_${ID}.bin" "${WORK}/checks_${ID}.json" "${WORK}/metrics_${ID}.json" "${STREAMHUB_EX}" -cfg "${HCFG}" > "${HUB_LOG}" 2>&1 & HUB_PID=$! sleep 1 timeout 120 "${MARTE_APP}" -l RealTimeLoader -f "${MCFG}" -s Running > "${APP_LOG}" 2>&1 & APP_PID=$! sleep 1 # APP_PID is the `timeout` wrapper; perf must target the real MARTeApp child. APP_PERF_PID="$(pgrep -P "${APP_PID}" 2>/dev/null | head -1)" [ -z "${APP_PERF_PID}" ] && APP_PERF_PID="${APP_PID}" TRIGARG="" [ -n "${TRIG}" ] && TRIGARG="-trigsig ${TRIG}" if "${CLIENT}" -hub "127.0.0.1:${WSPORT}" -scenario "${ID}" ${TRIGARG} \ -checks "${CHECKS}" -out "${WORK}" -dur 4 > "${OUT_DIR}/client_${ID}.log" 2>&1; then echo " client OK" else echo " client FAILED (see client_${ID}.log)" tail -3 "${OUT_DIR}/client_${ID}.log" | sed 's/^/ /' fi # Snapshot CPU/peak-RSS while the stack is still alive (peak RSS is only # legible before exit), then tear it down. [ -n "${HUB_PID}" ] && ${PY} "${SCRIPT_DIR}/proc_perf.py" "${HUB_PID}" streamhub "${WORK}/perf_${ID}_hub.json" || true [ -n "${APP_PERF_PID}" ] && ${PY} "${SCRIPT_DIR}/proc_perf.py" "${APP_PERF_PID}" marte "${WORK}/perf_${ID}_marte.json" || true cleanup # validate + plot VARGS="--scenario ${ID} --received ${WORK}/received_${ID}.bin --checks ${WORK}/checks_${ID}.json --out ${WORK}/metrics_${ID}.json" [ -n "${TAP}" ] && [ -f "${TAP}" ] && VARGS="${VARGS} --tap ${TAP}" if ${PY} "${SCRIPT_DIR}/validate_waveform.py" ${VARGS}; then echo "PASS" > "${WORK}/status_${ID}.txt" else echo "FAIL" > "${WORK}/status_${ID}.txt" fi ${PY} "${SCRIPT_DIR}/plots.py" --scenario "${ID}" --dir "${WORK}" >/dev/null 2>&1 || true done <<< "${LIST}" trap - EXIT cleanup # ── Aggregate results.json ─────────────────────────────────────────────────── # Scenarios carrying a `known_issue` marker exercise a documented, not-yet-fixed # chain gap: a raw FAIL is reclassified XFAIL (expected failure — does not break # the green baseline) and a raw PASS becomes XPASS (the bug was unexpectedly # fixed; the marker should be dropped). Overall is PASS when nothing FAILs and # nothing unexpectedly XPASSes. WORK="${WORK}" OUT_DIR="${OUT_DIR}" SCEN_IDS="${SCEN_IDS}" \ SCRIPT_DIR="${SCRIPT_DIR}" ${PY} - <<'PY' import json, os, sys work = os.environ["WORK"]; out = os.environ["OUT_DIR"] ids = os.environ["SCEN_IDS"].split() sys.path.insert(0, os.environ["SCRIPT_DIR"]) try: from scenarios import SCENARIOS known = {s["id"]: s.get("known_issue") for s in SCENARIOS} except Exception: known = {} results = [] for sid in ids: rec = {"id": sid} st = os.path.join(work, f"status_{sid}.txt") raw = open(st).read().strip() if os.path.exists(st) else "UNKNOWN" ki = known.get(sid) if ki: rec["known_issue"] = ki if raw == "FAIL": raw = "XFAIL" # expected failure — documented chain gap elif raw == "PASS": raw = "XPASS" # unexpectedly fixed — drop the marker rec["status"] = raw mp = os.path.join(work, f"metrics_{sid}.json") if os.path.exists(mp): rec["metrics"] = json.load(open(mp)) results.append(rec) # Green when no hard FAIL and no XPASS (an XPASS means a known_issue marker is # now stale and must be removed — surfaced as a failure to force the cleanup). overall = (bool(results) and all(r["status"] in ("PASS", "SKIP", "XFAIL") for r in results)) doc = {"overall": "PASS" if overall else "FAIL", "scenarios": results} with open(os.path.join(out, "results.json"), "w") as f: json.dump(doc, f, indent=2) c = lambda st: sum(r["status"] == st for r in results) print(f"\nresults.json: {c('PASS')} pass, {c('FAIL')} fail, {c('SKIP')} skip, " f"{c('XFAIL')} xfail, {c('XPASS')} xpass → {doc['overall']}") PY # ── Unit tests + coverage ──────────────────────────────────────────────────── echo "" echo "── Unit tests + coverage ──" # Optional C++ line coverage: rebuild the project's libraries + GTest with gcov # instrumentation in place (OPTIM/LFLAGS are the MARTe2-sanctioned override # hooks), let collect.py run the instrumented GTest (emits .gcda) and lcov, then # restore a clean build so later --skip-build runs aren't left instrumented. CPP_COV_FLAG="" if [ "${CPP_COV}" -eq 1 ]; then echo " building instrumented (gcov) libraries + GTest ..." COV_O="--coverage" COV_L="-Wl,--no-as-needed -fPIC --coverage" make -C "${REPO_ROOT}" -f Makefile.gcc clean >/dev/null 2>&1 || true make -C "${REPO_ROOT}" -f Makefile.gcc core TARGET="${TARGET}" \ OPTIM="${COV_O}" LFLAGS="${COV_L}" 2>&1 | tail -1 for d in Test/Components/DataSources/UDPStreamer Test/Applications/StreamHub Test/GTest; do make -C "${REPO_ROOT}/${d}" -f Makefile.gcc TARGET="${TARGET}" \ OPTIM="${COV_O}" LFLAGS="${COV_L}" 2>&1 | tail -1 done CPP_COV_FLAG="--cpp-coverage" fi ${PY} "${SCRIPT_DIR}/collect.py" --repo "${REPO_ROOT}" --target "${TARGET}" \ --out "${OUT_DIR}" --work "${WORK}" ${CPP_COV_FLAG} || true if [ "${CPP_COV}" -eq 1 ]; then echo " restoring non-instrumented build ..." make -C "${REPO_ROOT}" -f Makefile.gcc clean >/dev/null 2>&1 || true make -C "${REPO_ROOT}" -f Makefile.gcc core apps TARGET="${TARGET}" 2>&1 | tail -1 (cd "${SCRIPT_DIR}/client" && go build -o chain-client . >/dev/null 2>&1) || true fi # ── Stress matrix (opt-in) ─────────────────────────────────────────────────── # Capacity sibling of the correctness phase: sweep one load axis at a time and # gate survival/liveness (hard) + RSS/zoom-p95 (soft). Writes stress_results.json # into OUT_DIR/stress, which report_build.py folds into the PDF when present. STRESS_OUT="${OUT_DIR}/stress" if [ "${STRESS}" -eq 1 ]; then echo "" echo "── Stress matrix ──" mkdir -p "${STRESS_OUT}" ${PY} "${SCRIPT_DIR}/stress.py" >/dev/null || { echo "stress matrix invalid" >&2; exit 1; } ${PY} "${SCRIPT_DIR}/stress_run.py" \ --marte "${MARTE_APP}" --hub "${STREAMHUB_EX}" --client "${CLIENT}" \ --work "${WORK}" --out "${STRESS_OUT}" \ || { echo "WARN: stress_run.py failed, continuing" >&2; true; } fi # ── Consolidated report data (+ history/regression + trend plots) ──────────── ${PY} "${SCRIPT_DIR}/report_build.py" --repo "${REPO_ROOT}" \ --results "${OUT_DIR}/results.json" --work "${WORK}" --out "${OUT_DIR}" \ --stress-results "${OUT_DIR}/stress/stress_results.json" || true # ── PDF ────────────────────────────────────────────────────────────────────── if command -v typst >/dev/null 2>&1 && [ -f "${SCRIPT_DIR}/E2E_Report.typ" ]; then cp "${SCRIPT_DIR}/E2E_Report.typ" "${OUT_DIR}/" 2>/dev/null || true # Embedded waveform overviews live in WORK; the template references them by # bare name, so stage them next to report_data.json before compiling. cp "${WORK}"/wave_*.png "${OUT_DIR}/" 2>/dev/null || true if (cd "${OUT_DIR}" && typst compile E2E_Report.typ E2E_Report.pdf); then echo "PDF: ${OUT_DIR}/E2E_Report.pdf" else echo "typst compile failed (report_data.json present at ${OUT_DIR})" fi fi echo "Done — artifacts in ${OUT_DIR} and ${WORK}"