25 #include "gtest/gtest.h" 34 #if GTEST_HAS_DEATH_TEST 37 using FailureSignalHandlerDeathTest = ::testing::TestWithParam<int>;
40 void InstallHandlerAndRaise(
int signo) {
45 TEST_P(FailureSignalHandlerDeathTest, AbslFailureSignal) {
46 const int signo = GetParam();
49 " received at time=");
51 EXPECT_EXIT(InstallHandlerAndRaise(signo), testing::KilledBySignal(signo),
55 EXPECT_DEATH(InstallHandlerAndRaise(signo), exit_regex);
61 void WriteToErrorFile(
const char*
msg) {
69 std::string GetTmpDir() {
71 static const char*
const kTmpEnvVars[] = {
"TEST_TMPDIR",
"TMPDIR",
"TEMP",
73 for (
const char*
const var : kTmpEnvVars) {
74 const char* tmp_dir = std::getenv(var);
75 if (tmp_dir !=
nullptr) {
85 void InstallHandlerWithWriteToFileAndRaise(
const char* file,
int signo) {
86 error_file = fopen(file,
"w");
94 TEST_P(FailureSignalHandlerDeathTest, AbslFatalSignalsWithWriterFn) {
95 const int signo = GetParam();
96 std::string tmp_dir = GetTmpDir();
97 std::string file =
absl::StrCat(tmp_dir,
"/signo_", signo);
101 " received at time=");
103 EXPECT_EXIT(InstallHandlerWithWriteToFileAndRaise(file.c_str(), signo),
104 testing::KilledBySignal(signo), exit_regex);
107 EXPECT_DEATH(InstallHandlerWithWriteToFileAndRaise(file.c_str(), signo),
112 std::fstream error_output(file);
113 ASSERT_TRUE(error_output.is_open()) << file;
114 std::string error_line;
115 std::getline(error_output, error_line);
123 std::getline(error_output, error_line);
128 constexpr
int kFailureSignals[] = {
129 SIGSEGV, SIGILL, SIGFPE, SIGABRT, SIGTERM,
135 std::string SignalParamToString(const ::testing::TestParamInfo<int>& info) {
138 if (result.empty()) {
144 INSTANTIATE_TEST_SUITE_P(AbslDeathTest, FailureSignalHandlerDeathTest,
145 ::testing::ValuesIn(kFailureSignals),
146 SignalParamToString);
148 #endif // GTEST_HAS_DEATH_TEST 152 int main(
int argc,
char** argv) {
154 testing::InitGoogleTest(&argc, argv);
155 return RUN_ALL_TESTS();
const char * FailureSignalToString(int signo)
void InitializeSymbolizer(const char *argv0)
void(* writerfn)(const char *)
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
int main(int argc, char **argv)
#define ABSL_RAW_CHECK(condition, message)
bool StackTraceWorksForTest()
bool StartsWith(absl::string_view text, absl::string_view prefix)
void InstallFailureSignalHandler(const FailureSignalHandlerOptions &options)