// AllocsPerRun sets GOMAXPROCS to 1 during its measurement and will restore
// it before returning.
func AllocsPerRun(runs int, f func()) (avg float64) {
+ if parallelStart.Load() != parallelStop.Load() {
+ panic("testing: AllocsPerRun called during parallel test")
+ }
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(1))
// Warm up the function
var initRan bool
+var (
+ parallelStart atomic.Int64 // number of parallel tests started
+ parallelStop atomic.Int64 // number of parallel tests stopped
+)
+
// Init registers testing flags. These flags are automatically registered by
// the "go test" command before running test functions, so Init is only needed
// when calling functions such as Benchmark without using "go test".
if t.denyParallel {
panic(parallelConflict)
}
- t.isParallel = true
if t.parent.barrier == nil {
// T.Parallel has no effect when fuzzing.
// Multiple processes may run in parallel, but only one input can run at a
return
}
+ t.isParallel = true
+
// We don't want to include the time we spend waiting for serial tests
// in the test duration. Record the elapsed time thus far and reset the
// timer afterwards.
t.signal <- true // Release calling test.
<-t.parent.barrier // Wait for the parent test to complete.
t.tstate.waitParallel()
+ parallelStart.Add(1)
if t.chatty != nil {
t.chatty.Updatef(t.name, "=== CONT %s\n", t.name)
panic(err)
}
running.Delete(t.name)
+ if t.isParallel {
+ parallelStop.Add(1)
+ }
t.signal <- signal
}()