Changeset View
Changeset View
Standalone View
Standalone View
tools/regression/sockets/unix_cmsg/uc_check_time.c
Show All 29 Lines | |||||
#include <sys/time.h> | #include <sys/time.h> | ||||
#include <time.h> | #include <time.h> | ||||
#include "uc_check_time.h" | #include "uc_check_time.h" | ||||
static const struct timeval max_diff_tv = {.tv_sec = 1, .tv_usec = 0}; | static const struct timeval max_diff_tv = {.tv_sec = 1, .tv_usec = 0}; | ||||
static const struct timespec max_diff_ts = {.tv_sec = 1, .tv_nsec = 0}; | static const struct timespec max_diff_ts = {.tv_sec = 1, .tv_nsec = 0}; | ||||
#define timespeccmp(tvp, uvp, cmp) \ | |||||
(((tvp)->tv_sec == (uvp)->tv_sec) ? \ | |||||
((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \ | |||||
((tvp)->tv_sec cmp (uvp)->tv_sec)) | |||||
#define timespecsub(vvp, uvp) \ | |||||
do { \ | |||||
(vvp)->tv_sec -= (uvp)->tv_sec; \ | |||||
(vvp)->tv_nsec -= (uvp)->tv_nsec; \ | |||||
if ((vvp)->tv_nsec < 0) { \ | |||||
(vvp)->tv_sec--; \ | |||||
(vvp)->tv_nsec += 1000000000; \ | |||||
} \ | |||||
} while (0) | |||||
int | int | ||||
uc_check_bintime(const struct bintime *mt) | uc_check_bintime(const struct bintime *mt) | ||||
{ | { | ||||
struct timespec bt; | struct timespec bt; | ||||
bintime2timespec(mt, &bt); | bintime2timespec(mt, &bt); | ||||
return (uc_check_timespec_real(&bt)); | return (uc_check_timespec_real(&bt)); | ||||
} | } | ||||
Show All 14 Lines | |||||
int | int | ||||
uc_check_timespec_real(const struct timespec *bt) | uc_check_timespec_real(const struct timespec *bt) | ||||
{ | { | ||||
struct timespec ct; | struct timespec ct; | ||||
if (clock_gettime(CLOCK_REALTIME, &ct) < 0) | if (clock_gettime(CLOCK_REALTIME, &ct) < 0) | ||||
return (-1); | return (-1); | ||||
timespecsub(&ct, bt); | timespecsub(&ct, bt, &ct); | ||||
if (!timespeccmp(&ct, &max_diff_ts, <)) | if (!timespeccmp(&ct, &max_diff_ts, <)) | ||||
return (-1); | return (-1); | ||||
return (0); | return (0); | ||||
} | } | ||||
int | int | ||||
uc_check_timespec_mono(const struct timespec *bt) | uc_check_timespec_mono(const struct timespec *bt) | ||||
{ | { | ||||
struct timespec ct; | struct timespec ct; | ||||
if (clock_gettime(CLOCK_MONOTONIC, &ct) < 0) | if (clock_gettime(CLOCK_MONOTONIC, &ct) < 0) | ||||
return (-1); | return (-1); | ||||
timespecsub(&ct, bt); | timespecsub(&ct, bt, &ct); | ||||
if (!timespeccmp(&ct, &max_diff_ts, <)) | if (!timespeccmp(&ct, &max_diff_ts, <)) | ||||
return (-1); | return (-1); | ||||
return (0); | return (0); | ||||
} | } |