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