Skip to content

Commit 363f2f3

Browse files
committed
[dev.fuzz] testing: allow -fuzzminimizetime to be 0
Fixes #48321 Change-Id: I1547379eb7a703f7f3c4594d27833eb3587796a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/349089 Trust: Katie Hockman <[email protected]> Run-TryBot: Katie Hockman <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent b38e853 commit 363f2f3

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

src/cmd/go/testdata/script/test_fuzz_minimize.txt

+26
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,32 @@
66
# We clean the fuzz cache during this test. Don't clean the user's cache.
77
env GOCACHE=$WORK/gocache
88

9+
# Test that fuzzminimizetime can be zero seconds
10+
! go test -fuzz=FuzzMinimizerRecoverable -run=FuzzMinimizerRecoverable -fuzztime=10000x -fuzzminimizetime=0s minimizer_test.go
11+
! stdout '^ok'
12+
stdout 'contains a non-zero byte'
13+
stdout FAIL
14+
15+
# Test that fuzzminimizetime can be zero times
16+
! go test -fuzz=FuzzMinimizerRecoverable -run=FuzzMinimizerRecoverable -fuzztime=10000x -fuzzminimizetime=0x minimizer_test.go
17+
! stdout '^ok'
18+
stdout 'contains a non-zero byte'
19+
stdout FAIL
20+
21+
# Test that fuzzminimizetime cannot be negative seconds
22+
! go test -fuzz=FuzzMinimizerRecoverable -run=FuzzMinimizerRecoverable -fuzztime=10000x -fuzzminimizetime=-1ms minimizer_test.go
23+
! stdout '^ok'
24+
! stdout 'contains a non-zero byte'
25+
stdout 'invalid duration'
26+
stdout FAIL
27+
28+
# Test that fuzzminimizetime cannot be negative times
29+
! go test -fuzz=FuzzMinimizerRecoverable -run=FuzzMinimizerRecoverable -fuzztime=10000x -fuzzminimizetime=-1x minimizer_test.go
30+
! stdout '^ok'
31+
! stdout 'contains a non-zero byte'
32+
stdout 'invalid count'
33+
stdout FAIL
34+
935
# Test that minimization is working for recoverable errors.
1036
! go test -fuzz=FuzzMinimizerRecoverable -run=FuzzMinimizerRecoverable -fuzztime=10000x minimizer_test.go
1137
! stdout '^ok'

src/testing/benchmark.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ var (
3636
)
3737

3838
type durationOrCountFlag struct {
39-
d time.Duration
40-
n int
39+
d time.Duration
40+
n int
41+
allowZero bool
4142
}
4243

4344
func (f *durationOrCountFlag) String() string {
@@ -50,14 +51,14 @@ func (f *durationOrCountFlag) String() string {
5051
func (f *durationOrCountFlag) Set(s string) error {
5152
if strings.HasSuffix(s, "x") {
5253
n, err := strconv.ParseInt(s[:len(s)-1], 10, 0)
53-
if err != nil || n <= 0 {
54+
if err != nil || n < 0 || (!f.allowZero && n == 0) {
5455
return fmt.Errorf("invalid count")
5556
}
5657
*f = durationOrCountFlag{n: int(n)}
5758
return nil
5859
}
5960
d, err := time.ParseDuration(s)
60-
if err != nil || d <= 0 {
61+
if err != nil || d < 0 || (!f.allowZero && d == 0) {
6162
return fmt.Errorf("invalid duration")
6263
}
6364
*f = durationOrCountFlag{d: d}

src/testing/fuzz.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func initFuzzFlags() {
2828
var (
2929
matchFuzz *string
3030
fuzzDuration durationOrCountFlag
31-
minimizeDuration = durationOrCountFlag{d: 60 * time.Second}
31+
minimizeDuration = durationOrCountFlag{d: 60 * time.Second, allowZero: true}
3232
fuzzCacheDir *string
3333
isFuzzWorker *bool
3434

0 commit comments

Comments
 (0)