summaryrefslogtreecommitdiffstats
path: root/tests/pthread_test.cpp
diff options
context:
space:
mode:
authorYabin Cui <yabinc@google.com>2015-03-05 20:35:32 -0800
committerYabin Cui <yabinc@google.com>2015-04-14 13:32:09 -0700
commit5ddbb3f936ee44555a46020239e49ab45109a806 (patch)
tree70395ecf0897580781856c68cbcd57019ff831e3 /tests/pthread_test.cpp
parent4bd8f9637daaada333ff35945b00cfe6cb822376 (diff)
downloadbionic-5ddbb3f936ee44555a46020239e49ab45109a806.zip
bionic-5ddbb3f936ee44555a46020239e49ab45109a806.tar.gz
bionic-5ddbb3f936ee44555a46020239e49ab45109a806.tar.bz2
Prevent using static-allocated pthread keys before creation.
Bug: 19993460 Change-Id: I244dea7f5df3c8384f88aa48d635348fafc9cbaf
Diffstat (limited to 'tests/pthread_test.cpp')
-rw-r--r--tests/pthread_test.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index f96ccf9..6dbd964 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -181,6 +181,19 @@ TEST(pthread, pthread_key_dirty) {
ASSERT_EQ(0, pthread_key_delete(key));
}
+TEST(pthread, static_pthread_key_used_before_creation) {
+#if defined(__BIONIC__)
+ // See http://b/19625804. The bug is about a static/global pthread key being used before creation.
+ // So here tests if the static/global default value 0 can be detected as invalid key.
+ static pthread_key_t key;
+ ASSERT_EQ(nullptr, pthread_getspecific(key));
+ ASSERT_EQ(EINVAL, pthread_setspecific(key, nullptr));
+ ASSERT_EQ(EINVAL, pthread_key_delete(key));
+#else
+ GTEST_LOG_(INFO) << "This test tests bionic pthread key implementation detail.\n";
+#endif
+}
+
static void* IdFn(void* arg) {
return arg;
}