]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.fuzz] testing: adjust -fuzz multiple match stdout
authorKatie Hockman <katie@golang.org>
Tue, 14 Sep 2021 19:21:54 +0000 (15:21 -0400)
committerKatie Hockman <katie@golang.org>
Wed, 15 Sep 2021 18:52:34 +0000 (18:52 +0000)
Fixes golang/go#48131

Change-Id: I40ff130c849dffe38363ddc0282e93ceb74ae140
Reviewed-on: https://go-review.googlesource.com/c/go/+/349969
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/cmd/go/testdata/script/test_fuzz_match.txt
src/testing/fuzz.go
src/testing/testing.go

index 9d4c5125d3dd3fc00137d6b357672e40550731b0..47e143952acd185e7bc7302bea7604e84bfb301a 100644 (file)
@@ -30,11 +30,10 @@ stdout '^ok.*no tests to run'
 ! stdout 'no targets to fuzz'
 
 # Matches more than one fuzz target for fuzzing.
-go test -fuzz Fuzz -fuzztime 1x multiple_fuzz_test.go
-# The tests should run, but not be fuzzed
+! go test -fuzz Fuzz -fuzztime 1x multiple_fuzz_test.go
 ! stdout 'no tests to run'
 ! stdout 'no targets to fuzz'
-stdout ok
+stdout FAIL
 stdout 'will not fuzz, -fuzz matches more than one target'
 
 -- standalone_fuzz_test.go --
index 65c3437ed4fe1e268011e32da98c79c1867202d1..c2d9db843de6c6fa79b68d8e1b2d7efdcc4fa64a 100644 (file)
@@ -593,12 +593,12 @@ func runFuzzTargets(deps testDeps, fuzzTargets []InternalFuzzTarget, deadline ti
 //
 // If fuzzing is disabled (-test.fuzz is not set), runFuzzing
 // returns immediately.
-func runFuzzing(deps testDeps, fuzzTargets []InternalFuzzTarget) (ran bool, matched int, ok bool) {
+func runFuzzing(deps testDeps, fuzzTargets []InternalFuzzTarget) (ok bool) {
        // TODO(katiehockman,jayconrod): Should we do something special to make sure
        // we don't print f.Log statements again with runFuzzing, since we already
        // would have printed them when we ran runFuzzTargets (ie. seed corpus run)?
        if len(fuzzTargets) == 0 || *matchFuzz == "" {
-               return false, 0, true
+               return true
        }
        m := newMatcher(deps.MatchString, *matchFuzz, "-test.fuzz")
        tctx := newTestContext(1, m)
@@ -617,17 +617,23 @@ func runFuzzing(deps testDeps, fuzzTargets []InternalFuzzTarget) (ran bool, matc
        }
        var target *InternalFuzzTarget
        var targetName string
+       var matched []string
        for i := range fuzzTargets {
                name, ok, _ := tctx.match.fullName(nil, fuzzTargets[i].Name)
                if !ok {
                        continue
                }
-               matched++
+               matched = append(matched, name)
                target = &fuzzTargets[i]
                targetName = name
        }
-       if matched != 1 {
-               return false, matched, true
+       if len(matched) == 0 {
+               fmt.Fprintln(os.Stderr, "testing: warning: no targets to fuzz")
+               return true
+       }
+       if len(matched) > 1 {
+               fmt.Fprintf(os.Stderr, "testing: will not fuzz, -fuzz matches more than one target: %v\n", matched)
+               return false
        }
 
        f := &F{
@@ -649,7 +655,7 @@ func runFuzzing(deps testDeps, fuzzTargets []InternalFuzzTarget) (ran bool, matc
        }
        go fRunner(f, target.Fn)
        <-f.signal
-       return f.ran, matched, !f.failed
+       return !f.failed
 }
 
 // fRunner wraps a call to a fuzz target and ensures that cleanup functions are
index 5e66a0610bd20907aa5cc11c48985f204365a0b9..f4d2b26650b51ea32d4daa7fee305d6d409f8d0c 100644 (file)
@@ -1634,14 +1634,7 @@ func (m *M) Run() (code int) {
                }
        }
 
-       fuzzingRan, fuzzingMatched, fuzzingOk := runFuzzing(m.deps, m.fuzzTargets)
-       if *matchFuzz != "" && !fuzzingRan {
-               if fuzzingMatched == 0 {
-                       fmt.Fprintln(os.Stderr, "testing: warning: no targets to fuzz")
-               } else {
-                       fmt.Fprintln(os.Stderr, "testing: warning: will not fuzz, -fuzz matches more than one target")
-               }
-       }
+       fuzzingOk := runFuzzing(m.deps, m.fuzzTargets)
        if !*isFuzzWorker && !fuzzingOk {
                fmt.Println("FAIL")
                if *isFuzzWorker {