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