我是一名从事C++项目开发的人员,这个项目的结构类似于以下内容:
--- /src
|--comms
|--utils
|--interfaces
…
CMakeList.txt
--- /test
|---test1/
|--main.cpp
|--CMakelists.txt
--CMakeLists.txt
我需要控制我的测试覆盖率,为此我使用以下方式的GCOV和LCOV:
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")
Run test, generating the corresponding
.gcda
files.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.From the directory in which files
.gcno
and.gcda
are located I do the following:lcov –c –d . –o name.info
Generate the HTML report by using:
genhtml name.info.
然而,当我尝试为全局项目生成索引.html(覆盖率报告)时,它不起作用。
我使用一个Shell脚本,创建与我的项目相同的文件夹结构,并将每个.gcno和.gcda复制到相应的目录中。然后执行命令lcov和genhtml,但是index.html不包含所有项目覆盖范围。
我希望能得到任何帮助。