Skip to content

Commit 084794e

Browse files
committed
Avoid possible filename collision in coverage tests
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.
1 parent a216131 commit 084794e

File tree

1 file changed

+8
-6
lines changed
  • src/test/run-make-fulldeps/coverage-reports

1 file changed

+8
-6
lines changed

Diff for: src/test/run-make-fulldeps/coverage-reports/Makefile

+8-6
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ endif
8787
# Run it in order to generate some profiling data,
8888
# with `LLVM_PROFILE_FILE=<profdata_file>` environment variable set to
8989
# output the coverage stats for this run.
90-
LLVM_PROFILE_FILE="$(TMPDIR)"/$@-%p.profraw \
90+
LLVM_PROFILE_FILE="$(TMPDIR)"/$@.profraw \
9191
$(call RUN,$@) || \
9292
( \
9393
status=$$?; \
@@ -97,16 +97,19 @@ endif
9797
) \
9898
)
9999

100-
# Run it through rustdoc as well to cover doctests
101-
LLVM_PROFILE_FILE="$(TMPDIR)"/$@-%p.profraw \
100+
# Run it through rustdoc as well to cover doctests.
101+
# `%p` is the pid, and `%m` the binary signature. We suspect that the pid alone
102+
# might result in overwritten files and failed tests, as rustdoc spawns each
103+
# doctest as its own process, so make sure the filename is as unique as possible.
104+
LLVM_PROFILE_FILE="$(TMPDIR)"/$@-%p-%m.profraw \
102105
$(RUSTDOC) --crate-name workaround_for_79771 --test $(SOURCEDIR)/$@.rs \
103106
$$( sed -n 's/^\/\/ compile-flags: \([^#]*\).*/\1/p' $(SOURCEDIR)/$@.rs ) \
104107
-L "$(TMPDIR)" -Zinstrument-coverage \
105108
-Z unstable-options --persist-doctests=$(TMPDIR)/rustdoc-$@
106109

107110
# Postprocess the profiling data so it can be used by the llvm-cov tool
108111
"$(LLVM_BIN_DIR)"/llvm-profdata merge --sparse \
109-
"$(TMPDIR)"/$@-*.profraw \
112+
"$(TMPDIR)"/$@*.profraw \
110113
-o "$(TMPDIR)"/$@.profdata
111114

112115
# Generate a coverage report using `llvm-cov show`.
@@ -118,8 +121,7 @@ endif
118121
--instr-profile="$(TMPDIR)"/$@.profdata \
119122
$(call BIN,"$(TMPDIR)"/$@) \
120123
$$( \
121-
for file in $(TMPDIR)/rustdoc-$@/*/rust_out; \
122-
do \
124+
for file in $(TMPDIR)/rustdoc-$@/*/rust_out; do \
123125
[ -x "$$file" ] && printf "%s %s " -object $$file; \
124126
done \
125127
) \

0 commit comments

Comments
 (0)