tests/stubs/console: Allow enabling printk to print to stdout

By adding TEST_PRINT=1 to <test-name>-config field or by passing it as
a parameter to make one can enable printing in printk() and vprintk().
This can be helpful when developing unit tests.
Note, that to effectively enable or disable printk() printing to stdout,
test(s) have to be recompiled.

Signed-off-by: Jakub Czapiga <jacz@semihalf.com>
Change-Id: Ibdec8bb128f42ba4d9cb8bbb4a8c5159a2b52ac5
Reviewed-on: https://review.coreboot.org/c/coreboot/+/57526
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
This commit is contained in:
Jakub Czapiga 2021-09-09 12:11:39 +02:00 committed by Felix Held
parent c54e22c589
commit 29faa8a5a2
2 changed files with 18 additions and 0 deletions

View File

@ -55,6 +55,10 @@ TEST_CFLAGS += -D__TEST__
TEST_CFLAGS += -I$(cmockasrc)/include
ifneq ($(filter-out 0,$(TEST_PRINT)),)
TEST_CFLAGS += -DTEST_PRINT=1
endif
# Link against Cmocka
TEST_LDFLAGS := -L$(cmockaobj)/src -lcmocka -Wl,-rpath=$(cmockaobj)/src
TEST_LDFLAGS += -Wl,--gc-sections

View File

@ -3,14 +3,28 @@
#include <console/console.h>
#include <stdarg.h>
#include <stdio.h>
#include <tests/test.h>
#ifndef TEST_PRINT
#define TEST_PRINT 0
#endif
int printk(int msg_level, const char *fmt, ...)
{
#if TEST_PRINT
va_list v;
va_start(v, fmt);
vprint_message(fmt, v);
va_end(v);
#endif
return 0;
}
int vprintk(int msg_level, const char *fmt, va_list args)
{
#if TEST_PRINT
vprint_message(fmt, args);
#endif
return 0;
}