run-tests.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env bash
  2. # Build and run the C++ test suite in Debian 13, because the Void dev host
  3. # cannot: protobuf 35 removed google/protobuf/map_field_inl.h, which the
  4. # database's generated protos include, so libsmartbotic-db-client neither
  5. # compiles nor links there.
  6. #
  7. # Runs smartbotic-database inside the same container, so the ApiFixture
  8. # integration tests actually execute instead of GTEST_SKIP()ing.
  9. #
  10. # packaging/devstack/run-tests.sh # whole suite
  11. # packaging/devstack/run-tests.sh 'ApiFixture.*' # a ctest -R filter
  12. set -euo pipefail
  13. REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
  14. BASE_IMAGE="${BASE_IMAGE:-smartbotic-vectorapi-build-base:debian13}"
  15. DEB_REPO_DIR="${DEB_REPO_DIR:-/data/dev/smartbotics/smartbotics-deb-repo}"
  16. DB_DEB="${DB_DEB:-$DEB_REPO_DIR/dist/smartbotic-database_2.11.3-1_amd64.deb}"
  17. FILTER="${1:-}"
  18. docker image inspect "$BASE_IMAGE" >/dev/null 2>&1 || {
  19. echo "base image $BASE_IMAGE missing; build it with packaging/build.sh --rebuild-base" >&2
  20. exit 1
  21. }
  22. [[ -f "$DB_DEB" ]] || { echo "database deb not found: $DB_DEB" >&2; exit 1; }
  23. # The build tree is kept inside the container (a named volume) rather than in
  24. # the repo: objects built against Debian's toolchain must never be mixed with
  25. # whatever the host left in build/.
  26. docker run --rm \
  27. -v "$REPO:/src:ro" \
  28. -v svapi-testbuild:/build \
  29. -v "$DB_DEB:/tmp/db.deb:ro" \
  30. -e "CTEST_FILTER=$FILTER" \
  31. "$BASE_IMAGE" bash -euo pipefail -c '
  32. apt-get update -qq >/dev/null
  33. apt-get install -y -qq --no-install-recommends /tmp/db.deb >/dev/null 2>&1 || \
  34. dpkg -i /tmp/db.deb >/dev/null 2>&1 || true
  35. mkdir -p /var/lib/smartbotic-database
  36. /usr/bin/smartbotic-database --config /etc/smartbotic-database/config.json >/tmp/db.log 2>&1 &
  37. for i in $(seq 1 60); do
  38. (exec 3<>/dev/tcp/127.0.0.1/9004) 2>/dev/null && break
  39. sleep 1
  40. done
  41. (exec 3<>/dev/tcp/127.0.0.1/9004) 2>/dev/null || { echo "database never came up:"; tail -20 /tmp/db.log; exit 1; }
  42. cmake -B /build -G Ninja -DCMAKE_BUILD_TYPE=Release \
  43. -DBUILD_TESTS=ON -DBUILD_WEBUI=OFF -S /src
  44. cmake --build /build -j"$(nproc)"
  45. if [[ -n "${CTEST_FILTER:-}" ]]; then
  46. ctest --test-dir /build --output-on-failure -R "$CTEST_FILTER"
  47. else
  48. ctest --test-dir /build --output-on-failure
  49. fi
  50. '