Only have one copy of the kernel_sigset_t hack, and add more tests.
Change-Id: I377522fcba6fb4b5fd2754ab15b091014bd7c16f
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index da945b4..3e144db 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -126,3 +126,31 @@
EXPECT_EXIT(TestBug37410(), ::testing::ExitedWithCode(0), "");
}
#endif
+
+static void* SignalHandlerFn(void* arg) {
+ sigset_t wait_set;
+ sigfillset(&wait_set);
+ return reinterpret_cast<void*>(sigwait(&wait_set, reinterpret_cast<int*>(arg)));
+}
+
+TEST(pthread, pthread_sigmask) {
+ // Block SIGUSR1.
+ sigset_t set;
+ sigemptyset(&set);
+ sigaddset(&set, SIGUSR1);
+ ASSERT_EQ(0, pthread_sigmask(SIG_BLOCK, &set, NULL));
+
+ // Spawn a thread that calls sigwait and tells us what it received.
+ pthread_t signal_thread;
+ int received_signal = -1;
+ ASSERT_EQ(0, pthread_create(&signal_thread, NULL, SignalHandlerFn, &received_signal));
+
+ // Send that thread SIGUSR1.
+ pthread_kill(signal_thread, SIGUSR1);
+
+ // See what it got.
+ void* join_result;
+ ASSERT_EQ(0, pthread_join(signal_thread, &join_result));
+ ASSERT_EQ(SIGUSR1, received_signal);
+ ASSERT_EQ(0, reinterpret_cast<int>(join_result));
+}
diff --git a/tests/signal_test.cpp b/tests/signal_test.cpp
index 1292568..b100372 100644
--- a/tests/signal_test.cpp
+++ b/tests/signal_test.cpp
@@ -101,3 +101,27 @@
ASSERT_EQ(-1, raise(-1));
ASSERT_EQ(EINVAL, errno);
}
+
+static void HandleSIGALRM(int signal_number) {
+ ASSERT_EQ(SIGALRM, signal_number);
+}
+
+TEST(signal, sigwait) {
+ struct sigaction action;
+ sigemptyset(&action.sa_mask);
+ action.sa_flags = 0;
+ action.sa_handler = HandleSIGALRM;
+ sigaction(SIGALRM, &action, NULL);
+
+ sigset_t wait_set;
+ sigemptyset(&wait_set);
+ sigaddset(&wait_set, SIGALRM);
+
+ alarm(1);
+
+ int received_signal;
+ errno = 0;
+ ASSERT_EQ(0, sigwait(&wait_set, &received_signal));
+ ASSERT_EQ(0, errno);
+ ASSERT_EQ(SIGALRM, received_signal);
+}