diff options
Diffstat (limited to 'absl/synchronization/internal/kernel_timeout_test.cc')
-rw-r--r-- | absl/synchronization/internal/kernel_timeout_test.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/absl/synchronization/internal/kernel_timeout_test.cc b/absl/synchronization/internal/kernel_timeout_test.cc index c853c4bc..e3286f7f 100644 --- a/absl/synchronization/internal/kernel_timeout_test.cc +++ b/absl/synchronization/internal/kernel_timeout_test.cc @@ -14,14 +14,34 @@ #include "absl/synchronization/internal/kernel_timeout.h" +#include <ctime> #include <chrono> // NOLINT(build/c++11) #include <limits> +#include "absl/random/random.h" #include "gtest/gtest.h" #include "absl/base/config.h" #include "absl/time/clock.h" #include "absl/time/time.h" +// Test go/btm support by randomizing the value 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__ +extern "C" int __clock_gettime(clockid_t c, struct timespec* ts); + +extern "C" int clock_gettime(clockid_t c, struct timespec* ts) { + if (c == CLOCK_MONOTONIC && + !absl::synchronization_internal::KernelTimeout::SupportsSteadyClock()) { + absl::SharedBitGen gen; + ts->tv_sec = absl::Uniform(gen, 0, 1'000'000'000); + ts->tv_nsec = absl::Uniform(gen, 0, 1'000'000'000); + return 0; + } + return __clock_gettime(c, ts); +} +#endif // __GOOGLE_GRTE_VERSION__ + namespace { #if defined(ABSL_HAVE_ADDRESS_SANITIZER) || \ |