tests: Fix JUNIT_OUTPUT=y to write to files instead of stderr

CB:57144 broke JUNIT_OUTPUT=y, and unit-tests were writing to stderr
instead of selected XML files, because test name used for XML file
creation contains test path. Build system did not create necessary
directiories, which CMocka required to create output files.
This commit fixes writing to XML files with JUNIT_OUTPUT=y, but had to
sacrifice path in test name, as it was causing a lot of problems
(because CMocka does not know, how to write multiple test groups to one
XML file, so it uses test group name [here __TEST_NAME__(test_group)] as
part of output filename).
Example:
 Test: tests/lib/rtc-test
 Output file:
 `build/tests/junit-tests_lib_rtc-test(tests).xml

Change-Id: I09891aca923bf1271cafeaa09f89b6539022709c
Signed-off-by: Jakub Czapiga <jacz@semihalf.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/58163
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
This commit is contained in:
Jakub Czapiga 2021-10-07 09:06:42 +00:00 committed by Felix Held
parent 64fb9fc53e
commit 4d9694e6bc
1 changed files with 7 additions and 3 deletions

View File

@ -141,7 +141,7 @@ $$($(1)-config-file): $(TEST_KCONFIG_AUTOHEADER)
$($(1)-objs): TEST_CFLAGS += -I$$(dir $$($(1)-config-file)) \
-D__$$(shell echo $$($(1)-stage) | tr '[:lower:]' '[:upper:]')__ \
-D__TEST_NAME__=\"$(1)\"
-D__TEST_NAME__=\"$(subst /,_,$(1))\"
# Give us a way to distinguish between coreboot source files and test files in code.
$($(1)-srcobjs): TEST_CFLAGS += -D__TEST_SRCOBJ__
@ -220,13 +220,17 @@ $(TEST_KCONFIG_AUTOCONFIG): $(TEST_KCONFIG_AUTOHEADER)
.PHONY: $(alltests) $(addprefix clean-,$(alltests))
.PHONY: unit-tests build-unit-tests run-unit-tests clean-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-$(subst /,_,$^)-%g.xml
$(alltests): export CMOCKA_XML_FILE=$(testobj)/junit-%g.xml
endif
$(alltests): $$($$(@)-bin)
rm -f $(testobj)/junit-$(subst /,_,$^).xml $(testobj)/$(subst /,_,$^).failed
rm -f $(testobj)/junit-$(subst /,_,$(patsubst $(testobj)/%/,%,$(dir $^)))\(*\).xml
rm -f $(testobj)/$(subst /,_,$^).failed
-./$^ || echo failed > $(testobj)/$(subst /,_,$^).failed
# Build a code coverage report by collecting all the gcov files into a single