Brandon Potter has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/23683 )
Change subject: base: change logger exit behavior
......................................................................
base: change logger exit behavior
Under the old behavior, googletest tests with failing
statements throw an empty exception and then abort.
The behavior causes a problem in death/exit tests caused
by fatal statements since the googletest interface
is designed to either catch an exception or die. The
googletest interface does not provide a method to catch
an exception and then die.
With the googletest interface, you'd end up with something
resembling the following:
statement which fails:
Obj obj_fail_in_constructor();
googletest:
ASSERT_ANY_THROW(Obj obj_fail_in_constructor());
ASSERT_EXIT(Obj obj_fail_in_constructor(), "");
The ASSERT_ANY_THROW does not work in isolation because the
constructor fails immediately after the exception is handled
by the API.
The ASSERT_EXIT does not work in isolation because the
exception surfaces immediately before the exit.
The changeset simplifies the logger's exit_helper method to
just directly call the stdlib exit instead of tunneling
into the googletest logger's exit method. It avoids the
empty exception being thrown.
The result allows ASSERT_EXIT to be called within googletest
death tests to handle gem5's fatal calls.
Change-Id: Ifdd1769e398feea3f9ff06b88037d26398b32ee1
---
M src/base/gtest/logging.cc
M src/base/logging.cc
M src/base/logging.hh
3 files changed, 2 insertions(+), 22 deletions(-)
diff --git a/src/base/gtest/logging.cc b/src/base/gtest/logging.cc
index 92d2602..3139d66 100644
--- a/src/base/gtest/logging.cc
+++ b/src/base/gtest/logging.cc
@@ -35,14 +35,6 @@
namespace {
-// This custom exception type will help prevent fatal exceptions from being
-// caught by other code in gem5 and let them escape to the gtest framework.
-// Unfortunately that results in a somewhat confusing message about an
unknown
-// exception being thrown after the panic/fatal message has been printed,
but
-// there will at least be some indication what went wrong.
-struct GTestException
-{};
-
class GTestLogger : public Logger
{
public:
@@ -63,8 +55,6 @@
{
ADD_FAILURE_AT(loc.file, loc.line) << s;
}
- // Throw an exception to escape down to the gtest framework.
- void exit() override { throw GTestException(); }
};
GTestExitLogger panicLogger("panic: ");
diff --git a/src/base/logging.cc b/src/base/logging.cc
index adc3deb..6205a95 100644
--- a/src/base/logging.cc
+++ b/src/base/logging.cc
@@ -73,17 +73,8 @@
}
};
-class FatalLogger : public ExitLogger
-{
- public:
- using ExitLogger::ExitLogger;
-
- protected:
- void exit() override { ::exit(1); }
-};
-
ExitLogger panicLogger("panic: ");
-FatalLogger fatalLogger("fatal: ");
+ExitLogger fatalLogger("fatal: ");
NormalLogger warnLogger("warn: ");
NormalLogger infoLogger("info: ");
NormalLogger hackLogger("hack: ");
diff --git a/src/base/logging.hh b/src/base/logging.hh
index 7040037..f3f413b 100644
--- a/src/base/logging.hh
+++ b/src/base/logging.hh
@@ -121,13 +121,12 @@
// This helper is necessary since noreturn isn't inherited by virtual
// functions, and gcc will get mad if a function calls panic and then
// doesn't return.
- void exit_helper() M5_ATTR_NORETURN { exit(); ::abort(); }
+ void exit_helper() M5_ATTR_NORETURN { exit(1); }
protected:
bool enabled;
virtual void log(const Loc &loc, std::string s) = 0;
- virtual void exit() { /* Fall through to the abort in exit_helper. */ }
const char *prefix;
};
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/23683
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Ifdd1769e398feea3f9ff06b88037d26398b32ee1
Gerrit-Change-Number: 23683
Gerrit-PatchSet: 1
Gerrit-Owner: Brandon Potter <brandon.pot...@amd.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev