Skip to content

Commit 0f184d0

Browse files
committed
build: add thread sanitizer
We have a cmake option to build Tntcxx with sanitizers. Currently, only memory and UB sanitizers are used - let's populate the list with thread sanitizer since we have a test for a multithreaded scenario.
1 parent ec67826 commit 0f184d0

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

.github/actions/build-tntcxx/action.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ inputs:
44
build-type:
55
description: 'Corresponds to CMAKE_BUILD_TYPE variable of CMake'
66
required: true
7-
enable-sanitizers:
8-
description: 'Corresponds to TNTCXX_ENABLE_SANITIZERS option of CMake'
7+
enable-address-sanitizers:
8+
description: 'Corresponds to TNTCXX_ENABLE_ADDRESS_SANITIZERS option of CMake'
9+
default: 'false'
10+
enable-thread-sanitizers:
11+
description: 'Corresponds to TNTCXX_ENABLE_THREAD_SANITIZERS option of CMake'
912
default: 'false'
1013
cxx-standard:
1114
description: 'Corresponds to CMAKE_CXX_STANDARD option of CMake'
@@ -26,7 +29,8 @@ runs:
2629
-DTNTCXX_BUILD_TESTING=ON \
2730
-DTNTCXX_ENABLE_SSL=ON \
2831
-DCMAKE_BUILD_TYPE=${{ inputs.build-type }} \
29-
-DTNTCXX_ENABLE_SANITIZERS=${{ inputs.enable-sanitizers }} \
32+
-DTNTCXX_ENABLE_ADDRESS_SANITIZERS=${{ inputs.enable-address-sanitizers }} \
33+
-DTNTCXX_ENABLE_THREAD_SANITIZERS=${{ inputs.enable-thread-sanitizers }} \
3034
-DCMAKE_CXX_STANDARD=${{ inputs.cxx-standard }} \
3135
-DCMAKE_C_COMPILER=${{ inputs.c-compiler }} \
3236
-DCMAKE_CXX_COMPILER=${{ inputs.cxx-compiler }} \

.github/workflows/reusable-testing.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ on:
2121
use-valgrind:
2222
default: false
2323
type: boolean
24-
enable-sanitizers:
24+
enable-address-sanitizers:
25+
default: false
26+
type: boolean
27+
enable-thread-sanitizers:
2528
default: false
2629
type: boolean
2730
build-only:
@@ -49,7 +52,8 @@ jobs:
4952
uses: ./.github/actions/build-tntcxx
5053
with:
5154
build-type: ${{ inputs.build-type }}
52-
enable-sanitizers: ${{ inputs.enable-sanitizers }}
55+
enable-address-sanitizers: ${{ inputs.enable-address-sanitizers }}
56+
enable-thread-sanitizers: ${{ inputs.enable-thread-sanitizers }}
5357
cxx-standard: ${{ inputs.cxx-standard }}
5458
c-compiler: ${{ inputs.c-compiler }}
5559
cxx-compiler: ${{ inputs.cxx-compiler }}

.github/workflows/testing.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
build-type: ${{ matrix.build-type }}
8383
use-valgrind: true
8484

85-
sanitizers:
85+
address-sanitizers:
8686
uses: ./.github/workflows/reusable-testing.yml
8787
strategy:
8888
fail-fast: false
@@ -100,10 +100,36 @@ jobs:
100100
exclude:
101101
- runs-on: macos-14
102102
compiler: {c: gcc, cxx: g++}
103-
name: sanitizers (${{ matrix.runs-on }}, ${{ matrix.build-type }}, ${{ matrix.compiler.c }})
103+
name: address sanitizers (${{ matrix.runs-on }}, ${{ matrix.build-type }}, ${{ matrix.compiler.c }})
104104
with:
105105
runs-on: ${{ matrix.runs-on }}
106106
build-type: ${{ matrix.build-type }}
107107
c-compiler: ${{ matrix.compiler.c }}
108108
cxx-compiler: ${{ matrix.compiler.cxx }}
109-
enable-sanitizers: true
109+
enable-address-sanitizers: true
110+
111+
thread-sanitizers:
112+
uses: ./.github/workflows/reusable-testing.yml
113+
strategy:
114+
fail-fast: false
115+
matrix:
116+
runs-on:
117+
- ubuntu-22.04
118+
- macos-14
119+
build-type:
120+
- Debug
121+
- RelWithDebInfo
122+
compiler:
123+
- {c: gcc, cxx: g++}
124+
- {c: clang, cxx: clang++}
125+
# gcc on macos is just an alias for clang
126+
exclude:
127+
- runs-on: macos-14
128+
compiler: {c: gcc, cxx: g++}
129+
name: thread sanitizers (${{ matrix.runs-on }}, ${{ matrix.build-type }}, ${{ matrix.compiler.c }})
130+
with:
131+
runs-on: ${{ matrix.runs-on }}
132+
build-type: ${{ matrix.build-type }}
133+
c-compiler: ${{ matrix.compiler.c }}
134+
cxx-compiler: ${{ matrix.compiler.cxx }}
135+
enable-thread-sanitizers: true

CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ IF (TNTCXX_BUILD_TESTING)
9191
ENDIF()
9292

9393
OPTION(TNTCXX_ENABLE_SANITIZERS
94-
"If ON, tntcxx will be instrumented with sanitizers."
94+
"If passed, tntcxx will be instrumented with sanitizers. Possible values: \"NONE\", \"ADDRESS\", \"THREAD\""
9595
OFF)
9696

97-
IF (TNTCXX_ENABLE_SANITIZERS)
97+
IF (NOT TNTCXX_ENABLE_SANITIZERS)
98+
# Santiizers are disabled - do nothing.
99+
ELSEIF (TNTCXX_ENABLE_SANITIZERS STREQUAL "ARRDESS")
98100
SET(SANITIZER_FLAGS "-fsanitize=address")
99101
# FIXME(gh-62)
100102
IF (NOT CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
@@ -114,6 +116,12 @@ IF (TNTCXX_ENABLE_SANITIZERS)
114116
# for details).
115117
ADD_COMPILE_OPTIONS(${SANITIZER_FLAGS})
116118
ADD_LINK_OPTIONS(${SANITIZER_FLAGS})
119+
ELSEIF (TNTCXX_ENABLE_SANITIZERS STREQUAL "THREAD")
120+
SET(SANITIZER_FLAGS "-fsanitize=thread")
121+
ADD_COMPILE_OPTIONS(${SANITIZER_FLAGS})
122+
ADD_LINK_OPTIONS(${SANITIZER_FLAGS})
123+
ELSE ()
124+
MESSAGE(FATAL_ERROR "Unknown TNTCXX_ENABLED_SANITIZERS value")
117125
ENDIF()
118126

119127
# Common function for building tests.

0 commit comments

Comments
 (0)