From 8fb639ca9118a6522723d0bc09db59b432a803a9 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 12 Sep 2014 14:43:07 -0700 Subject: [PATCH] Add a test for pthread_gettid_np. Bug: 17475191 Change-Id: I8c6a2f4ceba2d24a77ae9a21269edce523aea421 --- tests/pthread_test.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp index 3a5c3dc85..43587f4a7 100644 --- a/tests/pthread_test.cpp +++ b/tests/pthread_test.cpp @@ -909,3 +909,29 @@ TEST(pthread, pthread_attr_getstack__main_thread) { EXPECT_EQ(stack_size, stack_size2); ASSERT_EQ(6666U, stack_size); } + +#if defined(__BIONIC__) +static void* pthread_gettid_np_helper(void* arg) { + *reinterpret_cast(arg) = gettid(); + return NULL; +} +#endif + +TEST(pthread, pthread_gettid_np) { +#if defined(__BIONIC__) + ASSERT_EQ(gettid(), pthread_gettid_np(pthread_self())); + + pid_t t_gettid_result; + pthread_t t; + pthread_create(&t, NULL, pthread_gettid_np_helper, &t_gettid_result); + + pid_t t_pthread_gettid_np_result = pthread_gettid_np(t); + + void* join_result; + pthread_join(t, &join_result); + + ASSERT_EQ(t_gettid_result, t_pthread_gettid_np_result); +#else + GTEST_LOG_(INFO) << "This test does nothing.\n"; +#endif +}