Skip to content

Commit

Permalink
Added an action with sanitizers enabled for GCC / Clang in GitHub CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
FranckRJ committed Apr 16, 2023
1 parent 04d9638 commit 5d6c990
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/ci_linux_clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,25 @@ jobs:
cc: "clang-14", cxx: "clang++-14",
cxx_standard: 20
}
- {
name: "Ubuntu 22.04 Clang with sanitizers",
os: ubuntu-22.04,
build_type: Debug,
cc: "clang", cxx: "clang++",
enable_sanitizers_in_tests: ON
}
steps:
- uses: actions/checkout@v2
- name: Build project
env:
CC: ${{ matrix.config.cc }}
CXX: ${{ matrix.config.cxx }}
run: |
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -DENABLE_TESTING=ON -DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }}
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
-DENABLE_TESTING=ON \
-DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }} \
-DENABLE_SANITIZERS_IN_TESTS=${{ matrix.config.enable_sanitizers_in_tests }}
cmake --build build -j
- name: Run tests
run: |
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/ci_linux_gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,25 @@ jobs:
cc: "gcc-12", cxx: "g++-12",
cxx_standard: 20
}
- {
name: "Ubuntu 22.04 GCC with sanitizers",
os: ubuntu-22.04,
build_type: Debug,
cc: "gcc", cxx: "g++",
enable_sanitizers_in_tests: ON
}
steps:
- uses: actions/checkout@v2
- name: Build project
env:
CC: ${{ matrix.config.cc }}
CXX: ${{ matrix.config.cxx }}
run: |
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -DENABLE_TESTING=ON -DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }}
cmake -S . -B build \
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
-DENABLE_TESTING=ON \
-DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }} \
-DENABLE_SANITIZERS_IN_TESTS=${{ matrix.config.enable_sanitizers_in_tests }}
cmake --build build -j
- name: Run tests
run: |
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/ci_windows_msvc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ jobs:
- uses: actions/checkout@v2
- name: Build project
run: |
cmake -S . -B build -G "${{ matrix.config.generator }}" -A ${{ matrix.config.architecture }} -DENABLE_TESTING=ON -DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }}
cmake -S . -B build \
-G "${{ matrix.config.generator }}" \
-A ${{ matrix.config.architecture }} \
-DENABLE_TESTING=ON \
-DOVERRIDE_CXX_STANDARD_FOR_TESTS=${{ matrix.config.cxx_standard }}
cmake --build build --config ${{ matrix.config.build_type }} -j
- name: Run tests
run: |
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ cmake_minimum_required(VERSION 3.14)

project(FakeIt VERSION 2.3.2 LANGUAGES CXX)

option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang." OFF)
option(ENABLE_TESTING "Enable build of tests." OFF)
option(OVERRIDE_CXX_STANDARD_FOR_TESTS "Override the C++ standard used for building tests." "")
option(ENABLE_SANITIZERS_IN_TESTS "Enable address / undefined sanitizers in tests." OFF)
option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang." OFF)

# Directory containing main targets of FakeIt.
add_subdirectory(include)
Expand Down
11 changes: 11 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ if(OVERRIDE_CXX_STANDARD_FOR_TESTS)
message(STATUS "Building tests in C++${OVERRIDE_CXX_STANDARD_FOR_TESTS}.")
endif()

if(ENABLE_SANITIZERS_IN_TESTS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
target_compile_options(FakeIt_tests PRIVATE -fsanitize=address,undefined -fno-sanitize-recover=address,undefined)
target_link_options(FakeIt_tests PRIVATE -fsanitize=address,undefined -fno-sanitize-recover=address,undefined)
target_compile_definitions(FakeIt_tests PRIVATE FAKEIT_DISABLE_UBSAN_TRIGGERING_TESTS)
message(STATUS "Sanitizers enabled: address, undefined.")
else()
message(SEND_ERROR "Sanitizers requested but compiler is not compatible.")
endif()
endif()

if(ENABLE_COVERAGE)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
target_compile_options(FakeIt_tests PRIVATE --coverage)
Expand Down

0 comments on commit 5d6c990

Please sign in to comment.