summaryrefslogtreecommitdiffstats
path: root/Documentation/technotes
diff options
context:
space:
mode:
authorPaul Fagerburg <pfagerburg@google.com>2021-05-11 09:56:48 -0600
committerPaul Fagerburg <pfagerburg@chromium.org>2021-05-19 19:56:02 +0000
commitde6cbac3c4e44de797bc2a4755fb765cf5a49f55 (patch)
treea67d8457e2463e67e5d3d35970f23c650dea6f8a /Documentation/technotes
parent12c0542e6fa54a3875c5786d9527bba5ffa8c45c (diff)
downloadcoreboot-de6cbac3c4e44de797bc2a4755fb765cf5a49f55.tar.gz
coreboot-de6cbac3c4e44de797bc2a4755fb765cf5a49f55.tar.bz2
coreboot-de6cbac3c4e44de797bc2a4755fb765cf5a49f55.zip
tests: improve code coverage support
Fix the exclusion path for lcov; it should exclude the directory with source code, not object files. Use the COV environment variable to * control whether we build for coverage or not * select the output directory Add a separate target for generating the report, so we can get a report for all of the tests together or just a single test. Add documentation. Signed-off-by: Paul Fagerburg <pfagerburg@google.com> Change-Id: I2bd2bfdedfab291aabeaa968c10b17e9b61c9c0a Reviewed-on: https://review.coreboot.org/c/coreboot/+/54072 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Jakub Czapiga <jacz@semihalf.com>
Diffstat (limited to 'Documentation/technotes')
-rw-r--r--Documentation/technotes/2021-05-code-coverage.md56
1 files changed, 56 insertions, 0 deletions
diff --git a/Documentation/technotes/2021-05-code-coverage.md b/Documentation/technotes/2021-05-code-coverage.md
new file mode 100644
index 000000000000..ec7f4cb5f979
--- /dev/null
+++ b/Documentation/technotes/2021-05-code-coverage.md
@@ -0,0 +1,56 @@
+# 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
+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-tests`
+* `build-unit-tests`
+* `run-unit-tests`
+* `unit-tests` (which is just `build-unit-tests` followed by `run-unit-tests`)
+
+There are two new `make` targets:
+* `coverage-report` generates a code coverage report from all of the
+GCOV data (`*.gcda` and `*.gcno` files) in the build directory. To view the
+coverage report, open `build/coverage/coverage_reports/index.html` in your web
+browser.
+* `clean-coverage-report` deletes 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:
+1. `make build-unit-tests` builds unit tests without code coverage into
+`build/tests`.
+2. `COV=1 make clean-unit-tests` cleans `build/coverage`
+3. `make build-unit-tests` doesn't need to build anything in `build/tests`,
+because those files weren't affected by the previous `clean-unit-tests`.