about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2021-06-16 13:31:04 +0900
committerGitHub <noreply@github.com>2021-06-16 13:31:04 +0900
commit163dbda22bb70d9ed05147b85670cc13dcf906f3 (patch)
treeb7de6a9358f69db2f4b9be551bf1c2d4c9ed2351
parentd192c80d2284ba6b5146bb3da586354c3762c72b (diff)
parent084794ed164199619d9bd6e5422b4feaee4a0a9a (diff)
downloadrust-163dbda22bb70d9ed05147b85670cc13dcf906f3.tar.gz
rust-163dbda22bb70d9ed05147b85670cc13dcf906f3.zip
Rollup merge of #85283 - Swatinem:ordered-profraw, r=tmandry
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.

should help with #83262

r? `@tmandry`
-rw-r--r--src/test/run-make-fulldeps/coverage-reports/Makefile14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/test/run-make-fulldeps/coverage-reports/Makefile b/src/test/run-make-fulldeps/coverage-reports/Makefile
index d3d398f1fac..78fbf811f12 100644
--- a/src/test/run-make-fulldeps/coverage-reports/Makefile
+++ b/src/test/run-make-fulldeps/coverage-reports/Makefile
@@ -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 \
 			$(call RUN,$@) || \
 			( \
 				status=$$?; \
@@ -97,8 +97,11 @@ endif
 				) \
 			)
 
-	# Run it through rustdoc as well to cover doctests
-	LLVM_PROFILE_FILE="$(TMPDIR)"/$@-%p.profraw \
+	# Run it through rustdoc as well to cover doctests.
+	# `%p` is the pid, and `%m` the binary signature. We suspect that the pid alone
+	# might result in overwritten files and failed tests, as rustdoc spawns each
+	# doctest as its own process, so make sure the filename is as unique as possible.
+	LLVM_PROFILE_FILE="$(TMPDIR)"/$@-%p-%m.profraw \
 			$(RUSTDOC) --crate-name workaround_for_79771 --test $(SOURCEDIR)/$@.rs \
 			$$( sed -n 's/^\/\/ compile-flags: \([^#]*\).*/\1/p' $(SOURCEDIR)/$@.rs ) \
 			-L "$(TMPDIR)" -Zinstrument-coverage \
@@ -106,7 +109,7 @@ endif
 
 	# Postprocess the profiling data so it can be used by the llvm-cov tool
 	"$(LLVM_BIN_DIR)"/llvm-profdata merge --sparse \
-			"$(TMPDIR)"/$@-*.profraw \
+			"$(TMPDIR)"/$@*.profraw \
 			-o "$(TMPDIR)"/$@.profdata
 
 	# Generate a coverage report using `llvm-cov show`.
@@ -118,8 +121,7 @@ endif
 			--instr-profile="$(TMPDIR)"/$@.profdata \
 			$(call BIN,"$(TMPDIR)"/$@) \
 			$$( \
-				for file in $(TMPDIR)/rustdoc-$@/*/rust_out; \
-				do \
+				for file in $(TMPDIR)/rustdoc-$@/*/rust_out; do \
 				[ -x "$$file" ] && printf "%s %s " -object $$file; \
 				done \
 			) \