Yabin Cui | 9df7040 | 2014-11-05 18:01:01 -0800 | [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 | #ifndef BIONIC_TESTS_BIONIC_DEATH_TEST_H_ |
| 18 | #define BIONIC_TESTS_BIONIC_DEATH_TEST_H_ |
| 19 | |
Josh Gao | 084f6ec | 2017-10-12 13:32:45 -0700 | [diff] [blame^] | 20 | #include <signal.h> |
Yabin Cui | 9df7040 | 2014-11-05 18:01:01 -0800 | [diff] [blame] | 21 | |
Josh Gao | 084f6ec | 2017-10-12 13:32:45 -0700 | [diff] [blame^] | 22 | #include <gtest/gtest.h> |
Yabin Cui | 9df7040 | 2014-11-05 18:01:01 -0800 | [diff] [blame] | 23 | |
| 24 | class BionicDeathTest : public testing::Test { |
| 25 | protected: |
| 26 | virtual void SetUp() { |
| 27 | // Suppress debuggerd stack traces. Too slow. |
Josh Gao | 084f6ec | 2017-10-12 13:32:45 -0700 | [diff] [blame^] | 28 | for (int signo : { SIGABRT, SIGBUS, SIGSEGV, SIGSYS }) { |
| 29 | struct sigaction action = {}; |
| 30 | action.sa_handler = SIG_DFL; |
| 31 | sigaction(signo, &action, &previous_); |
| 32 | } |
Yabin Cui | 9df7040 | 2014-11-05 18:01:01 -0800 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | virtual void TearDown() { |
Josh Gao | 084f6ec | 2017-10-12 13:32:45 -0700 | [diff] [blame^] | 36 | for (int signo : { SIGABRT, SIGBUS, SIGSEGV, SIGSYS }) { |
| 37 | sigaction(signo, &previous_, nullptr); |
| 38 | } |
Yabin Cui | 9df7040 | 2014-11-05 18:01:01 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | private: |
Josh Gao | 084f6ec | 2017-10-12 13:32:45 -0700 | [diff] [blame^] | 42 | struct sigaction previous_; |
Yabin Cui | 9df7040 | 2014-11-05 18:01:01 -0800 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | #endif // BIONIC_TESTS_BIONIC_DEATH_TEST_H_ |