xref: /xnu-8020.101.4/tests/rusage_tests.c (revision e7776783b89a353188416a9a346c6cdb4928faad)
1*e7776783SApple OSS Distributions #include <darwintest.h>
2*e7776783SApple OSS Distributions #include <sys/resource.h>
3*e7776783SApple OSS Distributions #include <libproc.h>
4*e7776783SApple OSS Distributions 
5*e7776783SApple OSS Distributions T_GLOBAL_META(T_META_NAMESPACE("xnu.RM"),
6*e7776783SApple OSS Distributions     T_META_RADAR_COMPONENT_NAME("xnu"),
7*e7776783SApple OSS Distributions     T_META_RADAR_COMPONENT_VERSION("RM"),
8*e7776783SApple OSS Distributions     T_META_OWNER("mwidmann"),
9*e7776783SApple OSS Distributions     T_META_CHECK_LEAKS(false));
10*e7776783SApple OSS Distributions 
11*e7776783SApple OSS Distributions T_DECL(rusage_kernel_cpu_time_sanity,
12*e7776783SApple OSS Distributions     "ensure the P-CPU time for kernel_task is sane", T_META_ASROOT(true))
13*e7776783SApple OSS Distributions {
14*e7776783SApple OSS Distributions 	struct rusage_info_v5 usage_info = { 0 };
15*e7776783SApple OSS Distributions 	T_SETUPBEGIN;
16*e7776783SApple OSS Distributions 	int ret = proc_pid_rusage(0, RUSAGE_INFO_V5, (void **)&usage_info);
17*e7776783SApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(ret, "proc_pid_rusage on kernel_task");
18*e7776783SApple OSS Distributions 	T_SETUPEND;
19*e7776783SApple OSS Distributions 
20*e7776783SApple OSS Distributions 	T_EXPECT_GT(usage_info.ri_system_time + usage_info.ri_user_time,
21*e7776783SApple OSS Distributions 	    UINT64_C(0), "kernel CPU time should be non-zero");
22*e7776783SApple OSS Distributions }
23