4

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?

Enjal Parajuli
  • 193
  • 1
  • 11

2 Answers2

4

The following code solved the issue

lcov --remove coverage.info '/usr/include/*' 'src/*' -o filtered_coverage.info
Enjal Parajuli
  • 193
  • 1
  • 11
0

For CMake users I strongly suggest using:

https://github.com/bilke/cmake-modules/blob/master/CodeCoverage.cmake

e.g. macro setup_target_for_coverage_lcov and its EXCLUDE parameter.

Quarra
  • 2,527
  • 1
  • 19
  • 27