我正在两个系统(Windows 7,cygwin,Lcov 1.10)上分析带有LCOV的C代码.在一个系统上,我从来没有遇到过问题,但在另一个系统上我得到了相同的代码:
$ lcov --directory CMakeFiles/UnitTest.dir/main --capture --output-file lcov.log
Capturing coverage data from CMakeFiles/UnitTest.dir/main
Found gcov version: 4.8.2
Scanning CMakeFiles/UnitTest.dir/main for .gcda files ...
Found 59 data files in CMakeFiles/UnitTest.dir/main
Processing analyze/analyze.c.gcda
[..]
Processing measure/measur.c.gcda
geninfo: Negative length at /usr/bin/geninfo line 2413.
Run Code Online (Sandbox Code Playgroud)
在两个系统上,文件夹和文件是相同的(通过subversion版本控制).我想,也许某些路径可能存在问题.有人知道这是关于什么的吗?谢谢,领导
附录:我发现有些时候它有助于彻底清理项目(删除所有CMakeFiles和CMakeCache)并重新运行lcov命令.
更新到Ubuntu 16.04后,我试图在我的项目上进行覆盖。我懂了
Deleted 665 files
Writing data to coverage.info.cleaned
lcov: ERROR: cannot write to coverage.info.cleaned!
CMakeFiles/coverage.dir/build.make:57: recipe for target 'CMakeFiles/coverage' failed
make[3]: *** [CMakeFiles/coverage] Error 13
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/coverage.dir/all' failed
make[2]: *** [CMakeFiles/coverage.dir/all] Error 2
CMakeFiles/Makefile2:74: recipe for target 'CMakeFiles/coverage.dir/rule' failed
make[1]: *** [CMakeFiles/coverage.dir/rule] Error 2
Makefile:129: recipe for target 'coverage' failed
make: *** [coverage] Error 2
enter code here
Run Code Online (Sandbox Code Playgroud)
在更新之前,我运行覆盖范围没有问题
最近的操作系统升级使我的覆盖脚本惨遭失败。
lcov 1.13
gcov (GCC) 9.1.1
我的 CMake 中用于生成覆盖率数据的部分:
if ($ENV{COVERAGE})
message("Setting up for coverage")
enable_testing()
include(CodeCoverage)
setup_target_for_coverage(${PROJECT_NAME}_coverage tests coverage)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
endif ()
Run Code Online (Sandbox Code Playgroud)
lcov我在构建测试后发出的命令:
lcov --capture --directory build/ --output-file coverage.info
不幸的是现在失败了:
Capturing coverage data from build/
Found gcov version: 9.1.1
Scanning build/ for .gcda files ...
geninfo: WARNING: no .gcda files found in build/ - skipping!
Finished .info-file creation
Run Code Online (Sandbox Code Playgroud)
错误消息是有道理的,因为没有.gcda文件 - 只有.gcno文件。我不确定它们是否具有相同的目的和/或可以与lcov.
我发出了nm some_binary | grep gcov,有很多符号的形式:
00000000004b3520 d …Run Code Online (Sandbox Code Playgroud) 我尝试了两种方法来添加LCOV_EXCL_LINE我的代码。
我将其添加为注释,编译并生成lcov报告,但lcov二进制将其作为注释并显示排除行的覆盖范围。
显示排除线覆盖范围的图像:

编译和执行后,我LCOV_EXCL_LINE在运行之前添加了lcov二进制genhtml文件,但在第一次排除后会导致错位。
显示错位覆盖范围的图像:

我想使用与系统默认不同的 gcc 来构建项目。因此我需要为 lcov 提供正确的 gcov-tool 版本。不幸的是,该--gcov-tool标志对我不起作用。即使 lcov 应该默认的版本也不行。
示例运行:
############## extract test coverage ##############
g++-8 (Debian 8.3.0-6) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
gcov-tool-8 (Debian 8.3.0-6) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. …Run Code Online (Sandbox Code Playgroud)