]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.fuzz] testing: cleanup a few small things
authorKatie Hockman <katie@golang.org>
Mon, 19 Oct 2020 15:04:37 +0000 (11:04 -0400)
committerFilippo Valsorda <filippo@golang.org>
Fri, 4 Dec 2020 18:17:29 +0000 (19:17 +0100)
Deletes the exported testing.Fuzz function
which would run a standalone fuzz target.
Similar to RunFuzzing and RunFuzzTargets,
which were previously removed, this will
likely be too complex to support.

Moves the deferred Exit in f.Fuzz higher up
the function so it is always run.

Change-Id: I9ea6210dc30dee8c2a943bfb8077225c369cfb95
Reviewed-on: https://go-review.googlesource.com/c/go/+/263642
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>
src/testing/fuzz.go

index ff13e0b4e06f4868b1eb85d1b9f77105148864ed..ce66000a3a3018ee59d7849dfdfc49780111cda5 100644 (file)
@@ -79,6 +79,8 @@ func (f *F) Add(args ...interface{}) {
 // target by calling runtime.Goexit. To run any code after this function, use
 // Cleanup.
 func (f *F) Fuzz(ff interface{}) {
+       defer runtime.Goexit() // exit after this function
+
        fn, ok := ff.(func(*T, []byte))
        if !ok {
                panic("testing: Fuzz function must have type func(*testing.T, []byte)")
@@ -92,8 +94,6 @@ func (f *F) Fuzz(ff interface{}) {
        f.corpus = append(f.corpus, bytesToCorpus(c)...)
        // TODO(jayconrod,katiehockman): dedupe testdata corpus with entries from f.Add
 
-       defer runtime.Goexit() // exit after this function
-
        var errStr string
        run := func(t *T, b []byte) {
                defer func() {
@@ -364,19 +364,3 @@ func runFuzzing(deps testDeps, fuzzTargets []InternalFuzzTarget) (ran, ok bool)
        <-f.signal
        return f.ran, !f.failed
 }
-
-// Fuzz runs a single fuzz target. It is useful for creating
-// custom fuzz targets that do not use the "go test" command.
-//
-// If fn depends on testing flags, then Init must be used to register
-// those flags before calling Fuzz and before calling flag.Parse.
-func Fuzz(fn func(f *F)) FuzzResult {
-       f := &F{
-               common: common{
-                       w: discard{},
-               },
-               fuzzFunc: fn,
-       }
-       // TODO(katiehockman): run the test
-       return f.result
-}