]>
git.saurik.com Git - apple/xnu.git/blob - tests/vm/zone_gc_replenish_test.c
1 #include <sys/sysctl.h>
4 #include <darwintest.h>
5 #include <darwintest_utils.h>
9 gc_thread_func(__unused
void *arg
)
12 unsigned int count
= 1;
13 size_t s
= sizeof(count
);
14 time_t start
= time(NULL
);
15 time_t end
= time(NULL
);
18 * Keep kicking the test for 15 seconds to see if we can panic() the kernel
20 while (time(&end
) < start
+ 15) {
21 err
= sysctlbyname("kern.zone_gc_replenish_test", &count
, &s
, &count
, s
);
23 /* If the sysctl isn't supported, test succeeds */
25 T_SKIP("sysctl kern.zone_gc_replenish_test not found, skipping test");
33 alloc_thread_func(__unused
void *arg
)
36 unsigned int count
= 1;
37 size_t s
= sizeof(count
);
38 time_t start
= time(NULL
);
39 time_t end
= time(NULL
);
42 * Keep kicking the test for 15 seconds to see if we can panic() the kernel
44 while (time(&end
) < start
+ 15) {
45 err
= sysctlbyname("kern.zone_alloc_replenish_test", &count
, &s
, &count
, s
);
47 /* If the sysctl isn't supported, test succeeds */
49 T_SKIP("sysctl kern.zone_alloc_replenish_test not found, skipping test");
56 T_DECL(zone_gc_replenish_test
,
57 "Test zone garbage collection, exhaustion and replenishment",
58 T_META_NAMESPACE("xnu.vm"),
59 T_META_CHECK_LEAKS(false))
63 pthread_t alloc_thread
;
66 ret
= pthread_attr_init(&attr
);
67 T_QUIET
; T_ASSERT_MACH_SUCCESS(ret
, "pthread_attr_init");
69 ret
= pthread_create(&gc_thread
, &attr
, gc_thread_func
, NULL
);
70 T_QUIET
; T_ASSERT_POSIX_ZERO(ret
, "gc pthread_create");
72 ret
= pthread_create(&alloc_thread
, &attr
, alloc_thread_func
, NULL
);
73 T_QUIET
; T_ASSERT_POSIX_ZERO(ret
, "alloc pthread_create");
75 T_ASSERT_POSIX_ZERO(pthread_join(gc_thread
, NULL
), NULL
);
76 T_ASSERT_POSIX_ZERO(pthread_join(alloc_thread
, NULL
), NULL
);
77 T_PASS("Ran 15 seconds with no panic");