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

Add --gcov-report flag to spin test #159

Merged

Conversation

ganesh-k13
Copy link
Contributor

@ganesh-k13 ganesh-k13 commented Jan 26, 2024

Changes

  • Added --gcov-report flag to spin test
spin test --help                                                                                                    1 ↵ ganesh@ganesh-MS-7B86
Usage: spin test [OPTIONS] [PYTEST_ARGS]...
...
  --gcov-report [html|xml|text|sonarqube]
                                  Generate a coverage report for C Code and exit
...

Testing

Happy Path

» spin test --gcov
...
» spin test --gcov-report html                                                                                    ganesh@ganesh-MS-7B86
Verifying installed packages for generating coverage reports...
$ ninja -C build -t targets all
Generating html coverage report...
$ ninja -C build coverage-html
Coverage report generated successfully and written to /home/ganesh/os/devpy/example_pkg/build/meson-logs/coveragereport/index.html

Failures

  1. No build found
» git clean -xdf                                                                                                           ganesh@ganesh-MS-7B86
Removing .spin/__pycache__/
Removing build-install/
Removing build/
» spin test --generate-gcov-report html                                                                                    ganesh@ganesh-MS-7B86
Verifying installed packages for generating coverage reports...
Error: `build` folder not found, cannot generate coverage reports. Generate coverage artefacts by running `spin test --gcov`
  1. Gcovr, etc not installed
» spin test --gcov-report html                                                                                   ganesh@ganesh-MS-7B86
Verifying installed packages for generating coverage reports...
$ ninja -C build -t targets all
Error: coverage-html is not supported... Ensure the following are installed: Gcovr/GenHTML, lcov and rerun `spin test --gcov`

Notes

ToDo

  • UT

Misc

resolves #158
continues #146

@jarrodmillman jarrodmillman added the type: Enhancement New feature or request label Jan 26, 2024
echo "Yes"
fi

# TODO: Test other coverage reports
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: I'll cover this as a part of #154 to avoid bloat here

spin/cmds/meson.py Outdated Show resolved Hide resolved
@ganesh-k13 ganesh-k13 force-pushed the enh_158_coverage_report branch 4 times, most recently from 4299ecd to 3b5fdfc Compare January 27, 2024 07:55
@ganesh-k13 ganesh-k13 marked this pull request as ready for review January 27, 2024 07:57
@stefanv
Copy link
Member

stefanv commented Jan 27, 2024

Thanks, Ganesh, I've done a brief pass and all looks good. There are a few small tweaks I'd like to make, which I'll do Monday morning.

Instead of generate-gcov-report, perhaps the shorter gcov-report? Happy to make that tweak myself, just wanted to make sure you don't object.

@ganesh-k13 ganesh-k13 changed the title Added --generate-gcov-report flag to spin test Added --gcov-report flag to spin test Jan 28, 2024
@ganesh-k13 ganesh-k13 changed the title Added --gcov-report flag to spin test Add --gcov-report flag to spin test Jan 28, 2024
@ganesh-k13
Copy link
Contributor Author

Thanks for the review @stefanv , I have renamed the flag to --gcov-report and updated the description.

if f"coverage-{coverage_type.value}" not in p.stdout.decode("ascii"):
raise click.ClickException(
f"coverage-{coverage_type.value} is not supported... "
f"Ensure the following are installed: {', '.join(requirements[coverage_type])} "
Copy link
Member

Choose a reason for hiding this comment

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

This error is raised when spin build; spin test --gcov-report. Needs to ensure that build was run with --gcov.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, shall I add a dependency to call spin build --gcov in case it's missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ok, I get the problem. We need to check for coverage artifacts. Let me add it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added checks and UT in f2c21eb

@stefanv
Copy link
Member

stefanv commented Jan 30, 2024

After looking at this some more, I'm wondering if the gcov-report option is associated with the right command. It seems unrelated to the test options, and rely on the build having been performed with --gcov.

Also, doing spin build, and then spin build --gcov isn't enough. You need spin build --clean --gcov.

So, I'd suggest moving --gcov-report to build, setting html as the default, automatically enabling --gcov when --gcov-report is set, and also detecting when the existing build wasn't run with --gcov (you can check the build/build.ninja file for coverage-* commands).

@rgommers
Copy link
Contributor

Also, doing spin build, and then spin build --gcov isn't enough. You need spin build --clean --gcov.

I'll note that this isn't specific to --gcov, it applies to anything that translates to a compile/link flag. --werror and --asan, which SciPy's dev.py has any would also be useful for spin, are good examples.

So, I'd suggest moving --gcov-report to build, setting html as the default, automatically enabling --gcov when --gcov-report is set

I'm not sure I understand that suggestion, or maybe I'm missing your point. You typically build from scratch once, and run tests many times when you're developing. You don't want a coverage report every time you run tests, so it shouldn't be done automatically. But conceptually, you want the coverage report for the tests you've just run I think, through a "give me the gcov coverage report". So it could be integrated with test, or possibly standalone - but it doesn't belong with build.

@stefanv
Copy link
Member

stefanv commented Jan 30, 2024

That was my original understanding, but then I couldn't see where the gcov outputs are generated by pytest. I clearly missed it, so I'll take another look.

@rgommers
Copy link
Contributor

That was my original understanding, but then I couldn't see where the gcov outputs are generated by pytest. I clearly missed it, so I'll take another look.

It's a separate command, unrelated to pytest. That command does need to be run after the test run of interest. E.g., see https://github.com/scipy/scipy/blob/maintenance/1.10.x/runtests.py#L510-L533.

spin/cmds/meson.py Outdated Show resolved Hide resolved
@ganesh-k13 ganesh-k13 force-pushed the enh_158_coverage_report branch from 0d18f0c to b57bc87 Compare February 29, 2024 06:33
@ganesh-k13 ganesh-k13 force-pushed the enh_158_coverage_report branch from 81ea2da to 9749de0 Compare March 9, 2024 04:19
@@ -3,5 +3,5 @@

@nox.session
def test(session: nox.Session) -> None:
session.install(".", "pytest", "build", "meson-python", "ninja")
session.install(".", "pytest", "build", "meson-python", "ninja", "gcovr")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stefanv / @jarrodmillman , should this be part of a test_requirements.yaml for depandabot to pick up and auto update or this is ok?

@ganesh-k13 ganesh-k13 requested a review from stefanv March 9, 2024 04:22
@stefanv stefanv force-pushed the enh_158_coverage_report branch from f2c21eb to 389193d Compare April 30, 2024 23:55
@stefanv
Copy link
Member

stefanv commented Apr 30, 2024

@ganesh-k13 Sorry for the delay working on this. I've reworked the logic a bit, as detailed in the commit message of 135279f. Take a look, and see if you approve of what I've done?

- Like the existing coverage option, `spin test --gcov` is now enough
  to generate gcov reports.
- The format of the report is set with `--gcov-format`.
- Coverage builds are triggered when `--gcov` is added (necessary
  to generate the coverage report), but no rebuild is done when the
  flag is removed (too expensive).
@stefanv stefanv force-pushed the enh_158_coverage_report branch from 389193d to 135279f Compare April 30, 2024 23:58
Copy link
Contributor Author

@ganesh-k13 ganesh-k13 left a comment

Choose a reason for hiding this comment

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

Thanks, looks good! I cannot approve as I'm the author, but looks good to go. I'll port this to NumPy and hopefully enable code cov reports in the CI soon.

@jarrodmillman jarrodmillman merged commit 00b9c31 into scientific-python:main May 1, 2024
17 checks passed
@jarrodmillman jarrodmillman added this to the 0.9 milestone May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate C code coverage reports
4 participants