Jakub Czapiga has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/52937 )
Change subject: tests: Enable config override for tests ......................................................................
tests: Enable config override for tests
Some tests require to change kconfig symbols values to cover the code. This patch enables one to set these vaues using <test-name>-config variable.
Example for integer values. timestamp-test-config += CONFIG_HAVE_MONOTONIC_TIMER=1
Example for string values. Notice escaped quotes. spd_cache-test-config += CONFIG_SPD_CACHE_FMAP_NAME="SPD_CACHE_FMAP_NAME"
Signed-off-by: Jakub Czapiga jacz@semihalf.com Change-Id: I1aeb78362c2609fbefbfd91c0f58ec19ed258ee1 --- M tests/Makefile.inc 1 file changed, 21 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/37/52937/1
diff --git a/tests/Makefile.inc b/tests/Makefile.inc index fd3cd9f..1172b8c 100644 --- a/tests/Makefile.inc +++ b/tests/Makefile.inc @@ -11,7 +11,7 @@
TEST_DEFAULT_CONFIG = $(top)/configs/config.emulation_qemu_x86_i440fx TEST_DOTCONFIG = $(testobj)/.config -TEST_KCONFIG_AUTOHEADER := $(testobj)/config.h +TEST_KCONFIG_AUTOHEADER := $(testobj)/config.src.h TEST_KCONFIG_AUTOCONFIG := $(testobj)/auto.conf TEST_KCONFIG_DEPENDENCIES := $(testobj)/auto.conf.cmd TEST_KCONFIG_SPLITCONFIG := $(testobj)/config @@ -52,7 +52,7 @@ TEST_LDFLAGS += -no-pie
# Extra attributes for unit tests, declared per test -attributes:= srcs cflags mocks stage +attributes:= srcs cflags config mocks stage
stages:= decompressor bootblock romstage smm verstage stages+= ramstage rmodule postcar libagesa @@ -83,6 +83,25 @@ # Create actual targets for unit test binaries # $1 - test name define TEST_CC_template + +# Generate custom config.h redefining given symbols +$(eval $(1)-config-file := $(obj)/$(1)/config.h) +$($(1)-config-file): $(TEST_KCONFIG_AUTOHEADER) +$($(1)-config-file): + mkdir -p $$(dir $$@) + printf '// File generated by tests/Makefile.inc\n// Do not change\n' > $$@ + printf '#include <config.src.h>\n\n' >> $$@ + for kv in $$($(1)-config); do \ + key="`echo $$$$kv | cut -d '=' -f -1`"; \ + value="`echo $$$$kv | cut -d '=' -f 2-`"; \ + printf '#ifdef %s\n' "$$$$key" >> $$@; \ + printf '#undef %s\n' "$$$$key" >> $$@; \ + printf '#endif\n' >> $$@; \ + printf '#define %s %s\n\n' "$$$$key" "$$$$value" >> $$@; \ + done + +$($(1)-objs): TEST_CFLAGS += -I$(dir $($(1)-config-file)) +$($(1)-objs): $(obj)/$(1)/%.o: $$$$*.c $($(1)-config-file) $($(1)-objs): TEST_CFLAGS+= \ -D__$$(shell echo $$($(1)-stage) | tr '[:lower:]' '[:upper:]')__ $($(1)-objs): $(obj)/$(1)/%.o: $$$$*.c $(TEST_KCONFIG_AUTOHEADER)