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