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.
Enable code coverage in your unit test build by setting the environment
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
depending on whether
COV=1 is set in the environment.
All of the unit test targets are available with and without
unit-tests(which is just
There are two new
coverage-reportgenerates a code coverage report from all of the GCOV data (
*.gcnofiles) in the build directory. To view the coverage report, open
build/coverage/coverage_reports/index.htmlin your web browser.
clean-coverage-reportdeletes just the coverage report.
clean-coverage-report targets automatically set
COV=1 if it is not already set in the environment.
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
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
As a demonstration that building with and without coverage uses different output directories:
make build-unit-testsbuilds unit tests without code coverage into
COV=1 make clean-unit-testscleans
make build-unit-testsdoesn’t need to build anything in
build/tests, because those files weren’t affected by the previous