aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuliano Procida <gprocida@google.com>2021-04-08 08:32:14 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-04-08 08:32:14 +0000
commit7d06b37270124ef734fa918cd5141827dd9f87a6 (patch)
treef7512884dfaaf5ba39aeac8627c29617315d58d5
parent24e0b57429075e612a0f3d77bef932e0eb583fa7 (diff)
parentebc88d26a5548d65b45bbec1091d5573d011cc0d (diff)
downloadbionic-7d06b37270124ef734fa918cd5141827dd9f87a6.tar.gz
Merge "Use mean CPU time in an attempt to reduce test flakiness"
-rw-r--r--tests/time_test.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index 7c2c890c6..16299cc52 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -851,11 +851,15 @@ TEST(time, clock_getres_unknown) {
}
TEST(time, clock) {
- // clock(3) is hard to test, but a 1s sleep should cost less than 20ms.
+ // clock(3) is hard to test, but a 1s sleep should cost less than 10ms on average.
+ static const clock_t N = 5;
+ static const clock_t mean_limit_ms = 10;
clock_t t0 = clock();
- sleep(1);
+ for (size_t i = 0; i < N; ++i) {
+ sleep(1);
+ }
clock_t t1 = clock();
- ASSERT_LT(t1 - t0, 20 * (CLOCKS_PER_SEC / 1000));
+ ASSERT_LT(t1 - t0, N * mean_limit_ms * (CLOCKS_PER_SEC / 1000));
}
static pid_t GetInvalidPid() {