Jakub Czapiga has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/56719 )
Change subject: tests/Makefile.inc: Add function wrapping mechanism ......................................................................
tests/Makefile.inc: Add function wrapping mechanism
This patch extends mocks functionality to allowing wrapping of mocked functions. Original function name will be prefixed with `__real_`. Example: - Mocked function: cbfs_lookup() - New function name: __real_cbfs_lookup() - Mock name: cbfs_lookup()
Signed-off-by: Jakub Czapiga jacz@semihalf.com Change-Id: I7cd0d66a17029955cbf75c8b155a7ebb7f5513aa --- M tests/Makefile.inc 1 file changed, 10 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/19/56719/1
diff --git a/tests/Makefile.inc b/tests/Makefile.inc index 056ad7d..e0ff17e 100644 --- a/tests/Makefile.inc +++ b/tests/Makefile.inc @@ -120,7 +120,16 @@ mkdir -p $$(dir $$@) $(HOSTCC) $(HOSTCFLAGS) $$(TEST_CFLAGS) $($(1)-cflags) -MMD \ -MF $$(basename $$@).d -MT $$@ -c $$< -o $$@.orig - $(OBJCOPY) $$@.orig $$(OBJCOPY_FLAGS) $$@ + $(OBJCOPY) $$@.orig $$(OBJCOPY_FLAGS) $$@.orig2 + objcopy_wrap_flags=''; \ + for sym in $$($(1)-mocks); do \ + sym_line="$$$$(objdump -t $$@.orig2 | grep -E '[0-9a-fA-F]+\s+w\s+F\s+.*\s'$$$$sym)"; \ + if [ ! -z "$$$$sym_line" ] ; then \ + addr="$$$$(echo "$$$$sym_line" | rev | awk '{ print $$$$2 }' | rev)"; \ + objcopy_wrap_flags="$$$$objcopy_wrap_flags --add-symbol __real_$$$${sym}=.text.$$$${sym}:0x$$$${addr},global"; \ + fi \ + done ; \ + $(OBJCOPY) $$@.orig2 $$$$objcopy_wrap_flags $$@
$($(1)-bin): $($(1)-objs) $(CMOCKA_LIB) $(HOSTCC) $$^ $($(1)-cflags) $$(TEST_LDFLAGS) -o $$@