aboutsummaryrefslogtreecommitdiff
path: root/src/testing/benchmark.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2023-05-09 15:10:26 -0700
committerGopher Robot <gobot@golang.org>2023-05-24 04:06:14 +0000
commit5b93af7f4f61ccc7d770ee24641b2fd9c71c0329 (patch)
tree476170b0c3a76252d68c7d16707c584123861a37 /src/testing/benchmark.go
parent298fe517a9333c05143a8a8e1f9d5499f0c6e59b (diff)
downloadgo-5b93af7f4f61ccc7d770ee24641b2fd9c71c0329.tar.xz
testing: only report subtest races once
Before this CL the code would record the number of race detector errors seen before starting a test, and then report an error if there were more race detector errors after the test completed. That approach did not work well for subtests or parallel tests. Race detector errors could be reported multiple times at each level of subtest, and parallel tests could accidentally drop race detector errors. Instead, report each race detector error at most once, associated with whatever test noticed the new error. This is still imperfect, as it may report race detector errors for the wrong parallel test. But it shouldn't drop any errors entirely, and it shouldn't report any errors more than once. Fixes #60083 Change-Id: Ic9afea5c692b6553896757766f631cd0e86192ad Reviewed-on: https://go-review.googlesource.com/c/go/+/494057 Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/testing/benchmark.go')
-rw-r--r--src/testing/benchmark.go5
1 files changed, 1 insertions, 4 deletions
diff --git a/src/testing/benchmark.go b/src/testing/benchmark.go
index be9b87f80b..a856312f8f 100644
--- a/src/testing/benchmark.go
+++ b/src/testing/benchmark.go
@@ -7,7 +7,6 @@ package testing
import (
"flag"
"fmt"
- "internal/race"
"internal/sysinfo"
"io"
"math"
@@ -185,7 +184,6 @@ func (b *B) runN(n int) {
// Try to get a comparable environment for each run
// by clearing garbage from previous runs.
runtime.GC()
- b.raceErrors = -race.Errors()
b.N = n
b.parallelism = 1
b.ResetTimer()
@@ -194,8 +192,7 @@ func (b *B) runN(n int) {
b.StopTimer()
b.previousN = n
b.previousDuration = b.duration
- b.raceErrors += race.Errors()
- if b.raceErrors > 0 {
+ if fetchRaceErrors() > 0 {
b.Errorf("race detected during execution of benchmark")
}
}