xref: /xnu-11215/tests/vm/vm_sysctl_tests.c (revision 4f1223e8)
1 #include <sys/sysctl.h>
2 #include <signal.h>
3 #include <darwintest.h>
4 #include <darwintest_utils.h>
5 
6 T_GLOBAL_META(
7 	T_META_NAMESPACE("xnu.vm"),
8 	T_META_RADAR_COMPONENT_NAME("xnu"),
9 	T_META_RADAR_COMPONENT_VERSION("VM"),
10 	T_META_ASROOT(YES),
11 	T_META_RUN_CONCURRENTLY(true),
12 	T_META_TAG_VM_PREFERRED);
13 
14 static int64_t
run_sysctl_test(const char * t,int64_t value)15 run_sysctl_test(const char *t, int64_t value)
16 {
17 	char name[1024];
18 	int64_t result = 0;
19 	size_t s = sizeof(value);
20 	int rc;
21 
22 	snprintf(name, sizeof(name), "debug.test.%s", t);
23 	rc = sysctlbyname(name, &result, &s, &value, s);
24 	T_ASSERT_POSIX_SUCCESS(rc, "sysctlbyname(%s)", t);
25 	return result;
26 }
27 
28 T_DECL(vm_map_non_aligned,
29     "Test that we can destroy map unaligned mappings (rdar://88969652)",
30     T_META_TAG_VM_PREFERRED)
31 {
32 	T_EXPECT_EQ(1ull, run_sysctl_test("vm_map_non_aligned", 0), "vm_map_non_aligned");
33 }
34 
35 T_DECL(vm_map_null,
36     "Test that we can call vm_map functions with VM_MAP_NULL",
37     T_META_TAG_VM_PREFERRED)
38 {
39 	int64_t result = run_sysctl_test("vm_map_null", 0);
40 	T_EXPECT_EQ(1ull, result, "vm_map_null");
41 }
42 
43 T_DECL(vm_memory_entry_pgz,
44     "Test that we can make a memory entry of a pgz protected allocation (rdar://122836976)",
45     T_META_TAG_VM_PREFERRED)
46 {
47 	int64_t result = run_sysctl_test("vm_memory_entry_pgz", 0);
48 	if (result == 2) {
49 		T_SKIP("Unable to pgz_protect allocation. Pgz slots might be full.");
50 	}
51 	T_EXPECT_EQ(1ull, result, "vm_memory_entry_pgz");
52 }
53 
54 T_DECL(vm_map_copy_entry_subrange,
55     "Test mapping a subrange of a copy entry")
56 {
57 	T_EXPECT_EQ(1ull, run_sysctl_test("vm_map_copy_entry_subrange", 0), "vm_map_copy_entry_subrange");
58 }
59 
60 T_DECL(vm_memory_entry_map_size_null,
61     "Test mach_memory_entry_map_size with NULL memory entry")
62 {
63 	T_EXPECT_EQ(1ull, run_sysctl_test("vm_memory_entry_map_size_null", 0), "vm_memory_entry_map_size_null");
64 }
65 
66 
67 T_DECL(vm_memory_entry_map_size_overflow,
68     "Test overflow cases in mach_memory_entry_map_size sanitization")
69 {
70 	T_EXPECT_EQ(1ull, run_sysctl_test("vm_memory_entry_map_size_overflow", 0), "vm_memory_entry_map_size_overflow");
71 }
72 
73 T_DECL(vm_memory_entry_map_size_copy,
74     "Test mach_memory_entry_map_size with copy memory entries and 4k/16k combinations")
75 {
76 	T_EXPECT_EQ(1ull, run_sysctl_test("vm_memory_entry_map_size_copy", 0), "vm_memory_entry_map_size_copy");
77 }
78 
79 T_DECL(vm_memory_entry_parent_submap,
80     "Test mach_make_memory_entry cases where parent is a submap")
81 {
82 	T_EXPECT_EQ(1ull, run_sysctl_test("vm_memory_entry_parent_submap", 0), "vm_memory_entry_parent_submap");
83 }
84