1 //===-- flang/unittests/Runtime/CrashHandlerFixture.cpp ---------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 #include "CrashHandlerFixture.h"
9 #include "../../runtime/terminator.h"
13 // Replaces Fortran runtime's crash handler so we can verify the crash message
14 [[noreturn
]] static void CatchCrash(
15 const char *sourceFile
, int sourceLine
, const char *message
, va_list &ap
) {
17 std::vsnprintf(buffer
, sizeof buffer
, message
, ap
);
21 << ::testing::UnitTest::GetInstance()->current_test_info()->name()
22 << " crashed in file "
23 << (sourceFile
? sourceFile
: "unknown source file") << '(' << sourceLine
24 << "): " << buffer
<< '\n';
25 std::exit(EXIT_FAILURE
);
28 // Register the crash handler above when creating each unit test in this suite
29 void CrashHandlerFixture::SetUp() {
30 static bool isCrashHanlderRegistered
{false};
32 if (!isCrashHanlderRegistered
) {
33 Fortran::runtime::Terminator::RegisterCrashHandler(CatchCrash
);
36 isCrashHanlderRegistered
= true;