Lcov 不计算功能顶线
Lcov not counting function toplines
我正在使用 lcov 为我正在处理的项目生成覆盖率信息。它主要是在工作,除了出于某种原因,它似乎不计算每一个案例中的函数顶线。这意味着 class 具有完整测试覆盖率的文件仍将缺少几行,因此显示为 90%。
这没什么大不了的,但有点烦人。我想知道是否有人知道为什么。
下面我提供了一个完整的最小示例来演示此问题。当这个程序是 运行 时,6 行中有 4 行是 'hit',尽管所有行都明确执行了,但我的行覆盖率为 68.7%。
GCOV 输出
Summary coverage rate:
lines......: 66.7% (4 of 6 lines)
functions..: 100.0% (2 of 2 functions)
branches...: no data found
例子
CMakeLists.txt
set(NAME MinTest)
project (${NAME})
cmake_minimum_required(VERSION 3.5.2)
set(CMAKE_C_FLAGS
"--coverage -O0 -g")
add_executable(
${NAME}
src/main.c
)
src/main.c
void function() {
printf("foo");
}
int main(void) {
function();
}
runWithCoverageInfo.sh
#!/bin/bash
# = source root
# = build directory
if [ ! -d "coverage" ]; then
echo "Creating coverage directory...";
mkdir coverage;
else
find ./coverage -name *.info -exec rm {} \;;
fi;
echo "Removing previous coverage output files...";
find -name *.gcda -exec rm {} \;;
echo "Analysing baseline coverage data...";
lcov --initial --no-external --capture --base-directory --directory --directory --output-file coverage/coverage_base.info ;
echo "Running tests...";
./MinTest;
returnCode=$?
echo "Generating coverage output";
lcov --capture --no-external --directory --directory --base-directory --output-file coverage/coverage_test.info --quiet ;
lcov -a coverage/coverage_base.info -a coverage/coverage_test.info -output-file coverage/coverage_total.info --quiet;
lcov --summary coverage/coverage_total.info;
genhtml coverage/coverage_total.info --output-directory coverage -quiet;
exit $returnCode;
曾几何时,LCOV 默认提供分支机构覆盖。现在没有了。 (至少,我的版本 [1.12] 没有。)所以你必须在你的 lcov
和 genhtml
命令中明确地告诉它来生成分支报告。例如:
lcov -d . --zerocounters
lcov -d . --rc lcov_branch_coverage=1 --no-external --capture -o ../reports/myproj.info
cd ../reports
genhtml --branch-coverage myproj.info
分支覆盖需要LCOV命令中的--rc lcov_branch_coverage=1
和HTML生成命令中的--branch-coverage
analysis/reporting.
如果您希望始终默认分支覆盖,您可以选择将 lcov_branch_coverage=1
和 genhtml_branch_coverage=1
放入 .lcovrc
资源文件中。有关详细信息,请参阅 lcovrc(5) 联机帮助页,或在线访问:http://ltp.sourceforge.net/coverage/lcov/lcovrc.5.php
我正在使用 lcov 为我正在处理的项目生成覆盖率信息。它主要是在工作,除了出于某种原因,它似乎不计算每一个案例中的函数顶线。这意味着 class 具有完整测试覆盖率的文件仍将缺少几行,因此显示为 90%。
这没什么大不了的,但有点烦人。我想知道是否有人知道为什么。
下面我提供了一个完整的最小示例来演示此问题。当这个程序是 运行 时,6 行中有 4 行是 'hit',尽管所有行都明确执行了,但我的行覆盖率为 68.7%。
GCOV 输出
Summary coverage rate:
lines......: 66.7% (4 of 6 lines)
functions..: 100.0% (2 of 2 functions)
branches...: no data found
例子
CMakeLists.txt
set(NAME MinTest)
project (${NAME})
cmake_minimum_required(VERSION 3.5.2)
set(CMAKE_C_FLAGS
"--coverage -O0 -g")
add_executable(
${NAME}
src/main.c
)
src/main.c
void function() {
printf("foo");
}
int main(void) {
function();
}
runWithCoverageInfo.sh
#!/bin/bash
# = source root
# = build directory
if [ ! -d "coverage" ]; then
echo "Creating coverage directory...";
mkdir coverage;
else
find ./coverage -name *.info -exec rm {} \;;
fi;
echo "Removing previous coverage output files...";
find -name *.gcda -exec rm {} \;;
echo "Analysing baseline coverage data...";
lcov --initial --no-external --capture --base-directory --directory --directory --output-file coverage/coverage_base.info ;
echo "Running tests...";
./MinTest;
returnCode=$?
echo "Generating coverage output";
lcov --capture --no-external --directory --directory --base-directory --output-file coverage/coverage_test.info --quiet ;
lcov -a coverage/coverage_base.info -a coverage/coverage_test.info -output-file coverage/coverage_total.info --quiet;
lcov --summary coverage/coverage_total.info;
genhtml coverage/coverage_total.info --output-directory coverage -quiet;
exit $returnCode;
曾几何时,LCOV 默认提供分支机构覆盖。现在没有了。 (至少,我的版本 [1.12] 没有。)所以你必须在你的 lcov
和 genhtml
命令中明确地告诉它来生成分支报告。例如:
lcov -d . --zerocounters
lcov -d . --rc lcov_branch_coverage=1 --no-external --capture -o ../reports/myproj.info
cd ../reports
genhtml --branch-coverage myproj.info
分支覆盖需要LCOV命令中的--rc lcov_branch_coverage=1
和HTML生成命令中的--branch-coverage
analysis/reporting.
如果您希望始终默认分支覆盖,您可以选择将 lcov_branch_coverage=1
和 genhtml_branch_coverage=1
放入 .lcovrc
资源文件中。有关详细信息,请参阅 lcovrc(5) 联机帮助页,或在线访问:http://ltp.sourceforge.net/coverage/lcov/lcovrc.5.php