Removing files from lcov tracefile using relative paths

1.4k Views Asked by At

I am attempting to remove certain directories from my lcov tracefile, but am not having any success. I am attempting to use relative paths, and I am using cygwin. My test framework is cpputest.

My directory structure looks like this

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

Here is an example

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

Ultimately I just want to produce coverage data of this foo.c file, and I would like to exclude or remove everything else.

I have tried using absolute paths to these directories, like 'cygdrive/C/Work/git/foo_library/test/bar/*', I have also tried

'`pwd`/test/bar/*'

I am also not really sure which paths I should be specifying, the paths to the gcda files, or the path to the source files. I've tried both.

I've also tried using -b ., and -b ../ in my capture and remove commands.

Edit: I have to run this from the test subdirectory for the paths to work out. The following shows the full paths

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

Edit: If I do this: $ lcov -r lcov.info '*bar*' '*baz*' '*cpp' -o lcov-filtered.info it does what I want. However that seems a little heavy handed.

1

There are 1 best solutions below

0
On

I had the same problem as you excluding folders. You should remove source code that you don't want to show in the result and add up to the total number of lines in the coverage ratio.

This way of relative paths works for me to exclude paths.

Set the following variable.

testBarSrcPath=pwd/test/bar/*

And then use the variable when you exclude content.

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