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 #pragma once 18 19 #include <signal.h> 20 21 #include <gtest/gtest.h> 22 23 #if !defined(__BIONIC__) 24 #define sigaction64 sigaction 25 #endif 26 27 // Disables debuggerd stack traces to speed up death tests and make them less 28 // noisy in logcat. 29 // 30 // Use `using my_DeathTest = SilentDeathTest;` instead of inheriting from 31 // testing::Test yourself. 32 class SilentDeathTest : public testing::Test { 33 protected: SetUp()34 virtual void SetUp() { 35 // Suppress debuggerd stack traces. Too slow. 36 for (int signo : {SIGABRT, SIGBUS, SIGSEGV, SIGSYS}) { 37 struct sigaction64 action = {.sa_handler = SIG_DFL}; 38 sigaction64(signo, &action, &previous_); 39 } 40 } 41 TearDown()42 virtual void TearDown() { 43 for (int signo : {SIGABRT, SIGBUS, SIGSEGV, SIGSYS}) { 44 sigaction64(signo, &previous_, nullptr); 45 } 46 } 47 48 private: 49 struct sigaction64 previous_; 50 }; 51