mirror of
https://github.com/golang/go
synced 2024-11-18 22:44:48 -07:00
crypto/internal/edwards25519: shorten quick.Check tests in short mode
The edwards25519 tests can be quite slow on platforms without a well-optimized implementation, especially if the race detector is also enabled. Since these tests aren't checking for specific inputs anyway, the extra coverage of a more aggressive quick.Config does not seem worth wasting extra time on slow CI builders and TryBots. For #60109. Change-Id: I530e75a0b76725585df5a2f5ded6705ab1b9da51 Reviewed-on: https://go-review.googlesource.com/c/go/+/522715 Reviewed-by: Filippo Valsorda <filippo@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Joedian Reid <joedian@golang.org>
This commit is contained in:
parent
c1dfbf72e1
commit
9a1136a654
@ -129,9 +129,9 @@ func TestAliasing(t *testing.T) {
|
||||
var err error
|
||||
switch {
|
||||
case tt.oneArgF != nil:
|
||||
err = quick.Check(checkAliasingOneArg(tt.oneArgF), &quick.Config{MaxCountScale: 1 << 8})
|
||||
err = quick.Check(checkAliasingOneArg(tt.oneArgF), quickCheckConfig(256))
|
||||
case tt.twoArgsF != nil:
|
||||
err = quick.Check(checkAliasingTwoArgs(tt.twoArgsF), &quick.Config{MaxCountScale: 1 << 8})
|
||||
err = quick.Check(checkAliasingTwoArgs(tt.twoArgsF), quickCheckConfig(256))
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("%v: %v", tt.name, err)
|
||||
|
@ -21,9 +21,15 @@ func (v Element) String() string {
|
||||
return hex.EncodeToString(v.Bytes())
|
||||
}
|
||||
|
||||
// quickCheckConfig1024 will make each quickcheck test run (1024 * -quickchecks)
|
||||
// times. The default value of -quickchecks is 100.
|
||||
var quickCheckConfig1024 = &quick.Config{MaxCountScale: 1 << 10}
|
||||
// quickCheckConfig returns a quick.Config that scales the max count by the
|
||||
// given factor if the -short flag is not set.
|
||||
func quickCheckConfig(slowScale int) *quick.Config {
|
||||
cfg := new(quick.Config)
|
||||
if !testing.Short() {
|
||||
cfg.MaxCountScale = float64(slowScale)
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
func generateFieldElement(rand *mathrand.Rand) Element {
|
||||
const maskLow52Bits = (1 << 52) - 1
|
||||
@ -114,7 +120,7 @@ func TestMultiplyDistributesOverAdd(t *testing.T) {
|
||||
return t1.Equal(t2) == 1 && isInBounds(t1) && isInBounds(t2)
|
||||
}
|
||||
|
||||
if err := quick.Check(multiplyDistributesOverAdd, quickCheckConfig1024); err != nil {
|
||||
if err := quick.Check(multiplyDistributesOverAdd, quickCheckConfig(1024)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@ -419,7 +425,7 @@ func TestMult32(t *testing.T) {
|
||||
return t1.Equal(t2) == 1 && isInBounds(t1) && isInBounds(t2)
|
||||
}
|
||||
|
||||
if err := quick.Check(mult32EquivalentToMul, quickCheckConfig1024); err != nil {
|
||||
if err := quick.Check(mult32EquivalentToMul, quickCheckConfig(1024)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@ -498,7 +504,7 @@ func TestCarryPropagate(t *testing.T) {
|
||||
return *t1 == *t2 && isInBounds(t2)
|
||||
}
|
||||
|
||||
if err := quick.Check(asmLikeGeneric, quickCheckConfig1024); err != nil {
|
||||
if err := quick.Check(asmLikeGeneric, quickCheckConfig(1024)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@ -522,7 +528,7 @@ func TestFeSquare(t *testing.T) {
|
||||
return t1 == t2 && isInBounds(&t2)
|
||||
}
|
||||
|
||||
if err := quick.Check(asmLikeGeneric, quickCheckConfig1024); err != nil {
|
||||
if err := quick.Check(asmLikeGeneric, quickCheckConfig(1024)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@ -546,7 +552,7 @@ func TestFeMul(t *testing.T) {
|
||||
b1 == b2 && isInBounds(&b2)
|
||||
}
|
||||
|
||||
if err := quick.Check(asmLikeGeneric, quickCheckConfig1024); err != nil {
|
||||
if err := quick.Check(asmLikeGeneric, quickCheckConfig(1024)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ func TestScalarAliasing(t *testing.T) {
|
||||
}, v, x, y)
|
||||
},
|
||||
} {
|
||||
err := quick.Check(f, &quick.Config{MaxCountScale: 1 << 5})
|
||||
err := quick.Check(f, quickCheckConfig(32))
|
||||
if err != nil {
|
||||
t.Errorf("%v: %v", name, err)
|
||||
}
|
||||
|
@ -14,6 +14,16 @@ import (
|
||||
"testing/quick"
|
||||
)
|
||||
|
||||
// quickCheckConfig returns a quick.Config that scales the max count by the
|
||||
// given factor if the -short flag is not set.
|
||||
func quickCheckConfig(slowScale int) *quick.Config {
|
||||
cfg := new(quick.Config)
|
||||
if !testing.Short() {
|
||||
cfg.MaxCountScale = float64(slowScale)
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
var scOneBytes = [32]byte{1}
|
||||
var scOne, _ = new(Scalar).SetCanonicalBytes(scOneBytes[:])
|
||||
var scMinusOne, _ = new(Scalar).SetCanonicalBytes(scalarMinusOneBytes[:])
|
||||
@ -53,15 +63,11 @@ func (Scalar) Generate(rand *mathrand.Rand, size int) reflect.Value {
|
||||
return reflect.ValueOf(val)
|
||||
}
|
||||
|
||||
// quickCheckConfig1024 will make each quickcheck test run (1024 * -quickchecks)
|
||||
// times. The default value of -quickchecks is 100.
|
||||
var quickCheckConfig1024 = &quick.Config{MaxCountScale: 1 << 10}
|
||||
|
||||
func TestScalarGenerate(t *testing.T) {
|
||||
f := func(sc Scalar) bool {
|
||||
return isReduced(sc.Bytes())
|
||||
}
|
||||
if err := quick.Check(f, quickCheckConfig1024); err != nil {
|
||||
if err := quick.Check(f, quickCheckConfig(1024)); err != nil {
|
||||
t.Errorf("generated unreduced scalar: %v", err)
|
||||
}
|
||||
}
|
||||
@ -76,7 +82,7 @@ func TestScalarSetCanonicalBytes(t *testing.T) {
|
||||
repr := sc.Bytes()
|
||||
return bytes.Equal(in[:], repr) && isReduced(repr)
|
||||
}
|
||||
if err := quick.Check(f1, quickCheckConfig1024); err != nil {
|
||||
if err := quick.Check(f1, quickCheckConfig(1024)); err != nil {
|
||||
t.Errorf("failed bytes->scalar->bytes round-trip: %v", err)
|
||||
}
|
||||
|
||||
@ -86,7 +92,7 @@ func TestScalarSetCanonicalBytes(t *testing.T) {
|
||||
}
|
||||
return sc1 == sc2
|
||||
}
|
||||
if err := quick.Check(f2, quickCheckConfig1024); err != nil {
|
||||
if err := quick.Check(f2, quickCheckConfig(1024)); err != nil {
|
||||
t.Errorf("failed scalar->bytes->scalar round-trip: %v", err)
|
||||
}
|
||||
|
||||
@ -115,7 +121,7 @@ func TestScalarSetUniformBytes(t *testing.T) {
|
||||
inBig := bigIntFromLittleEndianBytes(in[:])
|
||||
return inBig.Mod(inBig, mod).Cmp(scBig) == 0
|
||||
}
|
||||
if err := quick.Check(f, quickCheckConfig1024); err != nil {
|
||||
if err := quick.Check(f, quickCheckConfig(1024)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@ -175,7 +181,7 @@ func TestScalarMultiplyDistributesOverAdd(t *testing.T) {
|
||||
return t1 == t2 && isReduced(reprT1) && isReduced(reprT2)
|
||||
}
|
||||
|
||||
if err := quick.Check(multiplyDistributesOverAdd, quickCheckConfig1024); err != nil {
|
||||
if err := quick.Check(multiplyDistributesOverAdd, quickCheckConfig(1024)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@ -194,7 +200,7 @@ func TestScalarAddLikeSubNeg(t *testing.T) {
|
||||
return t1 == t2 && isReduced(t1.Bytes())
|
||||
}
|
||||
|
||||
if err := quick.Check(addLikeSubNeg, quickCheckConfig1024); err != nil {
|
||||
if err := quick.Check(addLikeSubNeg, quickCheckConfig(1024)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,6 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// quickCheckConfig32 will make each quickcheck test run (32 * -quickchecks)
|
||||
// times. The default value of -quickchecks is 100.
|
||||
quickCheckConfig32 = &quick.Config{MaxCountScale: 1 << 5}
|
||||
|
||||
// a random scalar generated using dalek.
|
||||
dalekScalar, _ = (&Scalar{}).SetCanonicalBytes([]byte{219, 106, 114, 9, 174, 249, 155, 89, 69, 203, 201, 93, 92, 116, 234, 187, 78, 115, 103, 172, 182, 98, 62, 103, 187, 136, 13, 100, 248, 110, 12, 4})
|
||||
// the above, times the edwards25519 basepoint.
|
||||
@ -83,7 +79,7 @@ func TestScalarMultDistributesOverAdd(t *testing.T) {
|
||||
return check.Equal(&r) == 1
|
||||
}
|
||||
|
||||
if err := quick.Check(scalarMultDistributesOverAdd, quickCheckConfig32); err != nil {
|
||||
if err := quick.Check(scalarMultDistributesOverAdd, quickCheckConfig(32)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@ -105,7 +101,7 @@ func TestScalarMultNonIdentityPoint(t *testing.T) {
|
||||
return p.Equal(&q) == 1
|
||||
}
|
||||
|
||||
if err := quick.Check(scalarMultNonIdentityPoint, quickCheckConfig32); err != nil {
|
||||
if err := quick.Check(scalarMultNonIdentityPoint, quickCheckConfig(32)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@ -149,7 +145,7 @@ func TestScalarMultMatchesBaseMult(t *testing.T) {
|
||||
return p.Equal(&q) == 1
|
||||
}
|
||||
|
||||
if err := quick.Check(scalarMultMatchesBaseMult, quickCheckConfig32); err != nil {
|
||||
if err := quick.Check(scalarMultMatchesBaseMult, quickCheckConfig(32)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
@ -177,7 +173,7 @@ func TestVarTimeDoubleBaseMultMatchesBaseMult(t *testing.T) {
|
||||
return p.Equal(&check) == 1
|
||||
}
|
||||
|
||||
if err := quick.Check(varTimeDoubleBaseMultMatchesBaseMult, quickCheckConfig32); err != nil {
|
||||
if err := quick.Check(varTimeDoubleBaseMultMatchesBaseMult, quickCheckConfig(32)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user