8000 line coverage is polluted by comment and function argument · Issue #646 · gcovr/gcovr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

line coverage is polluted by comment and function argument #646

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 GitHub? Sign in to your account

Closed
Autonomous-Wang opened this issue Aug 1, 2022 · 4 comments
Closed

line coverage is polluted by comment and function argument #646

Autonomous-Wang opened this issue Aug 1, 2022 · 4 comments

Comments

@Autonomous-Wang
Copy link
Autonomous-Wang commented Aug 1, 2022

I am using Gcovr to get line, branch and decision coverage. I notice commented out lines or comment are taken into account of line coverage.

The cmd I am using: gcovr --decision.
interesting thing to note: the line coverage is good if not generate decision coverage

Gcovr version:
commit fcc269a (HEAD -> master, origin/master, origin/HEAD)
Author: Klaus Weinbauer 51136324+klausweinbauer@users.noreply.github.com
Date: Sat Jul 30 11:34:56 2022 +0200

Fix assert and key error in --decisions flag (#642)
@latk
Copy link
Member
latk commented Aug 1, 2022

Yes, this is a known bug with the decision coverage analysis discovered in #600. The analysis looks up coverage data line by line, but this creates coverage data for that line if it doesn't already exist – defaulting to an uncovered line.

The decision coverage mode is fairly experimental. Please stick to the more reliable line- and branch-coverage metrics for now. As you correctly determined, the decision analysis only runs when explicitly requested.

@latk latk added the Type: Bug label Aug 1, 2022
@Autonomous-Wang
Copy link
Author

@latk Thx for the clarification.
The reason I need to use decision is due to:
With the gcovr --decisions option, gcovr parses the source code to extract a ISO 26262 compliant metric for decision coverage. This metric can be interpreted as the branch coverage on C/C++-Level.
is it possible to config branch coverage to achieve the same purpose? maybe not the right place to ask this question.

@latk
Copy link
Member
latk commented Aug 1, 2022

is it possible to config branch coverage to achieve the same purpose?

No, gcovr's branch coverage and decision coverage are fundamentally different concepts, though they are related. On simple C code, the two metrics should be almost equivalent.

  • The branch coverage data is provided directly by gcov, on the basis of the assembly code generated by the compiler. If the compiler generated machine code for some branch, it will turn up in the coverage report. While many of these branches are not visible in the source code, they are still real in the binary being tested. It is usually impossible to achieve 100% branch coverage in C++. See also FAQ: Why does C++ code have so many uncovered branches?

  • The decision coverage analysis is supposed to provide a metric that has to do with source code. It is created by checking if branch coverage data exists for lines that look like they contain control flow operators in C/C++, e.g. if or while. We can't actually parse C/C++, so this just uses some very crude heuristics. This will also fail when using gcovr on other languages supported by GCC or LLVM, and will fail with unexpected code formatting.

    While this decision coverage is closer to what users expect from “branch coverage”, the implementation is unfortunately a bit experimental and it doesn't quite deliver what it promises. In retrospect, it should have been marked clearly as an experimental option. I don't have the energy to fix this myself, but I hope that other people do.

@latk
Copy link
Member
latk commented Aug 5, 2022

The bug with the --decision option should have been fixed in #617. To try it out you can install the development version (see https://gcovr.com/en/stable/installation.html).

@latk latk closed this as completed Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0