You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by ti...@apache.org on 2022/06/02 08:20:38 UTC

[incubator-kvrocks] branch unstable updated: Improve using of ASan and TSan in CMake build (#599)

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

tison pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new a13465b  Improve using of ASan and TSan in CMake build (#599)
a13465b is described below

commit a13465b5306a40ca04e37db02595bee0b36b0192
Author: Twice <i...@twice.moe>
AuthorDate: Thu Jun 2 16:20:33 2022 +0800

    Improve using of ASan and TSan in CMake build (#599)
---
 .github/workflows/daily-ci.yaml | 29 +++++++++++++++++++++++++++++
 CMakeLists.txt                  | 19 ++++++++++++++++++-
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/daily-ci.yaml b/.github/workflows/daily-ci.yaml
index 587b457..8d6dd94 100644
--- a/.github/workflows/daily-ci.yaml
+++ b/.github/workflows/daily-ci.yaml
@@ -64,8 +64,37 @@ jobs:
         run: |
           mkdir build && cd build
           cmake -DDISABLE_JEMALLOC=true -DCMAKE_BUILD_TYPE=Release ..
+          make -j4
+          cd ..
+
+      - name: Redis Tcl Test
+        run: |
+          sudo apt-get install tcl8.5
+          cd tests/tcl && sh runtest && cd -
+
+  build-on-ubuntu-with-sanitizers:
+    strategy:
+      matrix:
+        os: [ubuntu-18.04]
+        sanitizer: [ENABLE_ASAN=ON, ENABLE_TSAN=ON]
+    
+    runs-on: ${{ matrix.os }}
+    steps:
+      - name: Checkout Code Base
+        uses: actions/checkout@v2.3.4
+        with:
+          fetch-depth: 64
+
+      - name: Build
+        run: |
+          mkdir build && cd build
+          cmake -D${{ matrix.sanitizer }} ..
           make -j4 kvrocks kvrocks2redis
           cd ..
+        
+      - name: Unit Test
+        run: |
+          ./build/unittest
 
       - name: Redis Tcl Test
         run: |
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2ea4878..00a68db 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,9 +21,15 @@ project(kvrocks
         LANGUAGES CXX)
 
 option(DISABLE_JEMALLOC "disable use of the jemalloc library" OFF)
-option(ENABLE_ASAN "enable ASAN santinizer" OFF)
+option(ENABLE_ASAN "enable address santinizer" OFF)
+option(ENABLE_TSAN "enable thread santinizer" OFF)
+option(ASAN_WITH_LSAN "enable leak santinizer while address santinizer is enabled" ON)
 option(ENABLE_STATIC_LIBSTDCXX "link kvrocks with static library of libstd++ instead of shared library" ON)
 
+if(ENABLE_ASAN AND ENABLE_TSAN)
+    message(FATAL_ERROR "ASan and TSan cannot be used at the same time")
+endif()
+
 # GLIBC < 2.17 should explict specify the real time library when use clock_*
 find_library(REALTIME_LIB rt)
 if (REALTIME_LIB)
@@ -94,9 +100,20 @@ target_compile_features(kvrocks_objs PUBLIC cxx_std_11)
 target_compile_options(kvrocks_objs PUBLIC ${WARNING_FLAGS} -fno-omit-frame-pointer)
 target_link_libraries(kvrocks_objs PUBLIC -fno-omit-frame-pointer)
 if(ENABLE_ASAN)
+    if(ASAN_WITH_LSAN)
+        if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5"))
+            message(FATAL_ERROR "leak sanitizer is not supported until gcc 5")
+        endif()
+        target_compile_options(kvrocks_objs PUBLIC -fsanitize=leak)
+        target_link_libraries(kvrocks_objs PUBLIC -fsanitize=leak)
+    endif()
     target_compile_options(kvrocks_objs PUBLIC -fsanitize=address)
     target_link_libraries(kvrocks_objs PUBLIC -fsanitize=address)
 endif()
+if(ENABLE_TSAN)
+    target_compile_options(kvrocks_objs PUBLIC -fsanitize=thread)
+    target_link_libraries(kvrocks_objs PUBLIC -fsanitize=thread)
+endif()
 target_link_libraries(kvrocks_objs PUBLIC ${EXTERNAL_LIBS})
 if(FOUND_UNWIND_LIB)
     target_link_libraries(kvrocks_objs PUBLIC ${FOUND_UNWIND_LIB})