19df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui/* 29df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui * Copyright (C) 2014 The Android Open Source Project 39df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui * 49df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui * Licensed under the Apache License, Version 2.0 (the "License"); 59df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui * you may not use this file except in compliance with the License. 69df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui * You may obtain a copy of the License at 79df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui * 89df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui * http://www.apache.org/licenses/LICENSE-2.0 99df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui * 109df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui * Unless required by applicable law or agreed to in writing, software 119df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui * distributed under the License is distributed on an "AS IS" BASIS, 129df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui * See the License for the specific language governing permissions and 149df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui * limitations under the License. 159df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui */ 169df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui 179df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui#ifndef BIONIC_TESTS_BIONIC_DEATH_TEST_H_ 189df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui#define BIONIC_TESTS_BIONIC_DEATH_TEST_H_ 199df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui 20084f6ec9af0c054f0386a13f62daf0790d6244aeJosh Gao#include <signal.h> 219df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui 22084f6ec9af0c054f0386a13f62daf0790d6244aeJosh Gao#include <gtest/gtest.h> 239df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui 243e235911c9cf5062adbb73efb53fe5ed712d7c53Elliott Hughes#if !defined(__BIONIC__) 253e235911c9cf5062adbb73efb53fe5ed712d7c53Elliott Hughes#define sigaction64 sigaction 263e235911c9cf5062adbb73efb53fe5ed712d7c53Elliott Hughes#endif 273e235911c9cf5062adbb73efb53fe5ed712d7c53Elliott Hughes 289df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cuiclass BionicDeathTest : public testing::Test { 299df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui protected: 309df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui virtual void SetUp() { 319df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui // Suppress debuggerd stack traces. Too slow. 32084f6ec9af0c054f0386a13f62daf0790d6244aeJosh Gao for (int signo : { SIGABRT, SIGBUS, SIGSEGV, SIGSYS }) { 333e235911c9cf5062adbb73efb53fe5ed712d7c53Elliott Hughes struct sigaction64 action = { .sa_handler = SIG_DFL }; 343e235911c9cf5062adbb73efb53fe5ed712d7c53Elliott Hughes sigaction64(signo, &action, &previous_); 35084f6ec9af0c054f0386a13f62daf0790d6244aeJosh Gao } 369df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui } 379df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui 389df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui virtual void TearDown() { 39084f6ec9af0c054f0386a13f62daf0790d6244aeJosh Gao for (int signo : { SIGABRT, SIGBUS, SIGSEGV, SIGSYS }) { 403e235911c9cf5062adbb73efb53fe5ed712d7c53Elliott Hughes sigaction64(signo, &previous_, nullptr); 41084f6ec9af0c054f0386a13f62daf0790d6244aeJosh Gao } 429df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui } 439df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui 449df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui private: 453e235911c9cf5062adbb73efb53fe5ed712d7c53Elliott Hughes struct sigaction64 previous_; 469df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui}; 479df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui 489df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui#endif // BIONIC_TESTS_BIONIC_DEATH_TEST_H_ 49