aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--searchlib/src/tests/query/streaming_query_large_test.cpp21
-rw-r--r--vespalib/src/tests/alloc/alloc_test.cpp11
-rw-r--r--vespalib/src/tests/exception_classes/silenceuncaught_test.cpp23
-rw-r--r--vespalib/src/vespa/vespalib/util/sanitizers.h53
4 files changed, 62 insertions, 46 deletions
diff --git a/searchlib/src/tests/query/streaming_query_large_test.cpp b/searchlib/src/tests/query/streaming_query_large_test.cpp
index 55c844723d9..b39dad43a7b 100644
--- a/searchlib/src/tests/query/streaming_query_large_test.cpp
+++ b/searchlib/src/tests/query/streaming_query_large_test.cpp
@@ -4,6 +4,7 @@
#include <vespa/searchlib/query/tree/simplequery.h>
#include <vespa/searchlib/query/tree/stackdumpcreator.h>
#include <vespa/vespalib/testkit/test_kit.h>
+#include <vespa/vespalib/util/sanitizers.h>
#include <vespa/vespalib/util/size_literals.h>
#include <sys/resource.h>
@@ -11,22 +12,6 @@ using namespace search;
using namespace search::query;
using namespace search::streaming;
-#ifndef __SANITIZE_ADDRESS__
-#if defined(__has_feature)
-#if __has_feature(address_sanitizer)
-#define __SANITIZE_ADDRESS__
-#endif
-#endif
-#endif
-
-#ifndef __SANITIZE_THREAD__
-#if defined(__has_feature)
-#if __has_feature(thread_sanitizer)
-#define __SANITIZE_THREAD__
-#endif
-#endif
-#endif
-
namespace {
[[maybe_unused]] void setMaxStackSize(rlim_t maxStackSize)
@@ -44,10 +29,10 @@ namespace {
// a stack overflow if the stack usage increases.
TEST("testveryLongQueryResultingInBug6850778") {
uint32_t NUMITEMS=20000;
-#ifdef __SANITIZE_ADDRESS__
+#ifdef VESPA_USE_ADDRESS_SANITIZER
setMaxStackSize(12_Mi);
#else
-#ifdef __SANITIZE_THREAD__
+#ifdef VESPA_USE_THREAD_SANITIZER
NUMITEMS = 10000;
#else
setMaxStackSize(4_Mi);
diff --git a/vespalib/src/tests/alloc/alloc_test.cpp b/vespalib/src/tests/alloc/alloc_test.cpp
index c65bb770f37..04e009fcf8a 100644
--- a/vespalib/src/tests/alloc/alloc_test.cpp
+++ b/vespalib/src/tests/alloc/alloc_test.cpp
@@ -5,6 +5,7 @@
#include <vespa/vespalib/util/memory_allocator.h>
#include <vespa/vespalib/util/exceptions.h>
#include <vespa/vespalib/util/round_up_to_page_size.h>
+#include <vespa/vespalib/util/sanitizers.h>
#include <vespa/vespalib/util/size_literals.h>
#include <cstddef>
#include <sys/mman.h>
@@ -12,14 +13,6 @@
using namespace vespalib;
using namespace vespalib::alloc;
-#ifndef __SANITIZE_ADDRESS__
-#if defined(__has_feature)
-#if __has_feature(address_sanitizer)
-#define __SANITIZE_ADDRESS__
-#endif
-#endif
-#endif
-
namespace {
size_t page_sz = round_up_to_page_size(1);
@@ -228,7 +221,7 @@ TEST("auto alloced mmap alloc can not be extended if no room") {
* or munmap calls, breaking some of the assumptions in the disabled
* tests.
*/
-#ifndef __SANITIZE_ADDRESS__
+#ifndef VESPA_USE_ADDRESS_SANITIZER
TEST("mmap alloc can be extended if room") {
Alloc dummy = Alloc::allocMMap(100);
Alloc reserved = Alloc::allocMMap(100);
diff --git a/vespalib/src/tests/exception_classes/silenceuncaught_test.cpp b/vespalib/src/tests/exception_classes/silenceuncaught_test.cpp
index 9f6917d5d65..8f8ce2cc915 100644
--- a/vespalib/src/tests/exception_classes/silenceuncaught_test.cpp
+++ b/vespalib/src/tests/exception_classes/silenceuncaught_test.cpp
@@ -1,26 +1,11 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/util/exception.h>
+#include <vespa/vespalib/util/sanitizers.h>
#include <vespa/vespalib/process/process.h>
using namespace vespalib;
-#ifndef __SANITIZE_ADDRESS__
-#if defined(__has_feature)
-#if __has_feature(address_sanitizer)
-#define __SANITIZE_ADDRESS__
-#endif
-#endif
-#endif
-
-#ifndef __SANITIZE_THREAD__
-#if defined(__has_feature)
-#if __has_feature(thread_sanitizer)
-#define __SANITIZE_THREAD__
-#endif
-#endif
-#endif
-
TEST("that uncaught exception causes negative exitcode.") {
Process proc("ulimit -c 0 && exec ./vespalib_caught_uncaught_app uncaught");
EXPECT_LESS(proc.join(), 0);
@@ -41,8 +26,8 @@ TEST("that caught silenced exception causes exitcode 0") {
EXPECT_EQUAL(proc.join(), 0);
}
-#ifndef __SANITIZE_ADDRESS__
-#ifndef __SANITIZE_THREAD__
+#ifndef VESPA_USE_SANITIZER
+
#ifdef __APPLE__
// setrlimit with RLIMIT_AS is broken on Darwin
#else
@@ -60,7 +45,7 @@ TEST("that mmap beyond limits with set VESPA_SILENCE_CORE_ON_OOM cause exitcode
Process proc("VESPA_SILENCE_CORE_ON_OOM=1 exec ./vespalib_mmap_app 100000000 10485760 10");
EXPECT_EQUAL(proc.join(), 66);
}
-#endif
+
#endif
#endif
diff --git a/vespalib/src/vespa/vespalib/util/sanitizers.h b/vespalib/src/vespa/vespalib/util/sanitizers.h
new file mode 100644
index 00000000000..b7ae9386275
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/util/sanitizers.h
@@ -0,0 +1,53 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#pragma once
+
+/**
+ * Convenience macros for determining if the build is instrumented using sanitizers.
+ *
+ * If any sanitizer is detected, VESPA_USE_SANITIZER will be defined as 1, otherwise not defined.
+ * Additionally, the macro VESPA_USE_<SANITIZER_NAME>_SANITIZER will be defined in case code needs to
+ * know exactly which sanitizer is being instrumented with.
+ */
+
+// Normalize compiler-specific sanitizer definitions
+#ifndef __SANITIZE_ADDRESS__
+# if defined(__has_feature)
+# if __has_feature(address_sanitizer)
+# define __SANITIZE_ADDRESS__
+# endif
+# endif
+#endif
+
+#ifndef __SANITIZE_THREAD__
+# if defined(__has_feature)
+# if __has_feature(thread_sanitizer)
+# define __SANITIZE_THREAD__
+# endif
+# endif
+#endif
+
+#ifndef __SANITIZE_UNDEFINED__
+# if defined(__has_feature)
+# if __has_feature(undefined_sanitizer)
+# define __SANITIZE_UNDEFINED__
+# endif
+# endif
+#endif
+
+#ifdef __SANITIZE_ADDRESS__
+# define VESPA_USE_SANITIZER 1
+# define VESPA_USE_ADDRESS_SANITIZER 1
+# define VESPA_SANITIZER_NAME "address"
+#endif
+
+#ifdef __SANITIZE_THREAD__
+# define VESPA_USE_SANITIZER 1
+# define VESPA_USE_THREAD_SANITIZER 1
+# define VESPA_SANITIZER_NAME "thread"
+#endif
+
+#ifdef __SANITIZE_UNDEFINED__
+# define VESPA_USE_SANITIZER 1
+# define VESPA_USE_UNDEFINED_SANITIZER 1
+# define VESPA_SANITIZER_NAME "undefined"
+#endif