【问题标题】:How to use lcov with `--gcov-tool` flag?如何使用带有`--gcov-tool`标志的lcov?
【发布时间】:2020-02-22 12:01:01
【问题描述】:

我想使用与系统默认设置不同的 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.
There is NO warranty; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.

+ echo 'will work!'
will work!
+ lcov --capture --directory /data/home/extcpp/repos/extcpp/libext-build/debug --output-file test_coverage.info
Capturing coverage data from /data/home/extcpp/repos/extcpp/libext-build/debug
Found gcov version: 8.3.0
Scanning /data/home/extcpp/repos/extcpp/libext-build/debug for .gcda files ...
Found 25 data files in /data/home/extcpp/repos/extcpp/libext-build/debug
Processing CMakeFiles/ext_shared.dir/src/logging.cpp.gcda
Processing external_libs/googletest/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.gcda
Processing tests/CMakeFiles/test_libext_shared.dir/logging.cpp.gcda
Processing tests/CMakeFiles/test_libext_shared.dir/gtest.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/util_cast.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/math.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/algorithm_knapsack.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/util_enum.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/util_serialization.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/util_lazy.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/util_encode.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/meta_is_one_of.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/util_endian.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/util_result.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/util_scoped_timer.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/util_except.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/util_string.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/algorithm_string_distances.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/util_any_printable.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/gtest.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/meta_if.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/util_basic.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/util_windows_strings.cpp.gcda
geninfo: WARNING: gcov did not create any files for /data/home/extcpp/repos/extcpp/libext-build/debug/tests/CMakeFiles/test_libext.dir/util_windows_strings.cpp.gcda!
Processing tests/CMakeFiles/test_libext.dir/algorithm_basic.cpp.gcda
Processing tests/CMakeFiles/test_libext.dir/meta_has_member.cpp.gcda
Finished .info-file creation
+ echo 'will fail!' 
will fail!
++ type -p gcov-tool-8
+ lcov --capture --directory /data/home/extcpp/repos/extcpp/libext-build/debug --gcov-tool /usr/bin/gcov-tool-8 --output-file test_coverage.info
Capturing coverage data from /data/home/extcpp/repos/extcpp/libext-build/debug
Found gcov version: 8.3.0
Scanning /data/home/extcpp/repos/extcpp/libext-build/debug for .gcda files ...
Found 25 data files in /data/home/extcpp/repos/extcpp/libext-build/debug
Processing CMakeFiles/ext_shared.dir/src/logging.cpp.gcda
Usage: gcov-tool-8 [OPTION]... SUB_COMMAND [OPTION]...

Offline tool to handle gcda counts

  -h, --help                            Print this help, then exit
  -v, --version                         Print version number, then exit
  merge [options] <dir1> <dir2>         Merge coverage file contents
    -o, --output <dir>                  Output directory
    -v, --verbose                       Verbose mode
    -w, --weight <w1,w2>                Set weights (float point values)
  rewrite [options] <dir>               Rewrite coverage file contents
    -n, --normalize <int64_t>           Normalize the profile 
    -o, --output <dir>                  Output directory
    -s, --scale <float or simple-frac>  Scale the profile counters
    -v, --verbose                       Verbose mode
  overlap [options] <dir1> <dir2>       Compute the overlap of two profiles
    -f, --function                      Print function level info
    -F, --fullname                      Print full filename
    -h, --hotonly                       Only print info for hot objects/functions
    -o, --object                        Print object level info
    -t <float>, --hot_threshold <float> Set the threshold for hotness
    -v, --verbose                       Verbose mode

For bug reporting instructions, please see:
<file:///usr/share/doc/gcc-8/README.Bugs>.
geninfo: ERROR: GCOV failed for /data/home/extcpp/repos/extcpp/libext-build/debug/CMakeFiles/ext_shared.dir/src/logging.cpp.gcda!
+ ferr 'failed to extract coverage'
+ echo 'failed to extract coverage'
failed to extract coverage
+ exit 1

【问题讨论】:

  • 你能提供 /usr/bin/gcov-tool-8 /data/home/extcpp/repos/extcpp/libext-build/debug/CMakeFiles/ext_shared.dir/src/logging 的输出吗? cpp.gcda -o /data/home/extcpp/repos/extcpp/libext-build/debug/CMakeFiles/ext_shared.dir/src/ -b -c -p -a

标签: c++ code-coverage travis-ci gcov lcov


【解决方案1】:

我认为您将 gcov-tool 二进制文件与 gcov 二进制文件混淆了。

--lcov 的gcov-tool 选项,需要gcov 二进制而不是gcov-tool 二进制

对于我的系统,gcov 二进制文件与 gcc 位于同一文件夹中

哪个gcc

/usr/bin/gcc

哪个gcov

/usr/bin/gcov

哪个 gcov 工具

/usr/bin/gcov-tool

所以对我来说

lcov --capture --directory /home/user/mydir

等价于

lcov --capture --directory /home/user/mydir --gcov-tool /usr/bin/gcov

下面会是不正确的(这是你想要做的)

lcov --capture --directory /home/user/mydir --gcov-tool /usr/bin/gcov-tool

【讨论】:

    猜你喜欢
    • 2011-06-18
    • 2015-08-01
    • 1970-01-01
    • 2018-11-28
    • 2015-04-09
    • 2011-02-15
    • 2013-09-16
    • 2015-01-30
    • 1970-01-01
    相关资源
    最近更新 更多