#include "absl/synchronization/internal/kernel_timeout.h"
#include <ctime>
#include <chrono>
#include <limits>
#include "absl/base/config.h"
#include "absl/random/random.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "gtest/gtest.h"
#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) {
if (c == CLOCK_MONOTONIC &&
!absl::synchronization_internal::KernelTimeout::SupportsSteadyClock()) {
thread_local absl::BitGen 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
namespace {
#if defined(ABSL_HAVE_ADDRESS_SANITIZER) || \
defined(ABSL_HAVE_MEMORY_SANITIZER) || \
defined(ABSL_HAVE_THREAD_SANITIZER) || defined(__ANDROID__) || \
defined(__APPLE__) || defined(_WIN32) || defined(_WIN64)
constexpr absl::Duration kTimingBound = absl::Milliseconds(5);
#else
constexpr absl::Duration kTimingBound = …;
#endif
KernelTimeout;
TEST(KernelTimeout, DISABLED_FiniteTimes) { … }
TEST(KernelTimeout, InfiniteFuture) { … }
TEST(KernelTimeout, DefaultConstructor) { … }
TEST(KernelTimeout, TimeMaxNanos) { … }
TEST(KernelTimeout, Never) { … }
TEST(KernelTimeout, InfinitePast) { … }
TEST(KernelTimeout, DISABLED_FiniteDurations) { … }
TEST(KernelTimeout, DISABLED_NegativeDurations) { … }
TEST(KernelTimeout, InfiniteDuration) { … }
TEST(KernelTimeout, DurationMaxNanos) { … }
TEST(KernelTimeout, OverflowNanos) { … }
}