]> git.saurik.com Git - apple/xnu.git/blame - tests/vm/zone_gc_replenish_test.c
xnu-7195.81.3.tar.gz
[apple/xnu.git] / tests / vm / zone_gc_replenish_test.c
CommitLineData
f427ee49
A
1#include <sys/sysctl.h>
2#include <time.h>
3
4#include <darwintest.h>
5#include <darwintest_utils.h>
6
7
8static void *
9gc_thread_func(__unused void *arg)
10{
11 int err;
12 unsigned int count = 1;
13 size_t s = sizeof(count);
14 time_t start = time(NULL);
15 time_t end = time(NULL);
16
17 /*
18 * Keep kicking the test for 15 seconds to see if we can panic() the kernel
19 */
20 while (time(&end) < start + 15) {
21 err = sysctlbyname("kern.zone_gc_replenish_test", &count, &s, &count, s);
22
23 /* If the sysctl isn't supported, test succeeds */
24 if (err != 0) {
25 T_SKIP("sysctl kern.zone_gc_replenish_test not found, skipping test");
26 break;
27 }
28 }
29 return NULL;
30}
31
32static void *
33alloc_thread_func(__unused void *arg)
34{
35 int err;
36 unsigned int count = 1;
37 size_t s = sizeof(count);
38 time_t start = time(NULL);
39 time_t end = time(NULL);
40
41 /*
42 * Keep kicking the test for 15 seconds to see if we can panic() the kernel
43 */
44 while (time(&end) < start + 15) {
45 err = sysctlbyname("kern.zone_alloc_replenish_test", &count, &s, &count, s);
46
47 /* If the sysctl isn't supported, test succeeds */
48 if (err != 0) {
49 T_SKIP("sysctl kern.zone_alloc_replenish_test not found, skipping test");
50 break;
51 }
52 }
53 return NULL;
54}
55
56T_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))
60{
61 pthread_attr_t attr;
62 pthread_t gc_thread;
63 pthread_t alloc_thread;
64 int ret;
65
66 ret = pthread_attr_init(&attr);
67 T_QUIET; T_ASSERT_MACH_SUCCESS(ret, "pthread_attr_init");
68
69 ret = pthread_create(&gc_thread, &attr, gc_thread_func, NULL);
70 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "gc pthread_create");
71
72 ret = pthread_create(&alloc_thread, &attr, alloc_thread_func, NULL);
73 T_QUIET; T_ASSERT_POSIX_ZERO(ret, "alloc pthread_create");
74
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");
78}