blob: 94102a27da6aca30cc08f1b9c1276c6d44deee87 [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#include "aos/common/time.h"
2
Austin Schuh793d6b92016-05-01 13:28:14 -07003#include <thread>
4
brians343bc112013-02-10 01:53:46 +00005#include "gtest/gtest.h"
6
7#include "aos/common/macros.h"
Brian Silverman0534df62014-05-26 21:19:15 -07008#include "aos/common/util/death_test_log_implementation.h"
brians343bc112013-02-10 01:53:46 +00009
10namespace aos {
11namespace time {
12namespace testing {
13
Brian Silverman3204dd82013-03-12 18:42:01 -070014
Brian Silvermandcaa3f72015-11-29 05:32:08 +000015TEST(TimeTest, FromRate) {
Austin Schuhf2a50ba2016-12-24 16:16:26 -080016 EXPECT_EQ(::std::chrono::milliseconds(10), FromRate(100));
Brian Silvermandcaa3f72015-11-29 05:32:08 +000017}
18
Austin Schuh793d6b92016-05-01 13:28:14 -070019// Test the monotonic_clock and sleep_until functions.
20TEST(TimeTest, MonotonicClockSleepAndNow) {
21 monotonic_clock::time_point start = monotonic_clock::now();
22 const auto kSleepTime = ::std::chrono::milliseconds(500);
23 ::std::this_thread::sleep_until(start + kSleepTime);
24 monotonic_clock::time_point end = monotonic_clock::now();
25 EXPECT_GE(end - start, kSleepTime);
26 EXPECT_LT(end - start, kSleepTime + ::std::chrono::milliseconds(200));
27}
28
brians343bc112013-02-10 01:53:46 +000029} // namespace testing
30} // namespace time
31} // namespace aos