Julius Werner has submitted this change. ( https://review.coreboot.org/c/coreboot/+/59495 )
Change subject: libpayload: Add mock assert support for unit testing purposes ......................................................................
libpayload: Add mock assert support for unit testing purposes
Some unit tests might require catching assert failures. This patch adds an assert() variant depending on __TEST__ define passed to unit tests.
Change-Id: I7e4620400f27dbebc57c71bbf2bf9144ca65807f Signed-off-by: Jakub Czapiga jacz@semihalf.com Reviewed-on: https://review.coreboot.org/c/coreboot/+/59495 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Julius Werner jwerner@chromium.org --- M payloads/libpayload/include/assert.h 1 file changed, 13 insertions(+), 0 deletions(-)
Approvals: build bot (Jenkins): Verified Julius Werner: Looks good to me, approved
diff --git a/payloads/libpayload/include/assert.h b/payloads/libpayload/include/assert.h index 50847a3..2152af4 100644 --- a/payloads/libpayload/include/assert.h +++ b/payloads/libpayload/include/assert.h @@ -29,6 +29,17 @@ #include <stdlib.h> #include <stdio.h>
+#ifdef __TEST__ + +/* CMocka function redefinition */ +void mock_assert(const int result, const char *const expression, const char *const file, + const int line); + +#define MOCK_ASSERT(result, expression) mock_assert((result), (expression), __FILE__, __LINE__) +#define assert(statement) MOCK_ASSERT(!!(statement), #statement) + +#else + // assert's existence depends on NDEBUG state on _last_ inclusion of assert.h, // so don't guard this against double-includes. #ifdef NDEBUG @@ -43,3 +54,5 @@ abort(); \ } #endif + +#endif /* __TEST__ */
1 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one.