Skip to content

Commit cf70d37

Browse files
committed
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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Than McIntosh <[email protected]>
1 parent 8bec956 commit cf70d37

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/runtime/coverage/testsupport.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"internal/coverage/pods"
1616
"io"
1717
"os"
18+
"strings"
1819
)
1920

2021
// processCoverTestDir is called (via a linknamed reference) from
@@ -80,7 +81,15 @@ func processCoverTestDirInternal(dir string, cfile string, cm string, cpkg strin
8081
cf: cformat.NewFormatter(cmode),
8182
cmode: cmode,
8283
}
84+
// Generate the expected hash string based on the final meta-data
85+
// hash for this test, then look only for pods that refer to that
86+
// hash (just in case there are multiple instrumented executables
87+
// in play). See issue #57924 for more on this.
88+
hashstring := fmt.Sprintf("%x", finalHash)
8389
for _, p := range podlist {
90+
if !strings.Contains(p.MetaFile, hashstring) {
91+
continue
92+
}
8493
if err := ts.processPod(p); err != nil {
8594
return err
8695
}

0 commit comments

Comments
 (0)