]>
git.saurik.com Git - apple/xnu.git/blob - tools/tests/unit_tests/test_waitqlocktry_12053360.c
2 * File: test_waitqlocktry_12053360.c
3 * Test Description: This is a load test for wait queues in the kernel. It is designed to excercise the locking of threads and
4 * wait queues in the face of timer expirations. The overall runtime is limited to 90 secs.
5 * In case of inconsistency we have found to be panic'ing within the first 15 secs.
6 * Radar: <rdar://problem/12053360> <rdar://problem/12323652>
11 #include <mach/semaphore.h>
16 #define MAX_TEST_RUN_TIME 90
17 uint32_t test_usleep_max
;
20 test_thread(void *arg __unused
)
23 usleep(random() % test_usleep_max
);
31 main(int argc
, const char **argv
)
38 printf("Usage: %s <max sleep in usecs> <nthreads>\n", argv
[0]);
39 printf("Currently defaulting to 100us and 100 threads\n");
40 test_usleep_max
= 100;
46 printf("Sleep time must be > 0.\n");
50 test_usleep_max
= (uint32_t)tmp
;
54 printf("Num threads must be > 0.\n");
57 nthreads
= (uint32_t)tmp
;
59 threads
= (pthread_t
*)malloc(nthreads
* sizeof(pthread_t
));
60 if (threads
== NULL
) {
61 printf("Failed to allocate thread array.\n");
65 printf("Creating %u threads with a max sleep time of %uusec.\n", nthreads
, test_usleep_max
);
67 for (i
= 0; i
< nthreads
; i
++) {
68 result
= pthread_create(&threads
[i
], NULL
, test_thread
, NULL
);
70 printf("Failed to allocate thread.\n");
75 printf("Main thread sleeping for %d secs\n", MAX_TEST_RUN_TIME
);
76 sleep(MAX_TEST_RUN_TIME
);
77 printf("Success. Exiting..\n");