Code coverage requires `lcov`, so update the docs to call it out specifically. Signed-off-by: Paul Fagerburg <pfagerburg@google.com> Change-Id: Ie2898faa5188a7174c4e56ba34f1a4f02f939b03 Reviewed-on: https://review.coreboot.org/c/coreboot/+/58633 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Martin Roth <martinroth@google.com>
2.4 KiB
Unit Test Code Coverage
Code coverage for the coreboot unit tests allows us to see what lines of code in the coreboot library are covered by unit tests, and allows a test author to see where they need to add test cases for additional coverage.
Code coverage requires lcov; install the tool if necessary by
sudo apt install lcov or the equivalent for your system.
Enable code coverage in your unit test build by setting the environment
variable COV to 1; either export COV=1 in your shell, or add it to your
make command, e.g. COV=1 make unit-tests.
The build output directory is either build/tests or build/coverage,
depending on whether COV=1 is set in the environment.
All of the unit test targets are available with and without COV=1
clean-unit-testsbuild-unit-testsrun-unit-testsunit-tests(which is justbuild-unit-testsfollowed byrun-unit-tests)
There are two new make targets:
coverage-reportgenerates a code coverage report from all of the GCOV data (*.gcdaand*.gcnofiles) in the build directory. To view the coverage report, openbuild/coverage/coverage_reports/index.htmlin your web browser.clean-coverage-reportdeletes just the coverage report.
The coverage-report and clean-coverage-report targets automatically set
COV=1 if it is not already set in the environment.
Examples
COV=1 make unit-tests coverage-report builds all of the unit tests with code
coverage, runs the unit tests, and generates the code coverage report.
COV=1 make build-unit-tests builds all of the unit tests with code coverage.
COV=1 make run-unit-tests runs the unit tests, building them with code
coverage if they are out-of-date.
COV=1 make coverage-report creates the code coverage report. This
target does not explicitly depend on the tests being built and run; it gathers
the code coverage data from the output directory, which it assumes already
exists.
COV=1 make tests/lib/uuid-test coverage-report builds the uuid test
with code coverage, runs it, and generates a code coverage report just for
that test.
As a demonstration that building with and without coverage uses different output directories:
make build-unit-testsbuilds unit tests without code coverage intobuild/tests.COV=1 make clean-unit-testscleansbuild/coveragemake build-unit-testsdoesn't need to build anything inbuild/tests, because those files weren't affected by the previousclean-unit-tests.