Skip to content

Commit

Permalink
[coverage] make ENVOY_BUGs non-fatal in coverage mode (#15104)
Browse files Browse the repository at this point in the history
Signed-off-by: Asra Ali <[email protected]>
  • Loading branch information
asraa authored Feb 18, 2021
1 parent d2305c2 commit 9ade06f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
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

0 comments on commit 9ade06f

Please sign in to comment.