Skip to content

Add macro DCHECK in quic_logging_impl.h#6358

Merged
alyssawilk merged 10 commits intoenvoyproxy:masterfrom
danzh2010:dcheck
Mar 25, 2019
Merged

Add macro DCHECK in quic_logging_impl.h#6358
alyssawilk merged 10 commits intoenvoyproxy:masterfrom
danzh2010:dcheck

Conversation

@danzh2010
Copy link
Copy Markdown
Contributor

Address one TOTO in that file that (D)CHECK is not explicit listed in platform API, but is supposed to be defined in some impl. Define them in quic_logging_impl.h seems appropriate.

Risk Level: low, not in use
Part of #2557

Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
@danzh2010
Copy link
Copy Markdown
Contributor Author

/assign @wu-bin

Copy link
Copy Markdown
Contributor

@wu-bin wu-bin left a comment

Choose a reason for hiding this comment

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

Thanks for doing this, just a few small comments.


#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

#ifndef NDEBUG
#define DCHECK(condition) CHECK(condition)
#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()

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


#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

TEST(QuicPlatformTest, QuicDCHECK) {
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.

EXPECT_DEBUG_DEATH({ CHECK(false) << " Supposed to fail in debug mode."; },
"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.

Signed-off-by: Dan Zhang <danzh@google.com>
wu-bin
wu-bin previously approved these changes Mar 22, 2019
Copy link
Copy Markdown
Contributor

@wu-bin wu-bin left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

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."; },
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.

nit, feel free to ignore: It'd be nicer visually if you

  • Put the first 2 CHECKs in adjacent lines
  • Then followed by an empty line
  • Then put the 2 EXPECT_DEBUG_DEATHs in adjacent lines
  • Then followed by an empty line
  • Then put the 2 EXPECT_DEATHs in adjacent lines

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

Signed-off-by: Dan Zhang <danzh@google.com>
@danzh2010
Copy link
Copy Markdown
Contributor Author

/assign @alyssawilk

@alyssawilk alyssawilk merged commit 2b6218c into envoyproxy:master Mar 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants