BionicDeathTest.h revision 3e235911c9cf5062adbb73efb53fe5ed712d7c53
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
20#include <signal.h>
21
22#include <gtest/gtest.h>
23
24#if !defined(__BIONIC__)
25#define sigaction64 sigaction
26#endif
27
28class BionicDeathTest : public testing::Test {
29 protected:
30  virtual void SetUp() {
31    // Suppress debuggerd stack traces. Too slow.
32    for (int signo : { SIGABRT, SIGBUS, SIGSEGV, SIGSYS }) {
33      struct sigaction64 action = { .sa_handler = SIG_DFL };
34      sigaction64(signo, &action, &previous_);
35    }
36  }
37
38  virtual void TearDown() {
39    for (int signo : { SIGABRT, SIGBUS, SIGSEGV, SIGSYS }) {
40      sigaction64(signo, &previous_, nullptr);
41    }
42  }
43
44 private:
45  struct sigaction64 previous_;
46};
47
48#endif // BIONIC_TESTS_BIONIC_DEATH_TEST_H_
49