8000 zero coverage rate · Issue #524 · gcovr/gcovr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

zero coverage rate #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on 8000 GitHub? Sign in to your account

Closed
qizr opened this issue Nov 7, 2021 · 12 comments · Fixed by #525
Closed

zero coverage rate #524

qizr opened this issue Nov 7, 2021 · 12 comments · Fixed by #525

Comments

@qizr
Copy link
qizr commented Nov 7, 2021

Describe the bug
i try the demo in the "get start page" and get zero coverage rate.

To Reproduce
Steps to reproduce the behavior:

  1. new example.cpp

// example.cpp
int foo(int param)
{
if (param)
{
return 1;
}
else
{
return 0;
}
}
int main(int argc, char* argv[])
{
foo(0);
return 0;
}

  1. g++ -fprofile-arcs -ftest-coverage -fPIC -O0 example.cpp -o program
  2. ./program
  3. gcovr -r .
  4. example.cpp 0 0 --%

Successful generation of example.gcda,example.gcno file.
Successful run gcov example.cpp ,display Lines executed:87.50% of 8

Desktop (please complete the following information):

  • OS: mac big sur 11.6
  • cpu: apple m1
  • GCC version gcc -dumpversion 13.0.0
  • GCOVR version 5.0
@qizr qizr added the Type: Bug label Nov 7, 2021
@latk
Copy link
Member
latk commented Nov 7, 2021

No GCC version 13 currently exists. This could indicate that your g++ program is actually Clang, which does have a version 13. However, it seems that gcov is working as expected so that isn't the problem.

Could you re-run your steps but in step 4 replace gcovr -r . with gcovr --keep? This will leave a plaintext example.cpp.gcov file in the same directory. If you can upload this file, that might contain a hint as to where the problem might be.

@Spacetown
Copy link
Member

o@latk You are right. g++ in Mac OS is based on clang. I've checked it on my machine and it the proble is that the gcov command doesn't find the example.cpp if called in a different directory. From the verbose output the command for running gcov is:

Running gcov: 'gcov /tmp/gcovr/doc/examples/example.gcda --branch-counts --branch-probabilities --preserve-paths --demangled-names --object-directory /tmp/gcovr/doc/examples' in '/var/folders/h9/qqdcgkxj0yg4_02ftkmlvnf00000gp/T/tmpbu4g0s81'

If I run the command I get the following output:

Function 'foo(int)'
Lines executed:80.00% of 5
No branches
No calls

Function 'main'
Lines executed:100.00% of 3
No branches
No calls

File 'example.cpp'
Lines executed:87.50% of 8
Branches executed:100.00% of 2
Taken at least once:50.00% of 2
No calls
Creating 'example.cpp.gcov'

example.cpp: No such file or directory

The content of the gcov file is:

        -:    0:Source:example.cpp
        -:    0:Graph:/tmp/gcovr/doc/examples/example.gcno
        -:    0:Data:/tmp/gcovr/doc/examples/example.gcda
        -:    0:Runs:1
        -:    0:Programs:1

If I run the same command in the source directory the gcov file also contains the source code and the coverage data.

It seems that the gcov treats the file path relati 8000 ve to the current working directory instead of --object-directory.

From the help:

 --object-file file
    Specify either the directory containing the gcov data files, or the object path name.
    The .gcno, and .gcda data files are searched for using this option. If a directory is
    specified, the data files are in that directory and named after the source file name,
    without its extension. If a file is specified here, the data files are named after that file,
    without its extension. If this option is not supplied, it defaults to the current directory.
...
gcov should be run with the current directory the same as that when you invoked the compiler.
Otherwise it will not be able to locate the source files. gcov produces files called
mangledname.gcov in the current directory.
...

Why is gcov called in a temporary directory?

@latk
Copy link
Member
latk commented Nov 7, 2021

Why is gcov called in a temporary directory?

I think this is related to the -j feature that attempts to run multiple gcov processes in parallel. Since multiple compilation units can contain coverage data for the foo.h file, the foo.h.gcov files would otherwise overwrite each other, leading to inconsistent coverage. There are two problems with the current solution:

  • this workaround is redundant with the --long-file-names option in newer gcov versions
  • the -j option is a pretty niche feature with little use

And it seems, this issue is pointing to a third problem: that LLVM's gcov emulation handles path resolution a bit differently.

@Spacetown
Copy link
Member

What about using --long-file-names if option -j is used and don't change the working directory?

@latk
Copy link
Member
latk commented Nov 7, 2021

Turns out that --long-file-names has been available since essentially forever (GCC 4.x) and is also implemented in llvm-cov gcov. So I think we can safely use it in ALL cases. But maybe there's a reason for the current design in the -j discussions (#239).

@Spacetown
Copy link
Member

Thanks ffor the link, I've found the reason (#3 (comment)):

It turns out parallelizing gcov isn't easy - it dumps all its output in the current directory so I've had to create a mutex that locks each directory. I think this limits the usefulness of the code as we're going to be serialized on the locked directory for some build systems. I've added in a temporary directory per thread though, so for some build systems (CMake...) it can output to its temporary directory and run all the gcov's at the same time.

My suggestion is to remove the temporary directory and the directory lock and adding the option --long-file-names.

@qizr qizr closed this as completed Nov 8, 2021
@qizr
Copy link
Author
qizr commented Nov 8, 2021

No GCC version 13 currently exists. This could indicate that your g++ program is actually Clang, which does have a version 13. However, it seems that gcov is working as expected so that isn't the problem.

Could you re-run your steps but in step 4 replace gcovr -r . with gcovr --keep? This will leave a plaintext example.cpp.gcov file in the same directory. If you can upload this file, that might contain a hint as to where the problem might be.

i can get the example.cpp.gcov use 'gcov ./example.cpp' , can not get it use 'gcovr --keep'

@qizr
Copy link
Author
qizr commented Nov 8, 2021

I solved this problem.
first ,i get the 'example.cpp.gcov' use command 'gcov ./example.cpp'
second, i get right result use command 'gcovr -g'

but i still don not know why 'gcovr -r . ' fail.

@Spacetown
Copy link
Member

As I wrote, it depends on the working directory of the gcoc command.

@Spacetown Spacetown reopened this Nov 8, 2021
@qizr
Copy link
Author
qizr commented Nov 8, 2021

What about using --long-file-names if option -j is used and don't change the working directory?

i can not find '--long-file-names' option.

@Spacetown
Copy link
Member

That's an option of gcov and not gcovr.

@Spacetown
Copy link
Member

After a little bit debugging I found the problem. I running gcov inside docker or linux in the temporary directory following message occure:

Cannot open source file example.cpp

This message is catched in

elif source_re.search(err):
and the newt working directory is used.
In the clang implementation the message is:

example.cpp: No such file or directory

I'll remove the temporary directory extend the regex to also catch this message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0