]> Cypherpunks repositories - gostls13.git/commitdiff
testing: convert common.hasSub to atomic type
authorcuiweixie <cuiweixie@gmail.com>
Sat, 27 Aug 2022 02:30:46 +0000 (10:30 +0800)
committerGopher Robot <gobot@golang.org>
Mon, 29 Aug 2022 20:19:15 +0000 (20:19 +0000)
Change-Id: I3d8a9b901efabe62f432c06361826f46c78d2605
Reviewed-on: https://go-review.googlesource.com/c/go/+/426080
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/testing/benchmark.go
src/testing/testing.go

index ce1ab6da37964d3ac05c6923a443c38f976c1b53..2f7936611f7df6b79e67b885bd2522a4c714b4b8 100644 (file)
@@ -242,7 +242,7 @@ func (b *B) run1() bool {
        b.mu.RLock()
        finished := b.finished
        b.mu.RUnlock()
-       if atomic.LoadInt32(&b.hasSub) != 0 || finished {
+       if b.hasSub.Load() || finished {
                tag := "BENCH"
                if b.skipped {
                        tag = "SKIP"
@@ -639,7 +639,7 @@ var hideStdoutForTesting = false
 func (b *B) Run(name string, f func(b *B)) bool {
        // Since b has subbenchmarks, we will no longer run it as a benchmark itself.
        // Release the lock and acquire it on exit to ensure locks stay paired.
-       atomic.StoreInt32(&b.hasSub, 1)
+       b.hasSub.Store(true)
        benchmarkLock.Unlock()
        defer benchmarkLock.Lock()
 
@@ -671,7 +671,7 @@ func (b *B) Run(name string, f func(b *B)) bool {
        if partial {
                // Partial name match, like -bench=X/Y matching BenchmarkX.
                // Only process sub-benchmarks, if any.
-               atomic.StoreInt32(&sub.hasSub, 1)
+               sub.hasSub.Store(true)
        }
 
        if b.chatty != nil {
index 5fd153954d1c78c782873b7e92d7b50a4911db13..7148537370fa6e23c6ad71ff606ee3e619cf0af5 100644 (file)
@@ -539,7 +539,7 @@ type common struct {
 
        chatty     *chattyPrinter // A copy of chattyPrinter, if the chatty flag is set.
        bench      bool           // Whether the current test is a benchmark.
-       hasSub     int32          // Written atomically.
+       hasSub     atomic.Bool    // whether there are sub-benchmarks.
        raceErrors int            // Number of races detected during test.
        runner     string         // Function name of tRunner running the test.
 
@@ -1459,7 +1459,7 @@ func tRunner(t *T, fn func(t *T)) {
                // Do not lock t.done to allow race detector to detect race in case
                // the user does not appropriately synchronize a goroutine.
                t.done = true
-               if t.parent != nil && atomic.LoadInt32(&t.hasSub) == 0 {
+               if t.parent != nil && !t.hasSub.Load() {
                        t.setRan()
                }
        }()
@@ -1486,7 +1486,7 @@ func tRunner(t *T, fn func(t *T)) {
 // Run may be called simultaneously from multiple goroutines, but all such calls
 // must return before the outer test function for t returns.
 func (t *T) Run(name string, f func(t *T)) bool {
-       atomic.StoreInt32(&t.hasSub, 1)
+       t.hasSub.Store(true)
        testName, ok, _ := t.context.match.fullName(&t.common, name)
        if !ok || shouldFailFast() {
                return true