blob: 6826ab72cd0c42c012b18ea7269a4234c77aff44 [file] [log] [blame]
Yabin Cui9df70402014-11-05 18:01:01 -08001/*
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
Josh Gao084f6ec2017-10-12 13:32:45 -070020#include <signal.h>
Yabin Cui9df70402014-11-05 18:01:01 -080021
Josh Gao084f6ec2017-10-12 13:32:45 -070022#include <gtest/gtest.h>
Yabin Cui9df70402014-11-05 18:01:01 -080023
Elliott Hughes3e235912018-02-01 14:21:51 -080024#if !defined(__BIONIC__)
25#define sigaction64 sigaction
26#endif
27
Yabin Cui9df70402014-11-05 18:01:01 -080028class BionicDeathTest : public testing::Test {
29 protected:
30 virtual void SetUp() {
31 // Suppress debuggerd stack traces. Too slow.
Josh Gao084f6ec2017-10-12 13:32:45 -070032 for (int signo : { SIGABRT, SIGBUS, SIGSEGV, SIGSYS }) {
Elliott Hughes3e235912018-02-01 14:21:51 -080033 struct sigaction64 action = { .sa_handler = SIG_DFL };
34 sigaction64(signo, &action, &previous_);
Josh Gao084f6ec2017-10-12 13:32:45 -070035 }
Yabin Cui9df70402014-11-05 18:01:01 -080036 }
37
38 virtual void TearDown() {
Josh Gao084f6ec2017-10-12 13:32:45 -070039 for (int signo : { SIGABRT, SIGBUS, SIGSEGV, SIGSYS }) {
Elliott Hughes3e235912018-02-01 14:21:51 -080040 sigaction64(signo, &previous_, nullptr);
Josh Gao084f6ec2017-10-12 13:32:45 -070041 }
Yabin Cui9df70402014-11-05 18:01:01 -080042 }
43
44 private:
Elliott Hughes3e235912018-02-01 14:21:51 -080045 struct sigaction64 previous_;
Yabin Cui9df70402014-11-05 18:01:01 -080046};
47
48#endif // BIONIC_TESTS_BIONIC_DEATH_TEST_H_