"bytes"
"compress/gzip"
"crypto"
- "crypto/internal/boring"
+ "crypto/internal/cryptotest"
"crypto/rand"
"crypto/sha512"
"encoding/hex"
- "internal/testenv"
"log"
"os"
"strings"
}
func TestAllocations(t *testing.T) {
- if boring.Enabled {
- t.Skip("skipping allocations test with BoringCrypto")
- }
- testenv.SkipIfOptimizationOff(t)
-
+ cryptotest.SkipTestAllocations(t)
if allocs := testing.AllocsPerRun(100, func() {
seed := make([]byte, SeedSize)
message := []byte("Hello, world!")
--- /dev/null
+// Copyright 2024 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package cryptotest
+
+import (
+ "crypto/internal/boring"
+ "internal/asan"
+ "internal/msan"
+ "internal/race"
+ "internal/testenv"
+ "runtime"
+ "testing"
+)
+
+// SkipTestAllocations skips the test if there are any factors that interfere
+// with allocation optimizations.
+func SkipTestAllocations(t *testing.T) {
+ // Go+BoringCrypto uses cgo.
+ if boring.Enabled {
+ t.Skip("skipping allocations test with BoringCrypto")
+ }
+
+ // The sanitizers sometimes cause allocations.
+ if race.Enabled || msan.Enabled || asan.Enabled {
+ t.Skip("skipping allocations test with sanitizers")
+ }
+
+ // The plan9 crypto/rand allocates.
+ if runtime.GOOS == "plan9" {
+ t.Skip("skipping allocations test on plan9")
+ }
+
+ // Some APIs rely on inliner and devirtualization to allocate on the stack.
+ testenv.SkipIfOptimizationOff(t)
+}
package edwards25519
import (
+ "crypto/internal/cryptotest"
"crypto/internal/edwards25519/field"
"encoding/hex"
- "internal/testenv"
"reflect"
"testing"
)
var testAllocationsSink byte
func TestAllocations(t *testing.T) {
- testenv.SkipIfOptimizationOff(t)
-
+ cryptotest.SkipTestAllocations(t)
if allocs := testing.AllocsPerRun(100, func() {
p := NewIdentityPoint()
p.Add(p, NewGeneratorPoint())
"encoding"
"encoding/hex"
"fmt"
- "internal/testenv"
"io"
"math/rand"
"strings"
var sink byte
func TestAllocations(t *testing.T) {
- testenv.SkipIfOptimizationOff(t)
+ cryptotest.SkipTestAllocations(t)
t.Run("New", func(t *testing.T) {
if allocs := testing.AllocsPerRun(10, func() {
h := New256()
import (
"bytes"
"crypto/elliptic"
+ "crypto/internal/cryptotest"
"crypto/internal/nistec"
"fmt"
- "internal/testenv"
"math/big"
"math/rand"
"testing"
)
func TestAllocations(t *testing.T) {
- testenv.SkipIfOptimizationOff(t)
-
+ cryptotest.SkipTestAllocations(t)
t.Run("P224", func(t *testing.T) {
if allocs := testing.AllocsPerRun(10, func() {
p := nistec.NewP224Point().SetGenerator()
import (
"bytes"
"compress/flate"
- "internal/asan"
- "internal/msan"
- "internal/race"
"internal/testenv"
"os"
"runtime"
wg.Wait()
}
-var sink byte
-
-func TestAllocations(t *testing.T) {
- if race.Enabled || msan.Enabled || asan.Enabled {
- t.Skip("urandomRead allocates under -race, -asan, and -msan")
- }
- if runtime.GOOS == "plan9" {
- t.Skip("plan9 allocates")
- }
- testenv.SkipIfOptimizationOff(t)
-
- n := int(testing.AllocsPerRun(10, func() {
- buf := make([]byte, 32)
- Read(buf)
- sink ^= buf[0]
- }))
- if n > 0 {
- t.Errorf("allocs = %d, want 0", n)
- }
-}
-
// TestNoUrandomFallback ensures the urandom fallback is not reached in
// normal operations.
func TestNoUrandomFallback(t *testing.T) {
}
func TestAllocations(t *testing.T) {
+ cryptotest.SkipTestAllocations(t)
in := []byte("hello, world!")
out := make([]byte, 0, Size)
h := New()
import (
"bytes"
"compress/flate"
- "crypto/internal/boring"
+ "crypto/internal/cryptotest"
"errors"
- "internal/asan"
- "internal/msan"
- "internal/race"
"internal/testenv"
"io"
"os"
- "runtime"
"sync"
"testing"
)
var sink byte
func TestAllocations(t *testing.T) {
- if boring.Enabled {
- // Might be fixable with https://go.dev/issue/56378.
- t.Skip("boringcrypto allocates")
- }
- if race.Enabled || msan.Enabled || asan.Enabled {
- t.Skip("urandomRead allocates under -race, -asan, and -msan")
- }
- if runtime.GOOS == "plan9" {
- t.Skip("plan9 allocates")
- }
- testenv.SkipIfOptimizationOff(t)
-
+ cryptotest.SkipTestAllocations(t)
n := int(testing.AllocsPerRun(10, func() {
buf := make([]byte, 32)
Read(buf)
"bufio"
"bytes"
"crypto"
- "crypto/internal/boring"
+ "crypto/internal/cryptotest"
"crypto/rand"
. "crypto/rsa"
"crypto/sha1"
"encoding/pem"
"flag"
"fmt"
- "internal/testenv"
"math/big"
"strings"
"testing"
}
func TestAllocations(t *testing.T) {
- if boring.Enabled {
- t.Skip("skipping allocations test with BoringCrypto")
- }
- testenv.SkipIfOptimizationOff(t)
+ cryptotest.SkipTestAllocations(t)
m := []byte("Hello Gophers")
c, err := EncryptPKCS1v15(rand.Reader, &test2048Key.PublicKey, m)
}
func TestAllocations(t *testing.T) {
- if boring.Enabled {
- t.Skip("BoringCrypto doesn't allocate the same way as stdlib")
- }
+ cryptotest.SkipTestAllocations(t)
in := []byte("hello, world!")
out := make([]byte, 0, Size)
h := New()
import (
"bytes"
- "crypto/internal/boring"
"crypto/internal/cryptotest"
"encoding"
"fmt"
"hash"
- "internal/testenv"
"io"
"testing"
)
}
func TestAllocations(t *testing.T) {
- testenv.SkipIfOptimizationOff(t)
- if boring.Enabled {
- t.Skip("BoringCrypto doesn't allocate the same way as stdlib")
- }
+ cryptotest.SkipTestAllocations(t)
if n := testing.AllocsPerRun(10, func() {
in := []byte("hello, world!")
out := make([]byte, 0, Size)
import (
"bytes"
- "crypto/internal/boring"
"crypto/internal/cryptotest"
"encoding"
"encoding/hex"
"fmt"
"hash"
- "internal/testenv"
"io"
"testing"
)
}
func TestAllocations(t *testing.T) {
- testenv.SkipIfOptimizationOff(t)
- if boring.Enabled {
- t.Skip("BoringCrypto doesn't allocate the same way as stdlib")
- }
+ cryptotest.SkipTestAllocations(t)
if n := testing.AllocsPerRun(10, func() {
in := []byte("hello, world!")
out := make([]byte, 0, Size)