#!/bin/bash #======================================================================= # FILE: ci/build-test.sh # DESC: Build the project, run unit tests and a startup smoke test. # Executed INSIDE the aarch64 build container (ci/Dockerfile). #======================================================================= set -euo pipefail SRC_DIR="${SRC_DIR:-/src}" cd "${SRC_DIR}" #----------------------------------------------------------------------- # 1. Build #----------------------------------------------------------------------- echo ">>> Building (aarch64, Release)..." rm -rf build mkdir -p build cd build cmake -DCMAKE_BUILD_TYPE=Release .. make -j"$(nproc)" BIN_DIR="${SRC_DIR}/bin" echo ">>> Build artifacts:" ls -la "${BIN_DIR}" #----------------------------------------------------------------------- # 2. Unit test (SQLiteTest) #----------------------------------------------------------------------- echo ">>> Running unit test: SQLiteTest" "${BIN_DIR}/SQLiteTest" echo ">>> SQLiteTest passed" #----------------------------------------------------------------------- # 3. Startup smoke test: MOOSDB + pPowerManger liveness #----------------------------------------------------------------------- echo ">>> Smoke test: launch MOOSDB + pPowerManger" # Locate MOOSDB (installed by MOOS build) MOOSDB="$(command -v MOOSDB || true)" if [ -z "${MOOSDB}" ]; then MOOSDB="$(ls /opt/moos-ivp/bin/MOOSDB 2>/dev/null || true)" fi if [ -z "${MOOSDB}" ] || [ ! -x "${MOOSDB}" ]; then echo "ERROR: MOOSDB not found" >&2 exit 1 fi echo "Using MOOSDB: ${MOOSDB}" # Minimal mission file for MOOSDB + pPowerManger MISSION_FILE="/tmp/smoke.moos" cat > "${MISSION_FILE}" <>> Smoke diagnostics" getent protocols tcp >/dev/null 2>&1 && echo "getprotobyname(tcp) OK" || echo "getprotobyname(tcp) FAILED" getent hosts localhost >/dev/null 2>&1 && echo "gethostbyname(localhost) OK" || echo "gethostbyname(localhost) FAILED" echo "ulimit -n: $(ulimit -n)" "${MOOSDB}" --moos_suicide_disable --moos_no_colour "${MISSION_FILE}" > /tmp/moosdb_smoke.log 2>&1 & MOOSDB_PID=$! sleep 3 if ! kill -0 "${MOOSDB_PID}" 2>/dev/null; then echo "--- MOOSDB crashed at startup; log: ---" cat /tmp/moosdb_smoke.log fi ./pPowerManger "${MISSION_FILE}" > /tmp/pm_smoke.log 2>&1 & PM_PID=$! sleep 5 if kill -0 "${PM_PID}" 2>/dev/null; then echo ">>> Smoke test PASSED (pPowerManger alive after 5s)" kill "${PM_PID}" "${MOOSDB_PID}" 2>/dev/null || true wait "${PM_PID}" "${MOOSDB_PID}" 2>/dev/null || true exit 0 else echo ">>> Smoke test FAILED (pPowerManger exited)" >&2 echo "--- pPowerManger log ---" >&2 cat /tmp/pm_smoke.log >&2 || true echo "--- MOOSDB log ---" >&2 cat /tmp/moosdb_smoke.log >&2 || true kill "${MOOSDB_PID}" 2>/dev/null || true exit 1 fi