Skip to content

Commit 4bc847d

Browse files
ianlancetaylorandybons
authored andcommitted
[release-branch.go1.10] cmd/go: if -race, don't run coverage on runtime packages
Don't compile the runtime packages with coverage when using the race detector. The user can, perhaps accidentally, request coverage for the runtime by using -coverpkg=all. If using the race detector, the runtime package coverage will call into the race detector before it has been initialized. This will cause the program to crash mysteriously on startup. Fixes #23882 Change-Id: I9a63867a9138797d8b8afb0856ae21079accdb27 Reviewed-on: https://go-review.googlesource.com/94898 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Andrew Bonventre <[email protected]> Reviewed-on: https://go-review.googlesource.com/103095 Run-TryBot: Andrew Bonventre <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent c917b3c commit 4bc847d

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/cmd/go/go_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5750,6 +5750,21 @@ func TestAtomicCoverpkgAll(t *testing.T) {
57505750
}
57515751
}
57525752

5753+
// Issue 23882.
5754+
func TestCoverpkgAllRuntime(t *testing.T) {
5755+
tg := testgo(t)
5756+
defer tg.cleanup()
5757+
tg.parallel()
5758+
5759+
tg.tempFile("src/x/x.go", `package x; import _ "runtime"; func F() {}`)
5760+
tg.tempFile("src/x/x_test.go", `package x; import "testing"; func TestF(t *testing.T) { F() }`)
5761+
tg.setenv("GOPATH", tg.path("."))
5762+
tg.run("test", "-coverpkg=all", "x")
5763+
if canRace {
5764+
tg.run("test", "-coverpkg=all", "-race", "x")
5765+
}
5766+
}
5767+
57535768
func TestBadCommandLines(t *testing.T) {
57545769
tg := testgo(t)
57555770
defer tg.cleanup()

src/cmd/go/internal/test/test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,14 @@ func runTest(cmd *base.Command, args []string) {
668668
continue
669669
}
670670

671+
// If using the race detector, silently ignore
672+
// attempts to run coverage on the runtime
673+
// packages. It will cause the race detector
674+
// to be invoked before it has been initialized.
675+
if cfg.BuildRace && p.Standard && (p.ImportPath == "runtime" || strings.HasPrefix(p.ImportPath, "runtime/internal")) {
676+
continue
677+
}
678+
671679
if haveMatch {
672680
testCoverPkgs = append(testCoverPkgs, p)
673681
}

0 commit comments

Comments
 (0)