summaryrefslogtreecommitdiff
path: root/src/base/gtest
diff options
context:
space:
mode:
authorBobby R. Bruce <bbruce@ucdavis.edu>2020-01-03 13:01:13 -0800
committerBobby R. Bruce <bbruce@ucdavis.edu>2020-01-09 22:02:43 +0000
commitb97111fc2333672741cf578ee15c45ba3924b5cb (patch)
treed8909c6e716aaab2dcde7626626b61cbda0e08e8 /src/base/gtest
parent02a1f8b28dda896e5400b8667008ad716ada3a52 (diff)
downloadgem5-b97111fc2333672741cf578ee15c45ba3924b5cb.tar.xz
tests: Updated gtest/logging.cc to print log rather than fail.
Previously the `GTestExitLogger.log` function utilized GTest's `ADD_FAILURE_AT` macro. This meant, whenever `GTestExitLogger.log` were called, the calling test would be fail. This is problematic when trying to test code we expect to fail (i.e., when testing the error handling code is working correctly). Therefore, the `log` function now writes to stderr. The `GTestExitLogger` class is used by the `panic` and `fatal` loggers when running GTests. Instead of callnig `exit(1)` they throw a GTest exception, which can be captured in a test using `EXPECT_ANY_THROW(expection_thrower())`. Catching and verifying error logs can be done via: ``` testing::internal::CaptureStderr(); /* * "exception_thrower()" is a method we'd expect to call `fatal` or * `panic`, and therefore exit the simulation with a non-zero exit * code. When running via GTest, an exception is thrown instead. */ EXPECT_ANY_THROW(exception_thrower()); EXPECT_EQ("<error message>", testing::internal::GetCapturedStderr())); ``` Change-Id: I84a5f86bc573668d3dd5b40f626b43108dddb8e9 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/23983 Reviewed-by: Jason Lowe-Power <jason@lowepower.com> Maintainer: Jason Lowe-Power <jason@lowepower.com> Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'src/base/gtest')
-rw-r--r--src/base/gtest/logging.cc2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/base/gtest/logging.cc b/src/base/gtest/logging.cc
index 92d260298..d9cb9eb95 100644
--- a/src/base/gtest/logging.cc
+++ b/src/base/gtest/logging.cc
@@ -61,7 +61,7 @@ class GTestExitLogger : public Logger
void
log(const Loc &loc, std::string s) override
{
- ADD_FAILURE_AT(loc.file, loc.line) << s;
+ std::cerr << loc.file << ":" << loc.line << ": " << s;
}
// Throw an exception to escape down to the gtest framework.
void exit() override { throw GTestException(); }