]>
git.saurik.com Git - apple/xnu.git/blob - tests/gettimeofday.c
3 #include <mach/mach_time.h>
5 #include <darwintest.h>
7 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
9 extern int __gettimeofday(struct timeval
*, struct timezone
*);
11 T_DECL(gettimeofday
, "gettimeofday()",
12 T_META_CHECK_LEAKS(false), T_META_ALL_VALID_ARCHS(true), T_META_LTEPHASE(LTE_POSTINIT
))
14 struct timeval tv_a
, tv_b
, tv_c
;
16 T_ASSERT_POSIX_ZERO(gettimeofday(&tv_a
, NULL
), NULL
);
17 T_ASSERT_GT(tv_a
.tv_sec
, 0L, NULL
);
21 T_ASSERT_POSIX_ZERO(__gettimeofday(&tv_b
, NULL
), NULL
);
22 T_ASSERT_GE(tv_b
.tv_sec
, tv_a
.tv_sec
, NULL
);
26 T_ASSERT_POSIX_ZERO(gettimeofday(&tv_c
, NULL
), NULL
);
27 T_ASSERT_GE(tv_c
.tv_sec
, tv_b
.tv_sec
, NULL
);
30 #if 0 // This symbol isn't exported so we can't test with stock libsyscall
31 extern int __gettimeofday_with_mach(struct timeval
*, struct timezone
*, uint64_t *mach_time
);
33 T_DECL(gettimeofday_with_mach
, "gettimeofday_with_mach()",
34 T_META_CHECK_LEAKS(false), T_META_ALL_VALID_ARCHS(true))
36 struct timeval gtod_ts
;
38 uint64_t mach_time_before
, mach_time
, mach_time_after
;
40 mach_time_before
= mach_absolute_time();
42 T_ASSERT_POSIX_ZERO(__gettimeofday_with_mach(>od_ts
, NULL
, &mach_time
), NULL
);
43 T_ASSERT_GT(gtod_ts
.tv_sec
, 0L, NULL
);
45 mach_time_after
= mach_absolute_time();
47 T_LOG("%llx > %llx > %llx", mach_time_before
, mach_time
, mach_time_after
);
49 T_ASSERT_LT(mach_time_before
, mach_time
, NULL
);
50 T_ASSERT_GT(mach_time_after
, mach_time
, NULL
);