8000 Don't use temporary directory for running gcov by Spacetown · Pull Request #525 · gcovr/gcovr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Don't use temporary directory for running gcov #525

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

Merged
merged 5 commits into from
Nov 9, 2021

Conversation

Spacetown
Copy link
Member

As discussed in #524 on MacOs there is a problem with the temporary directory. The files generated by gcov are prefixed with the name of the data file (Option --long-path-names) to be able to run gcov in parallel.
The regular expression to catch the "Source not found" error is extended to match the message for a clang based gcov command.
The test of the example is extended to test all available output formats except the detailed html.

Maybe we should also extend the check of the gcovr output to also try the next working directory if there is no coverage data in the gcov file instead of only rely on the "Source not found" message.

Closes #524

@codecov
Copy link
codecov bot commented Nov 8, 2021

Codecov Report

Merging #525 (d270daf) into master (9c88a8d) will decrease coverage by 0.50%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #525      +/-   ##
==========================================
- Coverage   96.17%   95.66%   -0.51%     
==========================================
  Files          21       21              
  Lines        2846     2835      -11     
  Branches      487      485       -2     
==========================================
- Hits         2737     2712      -25     
- Misses         48       61      +13     
- Partials       61       62       +1     
Flag Coverage Δ
ubuntu-18.04 95.66% <100.00%> (-0.02%) ⬇️
windows-2019 ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
gcovr/__main__.py 91.22% <ø> (-0.55%) ⬇️
gcovr/gcov.py 81.59% <100.00%> (-0.06%) ⬇️
gcovr/tests/test_html_generator.py 47.05% <0.00%> (-52.95%) ⬇️
gcovr/utils.py 90.74% <0.00%> (-1.39%) ⬇️
gcovr/writer/html.py 95.86% <0.00%> (-0.69%) ⬇️
gcovr/workers.py 98.79% <0.00%> (-0.03%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9c88a8d...d270daf. Read the comment docs.

Copy link
Member
@latk latk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Spacetown Spacetown merged commit 044b5c9 into gcovr:master Nov 9, 2021
@Spacetown Spacetown deleted the no_tmp_wd_for_gcov branch November 9, 2021 20:31
@latk
Copy link
Member
latk commented Nov 9, 2021

The updated test data in this PR shows a decrease in covered lines. More precisely, more lines are now detected as “noncode”, thus increasing the coverage percentage. This is quite unexpected, as the change in this PR should not have affected the coverage data.

Do you have any idea theory as to what is happening here?

@Spacetown
Copy link
Member Author

This is a result of extending the regular expression for the "File not found error". The verbose log is:

Processing file: /gcovr/gcovr/tests/nested/subdir/A/file3.gcda
Running gcov: 'llvm-cov-10 gcov /gcovr/gcovr/tests/nested/subdir/A/file3.gcda --branch-counts --branch-probabilities --preserve-paths --long-file-names --object-directory /gcovr/gcovr/tests/nested/subdir/A' in '/gcovr/gcovr/tests/nested/subdir'
Running gcov: 'llvm-cov-10 gcov /gcovr/gcovr/tests/nested/subdir/A/file3.gcda --branch-counts --branch-probabilities --preserve-paths --long-file-names --object-directory /gcovr/gcovr/tests/nested/subdir/A' in '/gcovr/gcovr/tests/nested/subdir/A'
Running gcov: 'llvm-cov-10 gcov /gcovr/gcovr/tests/nested/subdir/A/file3.gcda --branch-counts --branch-probabilities --preserve-paths --long-file-names --object-directory /gcovr/gcovr/tests/nested/subdir/A' in '/gcovr/gcovr/tests/nested/subdir'
Running gcov: 'llvm-cov-10 gcov /gcovr/gcovr/tests/nested/subdir/A/file3.gcda --branch-counts --branch-probabilities --preserve-paths --long-file-names --object-directory /gcovr/gcovr/tests/nested/subdir/A' in '/gcovr/gcovr/tests/nested'
Finding source file corresponding to a gcov data file
  currdir      /gcovr/gcovr/tests/nested
  gcov_fname   /gcovr/gcovr/tests/nested/#gcovr#gcovr#tests#nested#subdir#A#file3.gcda##subdir#A#file3.cpp.gcov
  source_fname /gcovr/gcovr/tests/nested/subdir/A/file3.gcda
  root         /gcovr/gcovr/tests/nested/subdir
  fname        /gcovr/gcovr/tests/nested/subdir/A/file3.cpp
Parsing coverage data for file /gcovr/gcovr/tests/nested/subdir/A/file3.cpp

And the result is:

        -:    0:Source:subdir/A/file3.cpp
        -:    0:Graph:/gcovr/gcovr/tests/nested/subdir/A/file3.gcno
        -:    0:Data:/gcovr/gcovr/tests/nested/subdir/A/file3.gcda
        -:    0:Runs:1
        -:    0:Programs:1
function _Z7fourbarv called 1 returned 100% blocks executed 100%
        1:    1:int fourbar()
        -:    2:{
        1:    3:int x=1;
        1:    4:int y=2;
        1:    5:return x+y;
        -:    6:}
        -:    7:
function _Z8fourbar_v called 0 returned 0% blocks executed 0%
    #####:    8:int fourbar_()
        -:    9:{
    #####:   10:int x=1;
    #####:   11:if (x)
branch  0 never executed
branch  1 never executed
    #####:   12:    return 2*x;     /* This is a really long comment that confirms whether gcovr colors lines that exceed normal expectations. */
        -:   13:else
    #####:   14:    return x;
    #####:   15:}

Without the change of the regular expression the output from a call in a different working directory is used:

Running gcov: 'llvm-cov-10 gcov /gcovr/gcovr/tests/nested/subdir/A/file3.gcda --branch-counts --branch-probabilities --preserve-paths --long-file-names --object-directory /gcovr/gcovr/tests/nested/subdir/A' in '/gcovr/gcovr/tests/nested/subdir'
Finding source file corresponding to a gcov data file
  currdir      /gcovr/gcovr/tests/nested
  gcov_fname   /gcovr/gcovr/tests/nested/subdir/#gcovr#gcovr#tests#nested#subdir#A#file3.gcda##subdir#A#file3.cpp.gcov
  source_fname /gcovr/gcovr/tests/nested/subdir/A/file3.gcda
  root         /gcovr/gcovr/tests/nested/subdir
  fname        /gcovr/gcovr/tests/nested/subdir/A/file3.cpp
Parsing coverage data for file /gcovr/gcovr/tests/nested/subdir/A/file3.cpp

with the result:

        -:    0:Source:subdir/A/file3.cpp
        -:    0:Graph:/gcovr/gcovr/tests/nested/subdir/A/file3.gcno
        -:    0:Data:/gcovr/gcovr/tests/nested/subdir/A/file3.gcda
        -:    0:Runs:1
        -:    0:Programs:1
function _Z7fourbarv called 1 returned 100% blocks executed 100%
        1:    1:/*EOF*/
        -:    2:/*EOF*/
        1:    3:/*EOF*/
        1:    4:/*EOF*/
        1:    5:/*EOF*/
        -:    6:/*EOF*/
        -:    7:/*EOF*/
function _Z8fourbar_v called 0 returned 0% blocks executed 0%
    #####:    8:/*EOF*/
        -:    9:/*EOF*/
    #####:   10:/*EOF*/
    #####:   11:/*EOF*/
branch  0 never executed
branch  1 never executed
    #####:   12:/*EOF*/
        -:   13:/*EOF*/
    #####:   14:/*EOF*/
    #####:   15:/*EOF*/

In the old version the function

def _is_non_code(code: str) -> bool:
returns False because C comments are not removed --> Code is uncovered.
Now it returns True --> Line isn't counted.

I suggest to change the function to:

    code = _CPP_STYLE_COMMENT_PATTERN.sub("", code)
    code = _C_STYLE_COMMENT_PATTERN.sub("", code)
    code = code.strip().replace(" ", "").replace("{", "").replace("}", "")
    return len(code) == 0 or code == "else"

@Spacetown
Copy link
Member Author

@latk I'm working on the adaption of _is_none_code and found out that the doctest:

    >>> _is_non_code('} else {')  # could be easily made detectable
    False

is working but if the spaces are removed (}else{) which is the same doe will result in True because the braces are removed. Syntctical it's the same code. There is also the comment:

    # This variant is more flexible, but would change JSON reports
    # code = code.replace("{", "").replace("}", "").strip()

I think removing the whilespaces as suggested is correct, what do you think?

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

Successfully merging this pull request may close these issues.

zero coverage rate
2 participants
0