From 45d37d5cb807cd285b0277e4c235d0e5fae28093 Mon Sep 17 00:00:00 2001 From: Jakub Czapiga Date: Thu, 25 Mar 2021 14:28:29 +0100 Subject: include/assert.h: Use mock_assert() for ENV_TEST targets Some tests have to be able to catch assertion errors. Adding CMocka mock_assert() enables that. Additionally fix test_imd_create_tiered_empty(), test_full_stack() and test_incorrectly_initialized_stack() by adding missing expect_assert_failure(). Signed-off-by: Jakub Czapiga Change-Id: I5e8dd1b198ee6fab61e2be3f92baf1178f79bf18 Reviewed-on: https://review.coreboot.org/c/coreboot/+/51804 Tested-by: build bot (Jenkins) Reviewed-by: Paul Fagerburg --- src/include/assert.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/include') diff --git a/src/include/assert.h b/src/include/assert.h index 944c67768a..829e73207e 100644 --- a/src/include/assert.h +++ b/src/include/assert.h @@ -29,12 +29,24 @@ #define __build_time_assert(x) 0 #endif +/* CMocka function redefinition. */ +void mock_assert(const int result, const char *const expression, + const char *const file, const int line); + +#if ENV_TEST +#define MOCK_ASSERT(result, expression) \ + mock_assert((result), (expression), __ASSERT_FILE__, __ASSERT_LINE__) +#else +#define MOCK_ASSERT(result, expression) +#endif + /* GCC and CAR versions */ #define ASSERT(x) { \ if (!__build_time_assert(x) && !(x)) { \ printk(BIOS_EMERG, \ "ASSERTION ERROR: file '%s', line %d\n", \ __ASSERT_FILE__, __ASSERT_LINE__); \ + MOCK_ASSERT(!!(x), #x); \ if (CONFIG(FATAL_ASSERTS)) \ hlt(); \ } \ @@ -45,6 +57,7 @@ "ASSERTION ERROR: file '%s', line %d\n", \ __ASSERT_FILE__, __ASSERT_LINE__); \ printk(BIOS_EMERG, "%s", msg); \ + MOCK_ASSERT(!!(x), (msg)); \ if (CONFIG(FATAL_ASSERTS)) \ hlt(); \ } \ @@ -53,6 +66,7 @@ printk(BIOS_EMERG, \ "ERROR: BUG ENCOUNTERED at file '%s', line %d\n", \ __ASSERT_FILE__, __ASSERT_LINE__); \ + MOCK_ASSERT(0, "BUG ENCOUNTERED"); \ if (CONFIG(FATAL_ASSERTS)) \ hlt(); \ } -- cgit v1.2.3