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