xref: /xnu-11417.101.15/tests/kalloc.c (revision e3723e1f17661b24996789d8afc084c0c3303b26)
1*e3723e1fSApple OSS Distributions #include <sys/sysctl.h>
2*e3723e1fSApple OSS Distributions #include <darwintest.h>
3*e3723e1fSApple OSS Distributions #include <darwintest_utils.h>
4*e3723e1fSApple OSS Distributions 
5*e3723e1fSApple OSS Distributions T_GLOBAL_META(
6*e3723e1fSApple OSS Distributions 	T_META_NAMESPACE("xnu.vm"),
7*e3723e1fSApple OSS Distributions 	T_META_RADAR_COMPONENT_NAME("xnu"),
8*e3723e1fSApple OSS Distributions 	T_META_RADAR_COMPONENT_VERSION("zalloc"));
9*e3723e1fSApple OSS Distributions 
10*e3723e1fSApple OSS Distributions static int64_t
run_sysctl_test(const char * t,int64_t value)11*e3723e1fSApple OSS Distributions run_sysctl_test(const char *t, int64_t value)
12*e3723e1fSApple OSS Distributions {
13*e3723e1fSApple OSS Distributions 	char name[1024];
14*e3723e1fSApple OSS Distributions 	int64_t result = 0;
15*e3723e1fSApple OSS Distributions 	size_t s = sizeof(value);
16*e3723e1fSApple OSS Distributions 	int rc;
17*e3723e1fSApple OSS Distributions 
18*e3723e1fSApple OSS Distributions 	snprintf(name, sizeof(name), "debug.test.%s", t);
19*e3723e1fSApple OSS Distributions 	rc = sysctlbyname(name, &result, &s, &value, s);
20*e3723e1fSApple OSS Distributions 	T_ASSERT_POSIX_SUCCESS(rc, "sysctlbyname(%s)", t);
21*e3723e1fSApple OSS Distributions 	return result;
22*e3723e1fSApple OSS Distributions }
23*e3723e1fSApple OSS Distributions 
24*e3723e1fSApple OSS Distributions T_DECL(kalloc_type, "kalloc_type_test",
25*e3723e1fSApple OSS Distributions     T_META_CHECK_LEAKS(false), T_META_TAG_VM_PREFERRED)
26*e3723e1fSApple OSS Distributions {
27*e3723e1fSApple OSS Distributions 	T_EXPECT_EQ(1ll, run_sysctl_test("kalloc_type", 260), "test succeeded");
28*e3723e1fSApple OSS Distributions }
29*e3723e1fSApple OSS Distributions 
30*e3723e1fSApple OSS Distributions T_DECL(kalloc, "kalloc_test",
31*e3723e1fSApple OSS Distributions     T_META_NAMESPACE("xnu.vm"),
32*e3723e1fSApple OSS Distributions     T_META_CHECK_LEAKS(false), T_META_TAG_VM_PREFERRED)
33*e3723e1fSApple OSS Distributions {
34*e3723e1fSApple OSS Distributions 	T_EXPECT_EQ(1ll, run_sysctl_test("kalloc", 0), "test succeeded");
35*e3723e1fSApple OSS Distributions }
36*e3723e1fSApple OSS Distributions 
37*e3723e1fSApple OSS Distributions T_DECL(kalloc_guard_regions, "Checks that guard regions are inserted frequently enough",
38*e3723e1fSApple OSS Distributions     T_META_NAMESPACE("xnu.vm"),
39*e3723e1fSApple OSS Distributions     T_META_CHECK_LEAKS(false), T_META_TAG_VM_PREFERRED)
40*e3723e1fSApple OSS Distributions {
41*e3723e1fSApple OSS Distributions 	T_EXPECT_EQ(1ll, run_sysctl_test("kalloc_guard_regions", 0), "kalloc_guard_regions");
42*e3723e1fSApple OSS Distributions }
43