From 23410a873a323fd0ca6a804fa555d05abf3087e6 Mon Sep 17 00:00:00 2001 From: Yu-Ping Wu Date: Fri, 23 Jan 2026 15:29:48 +0800 Subject: [PATCH] assert.h: Remove printk dependency for ENV_TEST With the current implementation of assert() for ENV_TEST, the printk() function must be linked. As we are already using cmocka's mock_assert() implementation for unit tests, those printk() calls within assert-related macros should be changed to no-ops. Also, disable __build_time_assert() for ENV_TEST. Change-Id: Ia9bea29a32362d68dff89bb7bbf417126ac31fb7 Signed-off-by: Yu-Ping Wu Reviewed-on: https://review.coreboot.org/c/coreboot/+/90870 Reviewed-by: Julius Werner Tested-by: build bot (Jenkins) --- src/include/assert.h | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/include/assert.h b/src/include/assert.h index 0e09eef392..19d041010f 100644 --- a/src/include/assert.h +++ b/src/include/assert.h @@ -22,7 +22,7 @@ #define __ASSERT_LINE__ __LINE__ #endif -#ifndef _PORTING_H_ /* TODO: Isolate AGESA properly. */ +#if !ENV_TEST && !defined(_PORTING_H_) /* TODO: Isolate AGESA properly. */ #define __build_time_assert(x) \ (__builtin_constant_p(x) ? ((x) ? 1 : dead_code_t(int)) : 0) #else @@ -34,11 +34,13 @@ 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) \ +#define _ASSERT_MSG(...) +#define _MOCK_ASSERT(result, expression) \ mock_assert((result), (expression), __ASSERT_FILE__, __ASSERT_LINE__) -#else -#define MOCK_ASSERT(result, expression) -#endif +#else /* ENV_TEST */ +#define _ASSERT_MSG(...) printk(BIOS_EMERG, __VA_ARGS__) +#define _MOCK_ASSERT(result, expression) +#endif /* ENV_TEST */ /* * assert() should be used to test stuff that the programmer *knows* to be true. @@ -54,30 +56,30 @@ void mock_assert(const int result, const char *const expression, */ #define ASSERT(x) { \ if (!__build_time_assert(x) && !(x)) { \ - printk(BIOS_EMERG, \ + _ASSERT_MSG( \ "ASSERTION ERROR: file '%s', line %d\n", \ __ASSERT_FILE__, __ASSERT_LINE__); \ - MOCK_ASSERT(!!(x), #x); \ + _MOCK_ASSERT(!!(x), #x); \ if (CONFIG(FATAL_ASSERTS)) \ hlt(); \ } \ } #define ASSERT_MSG(x, msg) { \ if (!__build_time_assert(x) && !(x)) { \ - printk(BIOS_EMERG, \ + _ASSERT_MSG( \ "ASSERTION ERROR: file '%s', line %d\n", \ __ASSERT_FILE__, __ASSERT_LINE__); \ - printk(BIOS_EMERG, "%s", msg); \ - MOCK_ASSERT(!!(x), (msg)); \ + _ASSERT_MSG("%s", msg); \ + _MOCK_ASSERT(!!(x), (msg)); \ if (CONFIG(FATAL_ASSERTS)) \ hlt(); \ } \ } #define BUG() { \ - printk(BIOS_EMERG, \ + _ASSERT_MSG( \ "ERROR: BUG ENCOUNTERED at file '%s', line %d\n", \ __ASSERT_FILE__, __ASSERT_LINE__); \ - MOCK_ASSERT(0, "BUG ENCOUNTERED"); \ + _MOCK_ASSERT(0, "BUG ENCOUNTERED"); \ if (CONFIG(FATAL_ASSERTS)) \ hlt(); \ }