Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve using of ASan and TSan in CMake build #599

Merged
merged 3 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/daily-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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})
Expand Down