Skip to content

Commit 31b9fe4

Browse files
committed
[actions] Run Clang ASAN, TSAN, and UBSAN
1 parent f10ccd9 commit 31b9fe4

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Clang Sanitizers
2+
3+
# On all pushes to branches and pull requests in general.
4+
on:
5+
push:
6+
pull_request:
7+
8+
env:
9+
# Build debug because tracepp only functions under debug builds.
10+
BUILD_TYPE: Debug
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
sanitizer: [ADDRESS_SANITIZER, THREAD_SANITIZER, UNDEFINED_SANITIZER]
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
22+
- name: Configure cmake
23+
run: CC=clang CXX=clang++ cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -D${{matrix.sanitizer}}=ON -DEVERY_WARNING=ON
24+
25+
- name: Build
26+
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --verbose
27+
28+
- name: Test
29+
working-directory: ${{github.workspace}}/build
30+
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
31+
32+
- name: Test sporadic failures
33+
working-directory: ${{github.workspace}}/build
34+
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure --repeat until-fail:20 -R tests
35+
36+
- name: Run examples
37+
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --verbose --target run_examples

CMakeLists.txt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.20)
22
project(tracepp)
33

44
option(ADDRESS_SANITIZER "Use memory error detector (clang only and implies debug mode!)" OFF)
5+
option(ADDRESS_SANITIZER "Use memory error detector (clang only and implies debug mode!)" OFF)
6+
option(THREAD_SANITIZER "Use thread data race detector (clang only and implies debug mode!)" OFF)
7+
option(UNDEFINED_SANITIZER "Use undefined behavior detector (clang only and implies debug mode!)" OFF)
58
option(EVERY_WARNING "Use -Weverything (clang only)" OFF)
69

710
# Exports the "compile_commands.json" file when the generator is Ninja or Makefile.
@@ -16,11 +19,15 @@ if (NOT CMAKE_BUILD_TYPE)
1619
endif()
1720

1821
if (ADDRESS_SANITIZER)
19-
if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
20-
message(FATAL_ERROR "Clang is required to use address sanitizer to detect memory errors!")
21-
endif()
22-
23-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1 -g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls")
22+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls")
23+
set(CMAKE_BUILD_TYPE Debug)
24+
endif()
25+
if (THREAD_SANITIZER)
26+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
27+
set(CMAKE_BUILD_TYPE Debug)
28+
endif()
29+
if (UNDEFINED_SANITIZER)
30+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
2431
set(CMAKE_BUILD_TYPE Debug)
2532
endif()
2633

0 commit comments

Comments
 (0)