xref: /xnu-10002.81.5/tests/mach_boottime_usec.c (revision 5e3eaea39dcf651e66cb99ba7d70e32cc4a99587)
1*5e3eaea3SApple OSS Distributions #include <stdlib.h>
2*5e3eaea3SApple OSS Distributions #include <time.h>
3*5e3eaea3SApple OSS Distributions #include <sys/time.h>
4*5e3eaea3SApple OSS Distributions #include <sys/types.h>
5*5e3eaea3SApple OSS Distributions #include <sys/sysctl.h>
6*5e3eaea3SApple OSS Distributions #include <mach/mach_time.h>
7*5e3eaea3SApple OSS Distributions 
8*5e3eaea3SApple OSS Distributions #include <darwintest.h>
9*5e3eaea3SApple OSS Distributions 
10*5e3eaea3SApple OSS Distributions T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
11*5e3eaea3SApple OSS Distributions 
12*5e3eaea3SApple OSS Distributions T_DECL(mach_boottime_usec, "mach_boottime_usec()",
13*5e3eaea3SApple OSS Distributions     T_META_ALL_VALID_ARCHS(true), T_META_LTEPHASE(LTE_POSTINIT))
14*5e3eaea3SApple OSS Distributions {
15*5e3eaea3SApple OSS Distributions 	uint64_t bt_usec = mach_boottime_usec();
16*5e3eaea3SApple OSS Distributions 
17*5e3eaea3SApple OSS Distributions 	struct timeval bt_tv;
18*5e3eaea3SApple OSS Distributions 	size_t len = sizeof(bt_tv);
19*5e3eaea3SApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(sysctlbyname("kern.boottime", &bt_tv, &len, NULL, 0), NULL);
20*5e3eaea3SApple OSS Distributions 
21*5e3eaea3SApple OSS Distributions 	T_EXPECT_EQ((uint64_t)bt_tv.tv_sec * USEC_PER_SEC + (uint64_t)bt_tv.tv_usec, bt_usec, NULL);
22*5e3eaea3SApple OSS Distributions }
23