summaryrefslogtreecommitdiffstats
path: root/staging_vespalib/src/tests/clock
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /staging_vespalib/src/tests/clock
Publish
Diffstat (limited to 'staging_vespalib/src/tests/clock')
-rw-r--r--staging_vespalib/src/tests/clock/.gitignore4
-rw-r--r--staging_vespalib/src/tests/clock/CMakeLists.txt8
-rw-r--r--staging_vespalib/src/tests/clock/DESC1
-rw-r--r--staging_vespalib/src/tests/clock/FILES1
-rw-r--r--staging_vespalib/src/tests/clock/clock_test.cpp38
5 files changed, 52 insertions, 0 deletions
diff --git a/staging_vespalib/src/tests/clock/.gitignore b/staging_vespalib/src/tests/clock/.gitignore
new file mode 100644
index 00000000000..1826ba1563b
--- /dev/null
+++ b/staging_vespalib/src/tests/clock/.gitignore
@@ -0,0 +1,4 @@
+.depend
+Makefile
+clock_test
+staging_vespalib_clock_test_app
diff --git a/staging_vespalib/src/tests/clock/CMakeLists.txt b/staging_vespalib/src/tests/clock/CMakeLists.txt
new file mode 100644
index 00000000000..8717a6411ab
--- /dev/null
+++ b/staging_vespalib/src/tests/clock/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(staging_vespalib_clock_test_app
+ SOURCES
+ clock_test.cpp
+ DEPENDS
+ staging_vespalib
+)
+vespa_add_test(NAME staging_vespalib_clock_test_app COMMAND staging_vespalib_clock_test_app)
diff --git a/staging_vespalib/src/tests/clock/DESC b/staging_vespalib/src/tests/clock/DESC
new file mode 100644
index 00000000000..061f9af2d0a
--- /dev/null
+++ b/staging_vespalib/src/tests/clock/DESC
@@ -0,0 +1 @@
+Unit tests for the clock.
diff --git a/staging_vespalib/src/tests/clock/FILES b/staging_vespalib/src/tests/clock/FILES
new file mode 100644
index 00000000000..c0a2e8e47ea
--- /dev/null
+++ b/staging_vespalib/src/tests/clock/FILES
@@ -0,0 +1 @@
+clock.cpp
diff --git a/staging_vespalib/src/tests/clock/clock_test.cpp b/staging_vespalib/src/tests/clock/clock_test.cpp
new file mode 100644
index 00000000000..f7f15dd3d24
--- /dev/null
+++ b/staging_vespalib/src/tests/clock/clock_test.cpp
@@ -0,0 +1,38 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("sharedptr_test");
+#include <vespa/vespalib/util/clock.h>
+#include <vespa/vespalib/testkit/testapp.h>
+
+using vespalib::Clock;
+using fastos::TimeStamp;
+
+class Test : public vespalib::TestApp
+{
+public:
+ int Main();
+};
+
+
+int
+Test::Main()
+{
+ TEST_INIT("clock_test");
+
+ Clock clock(0.050);
+ FastOS_ThreadPool pool(0x10000);
+ ASSERT_TRUE(pool.NewThread(&clock, NULL) != NULL);
+ uint64_t start = clock.getTimeNS();
+ FastOS_Thread::Sleep(5000);
+ uint64_t stop = clock.getTimeNS();
+ EXPECT_TRUE(stop > start);
+ FastOS_Thread::Sleep(6000);
+ clock.stop();
+ uint64_t stop2 = clock.getTimeNS();
+ EXPECT_TRUE(stop2 > stop);
+ EXPECT_TRUE((stop2 - stop)/TimeStamp::MICRO > 1000);
+ TEST_DONE();
+}
+
+TEST_APPHOOK(Test)