Commit 7013e5f9 authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

Reland "Reland "Make SECURITY_DCHECK play with Albatross.""

This is a reland of e9d46063
Original change's description:
> Reland "Make SECURITY_DCHECK play with Albatross."
> 
> This is a reland of 06d64c00
> Original change's description:
> > Make SECURITY_DCHECK play with Albatross.
> > 
> > In Albatross builds, DCHECKs can be compiled in, but non-fatal. See
> > https://docs.google.com/a/chromium.org/document/d/1QY4IbbJ8X6G-6-cMheEkP_mT7ZNPCuUJIW2sr_mEiH4
> > 
> > Bug: 596231
> > Change-Id: I84198f1d3f4122ac7a5bd8a90ed5ea96286b9022
> > Reviewed-on: https://chromium-review.googlesource.com/685498
> > Reviewed-by: Wez <wez@chromium.org>
> > Reviewed-by: Jochen Eisinger <jochen@chromium.org>
> > Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#504638}
> 
> Bug: 596231
> Change-Id: I2c1223ba264dbdb06e814b92b84adfe9c3c619b7
> Reviewed-on: https://chromium-review.googlesource.com/687874
> Reviewed-by: Gabriel Charette <gab@chromium.org>
> Reviewed-by: Jochen Eisinger <jochen@chromium.org>
> Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#505025}

TBR: jochen@chromium.org
Bug: 596231
Change-Id: I942bdcfac1b48a666095c8b7b76db6b3ae4f6fe7
Reviewed-on: https://chromium-review.googlesource.com/690814
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarSigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505412}
parent 126dc76b
...@@ -823,8 +823,9 @@ const LogSeverity LOG_DCHECK = LOG_FATAL; ...@@ -823,8 +823,9 @@ const LogSeverity LOG_DCHECK = LOG_FATAL;
#else // DCHECK_IS_ON() #else // DCHECK_IS_ON()
// This is a dummy value, since the DCHECK implementation is a no-op. // There may be users of LOG_DCHECK that are enabled independently
const LogSeverity LOG_DCHECK = LOG_INFO; // of DCHECK_IS_ON(), so default to FATAL logging for those.
const LogSeverity LOG_DCHECK = LOG_FATAL;
#endif // DCHECK_IS_ON() #endif // DCHECK_IS_ON()
......
...@@ -401,7 +401,28 @@ void DcheckEmptyFunction1() { ...@@ -401,7 +401,28 @@ void DcheckEmptyFunction1() {
} }
void DcheckEmptyFunction2() {} void DcheckEmptyFunction2() {}
#if DCHECK_IS_ON() && defined(SYZYASAN)
class ScopedDcheckSeverity {
public:
ScopedDcheckSeverity(LogSeverity new_severity) : old_severity_(LOG_DCHECK) {
LOG_DCHECK = new_severity;
}
~ScopedDcheckSeverity() { LOG_DCHECK = old_severity_; }
private:
LogSeverity old_severity_;
};
#endif // DCHECK_IS_ON() && defined(SYZYASAN)
TEST_F(LoggingTest, Dcheck) { TEST_F(LoggingTest, Dcheck) {
#if DCHECK_IS_ON() && defined(SYZYASAN)
// When DCHECKs are enabled in SyzyASAN builds, LOG_DCHECK is mutable but
// defaults to non-fatal. Set it to LOG_FATAL to get the expected behavior
// from the rest of this test.
ScopedDcheckSeverity dcheck_severity(LOG_FATAL);
#endif // DCHECK_IS_ON() && defined(SYZYASAN)
#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
// Release build. // Release build.
EXPECT_FALSE(DCHECK_IS_ON()); EXPECT_FALSE(DCHECK_IS_ON());
...@@ -418,13 +439,16 @@ TEST_F(LoggingTest, Dcheck) { ...@@ -418,13 +439,16 @@ TEST_F(LoggingTest, Dcheck) {
EXPECT_TRUE(DLOG_IS_ON(DCHECK)); EXPECT_TRUE(DLOG_IS_ON(DCHECK));
#endif #endif
// DCHECKs are fatal iff they're compiled in DCHECK_IS_ON() and the DCHECK
// log level is set to fatal.
const bool dchecks_are_fatal = DCHECK_IS_ON() && LOG_DCHECK == LOG_FATAL;
EXPECT_EQ(0, g_log_sink_call_count); EXPECT_EQ(0, g_log_sink_call_count);
DCHECK(false); DCHECK(false);
EXPECT_EQ(LOG_DCHECK == LOG_FATAL ? 1 : 0, g_log_sink_call_count); EXPECT_EQ(dchecks_are_fatal ? 1 : 0, g_log_sink_call_count);
DPCHECK(false); DPCHECK(false);
EXPECT_EQ(LOG_DCHECK == LOG_FATAL ? 2 : 0, g_log_sink_call_count); EXPECT_EQ(dchecks_are_fatal ? 2 : 0, g_log_sink_call_count);
DCHECK_EQ(0, 1); DCHECK_EQ(0, 1);
EXPECT_EQ(LOG_DCHECK == LOG_FATAL ? 3 : 0, g_log_sink_call_count); EXPECT_EQ(dchecks_are_fatal ? 3 : 0, g_log_sink_call_count);
// Test DCHECK on std::nullptr_t // Test DCHECK on std::nullptr_t
g_log_sink_call_count = 0; g_log_sink_call_count = 0;
...@@ -441,7 +465,7 @@ TEST_F(LoggingTest, Dcheck) { ...@@ -441,7 +465,7 @@ TEST_F(LoggingTest, Dcheck) {
DCHECK_EQ(Animal::DOG, Animal::DOG); DCHECK_EQ(Animal::DOG, Animal::DOG);
EXPECT_EQ(0, g_log_sink_call_count); EXPECT_EQ(0, g_log_sink_call_count);
DCHECK_EQ(Animal::DOG, Animal::CAT); DCHECK_EQ(Animal::DOG, Animal::CAT);
EXPECT_EQ(LOG_DCHECK == LOG_FATAL ? 1 : 0, g_log_sink_call_count); EXPECT_EQ(dchecks_are_fatal ? 1 : 0, g_log_sink_call_count);
// Test DCHECK on functions and function pointers. // Test DCHECK on functions and function pointers.
g_log_sink_call_count = 0; g_log_sink_call_count = 0;
...@@ -464,9 +488,9 @@ TEST_F(LoggingTest, Dcheck) { ...@@ -464,9 +488,9 @@ TEST_F(LoggingTest, Dcheck) {
DCHECK_EQ(mp2, &MemberFunctions::MemberFunction2); DCHECK_EQ(mp2, &MemberFunctions::MemberFunction2);
EXPECT_EQ(0, g_log_sink_call_count); EXPECT_EQ(0, g_log_sink_call_count);
DCHECK_EQ(fp1, fp2); DCHECK_EQ(fp1, fp2);
EXPECT_EQ(LOG_DCHECK == LOG_FATAL ? 1 : 0, g_log_sink_call_count); EXPECT_EQ(dchecks_are_fatal ? 1 : 0, g_log_sink_call_count);
DCHECK_EQ(mp2, &MemberFunctions::MemberFunction1); DCHECK_EQ(mp2, &MemberFunctions::MemberFunction1);
EXPECT_EQ(LOG_DCHECK == LOG_FATAL ? 2 : 0, g_log_sink_call_count); EXPECT_EQ(dchecks_are_fatal ? 2 : 0, g_log_sink_call_count);
} }
TEST_F(LoggingTest, DcheckReleaseBehavior) { TEST_F(LoggingTest, DcheckReleaseBehavior) {
......
...@@ -61,7 +61,7 @@ WTF_EXPORT PRINTF_FORMAT(1, 2) // NOLINT ...@@ -61,7 +61,7 @@ WTF_EXPORT PRINTF_FORMAT(1, 2) // NOLINT
// https://bugs.chromium.org/p/chromium/issues/entry?template=Security%20Bug // https://bugs.chromium.org/p/chromium/issues/entry?template=Security%20Bug
#if ENABLE_SECURITY_ASSERT #if ENABLE_SECURITY_ASSERT
#define SECURITY_DCHECK(condition) \ #define SECURITY_DCHECK(condition) \
LOG_IF(FATAL, !(condition)) << "Security DCHECK failed: " #condition ". " LOG_IF(DCHECK, !(condition)) << "Security DCHECK failed: " #condition ". "
// A SECURITY_CHECK failure is actually not vulnerable. // A SECURITY_CHECK failure is actually not vulnerable.
#define SECURITY_CHECK(condition) \ #define SECURITY_CHECK(condition) \
LOG_IF(FATAL, !(condition)) << "Security CHECK failed: " #condition ". " LOG_IF(FATAL, !(condition)) << "Security CHECK failed: " #condition ". "
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment