]> git.saurik.com Git - apple/xnu.git/blob - tools/tests/darwintests/mach_boottime_usec.c
xnu-4570.1.46.tar.gz
[apple/xnu.git] / tools / tests / darwintests / 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_DECL(mach_boottime_usec, "mach_boottime_usec()",
11 T_META_ALL_VALID_ARCHS(true), T_META_LTEPHASE(LTE_POSTINIT))
12 {
13 uint64_t bt_usec = mach_boottime_usec();
14
15 struct timeval bt_tv;
16 size_t len = sizeof(bt_tv);
17 T_ASSERT_POSIX_SUCCESS(sysctlbyname("kern.boottime", &bt_tv, &len, NULL, 0), NULL);
18
19 T_EXPECT_EQ((uint64_t)bt_tv.tv_sec * USEC_PER_SEC + (uint64_t)bt_tv.tv_usec, bt_usec, NULL);
20 }