]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.fuzz] cmd/go: call F.Fuzz from all fuzz script tests
authorJay Conrod <jayconrod@google.com>
Tue, 9 Feb 2021 15:15:02 +0000 (10:15 -0500)
committerJay Conrod <jayconrod@google.com>
Wed, 10 Feb 2021 18:20:35 +0000 (18:20 +0000)
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>
src/cmd/go/testdata/script/test_fuzz.txt
src/cmd/go/testdata/script/test_fuzz_chatty.txt
src/cmd/go/testdata/script/test_fuzz_match.txt

index eb65e0db2a8d0d15a3e4ab4b341ee3644b649e0b..ccdae830a597518c950675af0b93e0255c99b496 100644 (file)
@@ -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 --
index b70bb9e49f50d6c04b19de7b7a7194ef65a30c51..aaf385f293b2238b970a875f40447d4a19896b39 100644 (file)
@@ -77,4 +77,5 @@ import "testing"
 
 func Fuzz(f *testing.F) {
     f.Log("all good here")
+    f.Fuzz(func(*testing.T, []byte) {})
 }
index 44ebf0bf66134c4a3b2023c858257fa8bf5d5978..5ead41411fdee94f8621001549d36c276e643ddd 100644 (file)
@@ -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) {
-}
\ No newline at end of file
+       f.Fuzz(func (*testing.T, []byte) {})
+}