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