【问题标题】:Removing files from lcov tracefile using relative paths使用相对路径从 lcov 跟踪文件中删除文件
【发布时间】:2018-08-07 17:50:09
【问题描述】:

我正在尝试从我的 lcov 跟踪文件中删除某些目录,但没有任何成功。我正在尝试使用相对路径,并且正在使用 cygwin。我的测试框架是cpputest。

我的目录结构是这样的

foo_library
$ tree
├── bar
│   ├── bar.c
│   ├── bar.h
│   ├── bar.o
│   └── makefile
├── makefile
├── readme.md
├── foo.c
├── foo.h
├── foo.o
├── baz
│   ├── baz.c
│   └── baz.h
└── test
    ├── AllTests.cpp
    ├── bar
    │   ├── bar.d
    │   ├── bar.gcda
    │   ├── bar.gcno
    │   └── bar.o
    ├── lcov.info
    ├── lcov-filtered.info
    ├── Makefile
    ├── foo.d
    ├── foo.gcno
    ├── foo.o
    ├── baz
    │   ├── baz.d
    │   ├── baz.gcda
    │   ├── baz.gcno
    │   └── baz.o
    ├── test_foo.cpp
    ├── test-lib
    │   └── libfoo.a
    ├── test-obj
    │   ├── AllTests.d
    │   ├── AllTests.gcda
    │   ├── AllTests.gcno
    │   ├── AllTests.o
    │   ├── test_foo.d
    │   ├── test_foo.gcda
    │   ├── test_foo.gcno
    │   ├── test_foo.o
    │   ├── wrap_foo.d
    │   ├── wrap_foo.gcda
    │   ├── wrap_foo.gcno
    │   └── wrap_foo.o
    ├── foo_tests.exe
    ├── wrap_foo.c
    └── wrap_foo.h

这是一个例子

nick test 
$ pwd
/cygdrive/C/Work/git/foo_library/test

nick test 
$ lcov --capture --directory './' --output-file lcov.info
Capturing coverage data from ./
Found gcov version: 7.3.0
Scanning ./ for .gcda files ...
Found 5 data files in ./
Processing bar/bar.gcda
Processing baz/baz.gcda
Processing test-obj/AllTests.gcda
Processing test-obj/test_foo.gcda
geninfo: WARNING: cannot find an entry for c~#Work#cpputest#include#CppUTest#Utest.h.gcov in .gcno file, skipping file!
Processing test-obj/wrap_foo.gcda
Finished .info-file creation

nick test 
$ lcov --list lcov.info
Reading tracefile lcov.info
                                     |Lines       |Functions  |Branches
Filename                             |Rate     Num|Rate    Num|Rate     Num
===========================================================================
[/cygdrive/C/Work/git/foo_library/]
bar/bar.c                            |83.3%     24|66.7%     3|    -      0
foo.c                                |94.0%    100| 100%     4|    -      0
baz/baz.c                            | 100%      5| 100%     1|    -      0
test/AllTests.cpp                    | 100%      3| 100%     1|    -      0
test/test_foo.cpp                    | 100%    131|74.6%   189|    -      0
===========================================================================
                               Total:|96.2%    263|75.3%   198|    -      0

nick test 
$ lcov --remove lcov.info './bar/*' --output-file lcov-filtered.info
Reading tracefile lcov.info
Deleted 0 files
Writing data to lcov-filtered.info
Summary coverage rate:
  lines......: 96.2% (253 of 263 lines)
  functions..: 75.3% (149 of 198 functions)
  branches...: no data found

最终我只想生成这个 foo.c 文件的覆盖率数据,我想排除或删除其他所有内容。

我尝试过使用这些目录的绝对路径,例如'cygdrive/C/Work/git/foo_library/test/bar/*',我也尝试过

'`pwd`/test/bar/*'

我也不确定我应该指定哪些路径、gcda 文件的路径或源文件的路径。我都试过了。

我也尝试在我的捕获和删除命令中使用 -b . 和 -b ../。

编辑: 我必须从 test 子目录运行它才能确定路径。以下显示了完整路径

nick test 
$ lcov -c -d . -b ../ -o lcov.info
Capturing coverage data from .
Found gcov version: 7.3.0
Scanning . for .gcda files ...
Found 5 data files in .
Processing bar/bar.gcda
Processing baz/baz.gcda
Processing test-obj/AllTests.gcda
Processing test-obj/test_foo.gcda
geninfo: WARNING: cannot find an entry for c~#Work#cpputest#include#CppUTest#Utest.h.gcov in .gcno file, skipping file!
Processing test-obj/wrap_foo.gcda
Finished .info-file creation

nick test
$ lcov --list lcov.info --list-full-path
Reading tracefile lcov.info
                                                                                |Lines       |Functions  |Branches
Filename                                                                        |Rate     Num|Rate    Num|Rate     Num
======================================================================================================================
/cygdrive/C/Work/git/foo_library/bar/bar.c                                      |83.3%     24|66.7%     3|    -      0
/cygdrive/C/Work/git/foo_library/foo.c                                          |94.0%    100| 100%     4|    -      0
/cygdrive/C/Work/git/foo_library/baz/baz.c                                      | 100%      5| 100%     1|    -      0
/cygdrive/C/Work/git/foo_library/test/AllTests.cpp                              | 100%      3| 100%     1|    -      0
/cygdrive/C/Work/git/foo_library/test/test_foo.cpp                              | 100%    131|74.6%   189|    -      0
======================================================================================================================
                                                                          Total:|96.2%    263|75.3%   198|    -      0

编辑: 如果我这样做:$ lcov -r lcov.info '*bar*' '*baz*' '*cpp' -o lcov-filtered.info 它做我想要的。但是,这似乎有点沉重。

【问题讨论】:

    标签: c cygwin lcov cpputest


    【解决方案1】:

    排除文件夹时,我遇到了与您相同的问题。 您应该删除不想在结果中显示的源代码,并将覆盖率的总行数加起来。

    这种相对路径的方式对我来说可以排除路径。

    设置以下变量。

    testBarSrcPath=pwd/test/bar/*

    然后在排除内容时使用该变量。

    lcov -r lcov.info "$testBarSrcPath" -o lcov-filtered.info

    【讨论】:

      猜你喜欢
      • 2012-02-07
      • 1970-01-01
      • 2014-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-29
      • 1970-01-01
      • 2012-10-13
      相关资源
      最近更新 更多