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