Is there a way to focus lcov code coverage reports to just one or two directories?

后端 未结 3 1376
长情又很酷
长情又很酷 2020-12-24 02:03

I recently started using lcov to visualize my code coverage. It\'s a great tool.

One thing I\'m noticing is that it generates code coverage reports for all the file

相关标签:
3条回答
  • 2020-12-24 02:25

    lcov supports a command line argument --remove to do exactly what you are asking for.

    0 讨论(0)
  • 2020-12-24 02:30

    A possible approach is to constrain which files are compiled with the coverage flags (-fprofile-arcs -ftest-coverage). If you don't want to engineer your make file system to be selective about which files are built with test instrumentation, the following trick might work for you:

    • Build your application without instrumentation.
    • Remove the .o files for source that you want to instrument
    • Turn on instrumentation and rebuild. Only the deleted object files will be rebuilt with instrumentation.
    • Run lcov

    This should result in only the targeted areas emitting gcov artifacts, which are blindly consumed by the lcov scripts.

    0 讨论(0)
  • 2020-12-24 02:40

    I used the --no-external flag together with the --directory flag to exclude unwanted files.

    The definition of external from the man:

    External source files are files which are not located in one of the directories specified by --directory or --base-directory.

    So my command looked like this:

    $ lcov  --directory src -c -o report.info --no-external
    Capturing coverage data from src
    Found gcov version: 4.2.1
    Scanning src for .gcda files ...
    Found 4 data files in src
    Processing src/C####.gcda
      ignoring data for external file /usr/include/c++/4.2.1/bits/allocator.h
    
    0 讨论(0)
提交回复
热议问题