繁体   English   中英

使用相对路径从 lcov 跟踪文件中删除文件

[英]Removing files from lcov tracefile using relative paths

我试图从我的 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它做我想要的。 然而,这似乎有点沉重。

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

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

设置以下变量。

testBarSrcPath= pwd /test/bar/*

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM