]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: eventtest: fix build on macOS
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Sat, 19 Nov 2016 17:42:27 +0000 (20:42 +0300)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Thu, 24 Nov 2016 15:11:05 +0000 (18:11 +0300)
macOS doesn't support clock_gettime(2), at least versions prior 10.12
(I didn't actually check 10.12 though). So, use its own routines in
eventtest.

 * configure.ac: check for requires symbols and define
   HAVE_MACH_CLOCK_ROUTINES if found
 * tests/eventtest.c: add clock_get_time() based implementation

configure.ac
tests/eventtest.c

index fd50ff80e2e8e3837ad4dc9e852976609b5c1395..342db894df4e59399fa4187deb4e1debeee3bc88 100644 (file)
@@ -2524,6 +2524,15 @@ AC_CHECK_MEMBERS([struct if_data.ifi_oqdrops],
                 [#include <net/if.h>
                 ])
 
+AC_CHECK_DECLS([clock_serv_t, host_get_clock_service, clock_get_time],
+               [AC_DEFINE([HAVE_MACH_CLOCK_ROUTINES],
+                          [1],
+                          [whether Mach clock routines are available])],
+               [],
+               [#include <mach/clock.h>
+                #include <mach/mach.h>
+               ])
+
 # Check if we need to look for ifconfig
 if test "$want_ifconfig" = "yes"; then
      AC_PATH_PROG([IFCONFIG_PATH], [ifconfig])
index 011bedc33f309bd0e63e636b39f5c8782005414c..03ab3184726d49058567dc191e0212360ed3b968 100644 (file)
 #include <signal.h>
 #include <time.h>
 
+#if HAVE_MACH_CLOCK_ROUTINES
+# include <mach/clock.h>
+# include <mach/mach.h>
+#endif
+
 #include "testutils.h"
 #include "internal.h"
 #include "virfile.h"
@@ -262,7 +267,18 @@ finishJob(const char *name, int handle, int timer)
 {
     struct timespec waitTime;
     int rc;
+#if HAVE_MACH_CLOCK_ROUTINES
+    clock_serv_t cclock;
+    mach_timespec_t mts;
+
+    host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
+    clock_get_time(cclock, &mts);
+    mach_port_deallocate(mach_task_self(), cclock);
+    waitTime.tv_sec = mts.tv_sec;
+    waitTime.tv_nsec = mts.tv_nsec;
+#else
     clock_gettime(CLOCK_REALTIME, &waitTime);
+#endif
     waitTime.tv_sec += 5;
     rc = 0;
     while (!eventThreadJobDone && rc == 0)