Add missing test for atexit test suite.
Change-Id: I3d14d7df1da53ccef534c106633593551ab6a7cb
This commit is contained in:
parent
35cff760df
commit
6396da98cb
3 changed files with 70 additions and 11 deletions
|
@ -225,7 +225,7 @@ build_target := SHARED_LIBRARY
|
|||
include $(LOCAL_PATH)/Android.build.mk
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# This library used by atexit tests
|
||||
# Library used by atexit tests
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
libtest_atexit_src_files := \
|
||||
|
@ -248,6 +248,9 @@ bionic-unit-tests_src_files := \
|
|||
dlext_test.cpp \
|
||||
dlfcn_test.cpp \
|
||||
|
||||
bionic-unit-tests_cppflags := \
|
||||
$(test_cppflags)
|
||||
|
||||
bionic-unit-tests_ldflags := \
|
||||
-Wl,--export-dynamic \
|
||||
-Wl,-u,DlSymTestFunction \
|
||||
|
@ -304,6 +307,9 @@ bionic-unit-tests-glibc_whole_static_libraries := \
|
|||
bionic-unit-tests-glibc_ldlibs := \
|
||||
-lrt -ldl \
|
||||
|
||||
bionic-unit-tests-glibc_cppflags := \
|
||||
$(test_cppflags)
|
||||
|
||||
module := bionic-unit-tests-glibc
|
||||
module_tag := optional
|
||||
build_type := host
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
TEST(atexit, combined_test) {
|
||||
TEST(atexit, dlclose) {
|
||||
std::string atexit_call_sequence;
|
||||
bool valid_this_in_static_dtor = false;
|
||||
void* handle = dlopen("libtest_atexit.so", RTLD_NOW);
|
||||
|
@ -40,5 +40,57 @@ TEST(atexit, combined_test) {
|
|||
ASSERT_TRUE(valid_this_in_static_dtor);
|
||||
}
|
||||
|
||||
// TODO: test for static dtor calls from from exit(.) -> __cxa_finalize(NULL)
|
||||
class TestMainStaticDtorClass {
|
||||
public:
|
||||
TestMainStaticDtorClass() {
|
||||
expected_this = this;
|
||||
}
|
||||
|
||||
~TestMainStaticDtorClass() {
|
||||
if (this != expected_this) {
|
||||
fprintf(stderr, "\nerror: static d-tor called with incorrect this pointer: %p, expected: %p\n", this, expected_this);
|
||||
} else {
|
||||
fprintf(stderr, "6");
|
||||
}
|
||||
}
|
||||
private:
|
||||
static const TestMainStaticDtorClass* expected_this;
|
||||
};
|
||||
|
||||
const TestMainStaticDtorClass* TestMainStaticDtorClass::expected_this = NULL;
|
||||
|
||||
static void atexit_func5() {
|
||||
fprintf(stderr, "5");
|
||||
}
|
||||
|
||||
static void atexit_func4() {
|
||||
fprintf(stderr, "4");
|
||||
}
|
||||
|
||||
static void atexit_func3() {
|
||||
fprintf(stderr, "3");
|
||||
atexit(atexit_func4);
|
||||
}
|
||||
|
||||
static void atexit_func2() {
|
||||
fprintf(stderr, "2");
|
||||
}
|
||||
|
||||
static void atexit_func1() {
|
||||
fprintf(stderr, "1");
|
||||
}
|
||||
|
||||
static void atexit_main() {
|
||||
// This should result in "123456" output to stderr
|
||||
static TestMainStaticDtorClass static_obj;
|
||||
atexit(atexit_func5);
|
||||
atexit(atexit_func3);
|
||||
atexit(atexit_func2);
|
||||
atexit(atexit_func1);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
TEST(atexit, exit) {
|
||||
ASSERT_EXIT(atexit_main(), testing::ExitedWithCode(0), "123456");
|
||||
}
|
||||
|
||||
|
|
|
@ -22,19 +22,20 @@
|
|||
static std::string* atexit_sequence = NULL;
|
||||
static bool* atexit_valid_this_in_static_dtor = NULL;
|
||||
|
||||
class AtExitStaticClass;
|
||||
|
||||
static const AtExitStaticClass* valid_this = NULL;
|
||||
|
||||
static class AtExitStaticClass {
|
||||
public:
|
||||
AtExitStaticClass() { valid_this = this; }
|
||||
public:
|
||||
AtExitStaticClass() { expected_this = this; }
|
||||
~AtExitStaticClass() {
|
||||
if (atexit_valid_this_in_static_dtor) {
|
||||
*atexit_valid_this_in_static_dtor = (valid_this == this);
|
||||
*atexit_valid_this_in_static_dtor = (expected_this == this);
|
||||
}
|
||||
}
|
||||
} staticObj;
|
||||
private:
|
||||
static const AtExitStaticClass* expected_this;
|
||||
|
||||
} static_obj;
|
||||
|
||||
const AtExitStaticClass* AtExitStaticClass::expected_this = NULL;
|
||||
|
||||
// 4
|
||||
static void atexit_handler_from_atexit_from_atexit2() {
|
||||
|
|
Loading…
Reference in a new issue