stefan@webrtc.org | b8e7f4c | 2013-04-12 11:56:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "system_wrappers/include/clock.h" |
stefan@webrtc.org | b8e7f4c | 2013-04-12 11:56:23 +0000 | [diff] [blame] | 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "test/gtest.h" |
stefan@webrtc.org | b8e7f4c | 2013-04-12 11:56:23 +0000 | [diff] [blame] | 14 | |
| 15 | namespace webrtc { |
| 16 | |
| 17 | TEST(ClockTest, NtpTime) { |
| 18 | Clock* clock = Clock::GetRealTimeClock(); |
skvlad | de3f844 | 2016-10-05 01:55:04 -0700 | [diff] [blame] | 19 | |
| 20 | // To ensure the test runs correctly even on a heavily loaded system, do not |
| 21 | // compare the seconds/fractions and millisecond values directly. Instead, |
| 22 | // we check that the NTP time is between the "milliseconds" values returned |
| 23 | // right before and right after the call. |
| 24 | // The comparison includes 1 ms of margin to account for the rounding error in |
| 25 | // the conversion. |
| 26 | int64_t milliseconds_lower_bound = clock->CurrentNtpInMilliseconds(); |
danilchap | 4228784 | 2017-02-20 06:40:18 -0800 | [diff] [blame] | 27 | NtpTime ntp_time = clock->CurrentNtpTime(); |
skvlad | de3f844 | 2016-10-05 01:55:04 -0700 | [diff] [blame] | 28 | int64_t milliseconds_upper_bound = clock->CurrentNtpInMilliseconds(); |
| 29 | EXPECT_GT(milliseconds_lower_bound / 1000, kNtpJan1970); |
danilchap | 4228784 | 2017-02-20 06:40:18 -0800 | [diff] [blame] | 30 | EXPECT_LE(milliseconds_lower_bound - 1, ntp_time.ToMs()); |
| 31 | EXPECT_GE(milliseconds_upper_bound + 1, ntp_time.ToMs()); |
stefan@webrtc.org | b8e7f4c | 2013-04-12 11:56:23 +0000 | [diff] [blame] | 32 | } |
andrew@webrtc.org | a37bf2c | 2015-01-05 19:08:58 +0000 | [diff] [blame] | 33 | |
stefan@webrtc.org | b8e7f4c | 2013-04-12 11:56:23 +0000 | [diff] [blame] | 34 | } // namespace webrtc |