diff options
| author | Katie Hockman <katie@golang.org> | 2021-11-09 17:13:36 -0500 |
|---|---|---|
| committer | Katie Hockman <katie@golang.org> | 2021-11-11 21:06:07 +0000 |
| commit | 9d89a5eb64f25ce0e7cc6086d44b6f327cbb302c (patch) | |
| tree | b453ae64e87fe65a5c8cc16338d27634553760a9 /src/testing/testing.go | |
| parent | ccd41cc05e3ee2f0d0ded1d7faf9c1f43ce1037b (diff) | |
| download | go-9d89a5eb64f25ce0e7cc6086d44b6f327cbb302c.tar.xz | |
all: update terminology for fuzzing
This change doesn't modify any functionality.
It also doesn't update all of the comments and
variable names of the internal code, but everything
user facing should be correct.
Updates #49185
Change-Id: Ia8b2c94b89ba45897c4085ea0c17a3d8896f7ec7
Reviewed-on: https://go-review.googlesource.com/c/go/+/362794
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Diffstat (limited to 'src/testing/testing.go')
| -rw-r--r-- | src/testing/testing.go | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go index 2ad2266e2d..3458b46d97 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -146,11 +146,9 @@ // a function is called with randomly generated inputs to find bugs not // anticipated by unit tests. // -// A fuzz target is a function that declares a set of "seed" inputs by calling -// F.Add, then provides a fuzz function by calling F.Fuzz. A fuzz target has -// the form: -// +// Functions of the form // func FuzzXxx(*testing.F) +// are considered fuzz tests. // // For example: // @@ -170,35 +168,38 @@ // }) // } // -// Seed inputs may be registered by calling F.Add or by storing files in the -// directory testdata/fuzz/<Name> (where <Name> is the name of the fuzz target) -// within the package containing the fuzz target. Seed inputs are optional, but -// the fuzzing engine may find bugs more efficiently when provided with a set -// of small seed inputs with good code coverage. +// A fuzz test maintains a seed corpus, or a set of inputs which are run by +// default, and can seed input generation. Seed inputs may be registered by +// calling (*F).Add or by storing files in the directory testdata/fuzz/<Name> +// (where <Name> is the name of the fuzz test) within the package containing +// the fuzz test. Seed inputs are optional, but the fuzzing engine may find +// bugs more efficiently when provided with a set of small seed inputs with good +// code coverage. These seed inputs can also serve as regression tests for bugs +// identified through fuzzing. // -// The fuzz function provided to F.Fuzz must accept a *testing.T parameter, -// followed by one or more parameters for random inputs. The types of arguments -// passed to F.Add must be identical to the types of these parameters. The fuzz -// function may signal that it's found a problem the same way tests do: by -// calling T.Fail (or any method that calls it like T.Error or T.Fatal) or by -// panicking. +// The function passed to (*F).Fuzz within the fuzz test is considered the fuzz +// target. A fuzz target must accept a *T parameter, followed by one or more +// parameters for random inputs. The types of arguments passed to (*F).Add must +// be identical to the types of these parameters. The fuzz target may signal +// that it's found a problem the same way tests do: by calling T.Fail (or any +// method that calls it like T.Error or T.Fatal) or by panicking. // // When fuzzing is enabled (by setting the -fuzz flag to a regular expression -// that matches a specific fuzz target), the fuzz function is called with -// arguments generated by repeatedly making random changes to the seed inputs. -// On supported platforms, 'go test' compiles the test executable with fuzzing +// that matches a specific fuzz test), the fuzz target is called with arguments +// generated by repeatedly making random changes to the seed inputs. On +// supported platforms, 'go test' compiles the test executable with fuzzing // coverage instrumentation. The fuzzing engine uses that instrumentation to -// find and cache inputs that expand coverage, increasing the liklihood of -// finding bugs. If the fuzz function finds a problem, the fuzzing engine writes -// the inputs that caused the problem to a file in the directory +// find and cache inputs that expand coverage, increasing the likelihood of +// finding bugs. If the fuzz target fails for a given input, the fuzzing engine +// writes the inputs that caused the failure to a file in the directory // testdata/fuzz/<Name> within the package directory. This file later serves as // a seed input. If the file can't be written at that location (for example, // because the directory is read-only), the fuzzing engine writes the file to // the fuzz cache directory within the build cache instead. // -// When fuzzing is disabled, the fuzz function is called with the seed inputs +// When fuzzing is disabled, the fuzz target is called with the seed inputs // registered with F.Add and seed inputs from testdata/fuzz/<Name>. In this -// mode, the fuzz target acts much like a regular test, with subtests started +// mode, the fuzz test acts much like a regular test, with subtests started // with F.Fuzz instead of T.Run. // // TODO(#48255): write and link to documentation that will be helpful to users @@ -217,7 +218,7 @@ // } // // The Skip method of *T can be used in a fuzz target if the input is invalid, -// but should not be considered a crash. For example: +// but should not be considered a failing input. For example: // // func FuzzJSONMarshalling(f *testing.F) { // f.Fuzz(func(t *testing.T, b []byte) { @@ -500,7 +501,7 @@ type common struct { cleanupName string // Name of the cleanup function. cleanupPc []uintptr // The stack trace at the point where Cleanup was called. finished bool // Test function has completed. - inFuzzFn bool // Whether the fuzz function, if this is one, is running. + inFuzzFn bool // Whether the fuzz target, if this is one, is running. chatty *chattyPrinter // A copy of chattyPrinter, if the chatty flag is set. bench bool // Whether the current test is a benchmark. @@ -558,7 +559,7 @@ func Verbose() bool { func (c *common) checkFuzzFn(name string) { if c.inFuzzFn { - panic(fmt.Sprintf("testing: f.%s was called inside the f.Fuzz function, use t.%s instead", name, name)) + panic(fmt.Sprintf("testing: f.%s was called inside the fuzz target, use t.%s instead", name, name)) } } @@ -1687,7 +1688,7 @@ func (m *M) Run() (code int) { deadline := m.startAlarm() haveExamples = len(m.examples) > 0 testRan, testOk := runTests(m.deps.MatchString, m.tests, deadline) - fuzzTargetsRan, fuzzTargetsOk := runFuzzTargets(m.deps, m.fuzzTargets, deadline) + fuzzTargetsRan, fuzzTargetsOk := runFuzzTests(m.deps, m.fuzzTargets, deadline) exampleRan, exampleOk := runExamples(m.deps.MatchString, m.examples) m.stopAlarm() if !testRan && !exampleRan && !fuzzTargetsRan && *matchBenchmarks == "" && *matchFuzz == "" { |
