]>
Commit | Line | Data |
---|---|---|
39037602 A |
1 | #include <pthread.h> |
2 | #include <stdbool.h> | |
3 | #include <signal.h> | |
4 | #include <stdio.h> | |
5 | #include <string.h> | |
6 | #include <unistd.h> | |
7 | #include <sys/time.h> | |
8 | #include <mach/mach_time.h> | |
9 | #include <dispatch/dispatch.h> | |
10 | ||
11 | #include <darwintest.h> | |
12 | ||
13 | #if !TARGET_OS_IPHONE | |
14 | ||
15 | static pthread_t workq_thread; | |
16 | static bool signal_received; | |
17 | ||
18 | static void signal_handler(int sig __unused, siginfo_t *b __unused, void* unused __unused) { | |
19 | if (pthread_self() == workq_thread) { | |
20 | signal_received = true; | |
21 | } | |
22 | } | |
23 | ||
24 | static void workq_block(void *unused __unused) { | |
25 | workq_thread = pthread_self(); | |
26 | ||
27 | /* | |
28 | sigset_t set; | |
29 | sigemptyset(&set); | |
30 | sigaddset(&set, SIGPROF); | |
31 | pthread_sigmask(SIG_UNBLOCK, &set, NULL); | |
32 | */ | |
33 | ||
34 | uint64_t spin_start = mach_absolute_time(); | |
35 | while (mach_absolute_time() - spin_start < 30 * NSEC_PER_SEC) | |
36 | if (signal_received) { | |
37 | T_PASS("Got SIGPROF!"); | |
38 | T_END; | |
39 | } | |
40 | } | |
41 | ||
42 | T_DECL(workq_sigprof, "test that workqueue threads can receive sigprof") | |
43 | { | |
44 | struct sigaction sa = { | |
45 | .sa_sigaction = signal_handler | |
46 | }; | |
47 | sigfillset(&sa.sa_mask); | |
48 | T_ASSERT_POSIX_ZERO(sigaction(SIGPROF, &sa, NULL), NULL); | |
49 | ||
50 | dispatch_queue_t q = dispatch_get_global_queue(0, 0); | |
51 | dispatch_async_f(q, NULL, workq_block); | |
52 | ||
53 | struct itimerval timerval = { | |
54 | .it_interval = {.tv_usec = 10000}, | |
55 | .it_value = {.tv_usec = 10000} | |
56 | }; | |
57 | T_ASSERT_POSIX_ZERO(setitimer(ITIMER_PROF, &timerval, NULL), NULL); | |
58 | ||
59 | dispatch_main(); | |
60 | } | |
61 | ||
62 | #else //!TARGET_OS_IPHONE | |
63 | ||
64 | T_DECL(workq_sigprof, "test that workqueue threads can receive sigprof") | |
65 | { | |
66 | T_EXPECTFAIL; | |
67 | T_FAIL("<rdar://problem/25864196> setitimer/sigprof doesn't seem to be delivered on embeded platforms"); | |
68 | } | |
69 | ||
70 | #endif //!TARGET_OS_IPHONE |