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

时间:2018-08-07 17:50:10

标签: c cygwin lcov cpputest

我正在尝试从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文件的coverage数据,并且我想排除或删除其他所有内容。

我尝试使用这些目录的绝对路径,例如'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 它可以满足我的要求。但是,这似乎有些沉重。

0 个答案:

没有答案