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