From 9ade06f29f455034933a17b55c026fcbe95ca3a8 Mon Sep 17 00:00:00 2001 From: asraa Date: Thu, 18 Feb 2021 17:52:49 -0500 Subject: [PATCH] [coverage] make ENVOY_BUGs non-fatal in coverage mode (#15104) Signed-off-by: Asra Ali --- source/common/common/assert.h | 6 +++++- test/test_common/utility.h | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/source/common/common/assert.h b/source/common/common/assert.h index 4501ac84a142..00d0edb56e98 100644 --- a/source/common/common/assert.h +++ b/source/common/common/assert.h @@ -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() @@ -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__)) diff --git a/test/test_common/utility.h b/test/test_common/utility.h index 94a811318dd7..fd8f25ce68d9 100644 --- a/test/test_common/utility.h +++ b/test/test_common/utility.h @@ -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