Dmitriy Ivanov | 6b56691 | 2014-04-29 08:41:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <gtest/gtest.h> |
| 18 | |
| 19 | #include <dlfcn.h> |
| 20 | #include <libgen.h> |
| 21 | #include <limits.h> |
| 22 | #include <stdio.h> |
| 23 | #include <stdint.h> |
| 24 | |
| 25 | #include <string> |
| 26 | |
| 27 | TEST(atexit, combined_test) { |
| 28 | std::string atexit_call_sequence; |
| 29 | bool valid_this_in_static_dtor = false; |
| 30 | void* handle = dlopen("libtest_atexit.so", RTLD_NOW); |
| 31 | ASSERT_TRUE(handle != NULL); |
| 32 | |
| 33 | void* sym = dlsym(handle, "register_atexit"); |
| 34 | ASSERT_TRUE(sym != NULL); |
| 35 | reinterpret_cast<void (*)(std::string*, bool*)>(sym)(&atexit_call_sequence, &valid_this_in_static_dtor); |
| 36 | |
| 37 | ASSERT_EQ(0, dlclose(handle)); |
| 38 | // this test verifies atexit call from atexit handler. as well as the order of calls |
| 39 | ASSERT_EQ("Humpty Dumpty sat on a wall", atexit_call_sequence); |
| 40 | ASSERT_TRUE(valid_this_in_static_dtor); |
| 41 | } |
| 42 | |
| 43 | // TODO: test for static dtor calls from from exit(.) -> __cxa_finalize(NULL) |
| 44 | |