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