c69ea3285e58346dbaf543ad81a2fd6a6ce3fee3 — Jakub Czapiga 2 months ago 1620830 master
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>
1 files changed, 13 insertions(+), 0 deletions(-)

M payloads/libpayload/include/assert.h
M payloads/libpayload/include/assert.h => payloads/libpayload/include/assert.h +13 -0
@@ 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)


// 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 /* __TEST__ */