mirror of
https://github.com/golang/go
synced 2024-11-24 11:50:15 -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.
|
# We clean the fuzz cache during this test. Don't clean the user's cache.
|
||||||
env GOCACHE=$WORK/gocache
|
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.
|
# Test that minimization is working for recoverable errors.
|
||||||
! go test -fuzz=FuzzMinimizerRecoverable -run=FuzzMinimizerRecoverable -fuzztime=10000x minimizer_test.go
|
! go test -fuzz=FuzzMinimizerRecoverable -run=FuzzMinimizerRecoverable -fuzztime=10000x minimizer_test.go
|
||||||
! stdout '^ok'
|
! stdout '^ok'
|
||||||
|
@ -38,6 +38,7 @@ var (
|
|||||||
type durationOrCountFlag struct {
|
type durationOrCountFlag struct {
|
||||||
d time.Duration
|
d time.Duration
|
||||||
n int
|
n int
|
||||||
|
allowZero bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *durationOrCountFlag) String() string {
|
func (f *durationOrCountFlag) String() string {
|
||||||
@ -50,14 +51,14 @@ func (f *durationOrCountFlag) String() string {
|
|||||||
func (f *durationOrCountFlag) Set(s string) error {
|
func (f *durationOrCountFlag) Set(s string) error {
|
||||||
if strings.HasSuffix(s, "x") {
|
if strings.HasSuffix(s, "x") {
|
||||||
n, err := strconv.ParseInt(s[:len(s)-1], 10, 0)
|
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")
|
return fmt.Errorf("invalid count")
|
||||||
}
|
}
|
||||||
*f = durationOrCountFlag{n: int(n)}
|
*f = durationOrCountFlag{n: int(n)}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
d, err := time.ParseDuration(s)
|
d, err := time.ParseDuration(s)
|
||||||
if err != nil || d <= 0 {
|
if err != nil || d < 0 || (!f.allowZero && d == 0) {
|
||||||
return fmt.Errorf("invalid duration")
|
return fmt.Errorf("invalid duration")
|
||||||
}
|
}
|
||||||
*f = durationOrCountFlag{d: d}
|
*f = durationOrCountFlag{d: d}
|
||||||
|
@ -28,7 +28,7 @@ func initFuzzFlags() {
|
|||||||
var (
|
var (
|
||||||
matchFuzz *string
|
matchFuzz *string
|
||||||
fuzzDuration durationOrCountFlag
|
fuzzDuration durationOrCountFlag
|
||||||
minimizeDuration = durationOrCountFlag{d: 60 * time.Second}
|
minimizeDuration = durationOrCountFlag{d: 60 * time.Second, allowZero: true}
|
||||||
fuzzCacheDir *string
|
fuzzCacheDir *string
|
||||||
isFuzzWorker *bool
|
isFuzzWorker *bool
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user