]>
git.saurik.com Git - apple/xnu.git/blob - tests/workq_sigprof.c
8 #include <mach/mach_time.h>
9 #include <dispatch/dispatch.h>
11 #include <darwintest.h>
15 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
17 static pthread_t workq_thread
;
18 static bool signal_received
;
21 signal_handler(int sig __unused
, siginfo_t
*b __unused
, void* unused __unused
)
23 if (pthread_self() == workq_thread
) {
24 signal_received
= true;
29 workq_block(void *unused __unused
)
31 workq_thread
= pthread_self();
36 * sigaddset(&set, SIGPROF);
37 * pthread_sigmask(SIG_UNBLOCK, &set, NULL);
40 uint64_t spin_start
= mach_absolute_time();
41 while (mach_absolute_time() - spin_start
< 30 * NSEC_PER_SEC
) {
42 if (signal_received
) {
43 T_PASS("Got SIGPROF!");
49 T_DECL(workq_sigprof
, "test that workqueue threads can receive sigprof")
51 struct sigaction sa
= {
52 .sa_sigaction
= signal_handler
54 sigfillset(&sa
.sa_mask
);
55 T_ASSERT_POSIX_ZERO(sigaction(SIGPROF
, &sa
, NULL
), NULL
);
57 dispatch_queue_t q
= dispatch_get_global_queue(0, 0);
58 dispatch_async_f(q
, NULL
, workq_block
);
60 struct itimerval timerval
= {
61 .it_interval
= {.tv_usec
= 10000},
62 .it_value
= {.tv_usec
= 10000}
64 T_ASSERT_POSIX_ZERO(setitimer(ITIMER_PROF
, &timerval
, NULL
), NULL
);
69 #else //!TARGET_OS_IPHONE
71 T_DECL(workq_sigprof
, "test that workqueue threads can receive sigprof")
74 T_FAIL("<rdar://problem/25864196> setitimer/sigprof doesn't seem to be delivered on embeded platforms");
77 #endif //!TARGET_OS_IPHONE