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