diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d82014b..e4fddcb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,6 +3,7 @@ image: "ubuntu:latest" stages: - build - test + - sanitizer before_script: - apt update; apt-get install --yes --force-yes build-essential cmake @@ -10,7 +11,7 @@ before_script: build_cmake: stage: build script: - ./build_cmake_release.sh + ./ci_scripts/build_cmake_release.sh artifacts: paths: - cmake-build-release/bin/ @@ -18,4 +19,12 @@ build_cmake: run_tests: stage: test script: - ./build_cmake_release.sh; ./cmake-build-release/bin/tests \ No newline at end of file + ./ci_scripts/run_tests.sh + +run_thread_sanitizer: + stage: sanitizer + script: + ./ci_scripts/run_thread_sanitizer.sh + artifacts: + paths: + - cmake-build-release/sanitizer.log.* \ No newline at end of file diff --git a/build_cmake_release.sh b/ci_scripts/build_cmake_release.sh similarity index 85% rename from build_cmake_release.sh rename to ci_scripts/build_cmake_release.sh index 2be8977..d962672 100755 --- a/build_cmake_release.sh +++ b/ci_scripts/build_cmake_release.sh @@ -2,7 +2,7 @@ mkdir cmake-build-release cd cmake-build-release -cmake .. -DCMAKE_BUILD_TYPE=RELEASE +cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DTHREAD_SANITIZER=OFF make # echo the result of make to show it in gitlab diff --git a/ci_scripts/run_tests.sh b/ci_scripts/run_tests.sh new file mode 100755 index 0000000..5876b92 --- /dev/null +++ b/ci_scripts/run_tests.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +mkdir cmake-build-release +cd cmake-build-release +cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DTHREAD_SANITIZER=OFF +make + +# run the actual tests +./bin/tests diff --git a/ci_scripts/run_thread_sanitizer.sh b/ci_scripts/run_thread_sanitizer.sh new file mode 100755 index 0000000..453cfc8 --- /dev/null +++ b/ci_scripts/run_thread_sanitizer.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +mkdir cmake-build-release-thread-sunitizer +cd cmake-build-release +cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DTHREAD_SANITIZER=ON +make + +# run the actual tests with sanitizer enabled, reporting the result +TSAN_OPTIONS="log_path=sanitizer.log exitcode=1" ./bin/tests \ No newline at end of file diff --git a/cmake/SetupThreadSanitizer.cmake b/cmake/SetupThreadSanitizer.cmake index 3854a46..4a5debd 100644 --- a/cmake/SetupThreadSanitizer.cmake +++ b/cmake/SetupThreadSanitizer.cmake @@ -5,6 +5,6 @@ option(THREAD_SANITIZER "Add thread sanitizer" OFF) if(THREAD_SANITIZER) add_compile_options(-fsanitize=thread -g) - add_link_options(-fsanitize=thread) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread") endif() message("-- Thread Sanitizer: ${THREAD_SANITIZER}") \ No newline at end of file