summaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2014-09-09 12:31:07 -0700
committerRob Pike <r@golang.org>2014-09-09 12:31:07 -0700
commitf6c422eb4749f1983e1c2640fea5f63367f44bb9 (patch)
tree293675319aaf41b226d94be91a0b9cd18765c8d8 /src/testing
parentf447de583f8a101c406a2ed2e54300bdabb90034 (diff)
downloadgo-f6c422eb4749f1983e1c2640fea5f63367f44bb9.tar.gz
testing: read coverage counters atomically
For -mode=atomic, we need to read the counters using an atomic load to avoid a race. Not worth worrying about when -mode=atomic is set during generation of the profile, so we use atomic loads always. Fixes issue 8630. LGTM=rsc R=dvyukov, rsc CC=golang-codereviews https://codereview.appspot.com/141800043
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/cover.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/testing/cover.go b/src/testing/cover.go
index eb7249dcc..a4ce37f7c 100644
--- a/src/testing/cover.go
+++ b/src/testing/cover.go
@@ -9,6 +9,7 @@ package testing
import (
"fmt"
"os"
+ "sync/atomic"
)
// CoverBlock records the coverage data for a single basic block.
@@ -44,8 +45,8 @@ type Cover struct {
func Coverage() float64 {
var n, d int64
for _, counters := range cover.Counters {
- for _, c := range counters {
- if c > 0 {
+ for i := range counters {
+ if atomic.LoadUint32(&counters[i]) > 0 {
n++
}
d++
@@ -84,11 +85,13 @@ func coverReport() {
}
var active, total int64
+ var count uint32
for name, counts := range cover.Counters {
blocks := cover.Blocks[name]
- for i, count := range counts {
+ for i := range counts {
stmts := int64(blocks[i].Stmts)
total += stmts
+ count = atomic.LoadUint32(&counts[i]) // For -mode=atomic.
if count > 0 {
active += stmts
}