aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Romanko <me@blankhex.com>2025-01-29 22:41:39 +0300
committerMikhail Romanko <me@blankhex.com>2025-01-29 22:41:39 +0300
commit8d73a9b47335cad686da67c1f04ce50c84c601bd (patch)
tree7d4319a483531ce342b95a44374fab14fdb9f9b5
parent6ede63e18fcbbdc9457b6ac7b5d7af9b673ec657 (diff)
downloadbhlib-8d73a9b47335cad686da67c1f04ce50c84c601bd.tar.gz
Fix asan profile, add script for running tests
Linking against static asan library was a mistake. Now this should work better for other compilers. Also added script for running all tests under different profiles.
-rw-r--r--CMakeLists.txt4
-rwxr-xr-xutil/run-tests.sh42
2 files changed, 44 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e7f39c6..0e2a50c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -32,12 +32,12 @@ set(CMAKE_CXX_FLAGS_ASAN
)
set(CMAKE_EXE_LINKER_FLAGS_ASAN
- "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address,undefined -static-libasan" CACHE STRING
+ "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address,undefined" CACHE STRING
"Linker flags to be used to create executables for Asan build type." FORCE
)
set(CMAKE_SHARED_LINKER_FLAGS_ASAN
- "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address,undefined -static-libasan" CACHE STRING
+ "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -fsanitize=address,undefined" CACHE STRING
"Linker lags to be used to create shared libraries for Asan build type." FORCE
)
diff --git a/util/run-tests.sh b/util/run-tests.sh
new file mode 100755
index 0000000..1ee2183
--- /dev/null
+++ b/util/run-tests.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+# Set of compilers and profiles for testing
+compilers="gcc clang"
+profiles="Debug Release Asan"
+
+# Build and run tests
+build_and_run() {
+ compiler=$1
+ mode=$2
+
+ # Reconfigure project
+ rm -rf build
+ cmake -S . -B build -DCMAKE_BUILD_TYPE=${mode} -DCMAKE_C_COMPILER=${compiler}
+ if [ $? -ne 0 ]; then
+ return 1
+ fi
+
+ # Build
+ cmake --build build
+ if [ $? -ne 0 ]; then
+ return 1
+ fi
+
+ # Test
+ ctest -T test --test-dir build
+ if [ $? -ne 0 ]; then
+ return 1
+ fi
+
+ return 0
+}
+
+# For each compiler and profile - run test
+for compiler in $compilers; do
+ for profile in $profiles; do
+ if ! build_and_run $compiler $profile; then
+ echo "Tests failed for $compiler $profile"
+ exit 1
+ fi
+ done
+done