Can lcov/genhtml show files that were never executed?
Asked Answered
K

2

9

How can I make lcov and genhtml show files that are not linked / loaded? I'm using it to show test coverage and I would like to see every source file appear in the HTML report, even if it has zero coverage. That way I can use lcov to identify source files that are missing tests. The missing source files have a .gcno file created for them, but not a .gcda file.

Khajeh answered 26/5, 2017 at 13:42 Comment(1)
Can you provide a minimal example code which replicates this behaviour?Brest
H
8

If you want to see all files you have to create a baseline coverage data file with -i option. After capturing you data you have to combine the two files with -a option.

There is an example in lcov man page (https://linux.die.net/man/1/lcov):

Capture initial zero coverage data.

Run lcov with -c and this option on the directories containing .bb, .bbg or .gcno files before running any test case. The result is a "baseline" coverage data file that contains zero coverage for every instrumented line. Combine this data file (using lcov -a) with coverage data files captured after a test run to ensure that the percentage of total lines covered is correct even when not all source code files were loaded during the test.

Recommended procedure when capturing data for a test case:

  1. create baseline coverage data file

    lcov -c -i -d appdir -o app_base.info

  2. perform test

    appdir/test

  3. create test coverage data file

    lcov -c -d appdir -o app_test.info

  4. combine baseline and test coverage data

    lcov -a app_base.info -a app_test.info -o app_total.info

You then have to use the app_total.info as source for genhtml.

Hypothecate answered 14/7, 2017 at 14:45 Comment(0)
V
0

It seems that touch an empty gcda file for each gcno file that not covered works fine. It works for me. And it is faster, as lcov runs very slow and we only need to run lcov once in this solution.

Vegetable answered 19/4 at 2:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.