]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/internal/edwards25519: shorten quick.Check tests in short mode
authorBryan C. Mills <bcmills@google.com>
Thu, 24 Aug 2023 18:40:14 +0000 (14:40 -0400)
committerGopher Robot <gobot@golang.org>
Mon, 28 Aug 2023 17:26:17 +0000 (17:26 +0000)
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>
src/crypto/internal/edwards25519/field/fe_alias_test.go
src/crypto/internal/edwards25519/field/fe_test.go
src/crypto/internal/edwards25519/scalar_alias_test.go
src/crypto/internal/edwards25519/scalar_test.go
src/crypto/internal/edwards25519/scalarmult_test.go

index bf1efdceade95d1ef1f3a6680e6dc8e0140d3838..0c81239458d04a1f5d84cacdd3f1af36a082004b 100644 (file)
@@ -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)
index 945a024a41504aca97e79aabbdf1d2a70650024f..a24fbfeb903ae0435837fbdc9ea0823e4ad38a1d 100644 (file)
@@ -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)
        }
 }
index 4d83441a48b1e5b96d03f41f9d72dfa560d25b58..1893a7fc0c41025d11b210bad22086a171608b26 100644 (file)
@@ -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)
                }
index 67bcdafe91ed1c06cb497d247f505f3966dda310..05551ef771187b77b263e0864213989b90345e94 100644 (file)
@@ -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)
        }
 }
index 6c92ab3167f6405e60129864e6c1ca0ca8bcca26..4a00c79ace52bfc930a7f50699b69e9c50764e5e 100644 (file)
@@ -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)
        }
 }