diff options
author | Dmitriy Ivanov <dimitry@google.com> | 2014-08-15 14:22:07 -0700 |
---|---|---|
committer | Dmitriy Ivanov <dimitry@google.com> | 2014-08-15 14:22:07 -0700 |
commit | 4571f31bd49e4951c9f1e0ff642c74fd79fe740a (patch) | |
tree | 33ba9cc312e62586924c95eaadddb349a09df58f /tests/atexit_test.cpp | |
parent | 7d05f741e7885ad42f853b5fe2b1d31cdc756b5c (diff) | |
download | android_bionic-4571f31bd49e4951c9f1e0ff642c74fd79fe740a.tar.gz android_bionic-4571f31bd49e4951c9f1e0ff642c74fd79fe740a.tar.bz2 android_bionic-4571f31bd49e4951c9f1e0ff642c74fd79fe740a.zip |
Add atexit test for attributed c-tor/d-tor
1. Add test for __attribute__((constructor/destructor))
and static constructor
2. Compile C++ testlibs with -std=gnu++11
Change-Id: I67f9308144a0c638a51f111fcba8e1933fe0ba41
Diffstat (limited to 'tests/atexit_test.cpp')
-rw-r--r-- | tests/atexit_test.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/tests/atexit_test.cpp b/tests/atexit_test.cpp index e01220e1b..e92889d1c 100644 --- a/tests/atexit_test.cpp +++ b/tests/atexit_test.cpp @@ -24,20 +24,33 @@ #include <string> -TEST(atexit, dlclose) { +TEST(atexit, sofile) { std::string atexit_call_sequence; bool valid_this_in_static_dtor = false; + bool attr_dtor_called = false; + void* handle = dlopen("libtest_atexit.so", RTLD_NOW); - ASSERT_TRUE(handle != NULL); + ASSERT_TRUE(handle != nullptr); + + typedef int (*int_fn)(void); + int_fn get_cxx_ctor_called, get_attr_ctor_called; + get_cxx_ctor_called = reinterpret_cast<int_fn>(dlsym(handle, "get_cxx_ctor_called")); + get_attr_ctor_called = reinterpret_cast<int_fn>(dlsym(handle, "get_attr_ctor_called")); + ASSERT_TRUE(get_cxx_ctor_called != nullptr); + ASSERT_TRUE(get_attr_ctor_called != nullptr); + + ASSERT_EQ(1, get_cxx_ctor_called()); + ASSERT_EQ(1, get_attr_ctor_called()); void* sym = dlsym(handle, "register_atexit"); - ASSERT_TRUE(sym != NULL); - reinterpret_cast<void (*)(std::string*, bool*)>(sym)(&atexit_call_sequence, &valid_this_in_static_dtor); + ASSERT_TRUE(sym != nullptr); + reinterpret_cast<void (*)(std::string*, bool*, bool*)>(sym)(&atexit_call_sequence, &valid_this_in_static_dtor, &attr_dtor_called); ASSERT_EQ(0, dlclose(handle)); // this test verifies atexit call from atexit handler. as well as the order of calls ASSERT_EQ("Humpty Dumpty sat on a wall", atexit_call_sequence); ASSERT_TRUE(valid_this_in_static_dtor); + ASSERT_TRUE(attr_dtor_called); } class TestMainStaticDtorClass { @@ -57,7 +70,7 @@ class TestMainStaticDtorClass { static const TestMainStaticDtorClass* expected_this; }; -const TestMainStaticDtorClass* TestMainStaticDtorClass::expected_this = NULL; +const TestMainStaticDtorClass* TestMainStaticDtorClass::expected_this = nullptr; static void atexit_func5() { fprintf(stderr, "5"); |