aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/pthread_test.cpp4
-rw-r--r--tests/signal_test.cpp41
2 files changed, 44 insertions, 1 deletions
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 4a7c155c0..a03232ff4 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -284,11 +284,13 @@ static void pthread_kill__in_signal_handler_helper(int signal_number) {
TEST(pthread, pthread_kill__in_signal_handler) {
struct sigaction action;
+ struct sigaction original_action;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
action.sa_handler = pthread_kill__in_signal_handler_helper;
- sigaction(SIGALRM, &action, NULL);
+ ASSERT_EQ(0, sigaction(SIGALRM, &action, &original_action));
ASSERT_EQ(0, pthread_kill(pthread_self(), SIGALRM));
+ ASSERT_EQ(0, sigaction(SIGALRM, &original_action, NULL));
}
TEST(pthread, pthread_detach__no_such_thread) {
diff --git a/tests/signal_test.cpp b/tests/signal_test.cpp
index a719fe786..3070747c1 100644
--- a/tests/signal_test.cpp
+++ b/tests/signal_test.cpp
@@ -210,3 +210,44 @@ TEST(signal, sigsuspend_sigpending) {
// Restore the original set.
assert(0 == sigprocmask(SIG_SETMASK, &original_set, NULL));
}
+
+static void EmptySignalHandler(int) {}
+static void EmptySignalAction(int, siginfo_t*, void*) {}
+
+TEST(signal, sigaction) {
+ // See what's currently set for SIGALRM.
+ struct sigaction sa;
+ memset(&sa, 0, sizeof(sa));
+ ASSERT_EQ(0, sigaction(SIGALRM, NULL, &sa));
+ ASSERT_TRUE(sa.sa_handler == NULL);
+ ASSERT_TRUE(sa.sa_sigaction == NULL);
+ ASSERT_TRUE(sa.sa_flags == 0);
+
+ // Set a traditional sa_handler signal handler.
+ memset(&sa, 0, sizeof(sa));
+ sigaddset(&sa.sa_mask, SIGALRM);
+ sa.sa_flags = SA_ONSTACK;
+ sa.sa_handler = EmptySignalHandler;
+ ASSERT_EQ(0, sigaction(SIGALRM, &sa, NULL));
+
+ // Check that we can read it back.
+ memset(&sa, 0, sizeof(sa));
+ ASSERT_EQ(0, sigaction(SIGALRM, NULL, &sa));
+ ASSERT_TRUE(sa.sa_handler == EmptySignalHandler);
+ ASSERT_TRUE((void*) sa.sa_sigaction == (void*) sa.sa_handler);
+ ASSERT_TRUE(sa.sa_flags == SA_ONSTACK);
+
+ // Set a new-style sa_sigaction signal handler.
+ memset(&sa, 0, sizeof(sa));
+ sigaddset(&sa.sa_mask, SIGALRM);
+ sa.sa_flags = SA_ONSTACK | SA_SIGINFO;
+ sa.sa_sigaction = EmptySignalAction;
+ ASSERT_EQ(0, sigaction(SIGALRM, &sa, NULL));
+
+ // Check that we can read it back.
+ memset(&sa, 0, sizeof(sa));
+ ASSERT_EQ(0, sigaction(SIGALRM, NULL, &sa));
+ ASSERT_TRUE(sa.sa_sigaction == EmptySignalAction);
+ ASSERT_TRUE((void*) sa.sa_sigaction == (void*) sa.sa_handler);
+ ASSERT_TRUE(sa.sa_flags == (SA_ONSTACK | SA_SIGINFO));
+}