lcov

lcov ignores files not included in unit test project


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?


Solution

  • 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: