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