8158 Want named threads API
[unleashed.git] / usr / src / test / libc-tests / tests / timespec_get.c
blob5458acdc89868344ac3ba1f308f2186c5add93a7
1 /*
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
5 * 1.0 of the CDDL.
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).
20 #include <time.h>
21 #include <limits.h>
22 #include <sys/debug.h>
24 static int
25 timespec_cmp(const struct timespec *ls, const struct timespec *rs)
27 if (ls->tv_sec > rs->tv_sec)
28 return (-1);
29 if (ls->tv_sec < rs->tv_sec)
30 return (1);
31 if (ls->tv_nsec > rs->tv_nsec)
32 return (-1);
33 if (ls->tv_nsec > rs->tv_nsec)
34 return (-1);
35 if (ls->tv_nsec < rs->tv_nsec)
36 return (1);
38 return (0);
41 int
42 main(void)
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);
58 return (0);