0011-tests-Enable-config-override-for-tests.patch 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. From d654c14aa2f150d7b15abc89a3c267b24ca123a1 Mon Sep 17 00:00:00 2001
  2. From: Jakub Czapiga <jacz@semihalf.com>
  3. Date: Wed, 28 Apr 2021 16:50:51 +0200
  4. Subject: [PATCH 11/19] tests: Enable config override for tests
  5. Some tests require to change kconfig symbols values to cover the code.
  6. This patch enables one to set these vaues using <test-name>-config
  7. variable.
  8. Example for integer values.
  9. timestamp-test-config += CONFIG_HAVE_MONOTONIC_TIMER=1
  10. Example for string values. Notice escaped quotes.
  11. spd_cache-test-config += CONFIG_SPD_CACHE_FMAP_NAME=\"SPD_CACHE_FMAP_NAME\"
  12. Signed-off-by: Jakub Czapiga <jacz@semihalf.com>
  13. Change-Id: I1aeb78362c2609fbefbfd91c0f58ec19ed258ee1
  14. Reviewed-on: https://review.coreboot.org/c/coreboot/+/52937
  15. Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
  16. Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
  17. Reviewed-by: Julius Werner <jwerner@chromium.org>
  18. ---
  19. tests/Makefile.inc | 22 ++++++++++++++++++----
  20. 1 file changed, 18 insertions(+), 4 deletions(-)
  21. diff --git a/tests/Makefile.inc b/tests/Makefile.inc
  22. index 44e3c69618..cd25e0f809 100644
  23. --- a/tests/Makefile.inc
  24. +++ b/tests/Makefile.inc
  25. @@ -11,7 +11,7 @@ CMAKE:= cmake
  26. TEST_DEFAULT_CONFIG = $(top)/configs/config.emulation_qemu_x86_i440fx
  27. TEST_DOTCONFIG = $(testobj)/.config
  28. -TEST_KCONFIG_AUTOHEADER := $(testobj)/config.h
  29. +TEST_KCONFIG_AUTOHEADER := $(testobj)/config.src.h
  30. TEST_KCONFIG_AUTOCONFIG := $(testobj)/auto.conf
  31. TEST_KCONFIG_DEPENDENCIES := $(testobj)/auto.conf.cmd
  32. TEST_KCONFIG_SPLITCONFIG := $(testobj)/config
  33. @@ -52,7 +52,7 @@ TEST_CFLAGS += -fno-pie -fno-pic
  34. TEST_LDFLAGS += -no-pie
  35. # Extra attributes for unit tests, declared per test
  36. -attributes:= srcs cflags mocks stage
  37. +attributes:= srcs cflags config mocks stage
  38. stages:= decompressor bootblock romstage smm verstage
  39. stages+= ramstage rmodule postcar libagesa
  40. @@ -83,9 +83,23 @@ $(call evaluate_subdirs)
  41. # Create actual targets for unit test binaries
  42. # $1 - test name
  43. define TEST_CC_template
  44. -$($(1)-objs): TEST_CFLAGS+= \
  45. +
  46. +# Generate custom config.h redefining given symbols
  47. +$(1)-config-file := $(obj)/$(1)/config.h
  48. +$$($(1)-config-file): $(TEST_KCONFIG_AUTOHEADER)
  49. + mkdir -p $$(dir $$@)
  50. + printf '// File generated by tests/Makefile.inc\n// Do not change\n' > $$@
  51. + printf '#include <%s>\n\n' "$(notdir $(TEST_KCONFIG_AUTOHEADER))" >> $$@
  52. + for kv in $$($(1)-config); do \
  53. + key="`echo $$$$kv | cut -d '=' -f -1`"; \
  54. + value="`echo $$$$kv | cut -d '=' -f 2-`"; \
  55. + printf '#undef %s\n' "$$$$key" >> $$@; \
  56. + printf '#define %s %s\n\n' "$$$$key" "$$$$value" >> $$@; \
  57. + done
  58. +
  59. +$($(1)-objs): TEST_CFLAGS += -I$$(dir $$($(1)-config-file)) \
  60. -D__$$(shell echo $$($(1)-stage) | tr '[:lower:]' '[:upper:]')__
  61. -$($(1)-objs): $(obj)/$(1)/%.o: $$$$*.c $(TEST_KCONFIG_AUTOHEADER)
  62. +$($(1)-objs): $(obj)/$(1)/%.o: $$$$*.c $$($(1)-config-file)
  63. mkdir -p $$(dir $$@)
  64. $(HOSTCC) $(HOSTCFLAGS) $$(TEST_CFLAGS) $($(1)-cflags) -MMD \
  65. -MT $$@ -c $$< -o $$@
  66. --
  67. 2.25.1