summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d9cb0ed)
raw | patch | inline | side by side (parent: d9cb0ed)
author | Elliott Hughes <enh@google.com> | |
Mon, 22 Sep 2014 23:01:26 +0000 (16:01 -0700) | ||
committer | Elliott Hughes <enh@google.com> | |
Mon, 22 Sep 2014 23:27:19 +0000 (16:27 -0700) |
Change-Id: I5a623fa1e1da55f11d51f3a9bdfa0627698c486f
tests/pthread_test.cpp | patch | blob | history |
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 43587f4a754cf836a54333bfff23c4de2a97c9b6..9dbb4f56cd09d47d0209421270431a623a271ba8 100644 (file)
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
static void MakeDeadThread(pthread_t& t) {
ASSERT_EQ(0, pthread_create(&t, NULL, IdFn, NULL));
- void* result;
- ASSERT_EQ(0, pthread_join(t, &result));
+ ASSERT_EQ(0, pthread_join(t, NULL));
}
TEST(pthread, pthread_create) {
AssertDetached(t1, true);
// ...pthread_join should fail.
- void* result;
- ASSERT_EQ(EINVAL, pthread_join(t1, &result));
+ ASSERT_EQ(EINVAL, pthread_join(t1, NULL));
}
TEST(pthread, pthread_no_op_detach_after_join) {
}
TEST(pthread, pthread_join_self) {
- void* result;
- ASSERT_EQ(EDEADLK, pthread_join(pthread_self(), &result));
+ ASSERT_EQ(EDEADLK, pthread_join(pthread_self(), NULL));
}
struct TestBug37410 {
pthread_t dead_thread;
MakeDeadThread(dead_thread);
- void* result;
- ASSERT_EQ(ESRCH, pthread_join(dead_thread, &result));
+ ASSERT_EQ(ESRCH, pthread_join(dead_thread, NULL));
}
TEST(pthread, pthread_kill__no_such_thread) {
size_t result;
pthread_t t;
pthread_create(&t, &attributes, GetActualGuardSizeFn, &result);
- void* join_result;
- pthread_join(t, &join_result);
+ pthread_join(t, NULL);
return result;
}
size_t result;
pthread_t t;
pthread_create(&t, &attributes, GetActualStackSizeFn, &result);
- void* join_result;
- pthread_join(t, &join_result);
+ pthread_join(t, NULL);
return result;
}
pid_t t_pthread_gettid_np_result = pthread_gettid_np(t);
- void* join_result;
- pthread_join(t, &join_result);
+ pthread_join(t, NULL);
ASSERT_EQ(t_gettid_result, t_pthread_gettid_np_result);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
}
+
+static size_t cleanup_counter = 0;
+
+void AbortCleanupRoutine(void*) {
+ abort();
+}
+
+void CountCleanupRoutine(void*) {
+ ++cleanup_counter;
+}
+
+void PthreadCleanupTester() {
+ pthread_cleanup_push(CountCleanupRoutine, NULL);
+ pthread_cleanup_push(CountCleanupRoutine, NULL);
+ pthread_cleanup_push(AbortCleanupRoutine, NULL);
+
+ pthread_cleanup_pop(0); // Pop the abort without executing it.
+ pthread_cleanup_pop(1); // Pop one count while executing it.
+ ASSERT_EQ(1U, cleanup_counter);
+ // Exit while the other count is still on the cleanup stack.
+ pthread_exit(NULL);
+
+ // Calls to pthread_cleanup_pop/pthread_cleanup_push must always be balanced.
+ pthread_cleanup_pop(0);
+}
+
+void* PthreadCleanupStartRoutine(void*) {
+ PthreadCleanupTester();
+ return NULL;
+}
+
+TEST(pthread, pthread_cleanup_push__pthread_cleanup_pop) {
+ pthread_t t;
+ ASSERT_EQ(0, pthread_create(&t, NULL, PthreadCleanupStartRoutine, NULL));
+ pthread_join(t, NULL);
+ ASSERT_EQ(2U, cleanup_counter);
+}