summaryrefslogtreecommitdiff
path: root/payloads
diff options
context:
space:
mode:
authorJakub Czapiga <jacz@semihalf.com>2021-11-18 10:53:34 +0000
committerJulius Werner <jwerner@chromium.org>2021-11-23 23:38:15 +0000
commitc69ea3285e58346dbaf543ad81a2fd6a6ce3fee3 (patch)
treebaf3314016a4a5f087c7293503db1cb1cb78c2df /payloads
parent162083072eb42b3607208c2cf80ebb2695ac2217 (diff)
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>
Diffstat (limited to 'payloads')
-rw-r--r--payloads/libpayload/include/assert.h13
1 files changed, 13 insertions, 0 deletions
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 <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__ */