run-tests.sh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.4-1_amd64.deb}"
  17. # The base image pins a client version; tests must compile against the same one
  18. # the release does, so the dev package is installed here rather than assumed.
  19. CLIENT_DEV_DEB="${CLIENT_DEV_DEB:-$DEB_REPO_DIR/dist/libsmartbotic-db-client-dev_2.11.4-1_amd64.deb}"
  20. CLIENT_DEB="${CLIENT_DEB:-$DEB_REPO_DIR/dist/libsmartbotic-db-client_2.11.4-1_amd64.deb}"
  21. FILTER="${1:-}"
  22. docker image inspect "$BASE_IMAGE" >/dev/null 2>&1 || {
  23. echo "base image $BASE_IMAGE missing; build it with packaging/build.sh --rebuild-base" >&2
  24. exit 1
  25. }
  26. [[ -f "$DB_DEB" ]] || { echo "database deb not found: $DB_DEB" >&2; exit 1; }
  27. # The build tree is kept inside the container (a named volume) rather than in
  28. # the repo: objects built against Debian's toolchain must never be mixed with
  29. # whatever the host left in build/.
  30. docker run --rm \
  31. -v "$REPO:/src:ro" \
  32. -v svapi-testbuild:/build \
  33. -v "$DB_DEB:/tmp/db.deb:ro" \
  34. -v "$CLIENT_DEB:/tmp/client.deb:ro" \
  35. -v "$CLIENT_DEV_DEB:/tmp/client-dev.deb:ro" \
  36. -e "CTEST_FILTER=$FILTER" \
  37. "$BASE_IMAGE" bash -euo pipefail -c '
  38. apt-get update -qq >/dev/null
  39. apt-get install -y -qq --no-install-recommends \
  40. /tmp/client.deb /tmp/client-dev.deb /tmp/db.deb >/dev/null 2>&1 || \
  41. dpkg -i /tmp/client.deb /tmp/client-dev.deb /tmp/db.deb >/dev/null 2>&1 || true
  42. mkdir -p /var/lib/smartbotic-database
  43. /usr/bin/smartbotic-database --config /etc/smartbotic-database/config.json >/tmp/db.log 2>&1 &
  44. for i in $(seq 1 60); do
  45. (exec 3<>/dev/tcp/127.0.0.1/9004) 2>/dev/null && break
  46. sleep 1
  47. done
  48. (exec 3<>/dev/tcp/127.0.0.1/9004) 2>/dev/null || { echo "database never came up:"; tail -20 /tmp/db.log; exit 1; }
  49. cmake -B /build -G Ninja -DCMAKE_BUILD_TYPE=Release \
  50. -DBUILD_TESTS=ON -DBUILD_WEBUI=OFF -S /src
  51. cmake --build /build -j"$(nproc)"
  52. if [[ -n "${CTEST_FILTER:-}" ]]; then
  53. ctest --test-dir /build --output-on-failure -R "$CTEST_FILTER"
  54. else
  55. ctest --test-dir /build --output-on-failure
  56. fi
  57. '