Reputation: 365
My project is being cross-compiled for an ARM target. However my unit tests run on the development host for speed. So naturally I cannot unit-test some files.
I recently set up code coverage measurement with gcov/lcov. It is completely ignoring the untested files, so my coverage is near 100 % although I know that it should be much lower.
I read about lcov's --capture --initial
options, but I think I cannot run them on the source files that are not included in the unit test project.
How can I include the untested files with 0 % coverage and the correct line count?
Upvotes: 0
Views: 184
Reputation: 365
I found the following solution. It involves cross-compiling my main project twice, once for normal usage and a second time with coverage information.
I take these steps to measure the coverage:
build-main
).build-main-coverage
).lcov --capture --initial --directory build-main-coverage --output-file baseline-coverage.info
build-unit-test
).lcov --capture --directory build-unit-test --output-file coverage.info
lcov --add-tracefile baseline-coverage.info --add-tracefile coverage.info --output-file coverage.info
Upvotes: 0
Reputation: 91
The --initial
and/or --all
option tells lcov --capture
to look at .gcno files (compile-time coverage data) that do not also have a .gcda file (runtime coverage data).
There will be no runtime data if the corresponding compilation unit is not used in your executable.
As you point out: using either of those options will tell the tool to look at both used and unused sources.
Upvotes: 0