am e8a95624: Merge "Test pthread_cleanup_push(3)/pthread_cleanup_pop(3)."
				
					
				
			* commit 'e8a95624b6ee37f7ee85f0318f1fccd916292ebd': Test pthread_cleanup_push(3)/pthread_cleanup_pop(3).
This commit is contained in:
		@@ -168,8 +168,7 @@ static void AssertDetached(pthread_t t, bool is_detached) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
static void MakeDeadThread(pthread_t& t) {
 | 
					static void MakeDeadThread(pthread_t& t) {
 | 
				
			||||||
  ASSERT_EQ(0, pthread_create(&t, NULL, IdFn, NULL));
 | 
					  ASSERT_EQ(0, pthread_create(&t, NULL, IdFn, NULL));
 | 
				
			||||||
  void* result;
 | 
					  ASSERT_EQ(0, pthread_join(t, NULL));
 | 
				
			||||||
  ASSERT_EQ(0, pthread_join(t, &result));
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(pthread, pthread_create) {
 | 
					TEST(pthread, pthread_create) {
 | 
				
			||||||
@@ -201,8 +200,7 @@ TEST(pthread, pthread_no_join_after_detach) {
 | 
				
			|||||||
  AssertDetached(t1, true);
 | 
					  AssertDetached(t1, true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // ...pthread_join should fail.
 | 
					  // ...pthread_join should fail.
 | 
				
			||||||
  void* result;
 | 
					  ASSERT_EQ(EINVAL, pthread_join(t1, NULL));
 | 
				
			||||||
  ASSERT_EQ(EINVAL, pthread_join(t1, &result));
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(pthread, pthread_no_op_detach_after_join) {
 | 
					TEST(pthread, pthread_no_op_detach_after_join) {
 | 
				
			||||||
@@ -230,8 +228,7 @@ TEST(pthread, pthread_no_op_detach_after_join) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(pthread, pthread_join_self) {
 | 
					TEST(pthread, pthread_join_self) {
 | 
				
			||||||
  void* result;
 | 
					  ASSERT_EQ(EDEADLK, pthread_join(pthread_self(), NULL));
 | 
				
			||||||
  ASSERT_EQ(EDEADLK, pthread_join(pthread_self(), &result));
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct TestBug37410 {
 | 
					struct TestBug37410 {
 | 
				
			||||||
@@ -481,8 +478,7 @@ TEST(pthread, pthread_join__no_such_thread) {
 | 
				
			|||||||
  pthread_t dead_thread;
 | 
					  pthread_t dead_thread;
 | 
				
			||||||
  MakeDeadThread(dead_thread);
 | 
					  MakeDeadThread(dead_thread);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void* result;
 | 
					  ASSERT_EQ(ESRCH, pthread_join(dead_thread, NULL));
 | 
				
			||||||
  ASSERT_EQ(ESRCH, pthread_join(dead_thread, &result));
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(pthread, pthread_kill__no_such_thread) {
 | 
					TEST(pthread, pthread_kill__no_such_thread) {
 | 
				
			||||||
@@ -543,8 +539,7 @@ static size_t GetActualGuardSize(const pthread_attr_t& attributes) {
 | 
				
			|||||||
  size_t result;
 | 
					  size_t result;
 | 
				
			||||||
  pthread_t t;
 | 
					  pthread_t t;
 | 
				
			||||||
  pthread_create(&t, &attributes, GetActualGuardSizeFn, &result);
 | 
					  pthread_create(&t, &attributes, GetActualGuardSizeFn, &result);
 | 
				
			||||||
  void* join_result;
 | 
					  pthread_join(t, NULL);
 | 
				
			||||||
  pthread_join(t, &join_result);
 | 
					 | 
				
			||||||
  return result;
 | 
					  return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -559,8 +554,7 @@ static size_t GetActualStackSize(const pthread_attr_t& attributes) {
 | 
				
			|||||||
  size_t result;
 | 
					  size_t result;
 | 
				
			||||||
  pthread_t t;
 | 
					  pthread_t t;
 | 
				
			||||||
  pthread_create(&t, &attributes, GetActualStackSizeFn, &result);
 | 
					  pthread_create(&t, &attributes, GetActualStackSizeFn, &result);
 | 
				
			||||||
  void* join_result;
 | 
					  pthread_join(t, NULL);
 | 
				
			||||||
  pthread_join(t, &join_result);
 | 
					 | 
				
			||||||
  return result;
 | 
					  return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -927,11 +921,47 @@ TEST(pthread, pthread_gettid_np) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  pid_t t_pthread_gettid_np_result = pthread_gettid_np(t);
 | 
					  pid_t t_pthread_gettid_np_result = pthread_gettid_np(t);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void* join_result;
 | 
					  pthread_join(t, NULL);
 | 
				
			||||||
  pthread_join(t, &join_result);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ASSERT_EQ(t_gettid_result, t_pthread_gettid_np_result);
 | 
					  ASSERT_EQ(t_gettid_result, t_pthread_gettid_np_result);
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
  GTEST_LOG_(INFO) << "This test does nothing.\n";
 | 
					  GTEST_LOG_(INFO) << "This test does nothing.\n";
 | 
				
			||||||
#endif
 | 
					#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);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user