Skip to content
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

[coverage] make ENVOY_BUGs non-fatal in coverage mode #15104

Merged
merged 3 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion source/common/common/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ void resetEnvoyBugCountersForTest();
abort(); \
} while (false)

#if !defined(NDEBUG)
// We do not want to crash on failure in tests exercising ENVOY_BUGs while running coverage in debug
// mode. Crashing causes flakes when forking to expect a debug death and reduces lines of coverage.
#if !defined(NDEBUG) && !defined(ENVOY_CONFIG_COVERAGE)
#define ENVOY_BUG_ACTION abort()
#else
#define ENVOY_BUG_ACTION Envoy::Assert::invokeEnvoyBugFailureRecordActionForEnvoyBugMacroUseOnly()
Expand Down Expand Up @@ -209,6 +211,8 @@ void resetEnvoyBugCountersForTest();
* mode, it is logged and a stat is incremented with exponential back-off per ENVOY_BUG. In debug
* mode, it will crash if the condition is not met. ENVOY_BUG must be called with two arguments for
* verbose logging.
* Note: ENVOY_BUGs in coverage mode will never crash. They will log and increment a stat like in
* release mode. This prevents flakiness and increases code coverage.
*/
#define ENVOY_BUG(...) PASS_ON(PASS_ON(_ENVOY_BUG_VERBOSE)(__VA_ARGS__))

Expand Down
6 changes: 3 additions & 3 deletions test/test_common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ namespace Envoy {
::testing::Not(::testing::ContainsRegex(regex_str)))

// Expect that the statement hits an ENVOY_BUG containing the specified message.
#ifdef NDEBUG
// ENVOY_BUGs in release mode log error.
#if defined(NDEBUG) || defined(ENVOY_CONFIG_COVERAGE)
// ENVOY_BUGs in release mode or in a coverage test log error.
#define EXPECT_ENVOY_BUG(statement, message) EXPECT_LOG_CONTAINS("error", message, statement)
#else
// ENVOY_BUGs in debug mode is fatal.
// ENVOY_BUGs in (non-coverage) debug mode is fatal.
#define EXPECT_ENVOY_BUG(statement, message) \
EXPECT_DEBUG_DEATH(statement, ::testing::HasSubstr(message))
#endif
Expand Down