]> git.saurik.com Git - apple/xnu.git/blob - tests/mach_boottime_usec.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / tests / mach_boottime_usec.c
1 #include <stdlib.h>
2 #include <time.h>
3 #include <sys/time.h>
4 #include <sys/types.h>
5 #include <sys/sysctl.h>
6 #include <mach/mach_time.h>
7
8 #include <darwintest.h>
9
10 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
11
12 T_DECL(mach_boottime_usec, "mach_boottime_usec()",
13 T_META_ALL_VALID_ARCHS(true), T_META_LTEPHASE(LTE_POSTINIT))
14 {
15 uint64_t bt_usec = mach_boottime_usec();
16
17 struct timeval bt_tv;
18 size_t len = sizeof(bt_tv);
19 T_ASSERT_POSIX_SUCCESS(sysctlbyname("kern.boottime", &bt_tv, &len, NULL, 0), NULL);
20
21 T_EXPECT_EQ((uint64_t)bt_tv.tv_sec * USEC_PER_SEC + (uint64_t)bt_tv.tv_usec, bt_usec, NULL);
22 }