diff options
author | Giuliano Procida <gprocida@google.com> | 2021-04-09 11:43:20 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-04-09 11:43:20 +0000 |
commit | 47a2144628738c654a5b615f0e0f9e130475bda9 (patch) | |
tree | 3763ae06185db393f35488bbcf7f12333bad00f4 | |
parent | 97344f834ef30bbd4922d3578be07b73c9bbccb7 (diff) | |
parent | 84ccc05258b2defa1c938a669614679220fb84b0 (diff) | |
download | bionic-47a2144628738c654a5b615f0e0f9e130475bda9.tar.gz |
Merge "Deflake time.clock_gettime test" am: 84ccc05258
Original change: https://android-review.googlesource.com/c/platform/bionic/+/1668449
Change-Id: I49211da5fd17b3b6f24c637ba58173410862edd7
-rw-r--r-- | tests/time_test.cpp | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/tests/time_test.cpp b/tests/time_test.cpp index 16299cc52..b16fe16bc 100644 --- a/tests/time_test.cpp +++ b/tests/time_test.cpp @@ -31,8 +31,6 @@ #include "SignalUtils.h" #include "utils.h" -#include "private/bionic_constants.h" - using namespace std::chrono_literals; TEST(time, time) { @@ -760,22 +758,22 @@ TEST(time, timer_delete_from_timer_thread) { TEST(time, clock_gettime) { // Try to ensure that our vdso clock_gettime is working. + timespec ts0; timespec ts1; - ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &ts1)); timespec ts2; - ASSERT_EQ(0, syscall(__NR_clock_gettime, CLOCK_MONOTONIC, &ts2)); - - // What's the difference between the two? - ts2.tv_sec -= ts1.tv_sec; - ts2.tv_nsec -= ts1.tv_nsec; - if (ts2.tv_nsec < 0) { - --ts2.tv_sec; - ts2.tv_nsec += NS_PER_S; + ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &ts0)); + ASSERT_EQ(0, syscall(__NR_clock_gettime, CLOCK_MONOTONIC, &ts1)); + ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &ts2)); + + // Check we have a nice monotonic timestamp sandwich. + ASSERT_LE(ts0.tv_sec, ts1.tv_sec); + if (ts0.tv_sec == ts1.tv_sec) { + ASSERT_LE(ts0.tv_nsec, ts1.tv_nsec); + } + ASSERT_LE(ts1.tv_sec, ts2.tv_sec); + if (ts1.tv_sec == ts2.tv_sec) { + ASSERT_LE(ts1.tv_nsec, ts2.tv_nsec); } - - // To try to avoid flakiness we'll accept answers within 10,000,000ns (0.01s). - ASSERT_EQ(0, ts2.tv_sec); - ASSERT_LT(ts2.tv_nsec, 10'000'000); } TEST(time, clock_gettime_CLOCK_REALTIME) { |