From c69ea3285e58346dbaf543ad81a2fd6a6ce3fee3 Mon Sep 17 00:00:00 2001 From: Jakub Czapiga Date: Thu, 18 Nov 2021 10:53:34 +0000 Subject: 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/59495 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- payloads/libpayload/include/assert.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'payloads/libpayload') diff --git a/payloads/libpayload/include/assert.h b/payloads/libpayload/include/assert.h index 50847a3b47..2152af4f7a 100644 --- a/payloads/libpayload/include/assert.h +++ b/payloads/libpayload/include/assert.h @@ -29,6 +29,17 @@ #include #include +#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__ */ -- cgit v1.2.3