summaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/time
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2019-11-21 16:11:16 +0000
committerHåvard Pettersen <havardpe@oath.com>2019-11-21 16:14:48 +0000
commit75d5498f0ec6db8debf2b5e3adf54e8ea057979a (patch)
tree330dfe3e03cc4fdf4311ad0c74f4c28a11152a36 /vespalib/src/tests/time
parent968e96303f29e776a30d01f7ec7a11a7f6920f79 (diff)
added time.h to simplify chrono use
Diffstat (limited to 'vespalib/src/tests/time')
-rw-r--r--vespalib/src/tests/time/CMakeLists.txt8
-rw-r--r--vespalib/src/tests/time/time_test.cpp39
2 files changed, 47 insertions, 0 deletions
diff --git a/vespalib/src/tests/time/CMakeLists.txt b/vespalib/src/tests/time/CMakeLists.txt
index 4fa8bad5eed..e43bd9097e5 100644
--- a/vespalib/src/tests/time/CMakeLists.txt
+++ b/vespalib/src/tests/time/CMakeLists.txt
@@ -6,3 +6,11 @@ vespa_add_executable(vespalib_time_box_test_app TEST
vespalib
)
vespa_add_test(NAME vespalib_time_box_test_app COMMAND vespalib_time_box_test_app)
+vespa_add_executable(vespalib_time_test_app TEST
+ SOURCES
+ time_test.cpp
+ DEPENDS
+ vespalib
+ gtest
+)
+vespa_add_test(NAME vespalib_time_test_app COMMAND vespalib_time_test_app)
diff --git a/vespalib/src/tests/time/time_test.cpp b/vespalib/src/tests/time/time_test.cpp
new file mode 100644
index 00000000000..667511f6a94
--- /dev/null
+++ b/vespalib/src/tests/time/time_test.cpp
@@ -0,0 +1,39 @@
+// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include <vespa/vespalib/util/time.h>
+#include <vespa/vespalib/gtest/gtest.h>
+#include <thread>
+
+using namespace vespalib;
+
+TEST(TimeTest, steady_time_is_compatible_with_steady_clock) {
+ steady_time t = steady_clock::now();
+ (void) t;
+}
+
+TEST(TimeTest, system_time_is_compatible_with_system_clock) {
+ system_time t = system_clock::now();
+ (void) t;
+}
+
+TEST(TimeTest, timer_can_measure_elapsed_time) {
+ Timer timer;
+ std::this_thread::sleep_for(10ms);
+ auto elapsed = timer.elapsed();
+ EXPECT_GE(elapsed, 10ms);
+ fprintf(stderr, "sleep(10ms) took %ld us\n", count_us(elapsed));
+}
+
+TEST(TimeTest, double_conversion_works_as_expected) {
+ EXPECT_EQ(to_s(10ms), 0.010);
+ EXPECT_EQ(10ms, from_s(0.010));
+}
+
+TEST(TimeTest, unit_counting_works_as_expected) {
+ auto d = 3ms + 5us + 7ns;
+ EXPECT_EQ(count_ns(d), 3005007);
+ EXPECT_EQ(count_us(d), 3005);
+ EXPECT_EQ(count_ms(d), 3);
+}
+
+GTEST_MAIN_RUN_ALL_TESTS()