summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJakub Czapiga <jacz@semihalf.com>2022-09-06 10:42:16 +0200
committerPatrick Georgi <patrick@coreboot.org>2022-09-21 14:06:42 +0000
commita0e36d8cbaad6ead0102721fdedb3b4c50f0273c (patch)
tree6c62d045a8992ac1b786cf2be09c6560d6a61cae /tests
parentb525ea726b257ca6b4e03f4f4427f92046722e26 (diff)
tests: Add support for tests build failures detection
This patch introduces new target: junit.xml-unit-tests, which builds and runs unit-tests. It also creates build log containing build logs. This feature allows for one to see build failures in Jenkins dashboard. Signed-off-by: Jakub Czapiga <jacz@semihalf.com> Change-Id: I94184379dcc2ac10f1a47f4a9d205cacbeb640fe Reviewed-on: https://review.coreboot.org/c/coreboot/+/67372 Reviewed-by: Julius Werner <jwerner@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.common2
-rw-r--r--tests/Makefile.inc50
2 files changed, 48 insertions, 4 deletions
diff --git a/tests/Makefile.common b/tests/Makefile.common
index 04bd6c94c3..595f870aca 100644
--- a/tests/Makefile.common
+++ b/tests/Makefile.common
@@ -170,3 +170,5 @@ $(TEST_KCONFIG_AUTOHEADER): $(TEST_DOTCONFIG) $(objutil)/kconfig/conf
$(TEST_KCONFIG_AUTOCONFIG): $(TEST_KCONFIG_AUTOHEADER)
true
+
+TEST_COMMON_DEPENDENCIES := $(CMOCKA_LIB) $(TEST_KCONFIG_AUTOCONFIG)
diff --git a/tests/Makefile.inc b/tests/Makefile.inc
index 10caf0a1e1..2c1a30bb8d 100644
--- a/tests/Makefile.inc
+++ b/tests/Makefile.inc
@@ -60,22 +60,64 @@ $(foreach test, $(alltests), \
DEPENDENCIES += $(addsuffix .d,$(basename $(all-test-objs)))
-include $(DEPENDENCIES)
-.PHONY: $(alltests) $(addprefix clean-,$(alltests))
+.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__(<test-group-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)
-$(alltests): export CMOCKA_MESSAGE_OUTPUT=xml
-$(alltests): export CMOCKA_XML_FILE=$(testobj)/junit-%g.xml
+$(addprefix run-,$(alltests)): export CMOCKA_MESSAGE_OUTPUT=xml
+$(addprefix run-,$(alltests)): export CMOCKA_XML_FILE=$(testobj)/junit-%g.xml
endif
-$(alltests): $$($$(@)-bin)
+$(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 "<testcase classname='coreboot_build_unit_test' name='$*'>" >> $(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 "<failure type='buildFailed'>" >> $(testobj)/$*.tmp; \
+ else \
+ echo "<$$type>" >> $(testobj)/$*.tmp; \
+ fi; \
+ echo '<![CDATA[' >> $(testobj)/$*.tmp; \
+ cat $(testobj)/$*.tmp.2 >> $(testobj)/$*.tmp; \
+ echo "]]></$$type>" >> $(testobj)/$*.tmp; \
+ rm -f $(testobj)/$*.tmp.2; \
+ echo "</testcase>" >> $(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 '<?xml version="1.0" encoding="utf-8"?><testsuite>' > $@
+ for tst in $(alltests); do \
+ cat $(testobj)/$$tst.tmp >> $@; \
+ done
+ echo "</testsuite>" >> $@
+
+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