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

Avoid possible filename collision in coverage tests #85283

Merged
merged 1 commit into from
Jun 16, 2021

Conversation

Swatinem
Copy link
Contributor

@Swatinem Swatinem commented May 14, 2021

Previously, coverage tests were writing profiler data to files based on
their pid. As rustdoc spawns each doctest as its own process, it might
be possible in rare cases that a pid is being reused which would cause
a file to be overwritten, leading to incorrect coverage results.

should help with #83262

r? @tmandry

@Swatinem Swatinem force-pushed the ordered-profraw branch 2 times, most recently from 8e5a60a to 50c5b39 Compare May 14, 2021 10:24
@richkadel
Copy link
Contributor

@Swatinem - Thanks for the PR.

I need more time to consider these changes than I have right now (on vacation).

Would you be willing to upload a separate change that disables the doctest coverage test on MSVC (as discussed in #83262 (comment)) in the mean time?

If you feel strongly about this change, you could ask @tmandry or @wesleywiser to take a look in my place. Otherwise, I'll take a look at this PR next week.

@camelid camelid added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) A-testsuite Area: The testsuite used to check the correctness of rustc labels May 28, 2021
@Swatinem
Copy link
Contributor Author

ping @richkadel might this still be a worthwhile change for right now?

Surely, refactoring the tests to run directly via rustbuild/compiletest might be interesting, but not really something I feel like getting into right now.

@richkadel
Copy link
Contributor

Sorry for the delay! I'll take a look now.

Copy link
Contributor

@richkadel richkadel left a comment

Choose a reason for hiding this comment

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

@Swatinem - Thanks for the PR!

I left some inline comments. In my view, the only change that I think has a chance of resolving the issue (if our theory is right about reused PIDs) is adding the %m.

Please let me know if you see things differently, and add comments to the Makefile that explain the reasons for options you are adding and the expected impact/benefit of those options (for future reviewers).

Also, I don't understand the PR title, particularly, "Order profraw files explicitly". (I thought this was about filename collisions, and I don't see anything in your change that has to do with ordering files.)

What I think is happening (best guess) is the .profraw files are generated for each doc test, and at least some of the doctests are run under the same Windows PID. If that's happening, then some doc test .profraw results are overwritten, so the coverage for them is lost.

That would happen before running llvm-profdata, so adding --num-threads to the LLVM commands doesn't seem relevant to me.

So I may not fully understand what your change is doing, but if you agree with what I've said, then I recommend changing the title to be more accurate, something like, "Address possible PID-based profraw filename collisions on doc tests".

@@ -87,7 +87,7 @@ endif
# Run it in order to generate some profiling data,
# with `LLVM_PROFILE_FILE=<profdata_file>` environment variable set to
# output the coverage stats for this run.
LLVM_PROFILE_FILE="$(TMPDIR)"/$@-%p.profraw \
LLVM_PROFILE_FILE="$(TMPDIR)"/$@.profraw \
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 I support the change on this line (removing pid from the non-doc-test run), even though it shouldn't make a difference in the result.

@@ -98,28 +98,29 @@ endif
)

# Run it through rustdoc as well to cover doctests
LLVM_PROFILE_FILE="$(TMPDIR)"/$@-%p.profraw \
LLVM_PROFILE_FILE="$(TMPDIR)"/$@-%p-%m.profraw \
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will help, assuming our theory is correct that there could be PID-reuse on Windows. As I understand it, every doc test produces a new, program (new main() and unique source) so the binary signature (%m) should be different for each one.

In theory, adding the PID %p value is probably superfluous, because %m should be unique enough, but maybe keeping %p is an added safeguard to ensuring we don't have filename collisions, and there's probably harm keeping both.

src/test/run-make-fulldeps/coverage-reports/Makefile Outdated Show resolved Hide resolved
@richkadel
Copy link
Contributor

r? @tmandry

(I don't have privileges to approve in rust-lang/rust, but Tyler can.)

@richkadel
Copy link
Contributor

r? @tmandry

@Swatinem - You may have to update the reviewer. It doesn't seem like highfive is responding to my r? directive.

Previously, coverage tests were writing profiler data to files based on
their pid. As rustdoc spawns each doctest as its own process, it might
be possible in rare cases that a pid is being reused which would cause
a file to be overwritten, leading to incorrect coverage results.
@Swatinem
Copy link
Contributor Author

r? @tmandry

I rebased and added another comment, removing unrelated changes. (I was trying different things but couldn’t reproduce this) Will change the PR title and description in a moment.

@Swatinem Swatinem changed the title Order profraw files explicitly for llvm-profdata merge Avoid possible filename collision in coverage tests Jun 14, 2021
@tmandry
Copy link
Member

tmandry commented Jun 16, 2021

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jun 16, 2021

📌 Commit 084794e has been approved by tmandry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 16, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 16, 2021
Rollup of 8 pull requests

Successful merges:

 - rust-lang#85283 (Avoid possible filename collision in coverage tests)
 - rust-lang#86200 (Updates `Clone` docs for `Copy` comparison.)
 - rust-lang#86209 (fix minor wording/typo issues in core::option docs)
 - rust-lang#86242 (rustdoc- dont ICE on `ConstEvaluatable` predicates)
 - rust-lang#86280 (Add a regression test for issue-76510)
 - rust-lang#86293 (Allow to run only a few GUI tests)
 - rust-lang#86327 (Don't mark "safe" intrinsics as unsafe)
 - rust-lang#86345 (Remove some duplicate `char` assoc items on RELEASES.md)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 163dbda into rust-lang:master Jun 16, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jun 16, 2021
@Swatinem Swatinem deleted the ordered-profraw branch November 3, 2021 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants