xref: /xnu-11215.41.3/tests/vm/vm_sysctl_tests.c (revision 33de042d024d46de5ff4e89f2471de6608e37fa4)
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 
13 static int64_t
run_sysctl_test(const char * t,int64_t value)14 run_sysctl_test(const char *t, int64_t value)
15 {
16 	char name[1024];
17 	int64_t result = 0;
18 	size_t s = sizeof(value);
19 	int rc;
20 
21 	snprintf(name, sizeof(name), "debug.test.%s", t);
22 	rc = sysctlbyname(name, &result, &s, &value, s);
23 	T_ASSERT_POSIX_SUCCESS(rc, "sysctlbyname(%s)", t);
24 	return result;
25 }
26 
27 T_DECL(vm_map_non_aligned,
28     "Test that we can destroy map unaligned mappings (rdar://88969652)",
29     T_META_TAG_VM_PREFERRED)
30 {
31 	T_EXPECT_EQ(1ull, run_sysctl_test("vm_map_non_aligned", 0), "vm_map_non_aligned");
32 }
33 
34 T_DECL(vm_map_null,
35     "Test that we can call vm_map functions with VM_MAP_NULL",
36     T_META_TAG_VM_PREFERRED)
37 {
38 	int64_t result = run_sysctl_test("vm_map_null", 0);
39 	T_EXPECT_EQ(1ull, result, "vm_map_null");
40 }
41 
42 T_DECL(vm_memory_entry_pgz,
43     "Test that we can make a memory entry of a pgz protected allocation (rdar://122836976)",
44     T_META_TAG_VM_PREFERRED)
45 {
46 	int64_t result = run_sysctl_test("vm_memory_entry_pgz", 0);
47 	if (result == 2) {
48 		T_SKIP("Unable to pgz_protect allocation. Pgz slots might be full.");
49 	}
50 	T_EXPECT_EQ(1ull, result, "vm_memory_entry_pgz");
51 }
52