run-tests.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. # BUILD_RUNNER=ON also builds and tests the QuickJS runner. Off by default
  23. # because it vendors QuickJS from GitHub at configure time.
  24. BUILD_RUNNER="${BUILD_RUNNER:-OFF}"
  25. docker image inspect "$BASE_IMAGE" >/dev/null 2>&1 || {
  26. echo "base image $BASE_IMAGE missing; build it with packaging/build.sh --rebuild-base" >&2
  27. exit 1
  28. }
  29. [[ -f "$DB_DEB" ]] || { echo "database deb not found: $DB_DEB" >&2; exit 1; }
  30. # The build tree is kept inside the container (a named volume) rather than in
  31. # the repo: objects built against Debian's toolchain must never be mixed with
  32. # whatever the host left in build/.
  33. docker run --rm \
  34. -v "$REPO:/src:ro" \
  35. -v svapi-testbuild:/build \
  36. -v "$DB_DEB:/tmp/db.deb:ro" \
  37. -v "$CLIENT_DEB:/tmp/client.deb:ro" \
  38. -v "$CLIENT_DEV_DEB:/tmp/client-dev.deb:ro" \
  39. -e "CTEST_FILTER=$FILTER" \
  40. -e "BUILD_RUNNER=$BUILD_RUNNER" \
  41. "$BASE_IMAGE" bash -euo pipefail -c '
  42. apt-get update -qq >/dev/null
  43. apt-get install -y -qq --no-install-recommends \
  44. /tmp/client.deb /tmp/client-dev.deb /tmp/db.deb >/dev/null 2>&1 || \
  45. dpkg -i /tmp/client.deb /tmp/client-dev.deb /tmp/db.deb >/dev/null 2>&1 || true
  46. mkdir -p /var/lib/smartbotic-database
  47. /usr/bin/smartbotic-database --config /etc/smartbotic-database/config.json >/tmp/db.log 2>&1 &
  48. for i in $(seq 1 60); do
  49. (exec 3<>/dev/tcp/127.0.0.1/9004) 2>/dev/null && break
  50. sleep 1
  51. done
  52. (exec 3<>/dev/tcp/127.0.0.1/9004) 2>/dev/null || { echo "database never came up:"; tail -20 /tmp/db.log; exit 1; }
  53. cmake -B /build -G Ninja -DCMAKE_BUILD_TYPE=Release \
  54. -DBUILD_TESTS=ON -DBUILD_WEBUI=OFF \
  55. -DBUILD_RUNNER="${BUILD_RUNNER}" -S /src
  56. cmake --build /build -j"$(nproc)"
  57. if [[ -n "${CTEST_FILTER:-}" ]]; then
  58. ctest --test-dir /build --output-on-failure -R "$CTEST_FILTER"
  59. else
  60. ctest --test-dir /build --output-on-failure
  61. fi
  62. '