From 0acc1a2c8ea611fe8fcb5a3b9b94c42a9cf69407 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 22 Mar 2022 18:16:00 +0100 Subject: [PATCH] Add option for address sanitizer in tests, fixes valgrind in drone --- .drone.yml | 11 ++++++++++- CMakeLists.txt | 7 +++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.drone.yml b/.drone.yml index 8d3d870..3bcdf8b 100644 --- a/.drone.yml +++ b/.drone.yml @@ -28,6 +28,15 @@ steps: - cmake --build build-release --target all -- -j 4 - build-release/CreatureLibTests -s --duration=true --force-colors=true - valgrind --tool=memcheck --gen-suppressions=all --leak-check=full --leak-resolution=med --track-origins=yes --vgdb=no --error-exitcode=1 build-release/CreatureLibTests ~\[Exception\] + - name: test-release-linux + image: deukhoofd/linux64builder + environment: + CC: /usr/bin/clang + CXX: /usr/bin/clang++ + commands: + - cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ . -B build-release_valgrind -DSTATICC=ON -DCREATURELIB_TESTS=ON -DSANITIZER_TESTS=OFF + - cmake --build build-release_valgrind --target all -- -j 4 + - valgrind --tool=memcheck --gen-suppressions=all --leak-check=full --leak-resolution=med --track-origins=yes --vgdb=no --error-exitcode=1 build-release_valgrind/CreatureLibTests ~\[Exception\] - name: test-release-windows image: deukhoofd/windowsbuilder commands: @@ -54,6 +63,6 @@ steps: - ( cat Doxyfile ; echo "OUTPUT_DIRECTORY=/docs"; echo "GENERATE_TAGFILE=/docs/html/CreatureLib.tag" ) | doxygen - --- kind: signature -hmac: 898d10cca3267eb3643779b10100aeccef4f5066b7895fdb8758448641ff4705 +hmac: e77a3d4ab7ab136185b738a362354081ae86a7909e7f5c6c2610a06c1b3f568a ... diff --git a/CMakeLists.txt b/CMakeLists.txt index d60b6e2..8203365 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ set(CMAKE_CXX_STANDARD 20) option(WINDOWS "Whether the build target is Windows or not." OFF) option(SHARED "Whether we should build a shared library, instead of a static one." OFF) option(CREATURELIB_TESTS "Whether the test executable should be build as well." OFF) +option(SANITIZER_TESTS "Whether the test executable should be built using address sanitizer." ON) option(STATICC "Whether gcc and stdc++ should be linked statically to the library." OFF) set(LEVEL_SIZE "8" CACHE STRING "Number of bits to store the level as. Currently reserved, and can only be 8") @@ -125,6 +126,8 @@ if (CREATURELIB_TESTS) # Add a definition for the test library target_compile_definitions(CreatureLibTests PRIVATE TESTS_BUILD) - target_compile_options(CreatureLibTests PRIVATE -fsanitize=address) - target_link_options(CreatureLibTests PRIVATE -fsanitize=address) + if (SANITIZER_TESTS AND NOT WINDOWS) + target_compile_options(CreatureLibTests PRIVATE -fsanitize=address) + target_link_options(CreatureLibTests PRIVATE -fsanitize=address) + endif () endif ()