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