summaryrefslogtreecommitdiff
path: root/tests/Makefile.inc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Makefile.inc')
-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 $@)