Christopher Ferris | 50d81ac | 2018-06-29 16:05:35 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | #ifndef _LIBBACKTRACE_BACKTRACE_TEST_H |
| 18 | #define _LIBBACKTRACE_BACKTRACE_TEST_H |
| 19 | |
| 20 | #include <dlfcn.h> |
| 21 | |
| 22 | #include <gtest/gtest.h> |
| 23 | |
| 24 | class BacktraceTest : public ::testing::Test { |
| 25 | protected: |
| 26 | static void SetUpTestCase() { |
| 27 | dl_handle_ = dlopen("libbacktrace_test.so", RTLD_NOW | RTLD_LOCAL); |
| 28 | |
| 29 | test_level_one_ = reinterpret_cast<int (*)(int, int, int, int, void (*)(void*), void*)>( |
| 30 | dlsym(dl_handle_, "test_level_one")); |
| 31 | |
| 32 | test_level_two_ = reinterpret_cast<int (*)(int, int, int, int, void (*)(void*), void*)>( |
| 33 | dlsym(dl_handle_, "test_level_two")); |
| 34 | |
| 35 | test_level_three_ = reinterpret_cast<int (*)(int, int, int, int, void (*)(void*), void*)>( |
| 36 | dlsym(dl_handle_, "test_level_three")); |
| 37 | |
| 38 | test_level_four_ = reinterpret_cast<int (*)(int, int, int, int, void (*)(void*), void*)>( |
| 39 | dlsym(dl_handle_, "test_level_four")); |
| 40 | |
| 41 | test_recursive_call_ = reinterpret_cast<int (*)(int, void (*)(void*), void*)>( |
| 42 | dlsym(dl_handle_, "test_recursive_call")); |
| 43 | |
| 44 | test_get_context_and_wait_ = reinterpret_cast<void (*)(void*, volatile int*)>( |
| 45 | dlsym(dl_handle_, "test_get_context_and_wait")); |
| 46 | |
| 47 | test_signal_action_ = |
| 48 | reinterpret_cast<void (*)(int, siginfo_t*, void*)>(dlsym(dl_handle_, "test_signal_action")); |
| 49 | |
| 50 | test_signal_handler_ = |
| 51 | reinterpret_cast<void (*)(int)>(dlsym(dl_handle_, "test_signal_handler")); |
| 52 | } |
| 53 | |
| 54 | void SetUp() override { |
| 55 | ASSERT_TRUE(dl_handle_ != nullptr); |
| 56 | ASSERT_TRUE(test_level_one_ != nullptr); |
| 57 | ASSERT_TRUE(test_level_two_ != nullptr); |
| 58 | ASSERT_TRUE(test_level_three_ != nullptr); |
| 59 | ASSERT_TRUE(test_level_four_ != nullptr); |
| 60 | ASSERT_TRUE(test_recursive_call_ != nullptr); |
| 61 | ASSERT_TRUE(test_get_context_and_wait_ != nullptr); |
| 62 | ASSERT_TRUE(test_signal_action_ != nullptr); |
| 63 | ASSERT_TRUE(test_signal_handler_ != nullptr); |
| 64 | } |
| 65 | |
| 66 | public: |
| 67 | static void* dl_handle_; |
| 68 | static int (*test_level_one_)(int, int, int, int, void (*)(void*), void*); |
| 69 | static int (*test_level_two_)(int, int, int, int, void (*)(void*), void*); |
| 70 | static int (*test_level_three_)(int, int, int, int, void (*)(void*), void*); |
| 71 | static int (*test_level_four_)(int, int, int, int, void (*)(void*), void*); |
| 72 | static int (*test_recursive_call_)(int, void (*)(void*), void*); |
| 73 | static void (*test_get_context_and_wait_)(void*, volatile int*); |
| 74 | static void (*test_signal_action_)(int, siginfo_t*, void*); |
| 75 | static void (*test_signal_handler_)(int); |
| 76 | }; |
| 77 | |
| 78 | #endif // _LIBBACKTRACE_BACKTRACE_TEST_H |