diff options
author | Dmitriy Ivanov <dimitry@google.com> | 2015-03-26 11:07:04 -0700 |
---|---|---|
committer | Dmitriy Ivanov <dimitry@google.com> | 2015-03-27 12:05:36 -0700 |
commit | 947adedebc480917b8490bc16e8b2d82b441095a (patch) | |
tree | 7750e1e29c848a611e7723bdc20d1aa054d0b461 /tests/__cxa_thread_atexit_test.cpp | |
parent | cfd794a96d0c4f1d97e54b701b408dafdb514d17 (diff) | |
download | bionic-947adedebc480917b8490bc16e8b2d82b441095a.tar.gz |
Add test for thread_local keyword.
For gcc only for the time being.
Bug: 19800080
Bug: 16696563
Change-Id: Ifaa59a131ca2d9030554cee7ce631dcb1d081938
Diffstat (limited to 'tests/__cxa_thread_atexit_test.cpp')
-rw-r--r-- | tests/__cxa_thread_atexit_test.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/__cxa_thread_atexit_test.cpp b/tests/__cxa_thread_atexit_test.cpp index 017731498..fea60b719 100644 --- a/tests/__cxa_thread_atexit_test.cpp +++ b/tests/__cxa_thread_atexit_test.cpp @@ -20,6 +20,36 @@ #include <string> +static std::string class_with_dtor_output; + +class ClassWithDtor { + public: + void set_message(const std::string& msg) { + message = msg; + } + + ~ClassWithDtor() { + class_with_dtor_output += message; + } + private: + std::string message; +}; + +thread_local ClassWithDtor class_with_dtor; + +static void* thread_nop(void* arg) { + class_with_dtor.set_message(*static_cast<std::string*>(arg)); + return nullptr; +} + +TEST(thread_local, smoke) { + std::string msg("dtor called."); + pthread_t t; + ASSERT_EQ(0, pthread_create(&t, nullptr, thread_nop, &msg)); + ASSERT_EQ(0, pthread_join(t, nullptr)); + ASSERT_EQ("dtor called.", class_with_dtor_output); +} + extern "C" int __cxa_thread_atexit_impl(void (*fn)(void*), void* arg, void* dso_handle); static void thread_atexit_fn1(void* arg) { |