]>
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 | ||
f427ee49 | 13 | #if !defined(__arm__) |
39037602 | 14 | |
cb323159 A |
15 | T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true)); |
16 | ||
39037602 A |
17 | static pthread_t workq_thread; |
18 | static bool signal_received; | |
19 | ||
0a7de745 A |
20 | static void |
21 | signal_handler(int sig __unused, siginfo_t *b __unused, void* unused __unused) | |
22 | { | |
23 | if (pthread_self() == workq_thread) { | |
24 | signal_received = true; | |
25 | } | |
39037602 A |
26 | } |
27 | ||
0a7de745 A |
28 | static void |
29 | workq_block(void *unused __unused) | |
30 | { | |
31 | workq_thread = pthread_self(); | |
39037602 | 32 | |
0a7de745 A |
33 | /* |
34 | * sigset_t set; | |
35 | * sigemptyset(&set); | |
36 | * sigaddset(&set, SIGPROF); | |
37 | * pthread_sigmask(SIG_UNBLOCK, &set, NULL); | |
38 | */ | |
39037602 | 39 | |
0a7de745 A |
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!"); | |
44 | T_END; | |
45 | } | |
46 | } | |
47 | } | |
39037602 A |
48 | |
49 | T_DECL(workq_sigprof, "test that workqueue threads can receive sigprof") | |
50 | { | |
0a7de745 A |
51 | struct sigaction sa = { |
52 | .sa_sigaction = signal_handler | |
53 | }; | |
54 | sigfillset(&sa.sa_mask); | |
55 | T_ASSERT_POSIX_ZERO(sigaction(SIGPROF, &sa, NULL), NULL); | |
39037602 | 56 | |
0a7de745 A |
57 | dispatch_queue_t q = dispatch_get_global_queue(0, 0); |
58 | dispatch_async_f(q, NULL, workq_block); | |
39037602 | 59 | |
0a7de745 A |
60 | struct itimerval timerval = { |
61 | .it_interval = {.tv_usec = 10000}, | |
62 | .it_value = {.tv_usec = 10000} | |
63 | }; | |
64 | T_ASSERT_POSIX_ZERO(setitimer(ITIMER_PROF, &timerval, NULL), NULL); | |
39037602 | 65 | |
0a7de745 | 66 | dispatch_main(); |
39037602 A |
67 | } |
68 | ||
f427ee49 | 69 | #else //!defined(__arm__) |
39037602 A |
70 | |
71 | T_DECL(workq_sigprof, "test that workqueue threads can receive sigprof") | |
72 | { | |
0a7de745 | 73 | T_EXPECTFAIL; |
f427ee49 | 74 | T_FAIL("<rdar://problem/25864196> setitimer/sigprof not supported on 32bit arm platforms"); |
39037602 A |
75 | } |
76 | ||
f427ee49 | 77 | #endif //!defined(__arm__) |