summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Derek Mauro <dmauro@google.com>2023-04-13 10:25:13 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2023-04-13 10:25:56 -0700
commitc5f310de3ba06b7ad24da48145a099485322d2ac (patch)
tree3e4763c246fc38083692dd7b15daf9c4ed60a137
parentc23acb9b5636e7b908fba03d6b3584d8f80dba6d (diff)
Don't override clock_gettime in the KernelTimeout and Waiter
tests under sanitizers. The overrides break the sanitizers. PiperOrigin-RevId: 524037272 Change-Id: I85b87d3870c488cb316505e94b394c6f98e9f60f
-rw-r--r--absl/synchronization/BUILD.bazel1
-rw-r--r--absl/synchronization/CMakeLists.txt1
-rw-r--r--absl/synchronization/internal/kernel_timeout_test.cc13
-rw-r--r--absl/synchronization/internal/waiter_test.cc10
4 files changed, 17 insertions, 8 deletions
diff --git a/absl/synchronization/BUILD.bazel b/absl/synchronization/BUILD.bazel
index b6721e14..406c5b85 100644
--- a/absl/synchronization/BUILD.bazel
+++ b/absl/synchronization/BUILD.bazel
@@ -351,6 +351,7 @@ cc_test(
":kernel_timeout_internal",
":synchronization",
":thread_pool",
+ "//absl/base:config",
"//absl/random",
"//absl/time",
"@com_google_googletest//:gtest_main",
diff --git a/absl/synchronization/CMakeLists.txt b/absl/synchronization/CMakeLists.txt
index b6b3b27c..86278349 100644
--- a/absl/synchronization/CMakeLists.txt
+++ b/absl/synchronization/CMakeLists.txt
@@ -259,6 +259,7 @@ absl_cc_test(
COPTS
${ABSL_TEST_COPTS}
DEPS
+ absl::config
absl::kernel_timeout_internal
absl::random_random
absl::synchronization
diff --git a/absl/synchronization/internal/kernel_timeout_test.cc b/absl/synchronization/internal/kernel_timeout_test.cc
index e3286f7f..92ed2691 100644
--- a/absl/synchronization/internal/kernel_timeout_test.cc
+++ b/absl/synchronization/internal/kernel_timeout_test.cc
@@ -18,16 +18,19 @@
#include <chrono> // NOLINT(build/c++11)
#include <limits>
-#include "absl/random/random.h"
-#include "gtest/gtest.h"
#include "absl/base/config.h"
+#include "absl/random/random.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
+#include "gtest/gtest.h"
-// Test go/btm support by randomizing the value clock_gettime() for
+// Test go/btm support by randomizing the value of clock_gettime() for
// CLOCK_MONOTONIC. This works by overriding a weak symbol in glibc.
// We should be resistant to this randomization when !SupportsSteadyClock().
-#ifdef __GOOGLE_GRTE_VERSION__
+#if defined(__GOOGLE_GRTE_VERSION__) && \
+ !defined(ABSL_HAVE_ADDRESS_SANITIZER) && \
+ !defined(ABSL_HAVE_MEMORY_SANITIZER) && \
+ !defined(ABSL_HAVE_THREAD_SANITIZER)
extern "C" int __clock_gettime(clockid_t c, struct timespec* ts);
extern "C" int clock_gettime(clockid_t c, struct timespec* ts) {
@@ -40,7 +43,7 @@ extern "C" int clock_gettime(clockid_t c, struct timespec* ts) {
}
return __clock_gettime(c, ts);
}
-#endif // __GOOGLE_GRTE_VERSION__
+#endif
namespace {
diff --git a/absl/synchronization/internal/waiter_test.cc b/absl/synchronization/internal/waiter_test.cc
index 57a1a3da..9a933940 100644
--- a/absl/synchronization/internal/waiter_test.cc
+++ b/absl/synchronization/internal/waiter_test.cc
@@ -18,6 +18,7 @@
#include <iostream>
#include <ostream>
+#include "absl/base/config.h"
#include "absl/random/random.h"
#include "absl/synchronization/internal/create_thread_identity.h"
#include "absl/synchronization/internal/futex_waiter.h"
@@ -31,10 +32,13 @@
#include "absl/time/time.h"
#include "gtest/gtest.h"
-// Test go/btm support by randomizing the value clock_gettime() for
+// Test go/btm support by randomizing the value of clock_gettime() for
// CLOCK_MONOTONIC. This works by overriding a weak symbol in glibc.
// We should be resistant to this randomization when !SupportsSteadyClock().
-#ifdef __GOOGLE_GRTE_VERSION__
+#if defined(__GOOGLE_GRTE_VERSION__) && \
+ !defined(ABSL_HAVE_ADDRESS_SANITIZER) && \
+ !defined(ABSL_HAVE_MEMORY_SANITIZER) && \
+ !defined(ABSL_HAVE_THREAD_SANITIZER)
extern "C" int __clock_gettime(clockid_t c, struct timespec* ts);
extern "C" int clock_gettime(clockid_t c, struct timespec* ts) {
@@ -47,7 +51,7 @@ extern "C" int clock_gettime(clockid_t c, struct timespec* ts) {
}
return __clock_gettime(c, ts);
}
-#endif // __GOOGLE_GRTE_VERSION__
+#endif
namespace {