C++ using GCOV/LCOV in a CMake project

独自空忆成欢 提交于 2019-12-06 00:07:47

问题


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

I do need to control the coverage of my tests and for this purpose I use GCOV and LCOV in this way:

  1. 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")
    
  2. 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.

  3. From the directory in which files .gcno and .gcda are located I do the following:

    lcov –c –d . –o name.info      
    
  4. Generate the HTML report by using:

    genhtml  name.info.
    

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.

However when I try to generate the index.html (coverage report) for the global project, it doesn't work.

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.

I would appreciate any help.


回答1:


try to put --ignore-errors with genhtml command like that :

genhtml -o out name.info --ignore-errors source


来源:https://stackoverflow.com/questions/30345686/c-using-gcov-lcov-in-a-cmake-project

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