Deflake CpuTimeTest.TwoThreads

The test sometimes failed because thread creation on some platforms on
internal tests may take too much work.

Now checks are less strict.

Bug: none
Change-Id: Ibd3df02bda26b0c5e804360a909c61afa760b3bc
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/165960
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30267}
This commit is contained in:
Ilya Nikolaevskiy 2020-01-14 10:25:30 +01:00 committed by Commit Bot
parent d61338fa6e
commit 7787ebcd3f

View File

@ -26,7 +26,7 @@
namespace { namespace {
const int kAllowedErrorMillisecs = 30; const int kAllowedErrorMillisecs = 30;
const int kProcessingTimeMillisecs = 300; const int kProcessingTimeMillisecs = 500;
const int kWorkingThreads = 2; const int kWorkingThreads = 2;
// Consumes approximately kProcessingTimeMillisecs of CPU time in single thread. // Consumes approximately kProcessingTimeMillisecs of CPU time in single thread.
@ -77,10 +77,11 @@ TEST(CpuTimeTest, MAYBE_TEST(TwoThreads)) {
GetProcessCpuTimeNanos() - process_start_time_nanos; GetProcessCpuTimeNanos() - process_start_time_nanos;
int64_t thread_duration_nanos = int64_t thread_duration_nanos =
GetThreadCpuTimeNanos() - thread_start_time_nanos; GetThreadCpuTimeNanos() - thread_start_time_nanos;
// This thread did almost nothing. // This thread did almost nothing. Definetly less work than kProcessingTime.
// Therefore GetThreadCpuTime is not a wall clock. // Therefore GetThreadCpuTime is not a wall clock.
EXPECT_LE(thread_duration_nanos, EXPECT_LE(thread_duration_nanos,
kAllowedErrorMillisecs * kNumNanosecsPerMillisec); (kProcessingTimeMillisecs - kAllowedErrorMillisecs) *
kNumNanosecsPerMillisec);
// Total process time is at least twice working threads' CPU time. // Total process time is at least twice working threads' CPU time.
// Therefore process and thread times are correctly related. // Therefore process and thread times are correctly related.
EXPECT_GE(process_duration_nanos, EXPECT_GE(process_duration_nanos,
@ -97,7 +98,8 @@ TEST(CpuTimeTest, MAYBE_TEST(Sleeping)) {
// Sleeping should not introduce any additional CPU time. // Sleeping should not introduce any additional CPU time.
// Therefore GetProcessCpuTime is not a wall clock. // Therefore GetProcessCpuTime is not a wall clock.
EXPECT_LE(process_duration_nanos, EXPECT_LE(process_duration_nanos,
kWorkingThreads * kAllowedErrorMillisecs * kNumNanosecsPerMillisec); (kProcessingTimeMillisecs - kAllowedErrorMillisecs) *
kNumNanosecsPerMillisec);
} }
} // namespace rtc } // namespace rtc