File tree 3 files changed +32
-5
lines changed
3 files changed +32
-5
lines changed Original file line number Diff line number Diff line change 6
6
# We clean the fuzz cache during this test. Don't clean the user's cache.
7
7
env GOCACHE=$WORK/gocache
8
8
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
+
9
35
# Test that minimization is working for recoverable errors.
10
36
! go test -fuzz=FuzzMinimizerRecoverable -run=FuzzMinimizerRecoverable -fuzztime=10000x minimizer_test.go
11
37
! stdout '^ok'
Original file line number Diff line number Diff line change 36
36
)
37
37
38
38
type durationOrCountFlag struct {
39
- d time.Duration
40
- n int
39
+ d time.Duration
40
+ n int
41
+ allowZero bool
41
42
}
42
43
43
44
func (f * durationOrCountFlag ) String () string {
@@ -50,14 +51,14 @@ func (f *durationOrCountFlag) String() string {
50
51
func (f * durationOrCountFlag ) Set (s string ) error {
51
52
if strings .HasSuffix (s , "x" ) {
52
53
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 ) {
54
55
return fmt .Errorf ("invalid count" )
55
56
}
56
57
* f = durationOrCountFlag {n : int (n )}
57
58
return nil
58
59
}
59
60
d , err := time .ParseDuration (s )
60
- if err != nil || d <= 0 {
61
+ if err != nil || d < 0 || ( ! f . allowZero && d == 0 ) {
61
62
return fmt .Errorf ("invalid duration" )
62
63
}
63
64
* f = durationOrCountFlag {d : d }
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ func initFuzzFlags() {
28
28
var (
29
29
matchFuzz * string
30
30
fuzzDuration durationOrCountFlag
31
- minimizeDuration = durationOrCountFlag {d : 60 * time .Second }
31
+ minimizeDuration = durationOrCountFlag {d : 60 * time .Second , allowZero : true }
32
32
fuzzCacheDir * string
33
33
isFuzzWorker * bool
34
34
You can’t perform that action at this time.
0 commit comments