]> Cypherpunks.ru repositories - gostls13.git/commitdiff
internal/testenv: add and use OptimizationOff/SkipIfOptimizationOff
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 8 Aug 2022 17:55:13 +0000 (00:55 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 9 Aug 2022 12:16:31 +0000 (12:16 +0000)
So we don't have to duplicate the logic to detect noopt builder in
multiple places.

Based on khr@'s suggestion in CL 422037.

Change-Id: Idb338e8bc08cdf00460574bfc0d2f7018c79bbd5
Reviewed-on: https://go-review.googlesource.com/c/go/+/422038
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>

src/cmd/compile/internal/test/issue53888_test.go
src/crypto/ed25519/ed25519_test.go
src/crypto/internal/edwards25519/edwards25519_test.go
src/crypto/internal/nistec/nistec_test.go
src/internal/testenv/testenv.go
src/math/big/int_test.go
src/net/netip/netip_test.go
src/reflect/all_test.go
src/runtime/traceback_test.go

index 032412afcfb14af4db86187508a4e096a1d91048..89c40eca2b25480ef23898aa3669a204d78fe487 100644 (file)
@@ -8,15 +8,12 @@ package test
 
 import (
        "internal/testenv"
-       "strings"
        "testing"
 )
 
 // TODO(cuonglm,mdempsky): figure out why Unifed IR failed?
 func TestAppendOfMake(t *testing.T) {
-       if strings.HasSuffix(testenv.Builder(), "-noopt") {
-               t.Skip("append of make optimization is disabled on noopt builder")
-       }
+       testenv.SkipIfOptimizationOff(t)
        for n := 32; n < 33; n++ { // avoid stack allocation of make()
                b := make([]byte, n)
                f := func() {
index 7c5181788f60a6f28390676881930cf098967993..2e7fe23025bb304872373bca50073744f891e762 100644 (file)
@@ -12,6 +12,7 @@ import (
        "crypto/internal/boring"
        "crypto/rand"
        "encoding/hex"
+       "internal/testenv"
        "os"
        "strings"
        "testing"
@@ -190,9 +191,8 @@ func TestAllocations(t *testing.T) {
        if boring.Enabled {
                t.Skip("skipping allocations test with BoringCrypto")
        }
-       if strings.HasSuffix(os.Getenv("GO_BUILDER_NAME"), "-noopt") {
-               t.Skip("skipping allocations test without relevant optimizations")
-       }
+       testenv.SkipIfOptimizationOff(t)
+
        if allocs := testing.AllocsPerRun(100, func() {
                seed := make([]byte, SeedSize)
                message := []byte("Hello, world!")
index 9bc33f9017617f3af0ecb6ed607bd4fa124d8e1d..537e503b9de4c496c56ab8772c5f85d61ced7ee5 100644 (file)
@@ -7,9 +7,8 @@ package edwards25519
 import (
        "crypto/internal/edwards25519/field"
        "encoding/hex"
-       "os"
+       "internal/testenv"
        "reflect"
-       "strings"
        "testing"
 )
 
@@ -281,9 +280,8 @@ func TestNonCanonicalPoints(t *testing.T) {
 var testAllocationsSink byte
 
 func TestAllocations(t *testing.T) {
-       if strings.HasSuffix(os.Getenv("GO_BUILDER_NAME"), "-noopt") {
-               t.Skip("skipping allocations test without relevant optimizations")
-       }
+       testenv.SkipIfOptimizationOff(t)
+
        if allocs := testing.AllocsPerRun(100, func() {
                p := NewIdentityPoint()
                p.Add(p, NewGeneratorPoint())
index 1903f19af3195a48ef605fafcd8c3ee0a6a8b9bc..adddab23a0cf0d6216ca441266aa4b13a1a7d0da 100644 (file)
@@ -8,17 +8,15 @@ import (
        "bytes"
        "crypto/elliptic"
        "crypto/internal/nistec"
+       "internal/testenv"
        "math/big"
        "math/rand"
-       "os"
-       "strings"
        "testing"
 )
 
 func TestAllocations(t *testing.T) {
-       if strings.HasSuffix(os.Getenv("GO_BUILDER_NAME"), "-noopt") {
-               t.Skip("skipping allocations test without relevant optimizations")
-       }
+       testenv.SkipIfOptimizationOff(t)
+
        t.Run("P224", func(t *testing.T) {
                if allocs := testing.AllocsPerRun(100, func() {
                        p := nistec.NewP224Generator()
index 1feb630cf5fa38e137c0e1a9c1267d1a79b37dbd..4f8c0975736c1335269217d27f819cb50b0002d8 100644 (file)
@@ -408,6 +408,19 @@ func SkipIfShortAndSlow(t testing.TB) {
        }
 }
 
+// SkipIfOptimizationOff skips t if optimization is disabled.
+func SkipIfOptimizationOff(t testing.TB) {
+       if OptimizationOff() {
+               t.Helper()
+               t.Skip("skipping test with optimization disabled on builder")
+       }
+}
+
+// OptimizationOff reports whether optimization is disabled.
+func OptimizationOff() bool {
+       return strings.HasSuffix(Builder(), "-noopt")
+}
+
 // RunWithTimeout runs cmd and returns its combined output. If the
 // subprocess exits with a non-zero status, it will log that status
 // and return a non-nil error, but this is not considered fatal.
index 961ba0cdf555b21b90f7e5a8183c8df9a001321c..75831e5215bee18a343624ea9b09c6c975440cfd 100644 (file)
@@ -1906,9 +1906,7 @@ func TestNewIntMinInt64(t *testing.T) {
 }
 
 func TestNewIntAllocs(t *testing.T) {
-       if strings.HasSuffix(testenv.Builder(), "-noopt") {
-               t.Skip("inlining is disabled on noopt builder")
-       }
+       testenv.SkipIfOptimizationOff(t)
        for _, n := range []int64{0, 7, -7, 1 << 30, -1 << 30, 1 << 50, -1 << 50} {
                x := NewInt(3)
                got := testing.AllocsPerRun(100, func() {
index 74dcc974f8a69912925774f19ba961754a10efb4..b0915bd8e9a8b0d74ea270ce3d8c309817af200a 100644 (file)
@@ -1908,10 +1908,10 @@ func TestAddrStringAllocs(t *testing.T) {
                {"ipv4-in-ipv6", MustParseAddr("::ffff:192.168.1.1"), 1},
                {"ipv4-in-ipv6+zone", MustParseAddr("::ffff:192.168.1.1%eth0"), 1},
        }
-       isNooptBuilder := strings.HasSuffix(testenv.Builder(), "-noopt")
+       optimizationOff := testenv.OptimizationOff()
        for _, tc := range tests {
                t.Run(tc.name, func(t *testing.T) {
-                       if isNooptBuilder && strings.HasPrefix(tc.name, "ipv4-in-ipv6") {
+                       if optimizationOff && strings.HasPrefix(tc.name, "ipv4-in-ipv6") {
                                // Optimizations are required to remove some allocs.
                                t.Skipf("skipping on %v", testenv.Builder())
                        }
index fe40e6e2bf9e7cfef3c9f56e494ab58378988132..aa620bf0ee0e5b944434fdfc5436ff370d35ec8a 100644 (file)
@@ -364,7 +364,7 @@ func TestMapIterSet(t *testing.T) {
                }
        }
 
-       if strings.HasSuffix(testenv.Builder(), "-noopt") {
+       if testenv.OptimizationOff() {
                return // no inlining with the noopt builder
        }
 
index e50bd95eadea4d1f09a53d8fd75982899f22e2ed..97eb92103b47d3e373bc83e8a6c35da754335f91 100644 (file)
@@ -9,7 +9,6 @@ import (
        "internal/abi"
        "internal/testenv"
        "runtime"
-       "strings"
        "testing"
 )
 
@@ -19,7 +18,7 @@ func TestTracebackArgs(t *testing.T) {
        if *flagQuick {
                t.Skip("-quick")
        }
-       optimized := !strings.HasSuffix(testenv.Builder(), "-noopt")
+       optimized := !testenv.OptimizationOff()
        abiSel := func(x, y string) string {
                // select expected output based on ABI
                // In noopt build we always spill arguments so the output is the same as stack ABI.