我正在尝试使用gcc 4.8.2和lcov 1.10获得测试的html覆盖率。我确信我的源代码,对象和gcov文件位于同一个地方,并且我从运行编译器的目录运行lcov。
我收到以下错误:
$ lcov --capture --directory "objs/i386/MinGW/Os_SingleCore_SC3
/IocTest_tests_SingleCore_SC3" --output-file coverage.info
Capturing coverage data from objs/i386/MinGW/Os_SingleCore_SC3/IocTest_tests_SingleCore_SC3
Found gcov version: 4.8.2
Scanning objs/i386/MinGW/Os_SingleCore_SC3/IocTest_tests_SingleCore_SC3 for .gcda files ...
Found 3 data files in objs/i386/MinGW/Os_SingleCore_SC3/IocTest_tests_SingleCore_SC3
Processing IocTest_tests_SingleCore_SC3/IocTest.gcda
geninfo: WARNING: cannot find an entry for objs#i386#MinGW#Os_SingleCore_SC3#IocTest_tests_SingleCore_SC3#IocTest.c.gcov in .gcno file, skipping file!
geninfo: WARNING: no data found for /cygdrive/e/testRepo/WinPort-Os-cd354a27d1d9/WinPort/Os/Tests/OS_REQ/objs\i386\MinGW\Os_SingleCore_SC3\IocTest_tests_SingleCore_SC3\IocTest.c
Processing IocTest_tests_SingleCore_SC3/OS_REQ.gcda
geninfo: WARNING: cannot find an entry for objs#i386#MinGW#Os_SingleCore_SC3#IocTest_tests_SingleCore_SC3#OS_REQ.c.gcov in .gcno file, skipping file!
geninfo: WARNING: no data found for /cygdrive/e/testRepo/WinPort-Os-cd354a27d1d9/WinPort/Os/Tests/OS_REQ/objs\i386\MinGW\Os_SingleCore_SC3\IocTest_tests_SingleCore_SC3\OS_REQ.c
Processing IocTest_tests_SingleCore_SC3/TestMain.gcda
geninfo: WARNING: cannot find an entry for objs#i386#MinGW#Os_SingleCore_SC3#IocTest_tests_SingleCore_SC3#TestMain.c.gcov in .gcno file, skipping file!
geninfo: WARNING: no data found for /cygdrive/e/testRepo/WinPort-Os-cd354a27d1d9/WinPort/Os/Tests/OS_REQ/objs\i386\MinGW\Os_SingleCore_SC3\IocTest_tests_SingleCore_SC3\TestMain.c
Finished .info-file creation
答案 0 :(得分:0)
首先,我建议检查 gcov 是否返回正确的覆盖率数据。 意味着需要运行gcov工具并检查* .gcov文件以获得实际结果。如果它返回任何覆盖范围。
其次,您可以使用 - base-directory ,例如
$ lcov --base-directory . --directory . -c -o gcov/lcov.info
答案 1 :(得分:0)
您是否先使用-g -O0
和--coverage
标记进行编译?您是否将.gcno文件从构建目录复制到包含.gcda文件的同一目录?
您是否尝试过添加选项--ignore-errors gcov,source,graph?它实际上可能来自某些文件,这将确保lcov继续运行任何问题文件。如果您找到有效的文件,那么您可以退后一步,找出上述文件无法用于lcov的原因。也许他们错过了相应的.gcno文件。
答案 2 :(得分:0)
更新CMakeList.txt以添加以下标志:
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)
转到构建目录
cd {project/lib}
rm -rf * //Remove all items if you want
cmake ..
make
./MyTest
//运行测试用例以获取.gcda文件。可能还有其他方式生成gcda文件,但我更喜欢这种方式
lcov --capture --directory . --output-file AnyName.info
//AnyName.info将包含输出
genhtml AnyName.info --output-directory CODE_COVERAGE
您将在当前目录中找到一个目录CODE_COVERAGE,转到CODE_COVERAGE并双击index.html,它将显示测试用例的当前代码覆盖率
cd {project/lib}
rm -rf *
cmake ..
make
./MyTest
lcov --capture --directory . --output-file AnyName.info
genhtml AnyName.info --output-directory CODE_COVERAGE