]> git.meshlink.io Git - meshlink/blobdiff - test/channels-aio-fd.c
Remove gettimeofday() usage from test cases.
[meshlink] / test / channels-aio-fd.c
index 3559e8e7411e060c8b9ae2378e2c7fc4cba7d9b6..40fcf7fc605608187b98124a38091ece35be0c89 100644 (file)
@@ -7,7 +7,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/time.h>
+#include <time.h>
 #include <limits.h>
 
 #include "meshlink.h"
@@ -19,7 +19,7 @@ static const size_t nchannels = 4; // number of simultaneous channels
 struct aio_info {
        int callbacks;
        size_t size;
-       struct timeval tv;
+       struct timespec ts;
        struct sync_flag flag;
 };
 
@@ -35,7 +35,7 @@ static void aio_fd_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, int
        (void)len;
 
        struct aio_info *info = priv;
-       gettimeofday(&info->tv, NULL);
+       clock_gettime(CLOCK_MONOTONIC, &info->ts);
        info->callbacks++;
        info->size += len;
        set_sync_flag(&info->flag, true);
@@ -168,8 +168,8 @@ int main(int argc, char *argv[]) {
 
                // First batch of data should all be sent and received before the second batch
                for(size_t j = 0; j < nchannels; j++) {
-                       assert(timercmp(&out_infos[i].aio_infos[0].tv, &out_infos[j].aio_infos[1].tv, <=));
-                       assert(timercmp(&in_infos[i].aio_infos[0].tv, &in_infos[j].aio_infos[1].tv, <=));
+                       assert(timespec_lt(&out_infos[i].aio_infos[0].ts, &out_infos[j].aio_infos[1].ts));
+                       assert(timespec_lt(&in_infos[i].aio_infos[0].ts, &in_infos[j].aio_infos[1].ts));
                }
 
                // Files should be identical