Skip to content

Commit 9a1136a

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
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 <[email protected]> Auto-Submit: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Reviewed-by: Joedian Reid <[email protected]>
1 parent c1dfbf7 commit 9a1136a

File tree

5 files changed

+37
-29
lines changed

5 files changed

+37
-29
lines changed

src/crypto/internal/edwards25519/field/fe_alias_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ func TestAliasing(t *testing.T) {
129129
var err error
130130
switch {
131131
case tt.oneArgF != nil:
132-
err = quick.Check(checkAliasingOneArg(tt.oneArgF), &quick.Config{MaxCountScale: 1 << 8})
132+
err = quick.Check(checkAliasingOneArg(tt.oneArgF), quickCheckConfig(256))
133133
case tt.twoArgsF != nil:
134-
err = quick.Check(checkAliasingTwoArgs(tt.twoArgsF), &quick.Config{MaxCountScale: 1 << 8})
134+
err = quick.Check(checkAliasingTwoArgs(tt.twoArgsF), quickCheckConfig(256))
135135
}
136136
if err != nil {
137137
t.Errorf("%v: %v", tt.name, err)

src/crypto/internal/edwards25519/field/fe_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@ func (v Element) String() string {
2121
return hex.EncodeToString(v.Bytes())
2222
}
2323

24-
// quickCheckConfig1024 will make each quickcheck test run (1024 * -quickchecks)
25-
// times. The default value of -quickchecks is 100.
26-
var quickCheckConfig1024 = &quick.Config{MaxCountScale: 1 << 10}
24+
// quickCheckConfig returns a quick.Config that scales the max count by the
25+
// given factor if the -short flag is not set.
26+
func quickCheckConfig(slowScale int) *quick.Config {
27+
cfg := new(quick.Config)
28+
if !testing.Short() {
29+
cfg.MaxCountScale = float64(slowScale)
30+
}
31+
return cfg
32+
}
2733

2834
func generateFieldElement(rand *mathrand.Rand) Element {
2935
const maskLow52Bits = (1 << 52) - 1
@@ -114,7 +120,7 @@ func TestMultiplyDistributesOverAdd(t *testing.T) {
114120
return t1.Equal(t2) == 1 && isInBounds(t1) && isInBounds(t2)
115121
}
116122

117-
if err := quick.Check(multiplyDistributesOverAdd, quickCheckConfig1024); err != nil {
123+
if err := quick.Check(multiplyDistributesOverAdd, quickCheckConfig(1024)); err != nil {
118124
t.Error(err)
119125
}
120126
}
@@ -419,7 +425,7 @@ func TestMult32(t *testing.T) {
419425
return t1.Equal(t2) == 1 && isInBounds(t1) && isInBounds(t2)
420426
}
421427

422-
if err := quick.Check(mult32EquivalentToMul, quickCheckConfig1024); err != nil {
428+
if err := quick.Check(mult32EquivalentToMul, quickCheckConfig(1024)); err != nil {
423429
t.Error(err)
424430
}
425431
}
@@ -498,7 +504,7 @@ func TestCarryPropagate(t *testing.T) {
498504
return *t1 == *t2 && isInBounds(t2)
499505
}
500506

501-
if err := quick.Check(asmLikeGeneric, quickCheckConfig1024); err != nil {
507+
if err := quick.Check(asmLikeGeneric, quickCheckConfig(1024)); err != nil {
502508
t.Error(err)
503509
}
504510

@@ -522,7 +528,7 @@ func TestFeSquare(t *testing.T) {
522528
return t1 == t2 && isInBounds(&t2)
523529
}
524530

525-
if err := quick.Check(asmLikeGeneric, quickCheckConfig1024); err != nil {
531+
if err := quick.Check(asmLikeGeneric, quickCheckConfig(1024)); err != nil {
526532
t.Error(err)
527533
}
528534
}
@@ -546,7 +552,7 @@ func TestFeMul(t *testing.T) {
546552
b1 == b2 && isInBounds(&b2)
547553
}
548554

549-
if err := quick.Check(asmLikeGeneric, quickCheckConfig1024); err != nil {
555+
if err := quick.Check(asmLikeGeneric, quickCheckConfig(1024)); err != nil {
550556
t.Error(err)
551557
}
552558
}

src/crypto/internal/edwards25519/scalar_alias_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func TestScalarAliasing(t *testing.T) {
100100
}, v, x, y)
101101
},
102102
} {
103-
err := quick.Check(f, &quick.Config{MaxCountScale: 1 << 5})
103+
err := quick.Check(f, quickCheckConfig(32))
104104
if err != nil {
105105
t.Errorf("%v: %v", name, err)
106106
}

src/crypto/internal/edwards25519/scalar_test.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ import (
1414
"testing/quick"
1515
)
1616

17+
// quickCheckConfig returns a quick.Config that scales the max count by the
18+
// given factor if the -short flag is not set.
19+
func quickCheckConfig(slowScale int) *quick.Config {
20+
cfg := new(quick.Config)
21+
if !testing.Short() {
22+
cfg.MaxCountScale = float64(slowScale)
23+
}
24+
return cfg
25+
}
26+
1727
var scOneBytes = [32]byte{1}
1828
var scOne, _ = new(Scalar).SetCanonicalBytes(scOneBytes[:])
1929
var scMinusOne, _ = new(Scalar).SetCanonicalBytes(scalarMinusOneBytes[:])
@@ -53,15 +63,11 @@ func (Scalar) Generate(rand *mathrand.Rand, size int) reflect.Value {
5363
return reflect.ValueOf(val)
5464
}
5565

56-
// quickCheckConfig1024 will make each quickcheck test run (1024 * -quickchecks)
57-
// times. The default value of -quickchecks is 100.
58-
var quickCheckConfig1024 = &quick.Config{MaxCountScale: 1 << 10}
59-
6066
func TestScalarGenerate(t *testing.T) {
6167
f := func(sc Scalar) bool {
6268
return isReduced(sc.Bytes())
6369
}
64-
if err := quick.Check(f, quickCheckConfig1024); err != nil {
70+
if err := quick.Check(f, quickCheckConfig(1024)); err != nil {
6571
t.Errorf("generated unreduced scalar: %v", err)
6672
}
6773
}
@@ -76,7 +82,7 @@ func TestScalarSetCanonicalBytes(t *testing.T) {
7682
repr := sc.Bytes()
7783
return bytes.Equal(in[:], repr) && isReduced(repr)
7884
}
79-
if err := quick.Check(f1, quickCheckConfig1024); err != nil {
85+
if err := quick.Check(f1, quickCheckConfig(1024)); err != nil {
8086
t.Errorf("failed bytes->scalar->bytes round-trip: %v", err)
8187
}
8288

@@ -86,7 +92,7 @@ func TestScalarSetCanonicalBytes(t *testing.T) {
8692
}
8793
return sc1 == sc2
8894
}
89-
if err := quick.Check(f2, quickCheckConfig1024); err != nil {
95+
if err := quick.Check(f2, quickCheckConfig(1024)); err != nil {
9096
t.Errorf("failed scalar->bytes->scalar round-trip: %v", err)
9197
}
9298

@@ -115,7 +121,7 @@ func TestScalarSetUniformBytes(t *testing.T) {
115121
inBig := bigIntFromLittleEndianBytes(in[:])
116122
return inBig.Mod(inBig, mod).Cmp(scBig) == 0
117123
}
118-
if err := quick.Check(f, quickCheckConfig1024); err != nil {
124+
if err := quick.Check(f, quickCheckConfig(1024)); err != nil {
119125
t.Error(err)
120126
}
121127
}
@@ -175,7 +181,7 @@ func TestScalarMultiplyDistributesOverAdd(t *testing.T) {
175181
return t1 == t2 && isReduced(reprT1) && isReduced(reprT2)
176182
}
177183

178-
if err := quick.Check(multiplyDistributesOverAdd, quickCheckConfig1024); err != nil {
184+
if err := quick.Check(multiplyDistributesOverAdd, quickCheckConfig(1024)); err != nil {
179185
t.Error(err)
180186
}
181187
}
@@ -194,7 +200,7 @@ func TestScalarAddLikeSubNeg(t *testing.T) {
194200
return t1 == t2 && isReduced(t1.Bytes())
195201
}
196202

197-
if err := quick.Check(addLikeSubNeg, quickCheckConfig1024); err != nil {
203+
if err := quick.Check(addLikeSubNeg, quickCheckConfig(1024)); err != nil {
198204
t.Error(err)
199205
}
200206
}

src/crypto/internal/edwards25519/scalarmult_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import (
1010
)
1111

1212
var (
13-
// quickCheckConfig32 will make each quickcheck test run (32 * -quickchecks)
14-
// times. The default value of -quickchecks is 100.
15-
quickCheckConfig32 = &quick.Config{MaxCountScale: 1 << 5}
16-
1713
// a random scalar generated using dalek.
1814
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})
1915
// the above, times the edwards25519 basepoint.
@@ -83,7 +79,7 @@ func TestScalarMultDistributesOverAdd(t *testing.T) {
8379
return check.Equal(&r) == 1
8480
}
8581

86-
if err := quick.Check(scalarMultDistributesOverAdd, quickCheckConfig32); err != nil {
82+
if err := quick.Check(scalarMultDistributesOverAdd, quickCheckConfig(32)); err != nil {
8783
t.Error(err)
8884
}
8985
}
@@ -105,7 +101,7 @@ func TestScalarMultNonIdentityPoint(t *testing.T) {
105101
return p.Equal(&q) == 1
106102
}
107103

108-
if err := quick.Check(scalarMultNonIdentityPoint, quickCheckConfig32); err != nil {
104+
if err := quick.Check(scalarMultNonIdentityPoint, quickCheckConfig(32)); err != nil {
109105
t.Error(err)
110106
}
111107
}
@@ -149,7 +145,7 @@ func TestScalarMultMatchesBaseMult(t *testing.T) {
149145
return p.Equal(&q) == 1
150146
}
151147

152-
if err := quick.Check(scalarMultMatchesBaseMult, quickCheckConfig32); err != nil {
148+
if err := quick.Check(scalarMultMatchesBaseMult, quickCheckConfig(32)); err != nil {
153149
t.Error(err)
154150
}
155151
}
@@ -177,7 +173,7 @@ func TestVarTimeDoubleBaseMultMatchesBaseMult(t *testing.T) {
177173
return p.Equal(&check) == 1
178174
}
179175

180-
if err := quick.Check(varTimeDoubleBaseMultMatchesBaseMult, quickCheckConfig32); err != nil {
176+
if err := quick.Check(varTimeDoubleBaseMultMatchesBaseMult, quickCheckConfig(32)); err != nil {
181177
t.Error(err)
182178
}
183179
}

0 commit comments

Comments
 (0)