You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by fo...@apache.org on 2025/06/03 06:50:27 UTC

(iceberg-cpp) branch main updated: ci: add asan and ubsan support (#107)

This is an automated email from the ASF dual-hosted git repository.

fokko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-cpp.git


The following commit(s) were added to refs/heads/main by this push:
     new b4f7d5b   ci: add asan and ubsan support (#107)
b4f7d5b is described below

commit b4f7d5b429b642ecf15ab7a1eb28edff337b05c3
Author: METONLIULEI <44...@qq.com>
AuthorDate: Tue Jun 3 14:50:22 2025 +0800

     ci: add asan and ubsan support (#107)
    
    Co-authored-by: lei.liu <le...@clickzetta.com>
---
 .github/lsan-suppressions.txt         | 21 ++++++++++++
 .github/ubsan-suppressions.txt        | 20 +++++++++++
 .github/workflows/sanitizer_test.yml  | 63 +++++++++++++++++++++++++++++++++++
 CMakeLists.txt                        |  3 ++
 cmake_modules/IcebergBuildUtils.cmake |  6 ++++
 cmake_modules/IcebergSanitizer.cmake  | 41 +++++++++++++++++++++++
 6 files changed, 154 insertions(+)

diff --git a/.github/lsan-suppressions.txt b/.github/lsan-suppressions.txt
new file mode 100644
index 0000000..fc26ee8
--- /dev/null
+++ b/.github/lsan-suppressions.txt
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# Add specific leak suppressions here if needed
+# Format:
+# leak:SymbolName
+# leak:source_file.cc
diff --git a/.github/ubsan-suppressions.txt b/.github/ubsan-suppressions.txt
new file mode 100644
index 0000000..68e4ea1
--- /dev/null
+++ b/.github/ubsan-suppressions.txt
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# Add specific undefined suppressions here if needed
+# Format:
+# signed-integer-overflow:source_file.cc
diff --git a/.github/workflows/sanitizer_test.yml b/.github/workflows/sanitizer_test.yml
new file mode 100644
index 0000000..6c9c50e
--- /dev/null
+++ b/.github/workflows/sanitizer_test.yml
@@ -0,0 +1,63 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: ASAN and UBSAN Tests
+
+on:
+  push:
+    branches:
+      - '**'
+      - '!dependabot/**'
+    tags:
+      - '**'
+  pull_request:
+
+concurrency:
+  group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }}
+  cancel-in-progress: true
+
+permissions:
+  contents: read
+
+jobs:
+  sanitizer-test:
+    name: "ASAN and UBSAN Tests"
+    runs-on: ubuntu-24.04
+    strategy:
+      fail-fast: false
+    steps:
+      - name: Checkout iceberg-cpp
+        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
+      - name: Configure and Build with ASAN & UBSAN
+        run: |
+          mkdir build && cd build
+          cmake .. -DCMAKE_BUILD_TYPE=Debug -DICEBERG_ENABLE_ASAN=ON -DICEBERG_ENABLE_UBSAN=ON
+          cmake --build . --verbose
+      - name: Run Tests
+        working-directory: build
+        env:
+          ASAN_OPTIONS: log_path=out.log:detect_leaks=1:symbolize=1:strict_string_checks=1:halt_on_error=0:detect_container_overflow=0
+          LSAN_OPTIONS: suppressions=${{ github.workspace }}/.github/lsan-suppressions.txt
+          UBSAN_OPTIONS: log_path=out.log:halt_on_error=0:print_stacktrace=1:suppressions=${{ github.workspace }}/.github/ubsan-suppressions.txt
+        run: |
+          ctest --output-on-failure
+      - name: Save the test output
+        if: always()
+        uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
+        with:
+          name: test-output
+          path: build/test/out.log*
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b1fc22c..9c2a4fe 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -37,6 +37,8 @@ option(ICEBERG_BUILD_STATIC "Build static library" ON)
 option(ICEBERG_BUILD_SHARED "Build shared library" OFF)
 option(ICEBERG_BUILD_TESTS "Build tests" ON)
 option(ICEBERG_BUILD_BUNDLE "Build the battery included library" ON)
+option(ICEBERG_ENABLE_ASAN "Enable Address Sanitizer" OFF)
+option(ICEBERG_ENABLE_UBSAN "Enable Undefined Behavior Sanitizer" OFF)
 
 include(GNUInstallDirs)
 include(FetchContent)
@@ -55,6 +57,7 @@ endif()
 
 include(CMakeParseArguments)
 include(IcebergBuildUtils)
+include(IcebergSanitizer)
 include(IcebergThirdpartyToolchain)
 include(GenerateExportHeader)
 
diff --git a/cmake_modules/IcebergBuildUtils.cmake b/cmake_modules/IcebergBuildUtils.cmake
index 8a30753..a6a7212 100644
--- a/cmake_modules/IcebergBuildUtils.cmake
+++ b/cmake_modules/IcebergBuildUtils.cmake
@@ -147,6 +147,9 @@ function(add_iceberg_lib LIB_NAME)
                                  "$<INSTALL_INTERFACE:${ARG_SHARED_INSTALL_INTERFACE_LIBS}>"
                           PRIVATE ${ARG_SHARED_PRIVATE_LINK_LIBS})
 
+    target_link_libraries(${LIB_NAME}_shared
+                          PUBLIC "$<BUILD_INTERFACE:iceberg_sanitizer_flags>")
+
     install(TARGETS ${LIB_NAME}_shared
             EXPORT iceberg_targets
             ARCHIVE DESTINATION ${INSTALL_ARCHIVE_DIR}
@@ -202,6 +205,9 @@ function(add_iceberg_lib LIB_NAME)
                             PUBLIC "$<BUILD_INTERFACE:${ARG_STATIC_LINK_LIBS}>")
     endif()
 
+    target_link_libraries(${LIB_NAME}_static
+                          PUBLIC "$<BUILD_INTERFACE:iceberg_sanitizer_flags>")
+
     install(TARGETS ${LIB_NAME}_static
             EXPORT iceberg_targets
             ARCHIVE DESTINATION ${INSTALL_ARCHIVE_DIR}
diff --git a/cmake_modules/IcebergSanitizer.cmake b/cmake_modules/IcebergSanitizer.cmake
new file mode 100644
index 0000000..b2fbecd
--- /dev/null
+++ b/cmake_modules/IcebergSanitizer.cmake
@@ -0,0 +1,41 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+add_library(iceberg_sanitizer_flags INTERFACE)
+
+if(ICEBERG_ENABLE_ASAN)
+  if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
+    target_compile_options(iceberg_sanitizer_flags INTERFACE -fsanitize=address
+                                                             -fno-omit-frame-pointer)
+    target_link_options(iceberg_sanitizer_flags INTERFACE -fsanitize=address)
+    message(STATUS "Address Sanitizer enabled")
+  else()
+    message(WARNING "Address Sanitizer is only supported for GCC and Clang compilers")
+  endif()
+endif()
+
+if(ICEBERG_ENABLE_UBSAN)
+  if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
+    target_compile_options(iceberg_sanitizer_flags INTERFACE -fsanitize=undefined
+                                                             -fno-omit-frame-pointer)
+    target_link_options(iceberg_sanitizer_flags INTERFACE -fsanitize=undefined)
+    message(STATUS "Undefined Behavior Sanitizer enabled")
+  else()
+    message(WARNING "Undefined Behavior Sanitizer is only supported for GCC and Clang compilers"
+    )
+  endif()
+endif()