mirror of https://github.com/golang/go.git
[dev.fuzz] cmd/go: call F.Fuzz from all fuzz script tests
Fuzz targets must call F.Skip, F.Fail, or F.Fuzz. F.Fuzz must not be called more than once. If a fuzz target panics, calls runtime.Goexit, or returns normally without calling one of those functions, the target should panic, and 'go test' should exit with a non-zero status. For now, this isn't checked. It will be fixed in a follow-up CL. Change-Id: Ibb905954462b64af15332c285124d78a998f7762 Reviewed-on: https://go-review.googlesource.com/c/go/+/290689 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Katie Hockman <katie@golang.org>
This commit is contained in:
parent
b60f793850
commit
6f401df366
|
|
@ -1,6 +1,20 @@
|
|||
# TODO(jayconrod): support shared memory on more platforms.
|
||||
[!darwin] [!linux] [!windows] skip
|
||||
|
||||
# Test that running a fuzz target that returns without failing or calling
|
||||
# f.Fuzz fails and causes a non-zero exit status.
|
||||
# BUG(jayconrod): for now, it passes.
|
||||
go test noop_fuzz_test.go
|
||||
stdout ok
|
||||
! stdout FAIL
|
||||
|
||||
# Test that fuzzing a fuzz target that returns without failing or calling
|
||||
# f.Fuzz fails and causes a non-zero exit status.
|
||||
# BUG(jayconrod): for now, it passes.
|
||||
go test -fuzz=Fuzz -fuzztime=5s -parallel=1 noop_fuzz_test.go
|
||||
stdout ok
|
||||
! stdout FAIL
|
||||
|
||||
# Test that calling f.Error in a fuzz target causes a non-zero exit status.
|
||||
! go test -fuzz=Fuzz -fuzztime=5s -parallel=1 error_fuzz_test.go
|
||||
! stdout ^ok
|
||||
|
|
@ -13,6 +27,11 @@ stdout FAIL
|
|||
|
||||
# Test that successful test exits cleanly.
|
||||
go test success_fuzz_test.go
|
||||
stdout ^ok
|
||||
! stdout FAIL
|
||||
|
||||
# Test that successful fuzzing exits cleanly.
|
||||
go test -fuzz=Fuzz -fuzztime=5s -parallel=1 success_fuzz_test.go
|
||||
stdout ok
|
||||
! stdout FAIL
|
||||
|
||||
|
|
@ -21,11 +40,6 @@ stdout ok
|
|||
! stdout ^ok
|
||||
stdout FAIL
|
||||
|
||||
# Test that successful fuzzing exits cleanly.
|
||||
go test -fuzz=Fuzz -fuzztime=5s -parallel=1 success_fuzz_test.go
|
||||
stdout ok
|
||||
! stdout FAIL
|
||||
|
||||
# Test error with seed corpus in f.Fuzz
|
||||
! go test -run FuzzError fuzz_add_test.go
|
||||
! stdout ^ok
|
||||
|
|
@ -122,6 +136,13 @@ stdout ok
|
|||
! stdout FAIL
|
||||
! stdout 'fatal here'
|
||||
|
||||
-- noop_fuzz_test.go --
|
||||
package noop_fuzz
|
||||
|
||||
import "testing"
|
||||
|
||||
func Fuzz(f *testing.F) {}
|
||||
|
||||
-- error_fuzz_test.go --
|
||||
package error_fuzz
|
||||
|
||||
|
|
@ -155,6 +176,7 @@ package success_fuzz
|
|||
import "testing"
|
||||
|
||||
func Fuzz(f *testing.F) {
|
||||
f.Fuzz(func (*testing.T, []byte) {})
|
||||
}
|
||||
|
||||
-- skipped_fuzz_test.go --
|
||||
|
|
|
|||
|
|
@ -77,4 +77,5 @@ import "testing"
|
|||
|
||||
func Fuzz(f *testing.F) {
|
||||
f.Log("all good here")
|
||||
f.Fuzz(func(*testing.T, []byte) {})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ package standalone_fuzz
|
|||
import "testing"
|
||||
|
||||
func Fuzz(f *testing.F) {
|
||||
f.Fuzz(func (*testing.T, []byte) {})
|
||||
}
|
||||
|
||||
-- multiple_fuzz_test.go --
|
||||
|
|
@ -51,7 +52,9 @@ package multiple_fuzz
|
|||
import "testing"
|
||||
|
||||
func FuzzA(f *testing.F) {
|
||||
f.Fuzz(func (*testing.T, []byte) {})
|
||||
}
|
||||
|
||||
func FuzzB(f *testing.F) {
|
||||
}
|
||||
f.Fuzz(func (*testing.T, []byte) {})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue