Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down Expand Up @@ -76,6 +74,17 @@

#define QUIC_PREDICT_FALSE_IMPL(x) ABSL_PREDICT_FALSE(x)

#define CHECK(condition) \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this CHECK to before the #ifdef at line 56?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

QUIC_LOG_IF_IMPL(FATAL, ABSL_PREDICT_FALSE(!(condition))) << "CHECK failed: " #condition "."

#ifndef NDEBUG
#define DCHECK(condition) CHECK(condition)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to avoid this #ifndef. Can you move the two #define DCHECK to the existing #ifdef NDEBUG above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

#else
#define DCHECK(condition) \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to before line 65 and
#define DCHECK(condition) QUIC_COMPILED_OUT_LOG()

while (false && (condition)) \
quic::NullLogStream().stream()
#endif

namespace quic {

using QuicLogLevel = spdlog::level::level_enum;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,15 @@ TEST(QuicPlatformTest, QuicDLog) {

#undef VALUE_BY_COMPILE_MODE

TEST(QuicPlatformTest, QuicDCHECK) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call it QuicCHECK?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

CHECK(1 == 1);
CHECK(1 == 1) << " 1 == 1 is forever true.";
EXPECT_DEBUG_DEATH({ CHECK(false) << " Supposed to fail in debug mode."; },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be DCHECK since CHECK fails in release mode. Have you tried to test it with -c opt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, yes. Added both CHECK and DCHECK here.

"CHECK failed:.* Supposed to fail in debug mode.");

EXPECT_DEBUG_DEATH({ CHECK(false); }, "CHECK failed");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, should be DCHECK.

}

// Test the behaviors of the cross products of
//
// {QUIC_LOG, QUIC_DLOG} x {FATAL, DFATAL} x {debug, release}
Expand Down