Skip to content
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

parse_gcov_file: handle empty/no lnum #140

Merged
merged 1 commit into from
Mar 9, 2019

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Feb 18, 2019

Without this patch it would fail on the line b'xembed_window_array_take:\n',
trying to cast an empty string into an int.

        -:   46:
    #####:   47:DO_ARRAY(xembed_window_t, xembed_window, DO_NOTHING)
------------------
xembed_window_array_take:
    #####:   47:DO_ARRAY(xembed_window_t, xembed_window, DO_NOTHING)
------------------
xembed_window_array_splice:
    #####:   47:DO_ARRAY(xembed_window_t, xembed_window, DO_NOTHING)
------------------
xembed_window_array_grow:
    #####:   47:DO_ARRAY(xembed_window_t, xembed_window, DO_NOTHING)
------------------
        -:   48:

Using gcov (GCC) 8.2.1 20181127.

Without this patch it would fail on the line `b'xembed_window_array_take:\n'`,
trying to cast an empty string into an int.

            -:   46:
        #####:   47:DO_ARRAY(xembed_window_t, xembed_window, DO_NOTHING)
    ------------------
    xembed_window_array_take:
        #####:   47:DO_ARRAY(xembed_window_t, xembed_window, DO_NOTHING)
    ------------------
    xembed_window_array_splice:
        #####:   47:DO_ARRAY(xembed_window_t, xembed_window, DO_NOTHING)
    ------------------
    xembed_window_array_grow:
        #####:   47:DO_ARRAY(xembed_window_t, xembed_window, DO_NOTHING)
    ------------------
            -:   48:

Using gcov (GCC) 8.2.1 20181127.
blueyed added a commit to blueyed/awesome that referenced this pull request Feb 18, 2019
For/via eddyxu/cpp-coveralls#140; it fails
locally, but not on Travis.
blueyed added a commit to blueyed/awesome that referenced this pull request Feb 18, 2019
For/via eddyxu/cpp-coveralls#140; it fails
locally, but not on Travis.
@blueyed
Copy link
Contributor Author

blueyed commented Feb 18, 2019

Does not appear to be a problem with "gcov (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609" (used on Travis with Ubuntu Xenial).

@blueyed
Copy link
Contributor Author

blueyed commented Feb 18, 2019

According to #116 it can also happen with the older gcov version, so might be triggered by something else then.

I am using gcov -pb myself, both locally and on Travis, but have only seen it locally.

blueyed added a commit to blueyed/awesome that referenced this pull request Feb 19, 2019
For/via eddyxu/cpp-coveralls#140; it fails
locally, but not on Travis.
@eddyxu eddyxu merged commit d5a1a1e into eddyxu:master Mar 9, 2019
@blueyed blueyed deleted the handle-non-lnum branch March 9, 2019 21:26
@LAHumphreys
Copy link

@blueyed I'm not sure if I'm missing something - but I think we still have an issue in parsing this new gcov output?

Originally I saw the issue as nonsense coverage data on a personal repo - but I can reproduce the issue by running the regressions tests I created (#147) using gcov version >= 8. Whilst the parser doesn't crash it gets confused and ends up with more "coverage" lines than actual lines in the file. As a result, all of the coverage is assigned to the wrong lines.

>> Checking /home/travis/build/Grauniad/cpp-coveralls/test-src/template_includes using GCOV (CXX:g++-8, GCOV:gcov-8)...FAIL
   File 'common_header.h': expected 10 lines, but actually has 16
   Expected:
        {
            "source_files": [{
                    "name": "A.cpp",
                    "coverage": [null, null, null, null, 1, null, 1, null]
                }, {
                    "name": "B.cpp",
                    "coverage": [null, null, null, null, 1, null, 1, null]
                }, {
                    "name": "common_header.h",
                    "coverage": [null, null, 1, 1, null, null, 1, 1, null, null]
                }]
        }
    Actual Output:
        {"service_name": "travis-ci", "source_files": [{"source_digest": "9132796bebbb415868c33ca6ad462317", "coverage": [null, null, null, null, 1, null, 1, null], "name": "B.cpp"}, {"source_digest": "4399c8184507be95b3a0d71bd45d8415", "coverage": [null, null, null, null, 1, null, 1, null], "name": "A.cpp"}, {"source_digest": "7f5ea168524b2dd779034709dd29b4fd", "coverage": [null, null, 1, 1, null, 0, 0, null, 1, 1, null, null, 1, 1, null, null], "name": "common_header.h"}], "git": {"branch": "master", "remotes": [], "head": {"committer_email": "[email protected]", "committer_name": "Luke.Humphreys", "author_email": "[email protected]", "author_name": "Luke.Humphreys", "id": "7598296a5f15da37fcde6a8917be33c8ac47d3f8", "message": "Person utilities"}}, "service_job_id": "603626911"}

I believe the issue is that although this fix ensures the parser extracts the correct line number - we don't actually use it. Instead the coverage number is simply appended to a list (line ~280)? The result is that when coveralls proceses the file the gcov files produced by the test:

lhumphreys@LAPTOP-9BKDFPPT:~/dev/cpp-coveralls/test-src/template_includes$ cat A.gcno##common_header.h.gcov
        -:    0:Source:common_header.h
        -:    0:Graph:A.gcno
        -:    0:Data:A.gcda
        -:    0:Runs:1
        -:    1:template<class T>
        -:    2:struct Util {
       1*:    3:    T Method_A(const T& i) {
       1*:    4:        return 2*i;
        -:    5:    }
------------------
_ZN4UtilIcE8Method_AERKc:
    #####:    3:    T Method_A(const T& i) {
    #####:    4:        return 2*i;
        -:    5:    }
------------------
_ZN4UtilIiE8Method_AERKi:
        1:    3:    T Method_A(const T& i) {
        1:    4:        return 2*i;
        -:    5:    }
------------------
        -:    6:
    #####:    7:    T Method_B(const T& i) {
    #####:    8:        return 3*i;
        -:    9:    }
        -:   10:};

lhumphreys@LAPTOP-9BKDFPPT:~/dev/cpp-coveralls/test-src/template_includes$ cat B.gcno##common_header.h.gcov
        -:    0:Source:common_header.h
        -:    0:Graph:B.gcno
        -:    0:Data:B.gcda
        -:    0:Runs:1
        -:    1:template<class T>
        -:    2:struct Util {
    #####:    3:    T Method_A(const T& i) {
    #####:    4:        return 2*i;
        -:    5:    }
------------------
_ZN4UtilIcE8Method_AERKc:
    #####:    3:    T Method_A(const T& i) {
    #####:    4:        return 2*i;
        -:    5:    }
------------------
_ZN4UtilIiE8Method_AERKi:
    #####:    3:    T Method_A(const T& i) {
    #####:    4:        return 2*i;
        -:    5:    }
------------------
        -:    6:
       1*:    7:    T Method_B(const T& i) {
       1*:    8:        return 3*i;
        -:    9:    }
        -:   10:};

we end up with nonsense data:

lhumphreys@LAPTOP-9BKDFPPT:~/dev/cpp-coveralls/test-src/template_includes$ ../../test-utils/dump_output.py output.json common_header.h
WARNING: Coverage reports 16 lines, but file has 10
1             :  template<class T>
2             :  struct Util {
3            1:      T Method_A(const T& i) {
4            1:          return 2*i;
5             :      }
6         MISS:
7         MISS:      T Method_B(const T& i) {
8             :          return 3*i;
9            1:      }
10           1:  };
11            :  /*EOF*/
12            :  /*EOF*/
13           1:  /*EOF*/
14           1:  /*EOF*/
15            :  /*EOF*/
16            :  /*EOF*/

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

Successfully merging this pull request may close these issues.

3 participants