From 4571f31bd49e4951c9f1e0ff642c74fd79fe740a Mon Sep 17 00:00:00 2001 From: Dmitriy Ivanov Date: Fri, 15 Aug 2014 14:22:07 -0700 Subject: 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 --- tests/atexit_test.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'tests/atexit_test.cpp') 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 -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(dlsym(handle, "get_cxx_ctor_called")); + get_attr_ctor_called = reinterpret_cast(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(sym)(&atexit_call_sequence, &valid_this_in_static_dtor); + ASSERT_TRUE(sym != nullptr); + reinterpret_cast(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"); -- cgit v1.2.3