tests: enable code coverage for unit tests

Add a new `coverage-unit-tests` make target that builds the unit
tests for code coverage, runs the tests, and generates a coverage
report.

Signed-off-by: Paul Fagerburg <pfagerburg@google.com>
Change-Id: I6ea780ee9e246c0bb8c35b8e0de4252431dabbff
Reviewed-on: https://review.coreboot.org/c/coreboot/+/52444
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Jakub Czapiga <jacz@semihalf.com>
This commit is contained in:
Paul Fagerburg 2021-04-16 11:36:25 -06:00 committed by Patrick Georgi
parent 60243501f2
commit 045fbf138a
1 changed files with 16 additions and 5 deletions

View File

@ -154,6 +154,15 @@ $(alltests): $$($$(@)-bin)
rm -f $(testobj)/junit-$(subst /,_,$^).xml $(testobj)/$(subst /,_,$^).failed rm -f $(testobj)/junit-$(subst /,_,$^).xml $(testobj)/$(subst /,_,$^).failed
-./$^ || echo failed > $(testobj)/$(subst /,_,$^).failed -./$^ || echo failed > $(testobj)/$(subst /,_,$^).failed
.PHONY: coverage-unit-tests
coverage-unit-tests: TEST_CFLAGS += --coverage
coverage-unit-tests: TEST_LDFLAGS += --coverage
coverage-unit-tests: clean-unit-tests unit-tests
lcov -o $(testobj)/tests.info -c -d $(testobj) --exclude '*/$(testobj)/*'
genhtml -q -o build/tests/coverage_rpt -t "coreboot unit tests" \
-s $(testobj)/tests.info
unit-tests: build-unit-tests run-unit-tests unit-tests: build-unit-tests run-unit-tests
build-unit-tests: $(test-bins) build-unit-tests: $(test-bins)
@ -190,4 +199,6 @@ help-unit-tests help::
@echo ' list-unit-tests - List all unit-tests' @echo ' list-unit-tests - List all unit-tests'
@echo ' <unit-test> - Build and run single unit-test' @echo ' <unit-test> - Build and run single unit-test'
@echo ' clean-<unit-test> - Remove single unit-test build artifacts' @echo ' clean-<unit-test> - Remove single unit-test build artifacts'
@echo ' coverage-unit-tests - Build unit tests for code coverage and'
@echo ' generate a code coverage report'
@echo @echo