Skip to content

Make CC_CODE_COVERAGE_SCRIPT failures fail tests #15420

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

keith
Copy link
Member

@keith keith commented May 9, 2022

If you're editing, or overriding, this script and you introduce and
introduce an error, previously this wouldn't fail the test invocation.

Fixes #18650
Fixes #26541

@keith keith requested a review from lberki as a code owner May 9, 2022 02:44
@sgowroji sgowroji added team-Rules-Server Issues for serverside rules included with Bazel awaiting-user-response Awaiting a response from the author labels May 9, 2022
@lberki lberki requested review from c-mita and removed request for lberki May 9, 2022 06:56
@sgowroji sgowroji added awaiting-review PR is awaiting review from an assigned reviewer and removed awaiting-user-response Awaiting a response from the author labels Aug 11, 2022
@comius comius added awaiting-user-response Awaiting a response from the author and removed awaiting-review PR is awaiting review from an assigned reviewer labels Aug 26, 2022
@comius
Copy link
Contributor

comius commented Aug 26, 2022

there are CI failures

@keertk
Copy link
Member

keertk commented Dec 7, 2022

Hi there! Thank you for contributing to the Bazel repository. We appreciate your time and effort. We're doing a clean up of old PRs and will be closing this one since it seems to have stalled. Please feel free to reopen/let us know if you’re still interested in pursuing this or if you'd like to discuss anything further. We’ll respond as soon as we have the bandwidth/resources to do so.

@keertk keertk closed this Dec 7, 2022
@keith
Copy link
Member Author

keith commented Dec 7, 2022

@keertk can you reopen please

@keertk keertk reopened this Dec 7, 2022
@keith keith force-pushed the ks/make-cc_code_coverage_script-failures-fail-tests branch from 575b63f to 9a0b847 Compare January 10, 2023 01:23
@keith keith marked this pull request as draft August 4, 2023 16:43
@comius
Copy link
Contributor

comius commented Sep 25, 2023

Closing as another 2 months passed by. Feel free to reopen.

@comius comius closed this Sep 25, 2023
@keith
Copy link
Member Author

keith commented Oct 23, 2023

we should really do this but fixing the existing tests is definitely annoying

@keith keith reopened this Jan 9, 2024
@keith keith force-pushed the ks/make-cc_code_coverage_script-failures-fail-tests branch from 9a0b847 to 8313587 Compare January 9, 2024 18:03
@keith
Copy link
Member Author

keith commented Jan 9, 2024

reopening with a opt-in env var to continue ignoring this failure meant only to avoid all the issues with bazel tests + CI setup (users should avoid this flag)

@keith keith marked this pull request as ready for review January 10, 2024 17:42
@keith keith requested a review from a team as a code owner January 10, 2024 17:42
@keith
Copy link
Member Author

keith commented Jan 10, 2024

@comius what do you think about this solution to avoid having to fix all the tests + CI runner setup

@github-actions github-actions bot added team-Remote-Exec Issues and PRs for the Execution (Remote) team awaiting-review PR is awaiting review from an assigned reviewer labels Jan 10, 2024
@keith
Copy link
Member Author

keith commented Jan 22, 2024

@comius can you take a look?

@keith keith force-pushed the ks/make-cc_code_coverage_script-failures-fail-tests branch from ab3967d to 3dad2a9 Compare January 13, 2025 22:56
@keith
Copy link
Member Author

keith commented Jan 14, 2025

@c-mita @comius ptal

@keith keith force-pushed the ks/make-cc_code_coverage_script-failures-fail-tests branch 2 times, most recently from fc7a9cc to fbec90f Compare March 28, 2025 19:02
@keith
Copy link
Member Author

keith commented Mar 28, 2025

@c-mita @comius

@meisterT meisterT removed the team-Remote-Exec Issues and PRs for the Execution (Remote) team label May 7, 2025
@keith
Copy link
Member Author

keith commented Jun 10, 2025

@c-mita @comius ptal 🙏🏻

@keith
Copy link
Member Author

keith commented Jun 17, 2025

@pzembrod can you checkout this one too? 🙏🏻

Copy link
Contributor

@pzembrod pzembrod left a comment

Choose a reason for hiding this comment

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

Will double-check with @c-mita tomorrow.

@c-mita
Copy link
Member

c-mita commented Jun 18, 2025

How many tests fail without the flag set? I wouldn't think it's many?

@keith
Copy link
Member Author

keith commented Jun 18, 2025

last I checked it was many and i only added the opt outs as needed, i will test again.

@keith
Copy link
Member Author

keith commented Jun 18, 2025

The core issue is the CI machines don't have the tools installed GCov does not exist at the given path: ''

@keith
Copy link
Member Author

keith commented Jun 18, 2025

@c-mita
Copy link
Member

c-mita commented Jun 18, 2025

Ok, so before this can be accepted, I think one of two things needs to be changed:

  • collect_cc_coverage.sh is called if and only if C++ coverage is actually required.
  • The default is to ignore failures in the script.

The former is more complex but is I think the better solution. And we should get around to resolving the coverage linking issue (#15634 (comment)), although I don't think that's a hard requirement for this.

@fmeum
Copy link
Collaborator

fmeum commented Jun 18, 2025

collect_cc_coverage.sh is called if and only if C++ coverage is actually required.

I agree that this is the best approach, but I'm not sure how to determine whether this is the case. For example, what about a java_binary that has a JNI .so in data (not linked into the Java runtime)?

@c-mita
Copy link
Member

c-mita commented Jun 18, 2025

collect_cc_coverage.sh is called if and only if C++ coverage is actually required.

I agree that this is the best approach, but I'm not sure how to determine whether this is the case. For example, what about a java_binary that has a JNI .so in data (not linked into the Java runtime)?

I'm not a fan of it, but coverage_common.instrumented_files_info accepts a coverage_environment parameter, which the C++ rules are allowed to use (and they already do).

We could just add another environment variable saying "hey, C++ coverage is needed now"?
Maybe even just testing for the variables it already sets is enough?

@fmeum
Copy link
Collaborator

fmeum commented Jun 18, 2025

Checking for the variables sounds good to me

@keith
Copy link
Member Author

keith commented Jun 18, 2025

isn't this virtually already done by the fact that CC_CODE_COVERAGE_SCRIPT is only set if it has the relevant attr https://github.com/keith/bazel/blob/fbec90fb287618e3c46e71cbc961daf1587d88d4/src/main/java/com/google/devtools/build/lib/analysis/test/TestActionBuilder.java#L272-L276 which is only added to cc_test? https://github.com/keith/bazel/blob/fbec90fb287618e3c46e71cbc961daf1587d88d4/src/main/starlark/builtins_bzl/common/cc/cc_test.bzl#L101 (ignoring the fact that users could set this env var themselves)

@fmeum
Copy link
Collaborator

fmeum commented Jun 18, 2025

This attribute isn't specific to cc_test, every test rule that wants to support coverage should add it. But checking for COVERAGE_GCOV_PATH would work (maybe the script already does that).

@keith keith force-pushed the ks/make-cc_code_coverage_script-failures-fail-tests branch from fbec90f to 5dd7e60 Compare June 18, 2025 20:57
@keith
Copy link
Member Author

keith commented Jun 18, 2025

This attribute isn't specific to cc_test, every test rule that wants to support coverage should add it.

should, will, or does? since right now it really is only cc_test AFAICT.

I don't think the gcov one is entirely safe since there are codepaths that shouldn't need that tool today, but it looks like GENERATE_LLVM_LCOV is safe since it should always be present. Updated to use that. I will re-test CI to see if we can avoid some of the disables now

@fmeum
Copy link
Collaborator

fmeum commented Jun 18, 2025

Should and sometimes does, see https://github.com/bazel-contrib/rules_go/blob/1172e60b3fdb3c1b1f6efc781eda9819533375ac/go/private/rules/test.bzl#L466 and https://github.com/bazel-contrib/rules_python/blob/175a33610e853388c83730d9e2b5b2ac3626649d/python/private/attributes.bzl#L391.

https://bazel.build/extending/rules#test_rules documents this.

That variable is a good fit as well, it's unconditionally set to some value in the built-in Starlark logic.

@keith keith force-pushed the ks/make-cc_code_coverage_script-failures-fail-tests branch 3 times, most recently from 396177d to cdbc8dd Compare June 26, 2025 17:26

Verified

This commit was signed with the committer’s verified signature.
keith Keith Smiley
If you're editing, or overriding, this script and you introduce and
introduce an error, previously this wouldn't fail the test invocation.
@keith keith force-pushed the ks/make-cc_code_coverage_script-failures-fail-tests branch from cdbc8dd to a3d8e08 Compare June 26, 2025 21:11
@keith
Copy link
Member Author

keith commented Jun 26, 2025

green now, still had to disable in 1 place where it fails on macOS CI

@keith
Copy link
Member Author

keith commented Jul 15, 2025

@c-mita I think this is ready for another pass 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review PR is awaiting review from an assigned reviewer coverage team-Rules-Server Issues for serverside rules included with Bazel
Projects
None yet
8 participants