From c3a9bdb2b5b8370c92cba7e1b44c1fe5dc4d8e0b Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 22 Nov 2023 17:55:43 +0100 Subject: [PATCH] Detect enabled GCC/Clang sanitizers Occasionally we want tests to take advantage of sanitizers, or work around them. Signed-off-by: Gilles Peskine --- tests/include/test/helpers.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/include/test/helpers.h b/tests/include/test/helpers.h index fde8cc5c2ae5..17153b7d613c 100644 --- a/tests/include/test/helpers.h +++ b/tests/include/test/helpers.h @@ -19,6 +19,21 @@ #include MBEDTLS_CONFIG_FILE #endif +#if defined(__SANITIZE_ADDRESS__) /* gcc -fsanitize=address */ +# define MBEDTLS_TEST_HAVE_ASAN +#endif +#if defined(__has_feature) +# if __has_feature(address_sanitizer) /* clang -fsanitize=address */ +# define MBEDTLS_TEST_HAVE_ASAN +# endif +# if __has_feature(memory_sanitizer) /* clang -fsanitize=memory */ +# define MBEDTLS_TEST_HAVE_MSAN +# endif +# if __has_feature(thread_sanitizer) /* clang -fsanitize=thread */ +# define MBEDTLS_TEST_HAVE_TSAN +# endif +#endif + #if defined(MBEDTLS_THREADING_C) && defined(MBEDTLS_THREADING_PTHREAD) && \ defined(MBEDTLS_TEST_HOOKS) #define MBEDTLS_TEST_MUTEX_USAGE