summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJan Dabros <jsd@semihalf.com>2020-05-22 09:57:17 +0200
committerPatrick Georgi <pgeorgi@google.com>2020-05-26 16:21:06 +0000
commit7f00dba33beb65e0380ed4b3194102083630b2f4 (patch)
treeb38fa39336ba6e4de7865654a0db3b1c31ce1c05 /tests
parent0cbe320ac8711135657da36976f0055dc981ef24 (diff)
downloadcoreboot-7f00dba33beb65e0380ed4b3194102083630b2f4.tar.gz
tests: Build Cmocka from source
Relying on Cmocka packages, which are provided with different OS distributions, may introduce some problems with setup environments across developers (e.g. library version mismatch). Instead, let's build Cmocka from source code, which is now added to git submodules as 3rdparty/cmocka. Please note, that cmake tool is required for building Cmocka (thus also coreboot unit tests). Signed-off-by: Jan Dabros <jsd@semihalf.com> Change-Id: Ia947c5c60d5c58b76acebe4b614dd427ef995950 Reviewed-on: https://review.coreboot.org/c/coreboot/+/41653 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org> Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.inc23
1 files changed, 21 insertions, 2 deletions
diff --git a/tests/Makefile.inc b/tests/Makefile.inc
index be32434e83..a6689a2d06 100644
--- a/tests/Makefile.inc
+++ b/tests/Makefile.inc
@@ -2,6 +2,12 @@
testsrc = $(top)/tests
testobj = $(obj)/tests
+cmockasrc = 3rdparty/cmocka
+cmockaobj = $(cmockasrc)/build
+
+CMOCKA_LIB := $(cmockaobj)/src/libcmocka.so
+
+CMAKE:= cmake
TEST_DEFAULT_CONFIG = $(top)/configs/config.emulation_qemu_x86_i440fx
TEST_DOTCONFIG = $(testobj)/.config
@@ -26,8 +32,14 @@ TEST_CFLAGS += -I$(dir $(TEST_KCONFIG_AUTOHEADER))
TEST_CFLAGS += -std=gnu11 -Os -ffunction-sections -fdata-sections -fno-builtin
+# Checkout Cmocka repository
+forgetthis:=$(shell git submodule update --init --checkout 3rdparty/cmocka)
+
+TEST_CFLAGS += -I$(cmockasrc)/include
+
# Link against Cmocka
-TEST_LDFLAGS = -lcmocka -Wl,--gc-sections
+TEST_LDFLAGS = -L$(cmockaobj)/src -lcmocka -Wl,-rpath=$(cmockaobj)/src
+TEST_LDFLAGS += -Wl,--gc-sections
# Extra attributes for unit tests, declared per test
attributes:= srcs cflags mocks stage
@@ -69,7 +81,7 @@ $($(1)-objs): $(obj)/$(1)/%.o: $$$$*.c $(TEST_KCONFIG_AUTOHEADER)
-MT $$@ -c $$< -o $$@
$($(1)-bin): TEST_LDFLAGS+= $$(foreach mock,$$($(1)-mocks),-Wl,--wrap=$$(mock))
-$($(1)-bin): $($(1)-objs)
+$($(1)-bin): $($(1)-objs) $(CMOCKA_LIB)
$(HOSTCC) $$^ $($(1)-cflags) $$(TEST_LDFLAGS) -o $$@
endef
@@ -90,6 +102,13 @@ $(foreach test, $(alltests), \
DEPENDENCIES += $(addsuffix .d,$(basename $(all-test-objs)))
-include $(DEPENDENCIES)
+# Build cmocka
+$(CMOCKA_LIB):
+ echo "*** Building CMOCKA ***"
+ mkdir -p $(cmockaobj)
+ cd $(cmockaobj) && $(CMAKE) $(abspath $(cmockasrc))
+ $(MAKE) -C $(cmockaobj)
+
# Kconfig targets
$(TEST_DOTCONFIG):
mkdir -p $(dir $@)