]> git.saurik.com Git - apple/xnu.git/blame - tools/tests/darwintests/gettimeofday.c
xnu-3789.51.2.tar.gz
[apple/xnu.git] / tools / tests / darwintests / gettimeofday.c
CommitLineData
39037602
A
1#include <unistd.h>
2#include <sys/time.h>
3#include <mach/mach_time.h>
4
5#include <darwintest.h>
6
7extern int __gettimeofday(struct timeval *, struct timezone *);
8
9T_DECL(gettimeofday, "gettimeofday()",
813fb2f6 10 T_META_CHECK_LEAKS(false), T_META_ALL_VALID_ARCHS(true), T_META_LTEPHASE(LTE_POSTINIT))
39037602
A
11{
12 struct timeval tv_a, tv_b, tv_c;
13
14 T_ASSERT_POSIX_ZERO(gettimeofday(&tv_a, NULL), NULL);
15 T_ASSERT_GT(tv_a.tv_sec, 0L, NULL);
16
17 sleep(1);
18
19 T_ASSERT_POSIX_ZERO(__gettimeofday(&tv_b, NULL), NULL);
20 T_ASSERT_GE(tv_b.tv_sec, tv_a.tv_sec, NULL);
21
22 sleep(1);
23
24 T_ASSERT_POSIX_ZERO(gettimeofday(&tv_c, NULL), NULL);
25 T_ASSERT_GE(tv_c.tv_sec, tv_b.tv_sec, NULL);
26}
27
28#if 0 // This symbol isn't exported so we can't test with stock libsyscall
29extern int __gettimeofday_with_mach(struct timeval *, struct timezone *, uint64_t *mach_time);
30
31T_DECL(gettimeofday_with_mach, "gettimeofday_with_mach()",
813fb2f6 32 T_META_CHECK_LEAKS(false), T_META_ALL_VALID_ARCHS(true))
39037602
A
33{
34 struct timeval gtod_ts;
35
36 uint64_t mach_time_before, mach_time, mach_time_after;
37
38 mach_time_before = mach_absolute_time();
39
40 T_ASSERT_POSIX_ZERO(__gettimeofday_with_mach(&gtod_ts, NULL, &mach_time), NULL);
41 T_ASSERT_GT(gtod_ts.tv_sec, 0L, NULL);
42
43 mach_time_after = mach_absolute_time();
44
45 T_LOG("%llx > %llx > %llx", mach_time_before, mach_time, mach_time_after);
46
47 T_ASSERT_LT(mach_time_before, mach_time, NULL);
48 T_ASSERT_GT(mach_time_after, mach_time, NULL);
49}
50#endif // 0