问题描述
我正在一个C ++项目中,其结构类似于以下内容:
I'm working in a C++ Project with a structure similiar to the following:
--- /src
|--comms
|--utils
|--interfaces
…
CMakeList.txt
--- /test
|---test1/
|--main.cpp
|--CMakelists.txt
--CMakeLists.txt
我确实需要控制测试的覆盖范围,为此,我以这种方式使用GCOV和LCOV:
I do need to control the coverage of my tests and for this purpose I use GCOV and LCOV in this way:
-
在所有CMakeLists.txt中启用覆盖标志,以生成.gcno文件.
Enable coverage flags in all CMakeLists.txt to let the generation of .gcno files.
SET(CMAKE_CXX_FLAGS "-g -O0 -Wall -fprofile-arcs -ftest-coverage")
SET(CMAKE_C_FLAGS "-g -O0 -Wall -W -fprofile-arcs -ftest-coverage")
SET(CMAKE_EXE_LINKER_FLAGS "-fprofile-arcs -ftest-coverage")
运行测试,生成相应的.gcda
文件.
这时,文件gcno和gcda与相应的.o
文件位于同一目录中.我无法移动这些文件,因为如果这样做,报告覆盖率生成将无法正常工作.
At this point, files gcno and gcda are located in the same directory as the corresponding .o
file. I cannot move these files, because if I do it the report coverage generation doesn’t work.
从文件.gcno
和.gcda
所在的目录中执行以下操作:
From the directory in which files .gcno
and .gcda
are located I do the following:
lcov –c –d . –o name.info
使用以下方法生成HTML报告:
Generate the HTML report by using:
genhtml name.info.
编译项目时,由于以下事实,我复制了.gcno
文件,因为在编译测试时,它们需要重新编译其依赖项(comms,utils等),因为我不会为这些依赖项生成库.我认为如果不使用库,就无法避免这种情况.
When I compile my project, I have duplicated .gcno
files due to the fact that when tests are compiled they need to recompile their dependencies (comms, utils, …) because I don't generate libraries for theses dependencies. I think there is no way to avoid that if I don't use libraries.
但是,当我尝试为全局项目生成index.html
(覆盖率报告)时,它不起作用.
However when I try to generate the index.html
(coverage report) for the global project, it doesn't work.
我使用一个Shell脚本创建一个与我的项目相同的文件夹结构,并将每个.gcno
和.gcda
复制到相应的目录中.而且我执行了lcov
和genhtml
命令,尽管index.html
不不包括所有项目内容.
I use a Shell script that creates the same folder structure of my project and copy each .gcno
and .gcda
to the corresponding directory. And I execute the commands lcov
and genhtml
, nevertheless the index.html
does not include all project coverage.
我将不胜感激.
推荐答案
尝试使用genhtml命令放置--ignore-errors
:
try to put --ignore-errors
with genhtml command like that :
genhtml -o out name.info --ignore-errors source
这篇关于在CMake项目中使用GCOV/LCOV的C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!