From 14f4567570bd754c74a6bb6ed17f0cf3e04ac35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Kardos?= Date: Tue, 20 Feb 2024 23:06:57 +0100 Subject: [PATCH] sanitize CI --- .github/workflows/sanitizer.yml | 101 ++++++++++++++++++++++++++++++++ CMakeLists.txt | 4 ++ sanitize_ignorelist.txt | 1 + 3 files changed, 106 insertions(+) create mode 100644 .github/workflows/sanitizer.yml create mode 100644 sanitize_ignorelist.txt diff --git a/.github/workflows/sanitizer.yml b/.github/workflows/sanitizer.yml new file mode 100644 index 0000000..0825cf4 --- /dev/null +++ b/.github/workflows/sanitizer.yml @@ -0,0 +1,101 @@ +name: Sanitize + +on: + push: + branches: + - master + tags: + - v**.** + pull_request: + branches: + - master + +jobs: + sanitize: + strategy: + fail-fast: false + matrix: + # sanitize: [address, memory, thread] + sanitize: [address] + include: + - sanitize: address + sanitize_flag: ENABLE_LLVM_ADDRESS_SANITIZER + # - sanitize: memory + # sanitize_flag: ENABLE_LLVM_MEMORY_SANITIZER + # - sanitize: thread + # sanitize_flag: ENABLE_LLVM_THREAD_SANITIZER + + env: + os: "ubuntu-latest" + build_type: "Debug" + cxx_standard: "20" + c_compiler: "clang" + cxx_compiler: "clang++" + conan_preset: "conan-debug" + + name: ${{ matrix.sanitize }} + + runs-on: "ubuntu-latest" + + steps: + - uses: actions/checkout@v4 + - uses: seanmiddleditch/gha-setup-ninja@v4 + - uses: seanmiddleditch/gha-setup-vsdevenv@master + - uses: KyleMayes/install-llvm-action@v1 + with: + version: "17.0" + directory: ${{ runner.temp }}/llvm + + - name: Install GCC + shell: bash + run: | + sudo add-apt-repository ppa:ubuntu-toolchain-r/test + sudo apt update + sudo apt install gcc-13 g++-13 + sudo update-alternatives --remove-all gcc || true + sudo update-alternatives --remove-all g++ || true + sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 10 --slave /usr/bin/g++ g++ /usr/bin/g++-13 + + - name: Install conan + shell: bash + env: + CC: "${{ env.c_compiler != 'cl' && env.c_compiler || '' }}" + CXX: "${{ env.cxx_compiler != 'cl' && env.cxx_compiler || '' }}" + run: | + pip install conan + conan profile detect --name ci --force + python $GITHUB_WORKSPACE/support/update-conan-profile.py $(conan profile path ci) ${{env.build_type}} ${{env.c_compiler}} ${{env.cxx_compiler}} ${{env.cxx_standard}} + + - name: Cache conan packages + id: cache-conan + uses: actions/cache@v3 + with: + path: ~/.conan2/p + key: conan-cache-packages-${{ env.os }}-${{ env.c_compiler }}-${{ env.build_type }}-${{ env.cxx_standard }} + + - name: Create Build Environment + run: cmake -E make_directory ${{runner.workspace}}/build + + - name: Configure CMake + shell: bash + working-directory: ${{runner.workspace}}/build + env: + CC: ${{env.c_compiler}} + CXX: ${{env.cxx_compiler}} + run: | + conan install $GITHUB_WORKSPACE --output-folder=. --build="*" -pr ci -pr:b ci -s build_type=${{ env.build_type }} + conan cache clean + cmake $GITHUB_WORKSPACE --preset ${{ env.conan_preset }} -D${{ matrix.sanitize_flag }}:BOOL=ON + + - name: Build + working-directory: ${{runner.workspace}}/build + shell: bash + run: | + cmake --build ./build/${{ env.build_type }} + cmake -E make_directory ${{runner.workspace}}/installation/SEDManager + cmake --install ./build/${{ env.build_type }} --prefix '${{runner.workspace}}/installation/SEDManager' + + - name: Test + working-directory: ${{runner.workspace}}/build + shell: bash + run: ./build/${{ env.build_type }}/bin/test diff --git a/CMakeLists.txt b/CMakeLists.txt index 249d641..370d12f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,19 +19,23 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") add_compile_options("-fprofile-instr-generate" "-fcoverage-mapping" "-mllvm" "-enable-name-compression=false") add_link_options("-fprofile-instr-generate" "-fcoverage-mapping") endif() + file(REAL_PATH "${CMAKE_SOURCE_DIR}/sanitize_ignorelist.txt" sanitize_ignorelist) if (ENABLE_LLVM_ADDRESS_SANITIZER) message("Using address sanitizer") add_compile_options("-fsanitize=address") + add_compile_options("-fsanitize-ignorelist=${sanitize_ignorelist}") add_link_options("-fsanitize=address") endif() if (ENABLE_LLVM_MEMORY_SANITIZER) message("Using memory sanitizer") add_compile_options("-fsanitize=memory") + add_compile_options("-fsanitize-ignorelist=${sanitize_ignorelist}") add_link_options("-fsanitize=memory") endif() if (ENABLE_LLVM_THREAD_SANITIZER) message("Using thread sanitizer") add_compile_options("-fsanitize=thread") + add_compile_options("-fsanitize-ignorelist=${sanitize_ignorelist}") add_link_options("-fsanitize=thread") endif() endif() diff --git a/sanitize_ignorelist.txt b/sanitize_ignorelist.txt new file mode 100644 index 0000000..5f8e641 --- /dev/null +++ b/sanitize_ignorelist.txt @@ -0,0 +1 @@ +mainfile:*/catch2/* \ No newline at end of file