Skip to content

Commit 246ca22

Browse files
committed
build/ci: add thread sanitizer workflow
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 and use it on CI. Since address and thread sanitizers cannot be used together, existing cmake option `TNTCXX_ENABLE_SANITIZERS` is extended - now it accepts "address" and "thread" arguments to choose a sanitizer. Part of #110
1 parent 73f8f5e commit 246ca22

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ inputs:
66
required: true
77
enable-sanitizers:
88
description: 'Corresponds to TNTCXX_ENABLE_SANITIZERS option of CMake'
9-
default: 'false'
9+
default: ''
1010
cxx-standard:
1111
description: 'Corresponds to CMAKE_CXX_STANDARD option of CMake'
1212
cxx-compiler:

.github/workflows/reusable-testing.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ on:
2222
default: false
2323
type: boolean
2424
enable-sanitizers:
25-
default: false
26-
type: boolean
25+
default: ''
26+
type: string
2727
build-only:
2828
default: false
2929
type: boolean

.github/workflows/testing.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,13 @@ 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+
sanitizer:
104+
- thread
105+
- address
106+
name: sanitizers (${{ matrix.sanitizer }}, ${{ matrix.runs-on }}, ${{ matrix.build-type }}, ${{ matrix.compiler.c }})
104107
with:
105108
runs-on: ${{ matrix.runs-on }}
106109
build-type: ${{ matrix.build-type }}
107110
c-compiler: ${{ matrix.compiler.c }}
108111
cxx-compiler: ${{ matrix.compiler.cxx }}
109-
enable-sanitizers: true
112+
enable-sanitizers: ${{ matrix.sanitizer }}

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: \"address\", \"thread\""
9595
OFF)
9696

97-
IF (TNTCXX_ENABLE_SANITIZERS)
97+
IF (NOT TNTCXX_ENABLE_SANITIZERS)
98+
# Sanitizers are disabled - do nothing.
99+
ELSEIF (TNTCXX_ENABLE_SANITIZERS STREQUAL "address")
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_ENABLE_SANITIZERS value")
117125
ENDIF()
118126

119127
# Common function for building tests.

0 commit comments

Comments
 (0)