ClockTest.NtpTime was checking that the two methods for getting the system time are returning a value that is within a fixed error margin (100 ms) of each other. Unfortunately, even such a wide margin was sometimes exceeded on heavily loaded machines (https://build.chromium.org/p/client.webrtc/builders/Mac%20Asan/builds/9235/steps/system_wrappers_unittests/logs/stdio). This CL changes the test to sandwich clock->CurrentNtp() between clock->CurrentNtpTimeInMilliseconds(). This way the test will pass no matter how much time elapses between the two method calls, as long as the clock is monotonic. Repeated test runs showed that there may be 1 ms worth of rounding error between the two methods of getting time, so we have to allow that. BUG=None. Review-Url: https://codereview.webrtc.org/2393063002 Cr-Commit-Position: refs/heads/master@{#14520}
37 lines
1.4 KiB
C++
37 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "webrtc/system_wrappers/include/clock.h"
|
|
|
|
#include "webrtc/test/gtest.h"
|
|
|
|
namespace webrtc {
|
|
|
|
TEST(ClockTest, NtpTime) {
|
|
Clock* clock = Clock::GetRealTimeClock();
|
|
uint32_t seconds;
|
|
uint32_t fractions;
|
|
|
|
// To ensure the test runs correctly even on a heavily loaded system, do not
|
|
// compare the seconds/fractions and millisecond values directly. Instead,
|
|
// we check that the NTP time is between the "milliseconds" values returned
|
|
// right before and right after the call.
|
|
// The comparison includes 1 ms of margin to account for the rounding error in
|
|
// the conversion.
|
|
int64_t milliseconds_lower_bound = clock->CurrentNtpInMilliseconds();
|
|
clock->CurrentNtp(seconds, fractions);
|
|
int64_t milliseconds_upper_bound = clock->CurrentNtpInMilliseconds();
|
|
EXPECT_GT(milliseconds_lower_bound / 1000, kNtpJan1970);
|
|
EXPECT_LE(milliseconds_lower_bound - 1, Clock::NtpToMs(seconds, fractions));
|
|
EXPECT_GE(milliseconds_upper_bound + 1, Clock::NtpToMs(seconds, fractions));
|
|
}
|
|
|
|
} // namespace webrtc
|