diff --git a/.github/workflows/kvrocks.yaml b/.github/workflows/kvrocks.yaml index 1f30f4e55ab..432e03e1d3a 100644 --- a/.github/workflows/kvrocks.yaml +++ b/.github/workflows/kvrocks.yaml @@ -79,28 +79,26 @@ jobs: compiler: clang - name: Ubuntu GCC ASan os: ubuntu-18.04 + without_jemalloc: -DDISABLE_JEMALLOC=ON with_sanitizer: -DENABLE_ASAN=ON compiler: gcc - # - name: Ubuntu GCC TSan - # os: ubuntu-18.04 - # with_sanitizer: -DENABLE_TSAN=ON - # compiler: gcc - - name: Ubuntu GCC without Jemalloc + - name: Ubuntu GCC TSan os: ubuntu-18.04 without_jemalloc: -DDISABLE_JEMALLOC=ON + with_sanitizer: -DENABLE_TSAN=ON compiler: gcc + runtime_env_vars: TSAN_OPTIONS="suppressions=$(realpath ./tests/tsan-suppressions)" - name: Ubuntu Clang ASan os: ubuntu-18.04 with_sanitizer: -DENABLE_ASAN=ON + without_jemalloc: -DDISABLE_JEMALLOC=ON compiler: clang - # - name: Ubuntu Clang TSan - # os: ubuntu-18.04 - # with_sanitizer: -DENABLE_TSAN=ON - # compiler: clang - - name: Ubuntu Clang without Jemalloc + - name: Ubuntu Clang TSan os: ubuntu-18.04 + with_sanitizer: -DENABLE_TSAN=ON without_jemalloc: -DDISABLE_JEMALLOC=ON compiler: clang + runtime_env_vars: TSAN_OPTIONS="suppressions=$(realpath ./tests/tsan-suppressions)" - name: Ubuntu GCC Ninja os: ubuntu-18.04 with_ninja: --ninja @@ -158,10 +156,13 @@ jobs: run: ./x.py build -j$NPROC --unittest --compiler ${{ matrix.compiler }} ${{ matrix.with_ninja }} ${{ matrix.with_sanitizer }} ${{ matrix.without_jemalloc }} ${{ matrix.without_luajit }} - name: Run Unit Test - run: ./build/unittest + run: | + export ${{ matrix.runtime_env_vars }} + ./build/unittest - name: Run Redis Tcl Test run: | + export ${{ matrix.runtime_env_vars }} cp $HOME/local/bin/redis-cli tests/tcl/redis-cli cd tests/tcl ./runtest --dont-clean diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b7a65b1a5c..b2aed45f206 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,29 @@ if(ENABLE_ASAN AND ENABLE_TSAN) message(FATAL_ERROR "ASan and TSan cannot be used at the same time") endif() +if((ENABLE_ASAN OR ENABLE_TSAN) AND (NOT DISABLE_JEMALLOC)) + message(FATAL_ERROR "ASan/TSan does not work well with JeMalloc") +endif() + +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() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=leak") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=leak") + endif() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") +endif() +if(ENABLE_TSAN) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread") +endif() + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # GLIBC < 2.17 should explict specify the real time library when use clock_* @@ -121,21 +144,6 @@ target_include_directories(kvrocks_objs PUBLIC src ${PROJECT_BINARY_DIR}) 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}) diff --git a/cmake/lua.cmake b/cmake/lua.cmake index 8e55d4e3cec..a62ae9c9118 100644 --- a/cmake/lua.cmake +++ b/cmake/lua.cmake @@ -29,7 +29,7 @@ if(NOT lua_POPULATED) FetchContent_Populate(lua) set(LUA_CXX ${CMAKE_CXX_COMPILER}) - set(LUA_CFLAGS "${CMAKE_CXX_FLAGS} -fpermissive -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC= -DLUA_USE_MKSTEMP") + set(LUA_CFLAGS "-DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC= -DLUA_USE_MKSTEMP") if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") set(LUA_CFLAGS "${LUA_CFLAGS} -isysroot ${CMAKE_OSX_SYSROOT}") endif() diff --git a/cmake/luajit.cmake b/cmake/luajit.cmake index fd6010552d7..f7bdde26f06 100644 --- a/cmake/luajit.cmake +++ b/cmake/luajit.cmake @@ -33,14 +33,12 @@ if(NOT lua_POPULATED) set(LUA_CFLAGS "${LUA_CFLAGS} -isysroot ${CMAKE_OSX_SYSROOT}") endif() - set(MACOSX_TARGET "") if (CMAKE_HOST_APPLE) - set(MACOSX_TARGET "MACOSX_DEPLOYMENT_TARGET=11.0") + set(MACOSX_TARGET "MACOSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}") endif() add_custom_target(make_luajit COMMAND make libluajit.a - "CFLAGS=${LUA_CFLAGS}" - ${MACOSX_TARGET} + "CFLAGS=${LUA_CFLAGS}" ${MACOSX_TARGET} WORKING_DIRECTORY ${luajit_SOURCE_DIR}/src BYPRODUCTS ${luajit_SOURCE_DIR}/src/libluajit.a ) diff --git a/tests/tsan-suppressions b/tests/tsan-suppressions new file mode 100644 index 00000000000..77d670ee4e7 --- /dev/null +++ b/tests/tsan-suppressions @@ -0,0 +1,22 @@ +# 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. + +# ThreadSanitizer suppressions file for Kvrocks +# refer to https://github.com/google/sanitizers/wiki/ThreadSanitizerSuppressions + +# suppress data race in google::LogMessageTime::CalcGmtOffset() +race:google::LogMessageTime::CalcGmtOffset