Skip to content

Commit

Permalink
Add configuration option for more verbose VerifyOrDie messages. (proj…
Browse files Browse the repository at this point in the history
…ect-chip#9800)

We have a lot of VerifyOrDie with no messages, and when they fail it's
hard to tell what went wrong.  This change adds a configuration option
to automatically generate a verbose message string for VerifyOrDie if
one is not provided.  The option is off by default but enabled for
Darwin and Linux.

Log from a failing unit test without this change:

[1631900831920] [73638:57013508] CHIP: [EM] Piggybacking Ack for MessageCounter:0000000D with msg
../../third_party/pigweed/repo/targets/host/run_test: line 18: 73638 Abort trap: 6           "$@"
INF Test 1/1: [FAIL] TestReliableMessageProtocol

Log from the same failure with this change:

[1631900926163] [79197:57035322] CHIP: [EM] Piggybacking Ack for MessageCounter:0000000D with msg
[1631900926163] [79197:57035322] CHIP: [SPT] VerifyOrDie failure at ../../src/messaging/ReliableMessageMgr.cpp:262: rc != nullptr && !rc->IsOccupied()
../../third_party/pigweed/repo/targets/host/run_test: line 18: 79197 Abort trap: 6           "$@"
INF Test 1/1: [FAIL] TestReliableMessageProtocol
  • Loading branch information
bzbarsky-apple authored Sep 17, 2021
1 parent adb4180 commit e9f5b89
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib/core/CHIPConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -2488,6 +2488,16 @@ extern const char CHIP_NON_PRODUCTION_MARKER[];
#define CHIP_CONFIG_LAMBDA_EVENT_ALIGN (sizeof(void *))
#endif

/**
* @def CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE
*
* @brief If true, VerifyOrDie() calls with no message will use an
* automatically generated message that makes it clear what failed.
*/
#ifndef CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE
#define CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE 0
#endif

/**
* @}
*/
6 changes: 6 additions & 0 deletions src/lib/support/CodeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#ifdef __cplusplus

#include <lib/core/CHIPConfig.h>
#include <lib/core/CHIPError.h>
#include <lib/support/ErrorStr.h>
#include <lib/support/logging/CHIPLogging.h>
Expand Down Expand Up @@ -493,7 +494,12 @@ inline void chipDie(void)
* @sa #chipDie
*
*/
#if CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE
#define VerifyOrDie(aCondition) \
nlABORT_ACTION(aCondition, ChipLogDetail(Support, "VerifyOrDie failure at %s:%d: %s", __FILE__, __LINE__, #aCondition))
#else // CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE
#define VerifyOrDie(aCondition) nlABORT(aCondition)
#endif // CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE

/**
* @def VerifyOrDieWithMsg(aCondition, aModule, aMessage, ...)
Expand Down
2 changes: 2 additions & 0 deletions src/platform/Darwin/CHIPPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#define CHIP_CONFIG_ERROR_FORMAT_AS_STRING 1
#define CHIP_CONFIG_ERROR_SOURCE 1

#define CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE 1

// ==================== Security Adaptations ====================

#define CHIP_CONFIG_USE_OPENSSL_ECC 0
Expand Down
2 changes: 2 additions & 0 deletions src/platform/Linux/CHIPPlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ using CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE = const char *;
#define CHIP_CONFIG_ERROR_FORMAT_AS_STRING 1
#define CHIP_CONFIG_ERROR_SOURCE 1

#define CHIP_CONFIG_VERBOSE_VERIFY_OR_DIE 1

// ==================== Security Adaptations ====================

#define CHIP_CONFIG_USE_OPENSSL_ECC 0
Expand Down

0 comments on commit e9f5b89

Please sign in to comment.