Patrick Georgi submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Jakub Czapiga: Looks good to me, approved
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>
---
M tests/Makefile.inc
1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/tests/Makefile.inc b/tests/Makefile.inc
index fd3cd9f..44e3c69 100644
--- a/tests/Makefile.inc
+++ b/tests/Makefile.inc
@@ -154,6 +154,15 @@
rm -f $(testobj)/junit-$(subst /,_,$^).xml $(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

build-unit-tests: $(test-bins)
@@ -185,9 +194,11 @@

help-unit-tests help::
@echo '*** coreboot unit-tests targets ***'
- @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 ' <unit-test> - Build and run single unit-test'
- @echo ' clean-<unit-test> - Remove single unit-test build artifacts'
+ @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 ' <unit-test> - Build and run single unit-test'
+ @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

To view, visit change 52444. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I6ea780ee9e246c0bb8c35b8e0de4252431dabbff
Gerrit-Change-Number: 52444
Gerrit-PatchSet: 5
Gerrit-Owner: Paul Fagerburg <pfagerburg@chromium.org>
Gerrit-Reviewer: Jakub Czapiga <jacz@semihalf.com>
Gerrit-Reviewer: Martin Roth <martinroth@google.com>
Gerrit-Reviewer: Patrick Georgi <pgeorgi@google.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Angel Pons <th3fanbus@gmail.com>
Gerrit-CC: Paul Menzel <paulepanter@mailbox.org>
Gerrit-MessageType: merged