# Codecov invokes gcov incorrectly

**URL:** <https://community.codecov.com/t/codecov-invokes-gcov-incorrectly/1895>\
**Category:** Bug Fixes\
**Created:** [August 21, 2020, 1:02pm UTC](https://community.codecov.com/t/codecov-invokes-gcov-incorrectly/1895 "2020-08-21T13:02:00Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmouse](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/cmouse/32/1051_2.png) [@cmouse](https://community.codecov.com/u/cmouse)\
**Post date:** [August 21, 2020, 1:02pm UTC](https://community.codecov.com/t/codecov-invokes-gcov-incorrectly/1895/1 "2020-08-21T13:02:00Z")

</div>

When running codecov.sh (from [https://codecov.io/bash](https://codecov.io/bash)) I noticed that it invokes gcov incorrectly for project with subdirectories and then gets completely confused where the source files live.

I tried to run it with several different ways to get some sensible output, but I get only nonsense like 8% coverage, and looking at hits, I see it’s missing several that should have been hit. It’s like it can’t figure out the output of gcov.

Any hints on what to do?

---

<div class="post-metadata">

**Author:** ![tom](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/tom/32/8_2.png) [@tom](https://community.codecov.com/u/tom)\
**Post date:** [August 26, 2020, 7:42pm UTC](https://community.codecov.com/t/codecov-invokes-gcov-incorrectly/1895/2 "2020-08-26T19:42:23Z")

</div>

@cmouse, we’ll probably need more information here like the Codecov output or a build URL. Have you tried running the bash script in the subdirectories? Is this a monorepo?

---

<div class="post-metadata">

**Author:** ![cmouse](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/cmouse/32/1051_2.png) [@cmouse](https://community.codecov.com/u/cmouse)\
**Post date:** [August 27, 2020, 5:06pm UTC](https://community.codecov.com/t/codecov-invokes-gcov-incorrectly/1895/3 "2020-08-27T17:06:47Z")

</div>

Hi!

Codecov output is available here [https://codecov.io/gh/dovecot/core/commit/fea1bacab954d2f112da8a95756f198530e274af/build](https://codecov.io/gh/dovecot/core/commit/fea1bacab954d2f112da8a95756f198530e274af/build) and the repository is at [GitHub - dovecot/core: Dovecot mail server](https://github.com/dovecot/core).

I tried various ways, including manually running gcov using a find + helper script to generate gcov information in correct directories and then invoking codecov tool with -X gcov. You can also see the output at [https://codecov.io/gh/dovecot/core/commit/fea1bacab954d2f112da8a95756f198530e274af/](https://codecov.io/gh/dovecot/core/commit/fea1bacab954d2f112da8a95756f198530e274af/) - I compared this to what lcov gives us and it’s wildly different result.

---

<div class="post-metadata">

**Author:** ![tom](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/tom/32/8_2.png) [@tom](https://community.codecov.com/u/tom)\
**Post date:** [August 31, 2020, 10:09pm UTC](https://community.codecov.com/t/codecov-invokes-gcov-incorrectly/1895/4 "2020-08-31T22:09:04Z")

</div>

Hi @cmouse, apologies if I wasn’t clear. I meant the Codecov output that includes the banner which is typically found in the CI run. You can also post a build url.

---

<div class="post-metadata">

**Author:** ![cmouse](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/cmouse/32/1051_2.png) [@cmouse](https://community.codecov.com/u/cmouse)\
**Post date:** [September 3, 2020, 10:18am UTC](https://community.codecov.com/t/codecov-invokes-gcov-incorrectly/1895/5 "2020-09-03T10:18:12Z")

</div>

Hi tom, please find it here [codecov output · GitHub](https://gist.github.com/cmouse/87d0e1689ff3b4485e8ca17f727c6b87)

Thank you for looking into this.

edit:

This has been prepared by running `gcov -mbupa *.c *.h *.cc *.hh` in each source directory.

---

<div class="post-metadata">

**Author:** ![tom](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/tom/32/8_2.png) [@tom](https://community.codecov.com/u/tom)\
**Post date:** [September 4, 2020, 6:21pm UTC](https://community.codecov.com/t/codecov-invokes-gcov-incorrectly/1895/6 "2020-09-04T18:21:05Z")

</div>

Hi @cmouse, sorry to keep coming back for more information. I guess what I’m trying to attain is for a recent commit (1) what are you expecting coverage to look like via a report or screenshot, (2) what is the Codecov output, and (3) what is the commit SHA so we can take a look at the build and see where things might have gone wrong.

The output that you copied has `gcov` disabled, so it’s not getting invoked by Codecov.

---

<div class="post-metadata">

**Author:** ![cmouse](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/cmouse/32/1051_2.png) [@cmouse](https://community.codecov.com/u/cmouse)\
**Post date:** [September 9, 2020, 7:47am UTC](https://community.codecov.com/t/codecov-invokes-gcov-incorrectly/1895/7 "2020-09-09T07:47:55Z")

</div>

![Screenshot_2020-09-09 LCOV - cov info](https://canada1.discourse-cdn.com/flex029/uploads/codecov/original/2X/f/f04f5d549d9bc0883d68f5ce0c3843073c3f090f.png)

You can use the latest master, [https://github.com/dovecot/dovecot](https://github.com/dovecot/dovecot). You can see from above screenshot that the coverage should be around 50%, and in particular the lib directory should have ~78% coverage.

> [@tom](#):
>
> The output that you copied has `gcov` disabled, so it’s not getting invoked by Codecov.

As I explained in my comment, we need to prepare this outside codecov, because it calls gcov incorrectly, and stuffs all gcov output files to source root directory.

---

<div class="post-metadata">

**Author:** ![cmouse](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/cmouse/32/1051_2.png) [@cmouse](https://community.codecov.com/u/cmouse)\
**Post date:** [September 16, 2020, 6:56am UTC](https://community.codecov.com/t/codecov-invokes-gcov-incorrectly/1895/8 "2020-09-16T06:56:48Z")

</div>

@tom hi, do you still need further information?

---

<div class="post-metadata">

**Author:** ![tom](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/tom/32/8_2.png) [@tom](https://community.codecov.com/u/tom)\
**Post date:** [September 22, 2020, 10:38pm UTC](https://community.codecov.com/t/codecov-invokes-gcov-incorrectly/1895/9 "2020-09-22T22:38:35Z")

</div>

Hi @cmouse, sorry for the delay here. This is a bit of a beast to try to debug. Would you happen to have coverage for one file in particular? It would be a little easier to pinpoint where this might be failing.

---

<div class="post-metadata">

**Author:** ![cmouse](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/cmouse/32/1051_2.png) [@cmouse](https://community.codecov.com/u/cmouse)\
**Post date:** [September 23, 2020, 5:57am UTC](https://community.codecov.com/t/codecov-invokes-gcov-incorrectly/1895/10 "2020-09-23T05:57:22Z")

</div>

Hi!

To get coverage for, say, lib directory, you can just run `./test-lib` under there. The entire output has been gathered with `make check`. But, I have included screenshot of some of the files under lib, maybe this helps?

 ![kuva](https://canada1.discourse-cdn.com/flex029/uploads/codecov/original/2X/0/0111ab3b4142f6679389e794b41e1acb0a261b85.png)’

Including also full line coverage for aqueue.c

 ![kuva](https://canada1.discourse-cdn.com/flex029/uploads/codecov/original/2X/f/f99a8938ef51791b0058b3ffe3a86719894074f3.png)

---

<div class="post-metadata">

**Author:** ![tom](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/tom/32/8_2.png) [@tom](https://community.codecov.com/u/tom)\
**Post date:** [September 28, 2020, 8:39pm UTC](https://community.codecov.com/t/codecov-invokes-gcov-incorrectly/1895/11 "2020-09-28T20:39:12Z")

</div>

Hi @cmouse, the raw report [here](https://codecov.io/gh/dovecot/core/commit/b3f95fbad770bfe6a222239fea5b2115dacf7317/build) is showing that all of those lines should be uncovered. Would you be able to provide a build URL (from your CI)?

---

<div class="post-metadata">

**Author:** ![cmouse](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/cmouse/32/1051_2.png) [@cmouse](https://community.codecov.com/u/cmouse)\
**Post date:** [September 29, 2020, 6:48am UTC](https://community.codecov.com/t/codecov-invokes-gcov-incorrectly/1895/12 "2020-09-29T06:48:02Z")

</div>

I think I now realize what the problem is. Your script is not dealing correctly with libtool, which puts files into .libs directory.

```auto
buildbot@43cb795326f5:/buildslave/core-ci/build/core/src/lib$ gcov .libs/stats-dist  
File 'stats-dist.c'
Lines executed:93.83% of 81
Creating 'stats-dist.c.gcov'

File '/usr/include/x86_64-linux-gnu/bits/string_fortified.h'
Lines executed:100.00% of 1
Creating 'string_fortified.h.gcov'

File 'sort.h'
Lines executed:100.00% of 1
Creating 'sort.h.gcov'

buildbot@43cb795326f5:/buildslave/core-ci/build/core/src/lib$ gcov stats-dist.o
stats-dist.gcda:cannot open data file, assuming not executed
File 'stats-dist.c'
Lines executed:0.00% of 81
Creating 'stats-dist.c.gcov'

File '/usr/include/x86_64-linux-gnu/bits/string_fortified.h'
Lines executed:0.00% of 1
Creating 'string_fortified.h.gcov'

File 'sort.h'
Lines executed:0.00% of 1
Creating 'sort.h.gcov'

```

---

<div class="post-metadata">

**Author:** ![cmouse](https://yyz1.discourse-cdn.com/flex029/user_avatar/community.codecov.com/cmouse/32/1051_2.png) [@cmouse](https://community.codecov.com/u/cmouse)\
**Post date:** [September 29, 2020, 6:54am UTC](https://community.codecov.com/t/codecov-invokes-gcov-incorrectly/1895/13 "2020-09-29T06:54:48Z")

</div>

I ran this helper script first:

```auto
#!/usr/bin/env bash

filelist=`mktemp`

find . -name "*.o" > $filelist
basedir=$PWD

while read f; do
        if [[$f == */.libs/*]]; then
                echo $f
                # determine base directory
                d=${f%%.libs*}
                cd $basedir/$d
                f=${f#*/.libs/}
                gcov .libs/$f
        fi
done <$filelist

rm $filelist

```

followed with invoking codecov.sh as

```auto
codecov -X gcov

```

and now I’m seeing similar results in [latest report](https://codecov.io/github/dovecot/core/commit/645a30a6c74bdfe3cb167382c275222cb9f7a5f5) which lcov gives.
