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() {
"crypto/internal/boring"
"crypto/rand"
"encoding/hex"
+ "internal/testenv"
"os"
"strings"
"testing"
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!")
import (
"crypto/internal/edwards25519/field"
"encoding/hex"
- "os"
+ "internal/testenv"
"reflect"
- "strings"
"testing"
)
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())
"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()
}
}
+// 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.
}
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() {
{"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())
}
}
}
- if strings.HasSuffix(testenv.Builder(), "-noopt") {
+ if testenv.OptimizationOff() {
return // no inlining with the noopt builder
}
"internal/abi"
"internal/testenv"
"runtime"
- "strings"
"testing"
)
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.