Giter Site home page Giter Site logo

Comments (4)

cesaro avatar cesaro commented on September 8, 2024

I'm also hitting this issue. The problem is that --no-external incorrectly filters out files when they can be accessed via symbolic links.

Here is a simple script that reproduces the problem, in a format that should be easy to adapt for the regression tests, @henry2cox:

#!/bin/bash
set -xe

mkdir -p /tmp/bug
cd /tmp/bug

rm -Rf src src2

mkdir src
ln -s src src2

echo 'int a (int x) { return x + 1; }' > src/a.c
echo 'int b (int x) { return x + 2; }' > src/b.c

gcc -c --coverage src/a.c -o src/a.o
gcc -c --coverage src2/b.c -o src/b.o

lcov -o out -c -i --no-external -d src

You would expect that the call to lcov -c -i records the coverage of both a.c and b.c, but --no-external is incorrectly dropping b.c:

+ lcov -o out -c -i --no-external -d src
Capturing coverage data from src
geninfo cmd: '/path/to/geninfo src --output-filename out --initial --no-external'
Found gcov version: 12.3.0
Using intermediate gcov format
geninfo: WARNING: (usage) branch filter enabled but branch coverage not enabled
        (use "geninfo --ignore-errors usage,usage ..." to suppress this warning)
Recording 'internal' directories:
        /tmp/bug/src
Writing temporary data to /tmp/geninfo_datHcWj
Scanning src for .gcno files ...
Found 2 graph files in src
using: chunkSize: 1, nchunks:2, intervalLength:0
Dropping 'external' file '/tmp/bug/src2/b.c'
Finished processing 2 GCNO files
Excluded data for 1 file due to include/exclude options
Apply filtering..
Finished filter file processing
Finished .info-file creation
Summary coverage rate:
  source files: 1
  lines.......: 0.0% (0 of 1 line)
  functions...: 0.0% (0 of 1 function)
Message summary:
  1 warning message:
    usage: 1

And this is probably happening because /tmp/bug/src/b.gcno refers to the path that uses symbolic links:

$ strings /tmp/bug/src/b.gcno
oncg*32B
/tmp/bug
src2/b.c
src2/b.c
src2/b.c

and because lcov --no-external doesn't canonicalize file path names (see realpath(1)) before comparing them.

from lcov.

henry2cox avatar henry2cox commented on September 8, 2024

Hi -
Thanks for the testcase.
I actually think there is about an even chance that a user would want to include symlinked out-of-tree files and directories, or would want to exclude them - and an even better chance that (s)he would want to include some and exclude others.

In any case, I updated the man pages to note that --no-external is a bit of a blunt instrument, and that --include, --exclude can provide finer-grained control when --no-external fails to do what you want - and also added an option (really, re-used an existing option) to select how symlinked directories are treated.
I will push the update shortly.

Henry

from lcov.

henry2cox avatar henry2cox commented on September 8, 2024

fix pushed in 2efc0fb

from lcov.

henry2cox avatar henry2cox commented on September 8, 2024

Closing this issue as I believe it is fixed in commit listed above.
If there is still a problem, please reopen this issue or file a new one.
Please include a testcase and/or recipe to reproduce the problem.
Henry

from lcov.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.