Skip to content

TST: including C source line coverage for CI / codecov - #11610

Merged
charris merged 1 commit into
numpy:masterfrom
tylerjereddy:coverage_C_source
Aug 15, 2018
Merged

charris merged 1 commit into
numpy:masterfrom
tylerjereddy:coverage_C_source

Conversation

@tylerjereddy

Copy link
Copy Markdown
Contributor

First attempt at trying to get C source line coverage reported via codecov; inspired by the SciPy approach to doing this, but will almost certainly fail initially due to some differences between the CI setup for the two projects.

@tylerjereddy

Copy link
Copy Markdown
Contributor Author

I think I'm stuck with Travis problems when compiling _configtest.c after adjusting the C compiler flags to include --coverage. Seems to work just fine locally.

Any suggestions from the experienced NumPy devs? Strange things that sometimes have to be adjusted when playing with compiler flags?

The error message is quite sensible, undefined reference to __gcov_init, so it looks like I'm part of the way there since there's recognition that I'm trying to use gcov, but something is also still missing, and adjusting to include --coverage in link-time flags had no apparent effect.

@pv

pv commented Jul 30, 2018 •

Copy link
Copy Markdown
Member

Setting LDFLAGS environment variable overrides default Python flags, see gh-11525, which probably is the cause for all problems. Finding out what the "default Python flags" are is somewhat complex and annoying, as you probably found out.

This is the reason why in Scipy, the gcov setup is done by setting CC/CXX/F77/F90 compiler executables and not touch the *FLAGS environment variables. With the recent numpy distutils change you can in principle do it via the *FLAGS, but setting the compilers may be more robust.

@pv

pv commented Jul 30, 2018

Copy link
Copy Markdown
Member

Of course, I'm wrong above, since the Scipy stanza for this reads

            import distutils.sysconfig
            cvars = distutils.sysconfig.get_config_vars()
            env['OPT'] = '-O0 -ggdb'
            env['FOPT'] = '-O0 -ggdb'
            env['CC'] = cvars['CC'] + ' --coverage'
            env['CXX'] = cvars['CXX'] + ' --coverage'
            env['F77'] = 'gfortran --coverage '
            env['F90'] = 'gfortran --coverage '
            env['LDSHARED'] = cvars['LDSHARED'] + ' --coverage'
            env['LDFLAGS'] = " ".join(cvars['LDSHARED'].split()[1:]) + ' --coverage'

You may be able to do it in an easier way by setting export NPY_DISTUTILS_APPEND_FLAGS=1, so that it's not necessary to figure out what the old flags were.

@tylerjereddy
tylerjereddy force-pushed the coverage_C_source branch 2 times, most recently from 8cf898d to 64904dc Compare August 2, 2018 20:42
@tylerjereddy

Copy link
Copy Markdown
Contributor Author

So, the CI is finally green and we can see the coverage report for C source files now. Looks like another 40,000 lines of code are tracked now, with about a 1 % drop from the pure Python cov report.

I need to clean up a bit here still, and I'm somewhat concerned that I had to retrieve the above link from the CI job "terminal" in Travis rather than being able to click on the links at the bottom of the PR (maybe because this is the first activation for those new files?) to see the new C files with highlights.

Other discussion point -- any concern about manipulating the "full coverage" CI job with coverage compiler flags (i.e., is it preferred to expand the matrix for a seperate C cov job or combining is ok?).

@rgommers

rgommers commented Aug 3, 2018

Copy link
Copy Markdown
Member

is it preferred to expand the matrix for a seperate C cov job or combining is ok?

combining seems fine to me. we already have a very large build matrix, and unless there's a reason to grow its size then it's better not to

@tylerjereddy

Copy link
Copy Markdown
Contributor Author

I've removed debug code & cleaned up the commit history, but I'll leave the WIP tag for now because I'm still concerned about having to use the "Travis terminal link" to access the newly-covered files; perhaps one more slight adjustment is needed to get it just right for those links.

@tylerjereddy tylerjereddy changed the title [WIP] TST: including C source line coverage for CI / codecov TST: including C source line coverage for CI / codecov Aug 5, 2018
@tylerjereddy

Copy link
Copy Markdown
Contributor Author

I've removed the WIP tag--I don't see any evidence of a specific issue with the added C coverage report now. The codecov links at the bottom of the page are for the diffs between commit hashes at head of master and the current branch--naturally, you can't diff on a file that isn't tracked in the master coverage report yet; clicking on the newer commit from this branch properly shows the coverage for C files.

@mattip

mattip commented Aug 6, 2018

Copy link
Copy Markdown
Member

you can't diff on a file that isn't tracked in the master coverage report yet; clicking on the newer commit from this branch properly shows the coverage for C files.

For those like me who have not seen this before, it is pretty neat. @tylerjereddy took me through the results here, for example to see src/umath/loops.c.src, do this (I think you need to be logged in on a desktop to see the "Show all checks" link:

  • click on Show all checks to expand the test runs
  • click on details for either of the codecov runs
  • At the top note the Compare 8eed36a ... +0 ... 654a4c0, @tylerjereddy noted that the base commit has no coverage yet so click on the 654a4c0 changeset
  • Then drill down Files->numpy->core->src->umath->loops.c.src. Once you get past the macro definitions, you begin to see where our tests do not cover code paths.

@tylerjereddy

Copy link
Copy Markdown
Contributor Author

Rebased on latest master & force pushed to make sure this plays well with the setup.py ignore stuff for codecov (can't imagine it wouldn't though).

@charris

charris commented Aug 14, 2018

Copy link
Copy Markdown
Member

LGTM, any demurrers?

@charris

charris commented Aug 15, 2018

Copy link
Copy Markdown
Member

Well, let's see how this goes... Thanks @tylerjereddy .

@charris
charris merged commit 4e81bbf into numpy:master Aug 15, 2018
@tylerjereddy
tylerjereddy deleted the coverage_C_source branch August 16, 2018 16:54
@tylerjereddy

Copy link
Copy Markdown
Contributor Author

Clicking through the badge on our main readme / landing page on github now shows the C source line coverage as well.

@pv

pv commented Aug 19, 2018

Copy link
Copy Markdown
Member

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.

5 participants