From e3df18451c518c0019f35b9b4d5d06ff6bd3d5f2 Mon Sep 17 00:00:00 2001 From: Martin Roth Date: Thu, 18 Jan 2024 10:25:18 -0700 Subject: Makefiles: Rename top-level Makefiles from .inc to .mk The .inc suffix is confusing to various tools as it's not specific to Makefiles. This means that editors don't recognize the files, and don't open them with highlighting and any other specific editor functionality. This issue is also seen in the release notes generation script where Makefiles get renamed before running cloc. The rest of the Makefiles will be renamed in following commits. Signed-off-by: Martin Roth Change-Id: Idaf69c6871d0bc1ee5e2e53157b8631c55eb3db9 Reviewed-on: https://review.coreboot.org/c/coreboot/+/80063 Reviewed-by: Felix Singer Reviewed-by: Maximilian Brune Tested-by: build bot (Jenkins) Reviewed-by: Nico Huber --- tests/Makefile.inc | 196 ----------------------------------------------------- tests/Makefile.mk | 196 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 196 insertions(+), 196 deletions(-) delete mode 100644 tests/Makefile.inc create mode 100644 tests/Makefile.mk (limited to 'tests') diff --git a/tests/Makefile.inc b/tests/Makefile.inc deleted file mode 100644 index 584b4c0c9dae..000000000000 --- a/tests/Makefile.inc +++ /dev/null @@ -1,196 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only - -# Place the build output in one of two places depending on COV, so that code -# built with code coverage never mixes with code built without code coverage. -ifeq ($(COV),1) -testobj := $(obj)/coverage -else -testobj := $(obj)/tests -endif - -objutil := $(testobj)/util - -include $(top)/tests/Makefile.common - -# Enable GDB debug build if requested -GDB_DEBUG ?= 0 -ifneq ($(GDB_DEBUG),0) -TEST_CFLAGS += -g -Og -endif - -# Enable code coverage if requested -ifeq ($(COV),1) -TEST_CFLAGS += --coverage -TEST_LDFLAGS += --coverage -endif - -stages := decompressor bootblock romstage smm verstage -stages += ramstage rmodule postcar libagesa - -alltests := -subdirs := tests/arch tests/acpi tests/commonlib tests/console tests/cpu -subdirs += tests/device tests/drivers tests/ec tests/lib -subdirs += tests/mainboard tests/northbridge tests/security tests/soc -subdirs += tests/southbridge tests/superio tests/vendorcode - -define tests-handler -alltests += $(1)$(2) -$(foreach attribute,$(attributes), - $(eval $(1)$(2)-$(attribute) += $($(2)-$(attribute)))) -$(foreach attribute,$(attributes), - $(eval $(2)-$(attribute) := )) - -# Sanity check for stage attribute value -$(eval $(1)$(2)-stage := $(if $($(1)$(2)-stage),$($(1)$(2)-stage),ramstage)) -$(if $(findstring $($(1)$(2)-stage), $(stages)),, - $(error Wrong $(1)$(2)-stage value $($(1)$(2)-stage). \ - Check your $(dir $(1)$(2))Makefile.inc)) -endef - -$(call add-special-class, tests) -$(call evaluate_subdirs) - -$(foreach test, $(alltests), \ - $(eval $(test)-srcobjs := $(addprefix $(testobj)/$(test)/, \ - $(patsubst %.c,%.o,$(filter src/%,$($(test)-srcs))))) \ - $(eval $(test)-sysobjs := $(addprefix $(testobj)/$(test)/, \ - $(patsubst %.c,%.o,$($(test)-syssrcs)))) \ - $(eval $(test)-objs := $(addprefix $(testobj)/$(test)/, \ - $(patsubst %.c,%.o,$($(test)-srcs))))) -$(foreach test, $(alltests), \ - $(eval $(test)-bin := $(testobj)/$(test)/run)) -$(foreach test, $(alltests), \ - $(eval $(call TEST_CC_template,$(test)))) - -$(foreach test, $(alltests), \ - $(eval all-test-objs += $($(test)-objs))) -$(foreach test, $(alltests), \ - $(eval test-bins += $($(test)-bin))) - -DEPENDENCIES += $(addsuffix .d,$(basename $(all-test-objs))) --include $(DEPENDENCIES) - -.PHONY: $(alltests) $(addprefix clean-,$(alltests)) $(addprefix try-,$(alltests)) -.PHONY: $(addprefix build-,$(alltests)) $(addprefix run-,$(alltests)) -.PHONY: unit-tests build-unit-tests run-unit-tests clean-unit-tests -.PHONY: junit.xml-unit-tests clean-junit.xml-unit-tests - -# %g in CMOCKA_XML_FILE will be replaced with "__TEST_NAME__()" -# by macro cb_run_group_tests(), which should be used for running tests. -# __TEST_NAME__ contains test name including path e.g. tests_lib_rtc-test -ifeq ($(JUNIT_OUTPUT),y) -$(addprefix run-,$(alltests)): export CMOCKA_MESSAGE_OUTPUT=xml -$(addprefix run-,$(alltests)): export CMOCKA_XML_FILE=$(testobj)/junit-%g.xml -endif - -$(addprefix run-,$(alltests)): run-%: $$(%-bin) - rm -f $(testobj)/junit-$(subst /,_,$(patsubst $(testobj)/%/,%,$(dir $^)))\(*\).xml - rm -f $(testobj)/$(subst /,_,$^).failed - -$^ || echo failed > $(testobj)/$(subst /,_,$^).failed - -$(addprefix build-,$(alltests)): build-%: $$(%-bin) - -$(alltests): run-$$(@) - -$(addprefix try-,$(alltests)): try-%: clean-% $(TEST_COMMON_DEPENDENCIES) - mkdir -p $(testobj)/$* - echo "" >> $(testobj)/$*.tmp; \ - $(MAKE) V=$(V) Q=$(Q) COV=$(COV) JUNIT_OUTPUT=y "build-$*" >> $(testobj)/$*.tmp.2 2>&1 \ - && type="system-out" || type="failure"; \ - if [ $$type = "failure" ]; then \ - echo "" >> $(testobj)/$*.tmp; \ - else \ - echo "<$$type>" >> $(testobj)/$*.tmp; \ - fi; \ - echo '> $(testobj)/$*.tmp; \ - cat $(testobj)/$*.tmp.2 >> $(testobj)/$*.tmp; \ - echo "]]>" >> $(testobj)/$*.tmp; \ - rm -f $(testobj)/$*.tmp.2; \ - echo "" >> $(testobj)/$*.tmp; \ - if [ $$type != 'failure' ]; then \ - $(MAKE) V=$(V) Q=$(Q) COV=$(COV) JUNIT_OUTPUT=y "run-$*"; \ - fi - - -TESTS_BUILD_XML_FILE := $(testobj)/junit-tests-build.xml - -$(TESTS_BUILD_XML_FILE): clean-junit.xml-unit-tests $(addprefix try-,$(alltests)) - mkdir -p $(dir $@) - echo '' > $@ - for tst in $(alltests); do \ - cat $(testobj)/$$tst.tmp >> $@; \ - done - echo "" >> $@ - -junit.xml-unit-tests: $(TESTS_BUILD_XML_FILE) - -clean-junit.xml-unit-tests: - rm -f $(TESTS_BUILD_XML_FILE) - - -# Build a code coverage report by collecting all the gcov files into a single -# report. If COV is not set, this might be a user error, and they're trying -# to generate a coverage report without first having built and run the code -# with code coverage. So instead of silently correcting it by adding COV=1, -# let's flag it to the user so they can be sure they're doing the thing they -# want to do. - -.PHONY: coverage-report clean-coverage-report - -ifeq ($(COV),1) -coverage-report: - lcov -o $(testobj)/tests.info -c -d $(testobj) --exclude '$(testsrc)/*' - genhtml -q -o $(testobj)/$(coverage_dir) -t "coreboot unit tests" \ - -s $(testobj)/tests.info - -clean-coverage-report: - rm -Rf $(testobj)/$(coverage_dir) -else -coverage-report: - COV=1 V=$(V) $(MAKE) coverage-report - -clean-coverage-report: - COV=1 V=$(V) $(MAKE) clean-coverage-report -endif - -unit-tests: build-unit-tests run-unit-tests - -build-unit-tests: $(test-bins) - -run-unit-tests: $(alltests) - if [ `find $(testobj) -name '*.failed' | wc -l` -gt 0 ]; then \ - echo "**********************"; \ - echo " TESTS FAILED"; \ - echo "**********************"; \ - exit 1; \ - else \ - echo "**********************"; \ - echo " ALL TESTS PASSED"; \ - echo "**********************"; \ - exit 0; \ - fi - -$(addprefix clean-,$(alltests)): clean-%: - rm -rf $(testobj)/$* - -clean-unit-tests: - rm -rf $(testobj) - -list-unit-tests: - @echo "unit-tests:" - for t in $(sort $(alltests)); do \ - echo " $$t"; \ - done - -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 ' 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' - @echo ' - Build and run single unit-test' - @echo ' clean- - Remove single unit-test build artifacts' - @echo ' coverage-report - Generate a code coverage report' - @echo ' clean-coverage-report - Remove the code coverage report' - @echo diff --git a/tests/Makefile.mk b/tests/Makefile.mk new file mode 100644 index 000000000000..584b4c0c9dae --- /dev/null +++ b/tests/Makefile.mk @@ -0,0 +1,196 @@ +# SPDX-License-Identifier: GPL-2.0-only + +# Place the build output in one of two places depending on COV, so that code +# built with code coverage never mixes with code built without code coverage. +ifeq ($(COV),1) +testobj := $(obj)/coverage +else +testobj := $(obj)/tests +endif + +objutil := $(testobj)/util + +include $(top)/tests/Makefile.common + +# Enable GDB debug build if requested +GDB_DEBUG ?= 0 +ifneq ($(GDB_DEBUG),0) +TEST_CFLAGS += -g -Og +endif + +# Enable code coverage if requested +ifeq ($(COV),1) +TEST_CFLAGS += --coverage +TEST_LDFLAGS += --coverage +endif + +stages := decompressor bootblock romstage smm verstage +stages += ramstage rmodule postcar libagesa + +alltests := +subdirs := tests/arch tests/acpi tests/commonlib tests/console tests/cpu +subdirs += tests/device tests/drivers tests/ec tests/lib +subdirs += tests/mainboard tests/northbridge tests/security tests/soc +subdirs += tests/southbridge tests/superio tests/vendorcode + +define tests-handler +alltests += $(1)$(2) +$(foreach attribute,$(attributes), + $(eval $(1)$(2)-$(attribute) += $($(2)-$(attribute)))) +$(foreach attribute,$(attributes), + $(eval $(2)-$(attribute) := )) + +# Sanity check for stage attribute value +$(eval $(1)$(2)-stage := $(if $($(1)$(2)-stage),$($(1)$(2)-stage),ramstage)) +$(if $(findstring $($(1)$(2)-stage), $(stages)),, + $(error Wrong $(1)$(2)-stage value $($(1)$(2)-stage). \ + Check your $(dir $(1)$(2))Makefile.inc)) +endef + +$(call add-special-class, tests) +$(call evaluate_subdirs) + +$(foreach test, $(alltests), \ + $(eval $(test)-srcobjs := $(addprefix $(testobj)/$(test)/, \ + $(patsubst %.c,%.o,$(filter src/%,$($(test)-srcs))))) \ + $(eval $(test)-sysobjs := $(addprefix $(testobj)/$(test)/, \ + $(patsubst %.c,%.o,$($(test)-syssrcs)))) \ + $(eval $(test)-objs := $(addprefix $(testobj)/$(test)/, \ + $(patsubst %.c,%.o,$($(test)-srcs))))) +$(foreach test, $(alltests), \ + $(eval $(test)-bin := $(testobj)/$(test)/run)) +$(foreach test, $(alltests), \ + $(eval $(call TEST_CC_template,$(test)))) + +$(foreach test, $(alltests), \ + $(eval all-test-objs += $($(test)-objs))) +$(foreach test, $(alltests), \ + $(eval test-bins += $($(test)-bin))) + +DEPENDENCIES += $(addsuffix .d,$(basename $(all-test-objs))) +-include $(DEPENDENCIES) + +.PHONY: $(alltests) $(addprefix clean-,$(alltests)) $(addprefix try-,$(alltests)) +.PHONY: $(addprefix build-,$(alltests)) $(addprefix run-,$(alltests)) +.PHONY: unit-tests build-unit-tests run-unit-tests clean-unit-tests +.PHONY: junit.xml-unit-tests clean-junit.xml-unit-tests + +# %g in CMOCKA_XML_FILE will be replaced with "__TEST_NAME__()" +# by macro cb_run_group_tests(), which should be used for running tests. +# __TEST_NAME__ contains test name including path e.g. tests_lib_rtc-test +ifeq ($(JUNIT_OUTPUT),y) +$(addprefix run-,$(alltests)): export CMOCKA_MESSAGE_OUTPUT=xml +$(addprefix run-,$(alltests)): export CMOCKA_XML_FILE=$(testobj)/junit-%g.xml +endif + +$(addprefix run-,$(alltests)): run-%: $$(%-bin) + rm -f $(testobj)/junit-$(subst /,_,$(patsubst $(testobj)/%/,%,$(dir $^)))\(*\).xml + rm -f $(testobj)/$(subst /,_,$^).failed + -$^ || echo failed > $(testobj)/$(subst /,_,$^).failed + +$(addprefix build-,$(alltests)): build-%: $$(%-bin) + +$(alltests): run-$$(@) + +$(addprefix try-,$(alltests)): try-%: clean-% $(TEST_COMMON_DEPENDENCIES) + mkdir -p $(testobj)/$* + echo "" >> $(testobj)/$*.tmp; \ + $(MAKE) V=$(V) Q=$(Q) COV=$(COV) JUNIT_OUTPUT=y "build-$*" >> $(testobj)/$*.tmp.2 2>&1 \ + && type="system-out" || type="failure"; \ + if [ $$type = "failure" ]; then \ + echo "" >> $(testobj)/$*.tmp; \ + else \ + echo "<$$type>" >> $(testobj)/$*.tmp; \ + fi; \ + echo '> $(testobj)/$*.tmp; \ + cat $(testobj)/$*.tmp.2 >> $(testobj)/$*.tmp; \ + echo "]]>" >> $(testobj)/$*.tmp; \ + rm -f $(testobj)/$*.tmp.2; \ + echo "" >> $(testobj)/$*.tmp; \ + if [ $$type != 'failure' ]; then \ + $(MAKE) V=$(V) Q=$(Q) COV=$(COV) JUNIT_OUTPUT=y "run-$*"; \ + fi + + +TESTS_BUILD_XML_FILE := $(testobj)/junit-tests-build.xml + +$(TESTS_BUILD_XML_FILE): clean-junit.xml-unit-tests $(addprefix try-,$(alltests)) + mkdir -p $(dir $@) + echo '' > $@ + for tst in $(alltests); do \ + cat $(testobj)/$$tst.tmp >> $@; \ + done + echo "" >> $@ + +junit.xml-unit-tests: $(TESTS_BUILD_XML_FILE) + +clean-junit.xml-unit-tests: + rm -f $(TESTS_BUILD_XML_FILE) + + +# Build a code coverage report by collecting all the gcov files into a single +# report. If COV is not set, this might be a user error, and they're trying +# to generate a coverage report without first having built and run the code +# with code coverage. So instead of silently correcting it by adding COV=1, +# let's flag it to the user so they can be sure they're doing the thing they +# want to do. + +.PHONY: coverage-report clean-coverage-report + +ifeq ($(COV),1) +coverage-report: + lcov -o $(testobj)/tests.info -c -d $(testobj) --exclude '$(testsrc)/*' + genhtml -q -o $(testobj)/$(coverage_dir) -t "coreboot unit tests" \ + -s $(testobj)/tests.info + +clean-coverage-report: + rm -Rf $(testobj)/$(coverage_dir) +else +coverage-report: + COV=1 V=$(V) $(MAKE) coverage-report + +clean-coverage-report: + COV=1 V=$(V) $(MAKE) clean-coverage-report +endif + +unit-tests: build-unit-tests run-unit-tests + +build-unit-tests: $(test-bins) + +run-unit-tests: $(alltests) + if [ `find $(testobj) -name '*.failed' | wc -l` -gt 0 ]; then \ + echo "**********************"; \ + echo " TESTS FAILED"; \ + echo "**********************"; \ + exit 1; \ + else \ + echo "**********************"; \ + echo " ALL TESTS PASSED"; \ + echo "**********************"; \ + exit 0; \ + fi + +$(addprefix clean-,$(alltests)): clean-%: + rm -rf $(testobj)/$* + +clean-unit-tests: + rm -rf $(testobj) + +list-unit-tests: + @echo "unit-tests:" + for t in $(sort $(alltests)); do \ + echo " $$t"; \ + done + +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 ' 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' + @echo ' - Build and run single unit-test' + @echo ' clean- - Remove single unit-test build artifacts' + @echo ' coverage-report - Generate a code coverage report' + @echo ' clean-coverage-report - Remove the code coverage report' + @echo -- cgit v1.2.3