Search code examples
c++code-coveragegoogletestlcov

Exclude the header files coverage while doing the unitests for .cpp files using lcov


I have generated the html code coverage for unittest. The problem is that it generates the code coverage for everything that is defined in the include preprocessor.

The codecoverage for the unittest is inside the unitTest link of the code coverage report. I only need the unitTest

I also remove everything else and keep the gcda and gcno files of the test file before generating the code coverage but it still doesnot help. The code that does this is :

find obj/ ! -name '*_unittests*' -type f -delete

The code coverage report is show below : Coverage Report

I tried to add LCOV_EXCL_START and LCOV_EXCL_STOP at the beginning and end of include preprocessors as follows but it still doesnot help.

LCOV_EXCL_START
#include <inttypes.h> 
#include "../src/generators/buffersss.h" 
#include "gtest/gtest.h"
#include <getopt.h>  
LCOV_EXCL_STOP
Test code goes here.....

What am i doing wrong here?


Solution

  • The following code solved the issue

    lcov --remove coverage.info '/usr/include/*' 'src/*' -o filtered_coverage.info