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 <yupingso@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/90870 Reviewed-by: Julius Werner <jwerner@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
5cae481856
commit
23410a873a
1 changed files with 14 additions and 12 deletions
|
|
@ -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(); \
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue