Implement TestUtils_time

Untested on Windows


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/42fc9a4c
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/42fc9a4c
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/42fc9a4c

Branch: refs/heads/master
Commit: 42fc9a4c0bfc316f7c86e461eb9e5d92d9e02013
Parents: e77377a
Author: Nick Wellnhofer <[email protected]>
Authored: Sun May 10 02:28:25 2015 +0200
Committer: Nick Wellnhofer <[email protected]>
Committed: Tue May 12 20:15:25 2015 +0200

----------------------------------------------------------------------
 runtime/common/charmonizer.c                    |  3 ++
 runtime/common/charmonizer.main                 |  3 ++
 runtime/core/Clownfish/TestHarness/TestUtils.c  | 38 ++++++++++++++++++++
 .../core/Clownfish/TestHarness/TestUtils.cfh    |  5 +++
 4 files changed, 49 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/42fc9a4c/runtime/common/charmonizer.c
----------------------------------------------------------------------
diff --git a/runtime/common/charmonizer.c b/runtime/common/charmonizer.c
index fc3f3e4..b7d5383 100644
--- a/runtime/common/charmonizer.c
+++ b/runtime/common/charmonizer.c
@@ -7896,6 +7896,9 @@ int main(int argc, const char **argv) {
     chaz_VariadicMacros_run();
 
     /* Write custom postamble. */
+    if (chaz_HeadCheck_check_header("sys/time.h")) {
+        chaz_ConfWriter_append_conf("#define CHY_HAS_SYS_TIME_H\n\n");
+    }
     if (chaz_HeadCheck_defines_symbol("__sync_bool_compare_and_swap", "")) {
         chaz_ConfWriter_append_conf(
             "#define CHY_HAS___SYNC_BOOL_COMPARE_AND_SWAP\n\n");

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/42fc9a4c/runtime/common/charmonizer.main
----------------------------------------------------------------------
diff --git a/runtime/common/charmonizer.main b/runtime/common/charmonizer.main
index e14eef0..1602bd6 100644
--- a/runtime/common/charmonizer.main
+++ b/runtime/common/charmonizer.main
@@ -137,6 +137,9 @@ int main(int argc, const char **argv) {
     chaz_VariadicMacros_run();
 
     /* Write custom postamble. */
+    if (chaz_HeadCheck_check_header("sys/time.h")) {
+        chaz_ConfWriter_append_conf("#define CHY_HAS_SYS_TIME_H\n\n");
+    }
     if (chaz_HeadCheck_defines_symbol("__sync_bool_compare_and_swap", "")) {
         chaz_ConfWriter_append_conf(
             "#define CHY_HAS___SYNC_BOOL_COMPARE_AND_SWAP\n\n");

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/42fc9a4c/runtime/core/Clownfish/TestHarness/TestUtils.c
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/TestHarness/TestUtils.c 
b/runtime/core/Clownfish/TestHarness/TestUtils.c
index 22c9f06..228aef7 100644
--- a/runtime/core/Clownfish/TestHarness/TestUtils.c
+++ b/runtime/core/Clownfish/TestHarness/TestUtils.c
@@ -122,6 +122,44 @@ TestUtils_get_str(const char *ptr) {
 
 #include <windows.h>
 
+uint64_t
+TestUtils_time() {
+    SYSTEMTIME system_time;
+    GetSystemTime(&system_time);
+
+    FILETIME file_time;
+    SystemTimeToFileTime(&system_time, &file_time);
+
+    ULARGE_INTEGER ularge;
+    ularge.LowPart  = file_time.dwLowDateTime;
+    ularge.HighPart = file_time.dwHighDateTime;
+
+    return ularge.QuadPart / 10;
+
+}
+
+/********************************* UNIXEN *********************************/
+#elif defined(CHY_HAS_SYS_TIME_H)
+
+#include <sys/time.h>
+
+uint64_t
+TestUtils_time() {
+    struct timeval t;
+    gettimeofday(&t, NULL);
+
+    return (uint64_t)t.tv_sec * 1000000 + t.tv_usec;
+}
+
+#else
+  #error "Can't find a known time API."
+#endif // OS switch.
+
+/********************************* WINDOWS ********************************/
+#ifdef CHY_HAS_WINDOWS_H
+
+#include <windows.h>
+
 void
 TestUtils_usleep(uint64_t microseconds) {
     Sleep(microseconds / 1000);

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/42fc9a4c/runtime/core/Clownfish/TestHarness/TestUtils.cfh
----------------------------------------------------------------------
diff --git a/runtime/core/Clownfish/TestHarness/TestUtils.cfh 
b/runtime/core/Clownfish/TestHarness/TestUtils.cfh
index b46bf91..594f838 100644
--- a/runtime/core/Clownfish/TestHarness/TestUtils.cfh
+++ b/runtime/core/Clownfish/TestHarness/TestUtils.cfh
@@ -71,6 +71,11 @@ inert class Clownfish::TestHarness::TestUtils  {
     inert incremented String*
     random_string(size_t length);
 
+    /** Time in microseconds since the system-dependent epoch.
+     */
+    inert uint64_t
+    time();
+
     inert void
     usleep(uint64_t microseconds);
 

Reply via email to