]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/testing/benchmark.go
testing: use monotonic counts to attribute races in subtests
[gostls13.git] / src / testing / benchmark.go
index c9012ea0acb3d4e2b2f648e00f6851472590e7bf..261d0b2a040e55a28fca1c565e527ce16010a070 100644 (file)
@@ -7,7 +7,6 @@ package testing
 import (
        "flag"
        "fmt"
-       "internal/race"
        "internal/sysinfo"
        "io"
        "math"
@@ -179,11 +178,14 @@ func (b *B) ReportAllocs() {
 func (b *B) runN(n int) {
        benchmarkLock.Lock()
        defer benchmarkLock.Unlock()
-       defer b.runCleanup(normalPanic)
+       defer func() {
+               b.runCleanup(normalPanic)
+               b.checkRaces()
+       }()
        // Try to get a comparable environment for each run
        // by clearing garbage from previous runs.
        runtime.GC()
-       b.raceErrors = -race.Errors()
+       b.resetRaces()
        b.N = n
        b.parallelism = 1
        b.ResetTimer()
@@ -192,10 +194,6 @@ func (b *B) runN(n int) {
        b.StopTimer()
        b.previousN = n
        b.previousDuration = b.duration
-       b.raceErrors += race.Errors()
-       if b.raceErrors > 0 {
-               b.Errorf("race detected during execution of benchmark")
-       }
 }
 
 // run1 runs the first iteration of benchFunc. It reports whether more