Skip to content

Commit

Permalink
ci: Add thread and address sanitisation
Browse files Browse the repository at this point in the history
Signed-off-by: Ole Petter <[email protected]>
  • Loading branch information
oleorhagen committed Feb 16, 2023
1 parent 9621c1f commit c0ecdfd
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ config.h
**/CMakeFiles/
/_deps/
*.cmake
!/cmake/*.cmake
/Testing
/install_manifest*.txt
25 changes: 25 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@ test:
paths:
- coverage.lcov

.test:static-template:
stage: test
image: ubuntu:22.04
before_script:
- apt update && apt install -yyq clang cmake git make pkg-config liblmdb++-dev libboost-dev libboost-log-dev
- export CC=$(which clang)
- export CXX=$(which clang++)
script:
- cmake
-D CMAKE_BUILD_TYPE=${BUILD_TYPE}
.
- make check
tags:
- mender-qa-worker-generic

test:static:asan:
variables:
BUILD_TYPE: ASan
extends: .test:static-template

test:static:threadsan:
extends: .test:static-template
variables:
BUILD_TYPE: ThreadSan

test:modules-artifact-gen:
stage: test
image: python:3.10
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ endif (POLICY CMP0135)

project(mender)

include(cmake/asan.cmake)
include(cmake/threadsan.cmake)
# set(CMAKE_VERBOSE_MAKEFILE ON)
enable_testing()

Expand Down
7 changes: 7 additions & 0 deletions cmake/asan.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include(cmake/helper.cmake)

if (CMAKE_BUILD_TYPE STREQUAL "ASan")
sanitizer_add_compiler_flags(ASAN
"-fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-scope"
"-fsanitize=address")
endif()
24 changes: 24 additions & 0 deletions cmake/helper.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@


function (sanitizer_add_compiler_flags CONFIG SANITIZER_BUILD_FLAGS SANITIZER_SHARED_LINKER_FLAGS)

message (STATUS "Adding the compiler flags flags: ${SANITIZER_BUILD_FLAGS}")
message (STATUS "Adding the linked flags: ${SANITIZER_SHARED_LINKER_FLAGS}")

set(CMAKE_C_FLAGS_${CONFIG}
"${CMAKE_C_FLAGS_DEBUG} ${SANITIZER_BUILD_FLAGS}" CACHE STRING
"Flags used by the C compiler for ${CONFIG} build type or configuration." FORCE)

set(CMAKE_CXX_FLAGS_${CONFIG}
"${CMAKE_CXX_FLAGS_DEBUG} ${SANITIZER_BUILD_FLAGS}" CACHE STRING
"Flags used by the C++ compiler for ${CONFIG} build type or configuration." FORCE)

set(CMAKE_EXE_LINKER_FLAGS_${CONFIG}
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${SANITIZER_BUILD_FLAGS}" CACHE STRING
"Linker flags to be used to create executables for ${CONFIG} build type." FORCE)

set(CMAKE_SHARED_LINKER_FLAGS_${CONFIG}
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${SANITIZER_SHARED_LINKER_FLAGS}" CACHE STRING
"Linker lags to be used to create shared libraries for ${CONFIG} build type." FORCE)

endfunction ()
7 changes: 7 additions & 0 deletions cmake/threadsan.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include(cmake/helper.cmake)

if (CMAKE_BUILD_TYPE STREQUAL "ThreadSan")
sanitizer_add_compiler_flags(THREADSAN
"-fsanitize=thread -fPIE -fpie"
"-fsanitize=thread")
endif()

0 comments on commit c0ecdfd

Please sign in to comment.