mirror of
https://github.com/golang/go
synced 2024-11-17 06:54:48 -07:00
internal/testenv: add and use OptimizationOff/SkipIfOptimizationOff
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>
This commit is contained in:
parent
98277f30e4
commit
a292b3905c
@ -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() {
|
||||
|
@ -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!")
|
||||
|
@ -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())
|
||||
|
@ -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()
|
||||
|
@ -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.
|
||||
|
@ -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() {
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user