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

喜夏-厌秋 提交于 2021-02-09 07:31:37

问题


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 :

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?


回答1:


The following code solved the issue

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


来源:https://stackoverflow.com/questions/48040580/exclude-the-header-files-coverage-while-doing-the-unitests-for-cpp-files-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!