run-tests.sh 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. # The client version is DERIVED from build.sh's pin rather than written here.
  17. # These used to be hardcoded at 2.12.0 and were eight releases stale, which is
  18. # the exact failure this file's own warning describes: the TEST path can sit on
  19. # a different client than the RELEASE path, and then a green suite is not
  20. # evidence about the packages. Two places holding one version is one too many,
  21. # so there is now a single source and this reads it.
  22. DB_CLIENT_VERSION="${DB_CLIENT_VERSION:-$(
  23. sed -n 's/^DB_CLIENT_VERSION="\${DB_CLIENT_VERSION:-\(.*\)}"$/\1/p' "$REPO/packaging/build.sh"
  24. )}"
  25. [[ -n "$DB_CLIENT_VERSION" ]] || {
  26. echo "could not read DB_CLIENT_VERSION out of packaging/build.sh" >&2; exit 1; }
  27. # The DATABASE server version is a separate choice from the client: default to
  28. # the deploy target so the integration tests meet the server prod will run,
  29. # rather than whichever one happened to be current when this line was written.
  30. DB_VERSION="${DB_VERSION:-2.20.1-1}"
  31. DB_DEB="${DB_DEB:-$DEB_REPO_DIR/dist/smartbotic-database_${DB_VERSION}_amd64.deb}"
  32. CLIENT_DEV_DEB="${CLIENT_DEV_DEB:-$DEB_REPO_DIR/dist/libsmartbotic-db-client-dev_${DB_CLIENT_VERSION}_amd64.deb}"
  33. CLIENT_DEB="${CLIENT_DEB:-$DEB_REPO_DIR/dist/libsmartbotic-db-client_${DB_CLIENT_VERSION}_amd64.deb}"
  34. FILTER="${1:-}"
  35. # BUILD_RUNNER=ON also builds and tests the QuickJS runner. Off by default
  36. # because it vendors QuickJS from GitHub at configure time.
  37. BUILD_RUNNER="${BUILD_RUNNER:-OFF}"
  38. docker image inspect "$BASE_IMAGE" >/dev/null 2>&1 || {
  39. echo "base image $BASE_IMAGE missing; build it with packaging/build.sh --rebuild-base" >&2
  40. exit 1
  41. }
  42. [[ -f "$DB_DEB" ]] || { echo "database deb not found: $DB_DEB" >&2; exit 1; }
  43. # The build tree is kept inside the container (a named volume) rather than in
  44. # the repo: objects built against Debian's toolchain must never be mixed with
  45. # whatever the host left in build/.
  46. docker run --rm \
  47. -v "$REPO:/src:ro" \
  48. -v svapi-testbuild:/build \
  49. -v "$DB_DEB:/tmp/db.deb:ro" \
  50. -v "$CLIENT_DEB:/tmp/client.deb:ro" \
  51. -v "$CLIENT_DEV_DEB:/tmp/client-dev.deb:ro" \
  52. -e "CTEST_FILTER=$FILTER" \
  53. -e "BUILD_RUNNER=$BUILD_RUNNER" \
  54. "$BASE_IMAGE" bash -euo pipefail -c '
  55. apt-get update -qq >/dev/null
  56. apt-get install -y -qq --no-install-recommends \
  57. /tmp/client.deb /tmp/client-dev.deb /tmp/db.deb >/dev/null 2>&1 || \
  58. dpkg -i /tmp/client.deb /tmp/client-dev.deb /tmp/db.deb >/dev/null 2>&1 || true
  59. mkdir -p /var/lib/smartbotic-database
  60. /usr/bin/smartbotic-database --config /etc/smartbotic-database/config.json >/tmp/db.log 2>&1 &
  61. for i in $(seq 1 60); do
  62. (exec 3<>/dev/tcp/127.0.0.1/9004) 2>/dev/null && break
  63. sleep 1
  64. done
  65. (exec 3<>/dev/tcp/127.0.0.1/9004) 2>/dev/null || { echo "database never came up:"; tail -20 /tmp/db.log; exit 1; }
  66. cmake -B /build -G Ninja -DCMAKE_BUILD_TYPE=Release \
  67. -DBUILD_TESTS=ON -DBUILD_WEBUI=OFF \
  68. -DBUILD_RUNNER="${BUILD_RUNNER}" -S /src
  69. cmake --build /build -j"$(nproc)"
  70. if [[ -n "${CTEST_FILTER:-}" ]]; then
  71. ctest --test-dir /build --output-on-failure -R "$CTEST_FILTER"
  72. else
  73. ctest --test-dir /build --output-on-failure
  74. fi
  75. '