-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add macro DCHECK in quic_logging_impl.h #6358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
ac872f9
717885d
831bd35
4d4c80d
480f8fb
f3127a2
ca4b1d5
c38586b
0776a2d
d5023e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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". | ||
|
|
@@ -76,6 +74,17 @@ | |
|
|
||
| #define QUIC_PREDICT_FALSE_IMPL(x) ABSL_PREDICT_FALSE(x) | ||
|
|
||
| #define CHECK(condition) \ | ||
| QUIC_LOG_IF_IMPL(FATAL, ABSL_PREDICT_FALSE(!(condition))) << "CHECK failed: " #condition "." | ||
|
|
||
| #ifndef NDEBUG | ||
| #define DCHECK(condition) CHECK(condition) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| #else | ||
| #define DCHECK(condition) \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move to before line 65 and |
||
| while (false && (condition)) \ | ||
| quic::NullLogStream().stream() | ||
| #endif | ||
|
|
||
| namespace quic { | ||
|
|
||
| using QuicLogLevel = spdlog::level::level_enum; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -357,6 +357,15 @@ TEST(QuicPlatformTest, QuicDLog) { | |
|
|
||
| #undef VALUE_BY_COMPILE_MODE | ||
|
|
||
| TEST(QuicPlatformTest, QuicDCHECK) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call it QuicCHECK?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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."; }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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} | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done