diff --git a/source/extensions/quic_listeners/quiche/platform/quic_logging_impl.h b/source/extensions/quic_listeners/quiche/platform/quic_logging_impl.h index 813a9bb0f9631..b71dba7b39259 100644 --- a/source/extensions/quic_listeners/quiche/platform/quic_logging_impl.h +++ b/source/extensions/quic_listeners/quiche/platform/quic_logging_impl.h @@ -17,8 +17,6 @@ #include "absl/base/optimization.h" #include "absl/synchronization/mutex.h" -// TODO(wub): Add CHECK/DCHECK and variants, which are not explicitly exposed by quic_logging.h. - // If |condition| is true, use |logstream| to stream the log message and send it to spdlog. // If |condition| is false, |logstream| will not be instantiated. // The switch(0) is used to suppress a compiler warning on ambiguous "else". @@ -55,8 +53,12 @@ #define QUIC_LOG_WARNING_IS_ON_IMPL() quic::IsLogLevelEnabled(quic::WARNING) #define QUIC_LOG_ERROR_IS_ON_IMPL() quic::IsLogLevelEnabled(quic::ERROR) +#define CHECK(condition) \ + QUIC_LOG_IF_IMPL(FATAL, ABSL_PREDICT_FALSE(!(condition))) << "CHECK failed: " #condition "." + #ifdef NDEBUG // Release build +#define DCHECK(condition) QUIC_COMPILED_OUT_LOG() #define QUIC_COMPILED_OUT_LOG() QUIC_LOG_IMPL_INTERNAL(false, quic::NullLogStream().stream()) #define QUIC_DVLOG_IMPL(verbosity) QUIC_COMPILED_OUT_LOG() #define QUIC_DVLOG_IF_IMPL(verbosity, condition) QUIC_COMPILED_OUT_LOG() @@ -66,6 +68,7 @@ #define QUIC_NOTREACHED_IMPL() #else // Debug build +#define DCHECK(condition) CHECK(condition) #define QUIC_DVLOG_IMPL(verbosity) QUIC_VLOG_IMPL(verbosity) #define QUIC_DVLOG_IF_IMPL(verbosity, condition) QUIC_VLOG_IF_IMPL(verbosity, condition) #define QUIC_DLOG_IMPL(severity) QUIC_LOG_IMPL(severity) diff --git a/test/extensions/quic_listeners/quiche/platform/quic_platform_test.cc b/test/extensions/quic_listeners/quiche/platform/quic_platform_test.cc index cd8f513e8f9c6..10557ac8b91bb 100644 --- a/test/extensions/quic_listeners/quiche/platform/quic_platform_test.cc +++ b/test/extensions/quic_listeners/quiche/platform/quic_platform_test.cc @@ -357,6 +357,19 @@ TEST(QuicPlatformTest, QuicDLog) { #undef VALUE_BY_COMPILE_MODE +TEST(QuicPlatformTest, QuicCHECK) { + CHECK(1 == 1); + CHECK(1 == 1) << " 1 == 1 is forever true."; + + EXPECT_DEBUG_DEATH({ DCHECK(false) << " Supposed to fail in debug mode."; }, + "CHECK failed:.* Supposed to fail in debug mode."); + EXPECT_DEBUG_DEATH({ DCHECK(false); }, "CHECK failed"); + + EXPECT_DEATH({ CHECK(false) << " Supposed to fail in all modes."; }, + "CHECK failed:.* Supposed to fail in all modes."); + EXPECT_DEATH({ CHECK(false); }, "CHECK failed"); +} + // Test the behaviors of the cross products of // // {QUIC_LOG, QUIC_DLOG} x {FATAL, DFATAL} x {debug, release}