From f4a123f0554aa331906717eaf53f4b71db4ab388 Mon Sep 17 00:00:00 2001 From: "roccochen@chromium.com" Date: Tue, 14 Nov 2023 19:29:45 +0800 Subject: [PATCH] tests: Allow specifying using system Cmocka or building from source Add a flag "USE_SYSTEM_CMOCKA" in the Makefile of tests. (default 1) If USE_SYSTEM_CMOCKA=1, we will check if the system has Cmocka module, and link it directly. If the system doesn't have Cmocka, we will set the flag to 0 and print a warning message. If USE_SYSTEM_CMOCKA=0, we will build Cmocka from 3rdparty source code. BUG=none TEST=make unit-tests -j TEST=USE_SYSTEM_CMOCKA=0 make unit-tests -j BRANCH=none Signed-off-by: roccochen@chromium.com Change-Id: I091784ca541e2590e3db0a18ceea83e7895ed0c2 Reviewed-on: https://review.coreboot.org/c/coreboot/+/79019 Reviewed-by: Jakub "Kuba" Czapiga Tested-by: build bot (Jenkins) --- tests/Makefile.common | 5 ++++- tests/Makefile.mk | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/Makefile.common b/tests/Makefile.common index 74a3c5a7a9..a8bb19c4f1 100644 --- a/tests/Makefile.common +++ b/tests/Makefile.common @@ -157,11 +157,14 @@ $($(1)-sysobjs): $(testobj)/$(1)/%.o: $$$$*.c $$($(1)-config-file) # Link against Cmocka if not disabled ifeq ($(strip $(filter-out 0 n no,$($(1)-no_test_framework))),) +ifneq ($(USE_SYSTEM_CMOCKA),) $($(1)-objs): TEST_CFLAGS += -I$(cmockasrc)/include -$($(1)-bin): TEST_LDFLAGS += -L$(cmockaobj)/src -lcmocka -Wl,-rpath=$(cmockaobj)/src +$($(1)-bin): TEST_LDFLAGS += -L$(cmockaobj)/src -Wl,-rpath=$(cmockaobj)/src $($(1)-bin): TEST_CFLAGS += -I$(cmockasrc)/include $($(1)-bin): $(CMOCKA_LIB) endif +$($(1)-bin): TEST_LDFLAGS += -lcmocka +endif $($(1)-bin): $($(1)-objs) $($(1)-sysobjs) $(HOSTCC) $$^ $($(1)-cflags) $$(TEST_LDFLAGS) -o $$@ diff --git a/tests/Makefile.mk b/tests/Makefile.mk index f838f8336b..f3f122dd38 100644 --- a/tests/Makefile.mk +++ b/tests/Makefile.mk @@ -24,6 +24,15 @@ TEST_CFLAGS += --coverage TEST_LDFLAGS += --coverage endif +# Use system cmoka in default, or build from 3rdparty source code if requested +USE_SYSTEM_CMOCKA ?= 1 +ifeq ($(USE_SYSTEM_CMOCKA),1) +ifeq ($(shell $(HOSTPKG_CONFIG) --exists cmocka || echo 1),1) +$(warning No system cmocka, build from 3rdparty instead...) +USE_SYSTEM_CMOCKA=0 +endif +endif + stages := decompressor bootblock romstage smm verstage stages += ramstage rmodule postcar libagesa @@ -186,6 +195,7 @@ help-unit-tests help:: @echo '*** coreboot unit-tests targets ***' @echo ' Use "COV=1 make [target]" to enable code coverage for unit tests' @echo ' Use "GDB_DEBUG=1 make [target]" to build with debug symbols' + @echo ' Use "USE_SYSTEM_CMOCKA=0 make [target]" to build Cmocka from source' @echo ' unit-tests - Run all unit-tests from tests/' @echo ' clean-unit-tests - Remove unit-tests build artifacts' @echo ' list-unit-tests - List all unit-tests'