]>
git.saurik.com Git - apple/xnu.git/blob - tests/mach_get_times.c
d6fe33a7bec4e93af4eae5c36b3efa19f970e52c
4 #include <mach/mach_time.h>
6 #include <darwintest.h>
7 #include <darwintest_utils.h>
9 #define T_LOG_VERBOSE(...)
11 #define timespec2nanosec(ts) ((uint64_t)((ts)->tv_sec) * NSEC_PER_SEC + (uint64_t)((ts)->tv_nsec))
13 T_DECL(mach_get_times
, "mach_get_times()",
14 T_META_CHECK_LEAKS(false), T_META_ALL_VALID_ARCHS(true))
16 const int ITERATIONS
= 500000 * dt_ncpu();
17 struct timespec gtod_ts
;
19 uint64_t last_absolute
, last_continuous
, last_gtod
;
20 T_QUIET
; T_ASSERT_EQ(mach_get_times(&last_absolute
, &last_continuous
, >od_ts
), KERN_SUCCESS
, NULL
);
21 last_gtod
= timespec2nanosec(>od_ts
);
23 for (int i
= 0; i
< ITERATIONS
; i
++) {
24 uint64_t absolute
, continuous
, gtod
;
25 T_QUIET
; T_ASSERT_EQ(mach_get_times(&absolute
, &continuous
, >od_ts
), KERN_SUCCESS
, NULL
);
26 gtod
= timespec2nanosec(>od_ts
);
28 T_LOG_VERBOSE("[%d] abs: %llu.%09llu(+%llu)\tcont: %llu.%09llu(+%llu)\tgtod:%llu.%09llu(+%llu)", i
,
29 absolute
/ NSEC_PER_SEC
, absolute
% NSEC_PER_SEC
, absolute
- last_absolute
,
30 continuous
/ NSEC_PER_SEC
, continuous
% NSEC_PER_SEC
, continuous
- last_continuous
,
31 gtod
/ NSEC_PER_SEC
, gtod
% NSEC_PER_SEC
, gtod
- last_gtod
);
33 T_QUIET
; T_EXPECT_EQ(absolute
- last_absolute
, continuous
- last_continuous
, NULL
);
35 int64_t gtod_diff
= (int64_t)gtod
- (int64_t)last_gtod
;
36 T_QUIET
; T_ASSERT_LE((uint64_t)llabs(gtod_diff
), NSEC_PER_SEC
, NULL
);
38 last_absolute
= absolute
;
39 last_continuous
= continuous
;
42 gtod_ts
.tv_sec
= 0; gtod_ts
.tv_nsec
= 0;