mirror of
https://github.com/golang/go
synced 2024-11-22 15:04:52 -07:00
crypto/internal/cryptotest: add SkipTestAllocations
[ ] [ It has been [ 0 ] days since Filippo broke a TestAllocations. ] [ ] Concentrate all the skips in one place, so we don't have to re-discover always the same ones via trial and error. This might over-skip fixable allocations, but all these targets are not fast anyway, so they are not worth going back for. Removed the sysrand TestAllocations because it causes an import loop with cryptotest and it's covered by TestAllocations in crypto/rand. Change-Id: Icd40e97f9128e037f567147f8c9dafa758a47fac Reviewed-on: https://go-review.googlesource.com/c/go/+/626438 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Daniel McCarney <daniel@binaryparadox.net> Reviewed-by: Roland Shoemaker <roland@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Filippo Valsorda <filippo@golang.org>
This commit is contained in:
parent
cf531372b2
commit
ecdc8c1b3f
@ -9,11 +9,10 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/internal/boring"
|
"crypto/internal/cryptotest"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha512"
|
"crypto/sha512"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"internal/testenv"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -319,11 +318,7 @@ func TestMalleability(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAllocations(t *testing.T) {
|
func TestAllocations(t *testing.T) {
|
||||||
if boring.Enabled {
|
cryptotest.SkipTestAllocations(t)
|
||||||
t.Skip("skipping allocations test with BoringCrypto")
|
|
||||||
}
|
|
||||||
testenv.SkipIfOptimizationOff(t)
|
|
||||||
|
|
||||||
if allocs := testing.AllocsPerRun(100, func() {
|
if allocs := testing.AllocsPerRun(100, func() {
|
||||||
seed := make([]byte, SeedSize)
|
seed := make([]byte, SeedSize)
|
||||||
message := []byte("Hello, world!")
|
message := []byte("Hello, world!")
|
||||||
|
37
src/crypto/internal/cryptotest/allocations.go
Normal file
37
src/crypto/internal/cryptotest/allocations.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// 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)
|
||||||
|
}
|
@ -5,9 +5,9 @@
|
|||||||
package edwards25519
|
package edwards25519
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/internal/cryptotest"
|
||||||
"crypto/internal/edwards25519/field"
|
"crypto/internal/edwards25519/field"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"internal/testenv"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -280,8 +280,7 @@ func TestNonCanonicalPoints(t *testing.T) {
|
|||||||
var testAllocationsSink byte
|
var testAllocationsSink byte
|
||||||
|
|
||||||
func TestAllocations(t *testing.T) {
|
func TestAllocations(t *testing.T) {
|
||||||
testenv.SkipIfOptimizationOff(t)
|
cryptotest.SkipTestAllocations(t)
|
||||||
|
|
||||||
if allocs := testing.AllocsPerRun(100, func() {
|
if allocs := testing.AllocsPerRun(100, func() {
|
||||||
p := NewIdentityPoint()
|
p := NewIdentityPoint()
|
||||||
p.Add(p, NewGeneratorPoint())
|
p.Add(p, NewGeneratorPoint())
|
||||||
|
@ -12,7 +12,6 @@ import (
|
|||||||
"encoding"
|
"encoding"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"internal/testenv"
|
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strings"
|
"strings"
|
||||||
@ -370,7 +369,7 @@ func testClone(t *testing.T) {
|
|||||||
var sink byte
|
var sink byte
|
||||||
|
|
||||||
func TestAllocations(t *testing.T) {
|
func TestAllocations(t *testing.T) {
|
||||||
testenv.SkipIfOptimizationOff(t)
|
cryptotest.SkipTestAllocations(t)
|
||||||
t.Run("New", func(t *testing.T) {
|
t.Run("New", func(t *testing.T) {
|
||||||
if allocs := testing.AllocsPerRun(10, func() {
|
if allocs := testing.AllocsPerRun(10, func() {
|
||||||
h := New256()
|
h := New256()
|
||||||
|
@ -7,17 +7,16 @@ package nistec_test
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
|
"crypto/internal/cryptotest"
|
||||||
"crypto/internal/nistec"
|
"crypto/internal/nistec"
|
||||||
"fmt"
|
"fmt"
|
||||||
"internal/testenv"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAllocations(t *testing.T) {
|
func TestAllocations(t *testing.T) {
|
||||||
testenv.SkipIfOptimizationOff(t)
|
cryptotest.SkipTestAllocations(t)
|
||||||
|
|
||||||
t.Run("P224", func(t *testing.T) {
|
t.Run("P224", func(t *testing.T) {
|
||||||
if allocs := testing.AllocsPerRun(10, func() {
|
if allocs := testing.AllocsPerRun(10, func() {
|
||||||
p := nistec.NewP224Point().SetGenerator()
|
p := nistec.NewP224Point().SetGenerator()
|
||||||
|
@ -7,9 +7,6 @@ package sysrand
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/flate"
|
"compress/flate"
|
||||||
"internal/asan"
|
|
||||||
"internal/msan"
|
|
||||||
"internal/race"
|
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -72,27 +69,6 @@ func TestConcurrentRead(t *testing.T) {
|
|||||||
wg.Wait()
|
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
|
// TestNoUrandomFallback ensures the urandom fallback is not reached in
|
||||||
// normal operations.
|
// normal operations.
|
||||||
func TestNoUrandomFallback(t *testing.T) {
|
func TestNoUrandomFallback(t *testing.T) {
|
||||||
|
@ -225,6 +225,7 @@ func TestLargeHashes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAllocations(t *testing.T) {
|
func TestAllocations(t *testing.T) {
|
||||||
|
cryptotest.SkipTestAllocations(t)
|
||||||
in := []byte("hello, world!")
|
in := []byte("hello, world!")
|
||||||
out := make([]byte, 0, Size)
|
out := make([]byte, 0, Size)
|
||||||
h := New()
|
h := New()
|
||||||
|
@ -7,15 +7,11 @@ package rand
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/flate"
|
"compress/flate"
|
||||||
"crypto/internal/boring"
|
"crypto/internal/cryptotest"
|
||||||
"errors"
|
"errors"
|
||||||
"internal/asan"
|
|
||||||
"internal/msan"
|
|
||||||
"internal/race"
|
|
||||||
"internal/testenv"
|
"internal/testenv"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -157,18 +153,7 @@ func testConcurrentRead(t *testing.T, Read func([]byte) (int, error)) {
|
|||||||
var sink byte
|
var sink byte
|
||||||
|
|
||||||
func TestAllocations(t *testing.T) {
|
func TestAllocations(t *testing.T) {
|
||||||
if boring.Enabled {
|
cryptotest.SkipTestAllocations(t)
|
||||||
// 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)
|
|
||||||
|
|
||||||
n := int(testing.AllocsPerRun(10, func() {
|
n := int(testing.AllocsPerRun(10, func() {
|
||||||
buf := make([]byte, 32)
|
buf := make([]byte, 32)
|
||||||
Read(buf)
|
Read(buf)
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/internal/boring"
|
"crypto/internal/cryptotest"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
. "crypto/rsa"
|
. "crypto/rsa"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
@ -17,7 +17,6 @@ import (
|
|||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"internal/testenv"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -132,10 +131,7 @@ func testKeyBasics(t *testing.T, priv *PrivateKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAllocations(t *testing.T) {
|
func TestAllocations(t *testing.T) {
|
||||||
if boring.Enabled {
|
cryptotest.SkipTestAllocations(t)
|
||||||
t.Skip("skipping allocations test with BoringCrypto")
|
|
||||||
}
|
|
||||||
testenv.SkipIfOptimizationOff(t)
|
|
||||||
|
|
||||||
m := []byte("Hello Gophers")
|
m := []byte("Hello Gophers")
|
||||||
c, err := EncryptPKCS1v15(rand.Reader, &test2048Key.PublicKey, m)
|
c, err := EncryptPKCS1v15(rand.Reader, &test2048Key.PublicKey, m)
|
||||||
|
@ -231,9 +231,7 @@ func TestLargeHashes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAllocations(t *testing.T) {
|
func TestAllocations(t *testing.T) {
|
||||||
if boring.Enabled {
|
cryptotest.SkipTestAllocations(t)
|
||||||
t.Skip("BoringCrypto doesn't allocate the same way as stdlib")
|
|
||||||
}
|
|
||||||
in := []byte("hello, world!")
|
in := []byte("hello, world!")
|
||||||
out := make([]byte, 0, Size)
|
out := make([]byte, 0, Size)
|
||||||
h := New()
|
h := New()
|
||||||
|
@ -8,12 +8,10 @@ package sha256
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/internal/boring"
|
|
||||||
"crypto/internal/cryptotest"
|
"crypto/internal/cryptotest"
|
||||||
"encoding"
|
"encoding"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash"
|
"hash"
|
||||||
"internal/testenv"
|
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -298,10 +296,7 @@ func TestLargeHashes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAllocations(t *testing.T) {
|
func TestAllocations(t *testing.T) {
|
||||||
testenv.SkipIfOptimizationOff(t)
|
cryptotest.SkipTestAllocations(t)
|
||||||
if boring.Enabled {
|
|
||||||
t.Skip("BoringCrypto doesn't allocate the same way as stdlib")
|
|
||||||
}
|
|
||||||
if n := testing.AllocsPerRun(10, func() {
|
if n := testing.AllocsPerRun(10, func() {
|
||||||
in := []byte("hello, world!")
|
in := []byte("hello, world!")
|
||||||
out := make([]byte, 0, Size)
|
out := make([]byte, 0, Size)
|
||||||
|
@ -8,13 +8,11 @@ package sha512
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/internal/boring"
|
|
||||||
"crypto/internal/cryptotest"
|
"crypto/internal/cryptotest"
|
||||||
"encoding"
|
"encoding"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash"
|
"hash"
|
||||||
"internal/testenv"
|
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -903,10 +901,7 @@ func TestLargeHashes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAllocations(t *testing.T) {
|
func TestAllocations(t *testing.T) {
|
||||||
testenv.SkipIfOptimizationOff(t)
|
cryptotest.SkipTestAllocations(t)
|
||||||
if boring.Enabled {
|
|
||||||
t.Skip("BoringCrypto doesn't allocate the same way as stdlib")
|
|
||||||
}
|
|
||||||
if n := testing.AllocsPerRun(10, func() {
|
if n := testing.AllocsPerRun(10, func() {
|
||||||
in := []byte("hello, world!")
|
in := []byte("hello, world!")
|
||||||
out := make([]byte, 0, Size)
|
out := make([]byte, 0, Size)
|
||||||
|
Loading…
Reference in New Issue
Block a user