aboutsummaryrefslogtreecommitdiffstats
path: root/tests/pthread_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-02-21 11:22:23 -0800
committerElliott Hughes <enh@google.com>2013-02-21 11:22:23 -0800
commitfae89fc4042ee4c360842234dfda7831c313bd44 (patch)
treeaa35c41ee98aad9b065591a5497515163534e956 /tests/pthread_test.cpp
parentccd403161cdcc88a0ffcaecd1bc707e2d4c88a1c (diff)
downloadandroid_bionic-fae89fc4042ee4c360842234dfda7831c313bd44.tar.gz
android_bionic-fae89fc4042ee4c360842234dfda7831c313bd44.tar.bz2
android_bionic-fae89fc4042ee4c360842234dfda7831c313bd44.zip
Fix raise(3) so it works in signal handlers.
We could special-case raise(3) in non-threaded programs, but the more conservative course is to make pthread_kill(3) work in signal handlers at the cost of a race shared by other C libraries. Change-Id: I59fb23d03bdabf403435e731704b33acdf3e0234
Diffstat (limited to 'tests/pthread_test.cpp')
-rw-r--r--tests/pthread_test.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 239092ca2..98bc4e5a5 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -252,6 +252,24 @@ TEST(pthread, pthread_kill__invalid_signal) {
ASSERT_EQ(EINVAL, pthread_kill(pthread_self(), -1));
}
+static void pthread_kill__in_signal_handler_helper(int signal_number) {
+ static int count = 0;
+ ASSERT_EQ(SIGALRM, signal_number);
+ if (++count == 1) {
+ // Can we call pthread_kill from a signal handler?
+ ASSERT_EQ(0, pthread_kill(pthread_self(), SIGALRM));
+ }
+}
+
+TEST(pthread, pthread_kill__in_signal_handler) {
+ struct sigaction 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, pthread_kill(pthread_self(), SIGALRM));
+}
+
TEST(pthread, pthread_detach__no_such_thread) {
pthread_t dead_thread;
MakeDeadThread(dead_thread);