aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThan McIntosh <thanm@google.com>2023-01-19 10:16:07 -0500
committerMatthew Dempsky <mdempsky@google.com>2023-01-26 23:27:43 +0000
commitbe7e4fee4b6a96074d003d7211047c23ae9e6c18 (patch)
treebc2f6e3bfa50bec6253ae4e292afd570724dbc71
parentb68d699aa73291d3ab8c7547047308efcd582072 (diff)
downloadgo-be7e4fee4b6a96074d003d7211047c23ae9e6c18.tar.gz
go-be7e4fee4b6a96074d003d7211047c23ae9e6c18.zip
[release-branch.go1.20] runtime/coverage: avoid non-test coverage profiles in test report helper
When walking through the set of coverage data files generated from a "go test -cover" run, it's possible to encounter pods (clumps of data files) that were generated by a run from an instrumented Go tool (for example, cmd/compile). Add a guard to the test reporting code to ensure that it only processes files created by the currently running test. Fixes #57924. Change-Id: I1bb7dce88305e1088162e3cb1df628486ecee1c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/462756 Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Than McIntosh <thanm@google.com> (cherry picked from commit cf70d37967b8447af8305e02ef534c4c5f42d49c) Reviewed-on: https://go-review.googlesource.com/c/go/+/463417 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Auto-Submit: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
-rw-r--r--src/runtime/coverage/testsupport.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/runtime/coverage/testsupport.go b/src/runtime/coverage/testsupport.go
index 1d90ebd7a2..a481bbbd9d 100644
--- a/src/runtime/coverage/testsupport.go
+++ b/src/runtime/coverage/testsupport.go
@@ -15,6 +15,7 @@ import (
"internal/coverage/pods"
"io"
"os"
+ "strings"
)
// processCoverTestDir is called (via a linknamed reference) from
@@ -80,7 +81,15 @@ func processCoverTestDirInternal(dir string, cfile string, cm string, cpkg strin
cf: cformat.NewFormatter(cmode),
cmode: cmode,
}
+ // Generate the expected hash string based on the final meta-data
+ // hash for this test, then look only for pods that refer to that
+ // hash (just in case there are multiple instrumented executables
+ // in play). See issue #57924 for more on this.
+ hashstring := fmt.Sprintf("%x", finalHash)
for _, p := range podlist {
+ if !strings.Contains(p.MetaFile, hashstring) {
+ continue
+ }
if err := ts.processPod(p); err != nil {
return err
}