summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-02-15 19:21:51 -0800
committerElliott Hughes <enh@google.com>2013-02-19 12:21:41 -0800
commit9d23e04c43dbb8480bea8be28b8a2f37423bec49 (patch)
treee403288cf01ce40d6f330da09a317c7ad6dc2cb2 /tests
parent081318e3550b1a8d8384d98d7c94527681691120 (diff)
downloadbionic-9d23e04c43dbb8480bea8be28b8a2f37423bec49.zip
bionic-9d23e04c43dbb8480bea8be28b8a2f37423bec49.tar.gz
bionic-9d23e04c43dbb8480bea8be28b8a2f37423bec49.tar.bz2
Fix pthreads functions that should return ESRCH.
imgtec pointed out that pthread_kill(3) was broken, but most of the other functions that ought to return ESRCH for invalid/exited threads were equally broken. Change-Id: I96347f6195549aee0c72dc39063e6c5d06d2e01f
Diffstat (limited to 'tests')
-rw-r--r--tests/pthread_test.cpp71
1 files changed, 66 insertions, 5 deletions
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index aebf477..239092c 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -79,6 +79,12 @@ static void AssertDetached(pthread_t t, bool is_detached) {
ASSERT_EQ(is_detached, (detach_state == PTHREAD_CREATE_DETACHED));
}
+static void MakeDeadThread(pthread_t& t) {
+ ASSERT_EQ(0, pthread_create(&t, NULL, IdFn, NULL));
+ void* result;
+ ASSERT_EQ(0, pthread_join(t, &result));
+}
+
TEST(pthread, pthread_create) {
void* expected_result = reinterpret_cast<void*>(123);
// Can we create a thread?
@@ -229,12 +235,67 @@ TEST(pthread, pthread_setname_np__other) {
#if __BIONIC__ // Not all build servers have a new enough glibc? TODO: remove when they're on gprecise.
TEST(pthread, pthread_setname_np__no_such_thread) {
- pthread_t t1;
- ASSERT_EQ(0, pthread_create(&t1, NULL, IdFn, NULL));
- void* result;
- ASSERT_EQ(0, pthread_join(t1, &result));
+ pthread_t dead_thread;
+ MakeDeadThread(dead_thread);
// Call pthread_setname_np after thread has already exited.
- ASSERT_EQ(ENOENT, pthread_setname_np(t1, "short 3"));
+ ASSERT_EQ(ENOENT, pthread_setname_np(dead_thread, "short 3"));
}
#endif
+
+TEST(pthread, pthread_kill__0) {
+ // Signal 0 just tests that the thread exists, so it's safe to call on ourselves.
+ ASSERT_EQ(0, pthread_kill(pthread_self(), 0));
+}
+
+TEST(pthread, pthread_kill__invalid_signal) {
+ ASSERT_EQ(EINVAL, pthread_kill(pthread_self(), -1));
+}
+
+TEST(pthread, pthread_detach__no_such_thread) {
+ pthread_t dead_thread;
+ MakeDeadThread(dead_thread);
+
+ ASSERT_EQ(ESRCH, pthread_detach(dead_thread));
+}
+
+TEST(pthread, pthread_getcpuclockid__no_such_thread) {
+ pthread_t dead_thread;
+ MakeDeadThread(dead_thread);
+
+ clockid_t c;
+ ASSERT_EQ(ESRCH, pthread_getcpuclockid(dead_thread, &c));
+}
+
+TEST(pthread, pthread_getschedparam__no_such_thread) {
+ pthread_t dead_thread;
+ MakeDeadThread(dead_thread);
+
+ int policy;
+ sched_param param;
+ ASSERT_EQ(ESRCH, pthread_getschedparam(dead_thread, &policy, &param));
+}
+
+TEST(pthread, pthread_setschedparam__no_such_thread) {
+ pthread_t dead_thread;
+ MakeDeadThread(dead_thread);
+
+ int policy = 0;
+ sched_param param;
+ ASSERT_EQ(ESRCH, pthread_setschedparam(dead_thread, policy, &param));
+}
+
+TEST(pthread, pthread_join__no_such_thread) {
+ pthread_t dead_thread;
+ MakeDeadThread(dead_thread);
+
+ void* result;
+ ASSERT_EQ(ESRCH, pthread_join(dead_thread, &result));
+}
+
+TEST(pthread, pthread_kill__no_such_thread) {
+ pthread_t dead_thread;
+ MakeDeadThread(dead_thread);
+
+ ASSERT_EQ(ESRCH, pthread_kill(dead_thread, 0));
+}