mirror of
https://github.com/golang/go
synced 2024-11-24 06:20:02 -07:00
[dev.fuzz] testing: allow -fuzzminimizetime to be 0
Fixes golang/go#48321 Change-Id: I1547379eb7a703f7f3c4594d27833eb3587796a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/349089 Trust: Katie Hockman <katie@golang.org> Run-TryBot: Katie Hockman <katie@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
b38e853d04
commit
363f2f3df9
@ -6,6 +6,32 @@
|
||||
# We clean the fuzz cache during this test. Don't clean the user's cache.
|
||||
env GOCACHE=$WORK/gocache
|
||||
|
||||
# Test that fuzzminimizetime can be zero seconds
|
||||
! go test -fuzz=FuzzMinimizerRecoverable -run=FuzzMinimizerRecoverable -fuzztime=10000x -fuzzminimizetime=0s minimizer_test.go
|
||||
! stdout '^ok'
|
||||
stdout 'contains a non-zero byte'
|
||||
stdout FAIL
|
||||
|
||||
# Test that fuzzminimizetime can be zero times
|
||||
! go test -fuzz=FuzzMinimizerRecoverable -run=FuzzMinimizerRecoverable -fuzztime=10000x -fuzzminimizetime=0x minimizer_test.go
|
||||
! stdout '^ok'
|
||||
stdout 'contains a non-zero byte'
|
||||
stdout FAIL
|
||||
|
||||
# Test that fuzzminimizetime cannot be negative seconds
|
||||
! go test -fuzz=FuzzMinimizerRecoverable -run=FuzzMinimizerRecoverable -fuzztime=10000x -fuzzminimizetime=-1ms minimizer_test.go
|
||||
! stdout '^ok'
|
||||
! stdout 'contains a non-zero byte'
|
||||
stdout 'invalid duration'
|
||||
stdout FAIL
|
||||
|
||||
# Test that fuzzminimizetime cannot be negative times
|
||||
! go test -fuzz=FuzzMinimizerRecoverable -run=FuzzMinimizerRecoverable -fuzztime=10000x -fuzzminimizetime=-1x minimizer_test.go
|
||||
! stdout '^ok'
|
||||
! stdout 'contains a non-zero byte'
|
||||
stdout 'invalid count'
|
||||
stdout FAIL
|
||||
|
||||
# Test that minimization is working for recoverable errors.
|
||||
! go test -fuzz=FuzzMinimizerRecoverable -run=FuzzMinimizerRecoverable -fuzztime=10000x minimizer_test.go
|
||||
! stdout '^ok'
|
||||
|
@ -36,8 +36,9 @@ var (
|
||||
)
|
||||
|
||||
type durationOrCountFlag struct {
|
||||
d time.Duration
|
||||
n int
|
||||
d time.Duration
|
||||
n int
|
||||
allowZero bool
|
||||
}
|
||||
|
||||
func (f *durationOrCountFlag) String() string {
|
||||
@ -50,14 +51,14 @@ func (f *durationOrCountFlag) String() string {
|
||||
func (f *durationOrCountFlag) Set(s string) error {
|
||||
if strings.HasSuffix(s, "x") {
|
||||
n, err := strconv.ParseInt(s[:len(s)-1], 10, 0)
|
||||
if err != nil || n <= 0 {
|
||||
if err != nil || n < 0 || (!f.allowZero && n == 0) {
|
||||
return fmt.Errorf("invalid count")
|
||||
}
|
||||
*f = durationOrCountFlag{n: int(n)}
|
||||
return nil
|
||||
}
|
||||
d, err := time.ParseDuration(s)
|
||||
if err != nil || d <= 0 {
|
||||
if err != nil || d < 0 || (!f.allowZero && d == 0) {
|
||||
return fmt.Errorf("invalid duration")
|
||||
}
|
||||
*f = durationOrCountFlag{d: d}
|
||||
|
@ -28,7 +28,7 @@ func initFuzzFlags() {
|
||||
var (
|
||||
matchFuzz *string
|
||||
fuzzDuration durationOrCountFlag
|
||||
minimizeDuration = durationOrCountFlag{d: 60 * time.Second}
|
||||
minimizeDuration = durationOrCountFlag{d: 60 * time.Second, allowZero: true}
|
||||
fuzzCacheDir *string
|
||||
isFuzzWorker *bool
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user