From b85c4e8073dacd071ea407feaa1fb964e98a34ed Mon Sep 17 00:00:00 2001 From: "chenyangyang.cy" Date: Thu, 21 Sep 2023 17:04:24 +0800 Subject: [PATCH] Add sanitizer test --- .github/workflows/ci.yml | 39 +++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 14 ++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec72ce5..4778ab3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -169,6 +169,45 @@ jobs: run: | cd build lcov -c -d ./ -o cover.info + - uses: codecov/codecov-action@v1 + with: + file: build/cover.info + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true + + test-sanitizer-address-scan-mode: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: clone and make redis + run: | + sudo apt-get install git + git clone https://github.com/redis/redis + cd redis + git checkout 7.0 + make SANITIZER=address REDIS_CFLAGS='-Werror' BUILD_TLS=yes + - name: Install LCOV + run: | + sudo apt-get --assume-yes install lcov > /dev/null + - name: make tairhash + run: | + mkdir build + cd build + cmake ../ -DSANITIZER_MODE=address + make + - name: test + run: | + sudo apt-get install tcl8.6 tclx + work_path=$(pwd) + module_path=$work_path/lib + sed -e "s#your_path#$module_path#g" tests/tairhash.tcl > redis/tests/unit/type/tairhash.tcl + sed -i 's#unit/type/string#unit/type/tairhash#g' redis/tests/test_helper.tcl + cd redis + ./runtest --stack-logging --single unit/type/tairhash + - name: lcov collection + run: | + cd build + lcov -c -d ./ -o cover.info - uses: codecov/codecov-action@v1 with: file: build/cover.info diff --git a/CMakeLists.txt b/CMakeLists.txt index cafe310..9447861 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,20 @@ if (GCOV_MODE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") endif() +if(SANITIZER_MODE MATCHES "address") + set(CMAKE_BUILD_TYPE "DEBUG") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -fsanitize=address -fno-omit-frame-pointer") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -fsanitize=address -fno-omit-frame-pointer") +elseif(SANITIZER_MODE MATCHES "undefined") + set(CMAKE_BUILD_TYPE "DEBUG") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -fsanitize=undefined -fno-omit-frame-pointer") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -fsanitize=undefined -fno-omit-frame-pointer") +elseif(SANITIZER_MODE MATCHES "thread") + set(CMAKE_BUILD_TYPE "DEBUG") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -fsanitize=thread -fno-omit-frame-pointer") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -fsanitize=thread -fno-omit-frame-pointer") +endif(SANITIZER_MODE MATCHES "address") + set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_C_VISIBILITY_PRESET hidden)