diff --git a/tests/Makefile.inc b/tests/Makefile.inc index 44e3c69618..cd25e0f809 100644 --- a/tests/Makefile.inc +++ b/tests/Makefile.inc @@ -11,7 +11,7 @@ CMAKE:= cmake 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_CFLAGS += -fno-pie -fno-pic 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,9 +83,23 @@ $(call evaluate_subdirs) # Create actual targets for unit test binaries # $1 - test name define TEST_CC_template -$($(1)-objs): TEST_CFLAGS+= \ + +# Generate custom config.h redefining given symbols +$(1)-config-file := $(obj)/$(1)/config.h +$$($(1)-config-file): $(TEST_KCONFIG_AUTOHEADER) + mkdir -p $$(dir $$@) + printf '// File generated by tests/Makefile.inc\n// Do not change\n' > $$@ + printf '#include <%s>\n\n' "$(notdir $(TEST_KCONFIG_AUTOHEADER))" >> $$@ + for kv in $$($(1)-config); do \ + key="`echo $$$$kv | cut -d '=' -f -1`"; \ + value="`echo $$$$kv | cut -d '=' -f 2-`"; \ + printf '#undef %s\n' "$$$$key" >> $$@; \ + printf '#define %s %s\n\n' "$$$$key" "$$$$value" >> $$@; \ + done + +$($(1)-objs): TEST_CFLAGS += -I$$(dir $$($(1)-config-file)) \ -D__$$(shell echo $$($(1)-stage) | tr '[:lower:]' '[:upper:]')__ -$($(1)-objs): $(obj)/$(1)/%.o: $$$$*.c $(TEST_KCONFIG_AUTOHEADER) +$($(1)-objs): $(obj)/$(1)/%.o: $$$$*.c $$($(1)-config-file) mkdir -p $$(dir $$@) $(HOSTCC) $(HOSTCFLAGS) $$(TEST_CFLAGS) $($(1)-cflags) -MMD \ -MT $$@ -c $$< -o $$@