xref: /xnu-8792.81.2/tests/vm/kern_max_task_pmem.c (revision 19c3b8c28c31cb8130e034cfb5df6bf9ba342d90)
1*19c3b8c2SApple OSS Distributions #include <darwintest.h>
2*19c3b8c2SApple OSS Distributions #include <sys/sysctl.h>
3*19c3b8c2SApple OSS Distributions #include <sys/errno.h>
4*19c3b8c2SApple OSS Distributions 
5*19c3b8c2SApple OSS Distributions #define MAX_TASK_PMEM "kern.max_task_pmem"
6*19c3b8c2SApple OSS Distributions #define HW_MEMSIZE_STR "hw.memsize"
7*19c3b8c2SApple OSS Distributions #define HW_MEMSIZE_THRESHOLD 600 * 1024 * 1024
8*19c3b8c2SApple OSS Distributions 
9*19c3b8c2SApple OSS Distributions T_GLOBAL_META(
10*19c3b8c2SApple OSS Distributions 	T_META_NAMESPACE("xnu.vm"),
11*19c3b8c2SApple OSS Distributions 	T_META_RADAR_COMPONENT_NAME("xnu"),
12*19c3b8c2SApple OSS Distributions 	T_META_RADAR_COMPONENT_VERSION("VM"));
13*19c3b8c2SApple OSS Distributions 
14*19c3b8c2SApple OSS Distributions /*
15*19c3b8c2SApple OSS Distributions  * Embedded Device having physical memory greater than 600MB should have positive
16*19c3b8c2SApple OSS Distributions  * value for kern.max_task_pmem if present.
17*19c3b8c2SApple OSS Distributions  * Strategy:
18*19c3b8c2SApple OSS Distributions  *  Fetch hw.memsize for the device.
19*19c3b8c2SApple OSS Distributions  *  If hw.memsize > 600MB, and kern.max_task_pmem is present, assert that
20*19c3b8c2SApple OSS Distributions  *  kern.max_task_pmem is set to value > 0.
21*19c3b8c2SApple OSS Distributions  */
22*19c3b8c2SApple OSS Distributions T_DECL(kern_max_task_pmem, "Embedded platforms should have a positive value for kern.max_task_pmem when hw.memsize > 600MB")
23*19c3b8c2SApple OSS Distributions {
24*19c3b8c2SApple OSS Distributions 	int kern_max_task_pmem = 0;
25*19c3b8c2SApple OSS Distributions 	size_t pmem_size = sizeof(kern_max_task_pmem);
26*19c3b8c2SApple OSS Distributions 
27*19c3b8c2SApple OSS Distributions 	uint64_t hw_memsize = 0;
28*19c3b8c2SApple OSS Distributions 	size_t size_hw_memsize = sizeof(hw_memsize);
29*19c3b8c2SApple OSS Distributions 
30*19c3b8c2SApple OSS Distributions 	int ret = 0;
31*19c3b8c2SApple OSS Distributions 
32*19c3b8c2SApple OSS Distributions 	ret = sysctlbyname(HW_MEMSIZE_STR, &hw_memsize, &size_hw_memsize, NULL, 0);
33*19c3b8c2SApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(ret, "call sysctlbyname to get hardware mem size.");
34*19c3b8c2SApple OSS Distributions 
35*19c3b8c2SApple OSS Distributions 	T_LOG("Checking if %s > %d", HW_MEMSIZE_STR, HW_MEMSIZE_THRESHOLD);
36*19c3b8c2SApple OSS Distributions 	if (hw_memsize <= HW_MEMSIZE_THRESHOLD) {
37*19c3b8c2SApple OSS Distributions 		T_SKIP("Device has hw.memsize = %lld. Skipping the check for %s", hw_memsize, MAX_TASK_PMEM);
38*19c3b8c2SApple OSS Distributions 	}
39*19c3b8c2SApple OSS Distributions 
40*19c3b8c2SApple OSS Distributions 	T_LOG("Device has %s = %lld", HW_MEMSIZE_STR, hw_memsize);
41*19c3b8c2SApple OSS Distributions 	T_LOG("Testing for %s ...", MAX_TASK_PMEM);
42*19c3b8c2SApple OSS Distributions 
43*19c3b8c2SApple OSS Distributions 	ret = sysctlbyname(MAX_TASK_PMEM, &kern_max_task_pmem, &pmem_size, NULL, 0);
44*19c3b8c2SApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(ret, "call sysctlbyname to get max task physical memory");
45*19c3b8c2SApple OSS Distributions 
46*19c3b8c2SApple OSS Distributions 	T_LOG("%s = %d", MAX_TASK_PMEM, kern_max_task_pmem);
47*19c3b8c2SApple OSS Distributions 	T_ASSERT_GT_INT(kern_max_task_pmem, 0, "%s should be greater than 0", MAX_TASK_PMEM);
48*19c3b8c2SApple OSS Distributions }
49