From 269fac40fa50bd0fd3cbbc4da7bbe5ad43d085d6 Mon Sep 17 00:00:00 2001 From: Khushi Kathuria Date: Thu, 7 May 2026 14:04:53 +0530 Subject: [PATCH] fix(bq_driver): Asan CI check fix --- .../builds/integration-bq-driver-asan.sh | 5 +- .../ubuntu-22.04-install.Dockerfile | 90 +++---------------- ci/gha/builds/lib/lsan.supp | 6 ++ .../odbc/bq_client_interface/datasets.cc | 2 +- google/cloud/odbc/bq_client_interface/jobs.cc | 2 +- .../odbc_authentication.cc | 2 +- .../bq_client_interface/odbc_bq_client.cc | 2 +- .../odbc/bq_client_interface/projects.cc | 2 +- .../cloud/odbc/bq_client_interface/storage.cc | 2 +- .../cloud/odbc/bq_client_interface/tables.cc | 2 +- google/cloud/odbc/bq_client_interface/utils.h | 2 +- .../odbc/bq_driver/internal/trace_utils.cc | 4 +- .../odbc/bq_driver/internal/trace_utils.h | 10 +-- .../bq_driver/internal/trace_utils_test.cc | 2 +- .../odbc_driver_tests/connection_test.cc | 8 +- 15 files changed, 43 insertions(+), 98 deletions(-) diff --git a/ci/cloudbuild/builds/integration-bq-driver-asan.sh b/ci/cloudbuild/builds/integration-bq-driver-asan.sh index 54bf4fd821..be73a7c737 100755 --- a/ci/cloudbuild/builds/integration-bq-driver-asan.sh +++ b/ci/cloudbuild/builds/integration-bq-driver-asan.sh @@ -42,7 +42,6 @@ git checkout "$VCPKG_VERSION" ./bootstrap-vcpkg.sh -disableMetrics cd "$WORKSPACE_DIR" - # This runs all the unit tests mapfile -t args < <(bazel::common_args) mapfile -t unit_tests_args < <(unit_tests::bazel_args) @@ -56,6 +55,7 @@ mapfile -t cmake_args < <(cmake::common_args) BUILD_DIR="/opt/odbc-driver" # This is the name of DSN set in odbc.ini export ODBC_TESTS_DSN="SampleDSNGoogleDriver" +export ASAN_OPTIONS="detect_container_overflow=0:detect_leaks=1" export LSAN_OPTIONS="use_tls=0:suppressions=/opt/odbc-driver/lsan.supp:print_suppressions=0" export CPP_BIGQUERY_ODBC_TEST_TABLE_PREFIX=${TRIGGER_NAME//[-:;.,?]/_}_${BRANCH_NAME//[-:;.,?]/_} @@ -84,8 +84,9 @@ io::run cmake -B "$BUILD_DIR" \ -DODBC_EXAMPLES=ON \ -DODBC_UNIT_TESTING=OFF \ -DCLIENT_LIBRARY_INTEGRATION_TESTING=OFF - io::run cmake --build cmake-out +# Copy the roots.pem file to the .so directory to run test cases. +cp /opt/odbc-driver/roots.pem "cmake-out/google/cloud/odbc/roots.pem" mapfile -t ctest_args < <(ctest::common_args) io::run env -C cmake-out ctest "${ctest_args[@]}" diff --git a/ci/cloudbuild/dockerfiles/ubuntu-22.04-install.Dockerfile b/ci/cloudbuild/dockerfiles/ubuntu-22.04-install.Dockerfile index b468c5bc7b..2710fd5905 100644 --- a/ci/cloudbuild/dockerfiles/ubuntu-22.04-install.Dockerfile +++ b/ci/cloudbuild/dockerfiles/ubuntu-22.04-install.Dockerfile @@ -22,8 +22,7 @@ RUN apt-get update && \ build-essential \ # Dependency for arrow bison \ - clang-12 \ - lld-12 \ + clang \ cmake \ curl \ # Dependency for arrow @@ -32,10 +31,8 @@ RUN apt-get update && \ git \ gcc \ g++ \ - # Required by Ubsan in Ubuntu 22.04 - libunwind-12-dev \ - libc++-12-dev \ - libc++abi-12-dev \ + libc++-dev \ + libc++abi-dev \ libcurl4-openssl-dev \ # Needed to use autoreconf libltdl-dev \ @@ -61,7 +58,15 @@ RUN apt-get update && \ apt-utils \ ca-certificates \ apt-transport-https \ - clang-tidy-12 + clang-tidy + +# Set Clang 12 as default +RUN update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100 && \ + update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100 + +# Set the compiler environment variables +ENV CC=/usr/bin/clang +ENV CXX=/usr/bin/clang++ # Needed for the existing driver v3.1.2.1004+ RUN locale-gen en_US.UTF-8 @@ -69,20 +74,6 @@ ENV LANG en_US.UTF-8 ENV LANGUAGE en_US.UTF-8 ENV LC_ALL en_US.UTF-8 -# Set clang as default -RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-12 100 && \ - update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 100 - -ENV CC=clang -ENV CXX=clang++ - -# Install modern CMake locally -RUN mkdir -p /opt/cmake && \ - curl -fsSL https://github.com/Kitware/CMake/releases/download/v3.30.1/cmake-3.30.1-linux-x86_64.tar.gz \ - | tar -xz --strip-components=1 -C /opt/cmake - -ENV PATH=/opt/cmake/bin:$PATH - # clang-tidy-cache needs python RUN update-alternatives --install /usr/bin/python python $(which python3) 10 @@ -91,63 +82,6 @@ WORKDIR /var/tmp/downloads RUN if [ $(ls /var/tmp/ci/requirements.txt | grep -c requirements.txt) -eq 0 ] ; \ then echo 'Unable to find requirements.txt for python...' ; exit 1 ; fi RUN pip3 install --require-hashes --no-deps -r /var/tmp/ci/requirements.txt - -# Install all the direct (and indirect) dependencies for cpp-bigquery-odbc. -# Use a different directory for each build, and remove the downloaded -# files and any temporary artifacts after a successful build to keep the -# image smaller (and with fewer layers) - -WORKDIR /var/tmp/build/abseil-cpp -RUN curl -fsSL https://github.com/abseil/abseil-cpp/archive/20240722.0.tar.gz | \ - tar -xzf - --strip-components=1 && \ - cmake \ - -DCMAKE_BUILD_TYPE="Release" \ - -DCMAKE_CXX_STANDARD=17 \ - -DABSL_BUILD_TESTING=OFF \ - -DABSL_PROPAGATE_CXX_STD=ON \ - -DBUILD_SHARED_LIBS=yes \ - -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ - -S . -B cmake-out -GNinja && \ - cmake --build cmake-out --target install && \ - ldconfig && \ - cd /var/tmp && rm -fr build - -WORKDIR /var/tmp/build/googletest -RUN curl -fsSL https://github.com/google/googletest/archive/v1.15.2.tar.gz | \ - tar -xzf - --strip-components=1 && \ - cmake \ - -DCMAKE_BUILD_TYPE="Release" \ - -DBUILD_SHARED_LIBS=yes \ - -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ - -S . -B cmake-out -GNinja && \ - cmake --build cmake-out --target install && \ - ldconfig && \ - cd /var/tmp && rm -fr build - -# Install ctcache to speed up our clang-tidy build -WORKDIR /var/tmp/build -RUN curl -fsSL https://github.com/matus-chochlik/ctcache/archive/0ad2e227e8a981a9c1a6060ee6c8ec144bb976c6.tar.gz | \ - tar -xzf - --strip-components=1 && \ - cp clang-tidy /usr/local/bin/clang-tidy-wrapper && \ - cp clang-tidy-cache /usr/local/bin/clang-tidy-cache && \ - cd /var/tmp && rm -fr build - -# Install sccache from https://github.com/mozilla/sccache -WORKDIR /var/tmp/sccache -RUN curl -fsSL https://github.com/mozilla/sccache/releases/download/v0.5.4/sccache-v0.5.4-x86_64-unknown-linux-musl.tar.gz | \ - tar -zxf - --strip-components=1 && \ - mkdir -p /usr/local/bin && \ - mv sccache /usr/local/bin/sccache && \ - chmod +x /usr/local/bin/sccache - -# Needed to use autoreconf -WORKDIR /var/tmp/m4 -RUN curl -fsSL https://ftp.gnu.org/gnu/m4/m4-1.4.1.tar.gz | \ - tar -zxf - --strip-components=1 && \ - ./configure --enable-gui=no && \ - make && \ - make install -j "$(nproc)" - # Install the Cloud SDK COPY ./dependencies/cloud-sdk.sh /var/tmp/ci/dependencies/cloud-sdk.sh WORKDIR /var/tmp/downloads diff --git a/ci/gha/builds/lib/lsan.supp b/ci/gha/builds/lib/lsan.supp index 37afd5d2a3..c60d360db1 100644 --- a/ci/gha/builds/lib/lsan.supp +++ b/ci/gha/builds/lib/lsan.supp @@ -7,3 +7,9 @@ leak:Diagnostics::AddStatusRecord leak:StatusRecord leak:std::__cxx11::basic_string leak:_iodbcdm_SetConnectOption_init +leak:ld-linux-x86-64.so.2 +leak:_dl_exception_create_format +leak:libc.so.6 +leak:CRYPTO_zalloc +leak:grpc_jwt_encode_and_sign +leak:_iodbcdm_pushsqlerr diff --git a/google/cloud/odbc/bq_client_interface/datasets.cc b/google/cloud/odbc/bq_client_interface/datasets.cc index 2a2c4a8ca5..834403ef66 100644 --- a/google/cloud/odbc/bq_client_interface/datasets.cc +++ b/google/cloud/odbc/bq_client_interface/datasets.cc @@ -15,7 +15,7 @@ #include "google/cloud/odbc/bq_client_interface/datasets.h" #include "google/cloud/odbc/internal/status_record_or.h" #include "google/cloud/bigquery/v2/minimal/internal/dataset_client.h" -#include +#include "absl/log/log.h" namespace google::cloud::odbc_bigquery_client_interface { diff --git a/google/cloud/odbc/bq_client_interface/jobs.cc b/google/cloud/odbc/bq_client_interface/jobs.cc index a46034feb5..b54eeab4f8 100644 --- a/google/cloud/odbc/bq_client_interface/jobs.cc +++ b/google/cloud/odbc/bq_client_interface/jobs.cc @@ -18,7 +18,7 @@ #include "google/cloud/odbc/internal/status_record_or.h" #include "google/cloud/bigquery/v2/minimal/internal/job_client.h" #include "google/cloud/bigquery/v2/minimal/internal/job_request.h" -#include +#include "absl/log/log.h" #include namespace google::cloud::odbc_bigquery_client_interface { diff --git a/google/cloud/odbc/bq_client_interface/odbc_authentication.cc b/google/cloud/odbc/bq_client_interface/odbc_authentication.cc index cb101a9e82..b8c1d7aa92 100644 --- a/google/cloud/odbc/bq_client_interface/odbc_authentication.cc +++ b/google/cloud/odbc/bq_client_interface/odbc_authentication.cc @@ -20,7 +20,7 @@ #include "google/cloud/internal/getenv.h" #include "google/cloud/oauth2/access_token_generator.h" #include "google/cloud/status_or.h" -#include +#include "absl/log/log.h" #include #include namespace google::cloud::odbc_bigquery_client_interface { diff --git a/google/cloud/odbc/bq_client_interface/odbc_bq_client.cc b/google/cloud/odbc/bq_client_interface/odbc_bq_client.cc index bf95996ca5..b3184c7a7b 100644 --- a/google/cloud/odbc/bq_client_interface/odbc_bq_client.cc +++ b/google/cloud/odbc/bq_client_interface/odbc_bq_client.cc @@ -25,7 +25,7 @@ #include "google/cloud/credentials.h" #include "google/cloud/grpc_options.h" #include "google/cloud/universe_domain_options.h" -#include +#include "absl/log/log.h" #include #include diff --git a/google/cloud/odbc/bq_client_interface/projects.cc b/google/cloud/odbc/bq_client_interface/projects.cc index eb34fe472b..fe9826ffde 100644 --- a/google/cloud/odbc/bq_client_interface/projects.cc +++ b/google/cloud/odbc/bq_client_interface/projects.cc @@ -16,8 +16,8 @@ #include "google/cloud/odbc/bq_client_interface/datasets.h" #include "google/cloud/odbc/internal/sql_state_constants.h" #include "google/cloud/odbc/internal/status_record_or.h" +#include "absl/log/log.h" #include -#include namespace google::cloud::odbc_bigquery_client_interface { diff --git a/google/cloud/odbc/bq_client_interface/storage.cc b/google/cloud/odbc/bq_client_interface/storage.cc index e53cc6d6fd..4fe29a8aa0 100644 --- a/google/cloud/odbc/bq_client_interface/storage.cc +++ b/google/cloud/odbc/bq_client_interface/storage.cc @@ -14,7 +14,7 @@ #include "google/cloud/odbc/internal/status_record_or.h" #include "google/cloud/bigquery/storage/v1/bigquery_read_client.h" -#include +#include "absl/log/log.h" namespace google::cloud::odbc_bigquery_client_interface { diff --git a/google/cloud/odbc/bq_client_interface/tables.cc b/google/cloud/odbc/bq_client_interface/tables.cc index ee02867632..d51903cb0c 100644 --- a/google/cloud/odbc/bq_client_interface/tables.cc +++ b/google/cloud/odbc/bq_client_interface/tables.cc @@ -17,7 +17,7 @@ #include "google/cloud/odbc/bq_client_interface/utils.h" #include "google/cloud/odbc/internal/status_record_or.h" #include "google/cloud/bigquery/v2/minimal/internal/table_client.h" -#include +#include "absl/log/log.h" namespace google::cloud::odbc_bigquery_client_interface { diff --git a/google/cloud/odbc/bq_client_interface/utils.h b/google/cloud/odbc/bq_client_interface/utils.h index 072f1a673d..60ae235e9c 100644 --- a/google/cloud/odbc/bq_client_interface/utils.h +++ b/google/cloud/odbc/bq_client_interface/utils.h @@ -15,7 +15,7 @@ #ifndef CPP_BIGQUERY_ODBC_GOOGLE_CLOUD_ODBC_BQ_CLIENT_INTERFACE_UTILS_H #define CPP_BIGQUERY_ODBC_GOOGLE_CLOUD_ODBC_BQ_CLIENT_INTERFACE_UTILS_H -#include +#include "absl/log/log.h" #include #include #include diff --git a/google/cloud/odbc/bq_driver/internal/trace_utils.cc b/google/cloud/odbc/bq_driver/internal/trace_utils.cc index cbbd0a0730..9d9ee8aded 100644 --- a/google/cloud/odbc/bq_driver/internal/trace_utils.cc +++ b/google/cloud/odbc/bq_driver/internal/trace_utils.cc @@ -13,8 +13,8 @@ // limitations under the License. #include "google/cloud/odbc/bq_driver/internal/trace_utils.h" -#include -#include +#include "absl/log/internal/globals.h" +#include "absl/strings/str_format.h" #include namespace google::cloud::odbc_bq_driver_internal { diff --git a/google/cloud/odbc/bq_driver/internal/trace_utils.h b/google/cloud/odbc/bq_driver/internal/trace_utils.h index a6ba839f72..6124b12495 100644 --- a/google/cloud/odbc/bq_driver/internal/trace_utils.h +++ b/google/cloud/odbc/bq_driver/internal/trace_utils.h @@ -18,11 +18,11 @@ #include "google/cloud/odbc/bq_driver/internal/utils.h" #include "google/cloud/odbc/internal/odbc_includes.h" #include "google/cloud/odbc/internal/status_record_or.h" -#include -#include -#include -#include -#include +#include "absl/log/globals.h" +#include "absl/log/initialize.h" +#include "absl/log/internal/log_sink_set.h" +#include "absl/log/log.h" +#include "absl/log/log_sink.h" #include #include #include diff --git a/google/cloud/odbc/bq_driver/internal/trace_utils_test.cc b/google/cloud/odbc/bq_driver/internal/trace_utils_test.cc index d75e3b3227..089820e081 100644 --- a/google/cloud/odbc/bq_driver/internal/trace_utils_test.cc +++ b/google/cloud/odbc/bq_driver/internal/trace_utils_test.cc @@ -15,7 +15,7 @@ #include "google/cloud/odbc/bq_driver/internal/trace_utils.h" #include "google/cloud/odbc/testing/utils/status_matchers.h" #include "google/cloud/internal/getenv.h" -#include +#include "absl/strings/str_format.h" #include namespace google::cloud::odbc_bq_driver_internal { diff --git a/google/cloud/odbc/integration_tests/odbc_driver_tests/connection_test.cc b/google/cloud/odbc/integration_tests/odbc_driver_tests/connection_test.cc index 562b157b27..70c79d51cc 100644 --- a/google/cloud/odbc/integration_tests/odbc_driver_tests/connection_test.cc +++ b/google/cloud/odbc/integration_tests/odbc_driver_tests/connection_test.cc @@ -1176,9 +1176,13 @@ TEST(ConnectionTest, SQLBrowseConnect_InvalidConnectionAttribute) { HasSubstr("Catalog:Catalog=?;OAuthMechanism:OAuthMechanism=?")); #endif // _WIN32 } - // Pass `false` to indicate that the Driver Manager (DM) will automatically - // free the environment handle when the last connection handle is released. +// Pass `false` to indicate that the Driver Manager (DM) will automatically +// free the environment handle when the last connection handle is released. +#ifdef _WIN32 CleanupODBCHandles(*conn, false); +#else + CleanupODBCHandles(*conn); +#endif } TEST(ConnectionTest, SQLBrowseConnect_InvalidConnectionString) {