2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2016 Joyent, Inc.
17 * Basic tests for timespec_get(3C).
22 #include <sys/debug.h>
25 timespec_cmp(const struct timespec
*ls
, const struct timespec
*rs
)
27 if (ls
->tv_sec
> rs
->tv_sec
)
29 if (ls
->tv_sec
< rs
->tv_sec
)
31 if (ls
->tv_nsec
> rs
->tv_nsec
)
33 if (ls
->tv_nsec
> rs
->tv_nsec
)
35 if (ls
->tv_nsec
< rs
->tv_nsec
)
44 struct timespec ts
, pre
, post
;
46 VERIFY0(timespec_get(&ts
, TIME_UTC
+ 1));
47 VERIFY0(timespec_get(&ts
, TIME_UTC
- 1));
48 VERIFY0(timespec_get(&ts
, UINT16_MAX
));
50 VERIFY0(clock_gettime(CLOCK_REALTIME
, &pre
));
51 VERIFY3S(timespec_get(&ts
, TIME_UTC
), ==, TIME_UTC
);
52 VERIFY0(clock_gettime(CLOCK_REALTIME
, &post
));
53 VERIFY3S(timespec_cmp(&pre
, &post
), ==, 1);
55 VERIFY3S(timespec_cmp(&pre
, &ts
), ==, 1);
56 VERIFY3S(timespec_cmp(&ts
, &post
), ==, 1);