1 #include <utest/utest.h>
6 /* <--- Begin definition of test cases ---> */
8 bool test_sigmask(void) {
11 void *thread_handler(void *arg)
15 sigaddset(&s, SIGUSR2);
16 pthread_sigmask(SIG_BLOCK, &s, NULL);
17 for (int i=0; i<100000; i++)
21 void signal_handler(int signo)
23 sigphandle = pthread_self();
24 __sync_fetch_and_add(&count, 1);
27 struct sigaction sigact = {.sa_handler = signal_handler, 0};
28 sigaction(SIGUSR1, &sigact, 0);
29 sigaction(SIGUSR2, &sigact, 0);
32 pthread_create(&phandle, NULL, thread_handler, NULL);
33 for (int i=0; i<100; i++)
35 pthread_kill(phandle, SIGUSR1);
36 pthread_kill(phandle, SIGUSR2);
37 pthread_join(phandle, NULL);
39 UT_ASSERT_M("Should only receive one signal", count == 1);
40 UT_ASSERT_M("Signal handler run on wrong thread", sigphandle == phandle);
44 /* <--- End definition of test cases ---> */
46 struct utest utests[] = {
49 int num_utests = sizeof(utests) / sizeof(struct utest);
51 int main(int argc, char *argv[]) {
52 // Run test suite passing it all the args as whitelist of what tests to run.
53 char **whitelist = &argv[1];
54 int whitelist_len = argc - 1;
55 RUN_TEST_SUITE(utests, num_utests, whitelist, whitelist_len);