Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1767)

Unified Diff: base/logging_unittest.cc

Issue 1884023002: Implement Dump-on-DCHECK (via alternate DCHECK and DCHECK_OP macro implementations). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on cleanups Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/logging.cc ('k') | base/test/gtest_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/logging_unittest.cc
diff --git a/base/logging_unittest.cc b/base/logging_unittest.cc
index 16c89cf76fced5d9f95464e42d7455dbb4c2f78d..3638b4a68382aa20a67e22f05582585eb4abd5d6 100644
--- a/base/logging_unittest.cc
+++ b/base/logging_unittest.cc
@@ -4,6 +4,7 @@
#include "base/logging.h"
#include "base/compiler_specific.h"
+#include "base/debug/dump_without_crashing.h"
#include "base/macros.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -101,7 +102,7 @@ TEST_F(LoggingTest, BasicLogging) {
}
TEST_F(LoggingTest, LogIsOn) {
-#if defined(NDEBUG)
+#if defined(NDEBUG) || defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
const bool kDfatalIsFatal = false;
#else // defined(NDEBUG)
const bool kDfatalIsFatal = true;
@@ -380,6 +381,7 @@ TEST_F(LoggingTest, DcheckStreamsAreLazy) {
#endif
}
+#if !defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
void DcheckEmptyFunction1() {
// Provide a body so that Release builds do not cause the compiler to
// optimize DcheckEmptyFunction1 and DcheckEmptyFunction2 as a single
@@ -455,6 +457,7 @@ TEST_F(LoggingTest, Dcheck) {
DCHECK_EQ(mp2, &MemberFunctions::MemberFunction1);
EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, g_log_sink_call_count);
}
+#endif // !defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
TEST_F(LoggingTest, DcheckReleaseBehavior) {
int some_variable = 1;
@@ -489,6 +492,32 @@ TEST_F(LoggingTest, CheckEqStatements) {
CHECK_EQ(false, true); // Unreached.
}
+#if defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
+namespace {
+
+int g_fake_dump_without_crashing_count = 0;
+void FakeDumpWithoutCrashing() {
+ g_fake_dump_without_crashing_count++;
+}
+
+} // namespace
+
+TEST_F(LoggingTest, DCheckIsDumpWithoutCrash) {
+ // Replace the dump-without-crashing function, to test.
+ base::debug::SetDumpWithoutCrashingFunction(&FakeDumpWithoutCrashing);
+
+ // Invoke DCHECK(false) twice, and verify that only one dump call is made.
+ DCHECK(false);
+ EXPECT_EQ(1, g_fake_dump_without_crashing_count);
+ DCHECK(false);
+ EXPECT_EQ(1, g_fake_dump_without_crashing_count);
+
+ EXPECT_EQ(LOG_ERROR, LOG_DFATAL);
+
+ base::debug::SetDumpWithoutCrashingFunction(nullptr);
+}
+#endif // defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
+
// Test that defining an operator<< for a type in a namespace doesn't prevent
// other code in that namespace from calling the operator<<(ostream, wstring)
// defined by logging.h. This can fail if operator<<(ostream, wstring) can't be
« no previous file with comments | « base/logging.cc ('k') | base/test/gtest_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698