BionicDeathTest.h revision 084f6ec9af0c054f0386a13f62daf0790d6244ae
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 249df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cuiclass BionicDeathTest : public testing::Test { 259df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui protected: 269df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui virtual void SetUp() { 279df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui // Suppress debuggerd stack traces. Too slow. 28084f6ec9af0c054f0386a13f62daf0790d6244aeJosh Gao for (int signo : { SIGABRT, SIGBUS, SIGSEGV, SIGSYS }) { 29084f6ec9af0c054f0386a13f62daf0790d6244aeJosh Gao struct sigaction action = {}; 30084f6ec9af0c054f0386a13f62daf0790d6244aeJosh Gao action.sa_handler = SIG_DFL; 31084f6ec9af0c054f0386a13f62daf0790d6244aeJosh Gao sigaction(signo, &action, &previous_); 32084f6ec9af0c054f0386a13f62daf0790d6244aeJosh Gao } 339df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui } 349df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui 359df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui virtual void TearDown() { 36084f6ec9af0c054f0386a13f62daf0790d6244aeJosh Gao for (int signo : { SIGABRT, SIGBUS, SIGSEGV, SIGSYS }) { 37084f6ec9af0c054f0386a13f62daf0790d6244aeJosh Gao sigaction(signo, &previous_, nullptr); 38084f6ec9af0c054f0386a13f62daf0790d6244aeJosh Gao } 399df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui } 409df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui 419df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui private: 42084f6ec9af0c054f0386a13f62daf0790d6244aeJosh Gao struct sigaction previous_; 439df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui}; 449df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui 459df70403d95f5cfe6824e38a9a6c35f9b9bbc76aYabin Cui#endif // BIONIC_TESTS_BIONIC_DEATH_TEST_H_ 46