From 9661e04e60011bc7ce3b7b9ec345be770983f09b Mon Sep 17 00:00:00 2001
From: Dor Laor <dor@cloudius-systems.com>
Date: Mon, 11 Feb 2013 17:48:33 +0200
Subject: [PATCH] Move the timer test code into its own file

---
 loader.cc          | 17 -----------------
 tests/tst-hub.cc   |  3 +++
 tests/tst-timer.hh | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 17 deletions(-)
 create mode 100644 tests/tst-timer.hh

diff --git a/loader.cc b/loader.cc
index d6d333f7a..1de496994 100644
--- a/loader.cc
+++ b/loader.cc
@@ -150,23 +150,6 @@ void* do_main_thread(void *_args)
     drvman->load_all();
     drvman->list_drivers();
 
-    auto t1 = clock::get()->time();
-    auto t2 = clock::get()->time();
-    debug(fmt("clock@t1 %1%") % t1);
-    debug(fmt("clock@t2 %1%") % t2);
-
-    timespec ts = {};
-    ts.tv_nsec = 100;
-    t1 = clock::get()->time();
-    nanosleep(&ts, nullptr);
-    t2 = clock::get()->time();
-    debug(fmt("nanosleep(100) -> %d") % (t2 - t1));
-    ts.tv_nsec = 100000;
-    t1 = clock::get()->time();
-    nanosleep(&ts, nullptr);
-    t2 = clock::get()->time();
-    debug(fmt("nanosleep(100000) -> %d") % (t2 - t1));
-
     run_main(prog, args);
 
     while (true)
diff --git a/tests/tst-hub.cc b/tests/tst-hub.cc
index 032c1d7a6..6fe00450a 100644
--- a/tests/tst-hub.cc
+++ b/tests/tst-hub.cc
@@ -1,15 +1,18 @@
 #include "tst-hub.hh"
 #include "tst-threads.hh"
 #include "tst-malloc.hh"
+#include "tst-timer.hh"
 
 using namespace unit_tests;
 
 void tests::execute_tests() {
     test_threads threads;
     test_malloc malloc;
+    test_timer timer;
 
     instance().register_test(&threads);
     instance().register_test(&malloc);
+    instance().register_test(&timer);
 
     instance().run();
 }
diff --git a/tests/tst-timer.hh b/tests/tst-timer.hh
new file mode 100644
index 000000000..4247f3b95
--- /dev/null
+++ b/tests/tst-timer.hh
@@ -0,0 +1,33 @@
+#ifndef __TST_TIMER__
+#define __TST_TIMER__
+
+#include "tst-hub.hh"
+#include "drivers/clock.hh"
+#include "debug.hh"
+
+class test_timer : public unit_tests::vtest {
+
+public:
+
+    void run()
+    {
+        auto t1 = clock::get()->time();
+        auto t2 = clock::get()->time();
+        debug(fmt("Timer test: clock@t1 %1%") % t1);
+        debug(fmt("Timer test: clock@t2 %1%") % t2);
+
+        timespec ts = {};
+        ts.tv_nsec = 100;
+        t1 = clock::get()->time();
+        nanosleep(&ts, nullptr);
+        t2 = clock::get()->time();
+        debug(fmt("Timer test: nanosleep(100) -> %d") % (t2 - t1));
+        ts.tv_nsec = 100000;
+        t1 = clock::get()->time();
+        nanosleep(&ts, nullptr);
+        t2 = clock::get()->time();
+        debug(fmt("Timer test: nanosleep(100000) -> %d") % (t2 - t1));
+    }
+};
+
+#endif
-- 
GitLab