]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.fuzz] cmd/go: exclude additional packages from fuzzing instrumentation
authorJay Conrod <jayconrod@google.com>
Mon, 16 Aug 2021 22:09:05 +0000 (15:09 -0700)
committerJay Conrod <jayconrod@google.com>
Fri, 20 Aug 2021 20:13:57 +0000 (20:13 +0000)
Counters in these packages are incremented by background goroutines
for testing and internal/fuzz. They cause some inputs to seem
"interesting" when they don't directly provide new coverage.

Updates golang/go#46410

Change-Id: Ibe6bb3177f3b2ba23382a1693a4c6a576f94a423
Reviewed-on: https://go-review.googlesource.com/c/go/+/342993
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
src/cmd/go/internal/test/test.go
src/cmd/go/testdata/script/test_fuzz_cache.txt

index 012a75123b51be16994fbf10c5d9ae86375cf6a5..75345a82238238cdff7e19dd1221d146a5c6ff52 100644 (file)
@@ -831,11 +831,18 @@ func runTest(ctx context.Context, cmd *base.Command, args []string) {
        fuzzFlags := work.FuzzInstrumentFlags()
        if testFuzz != "" && fuzzFlags != nil {
                // Don't instrument packages which may affect coverage guidance but are
-               // unlikely to be useful.
+               // unlikely to be useful. Most of these are used by the testing or
+               // internal/fuzz concurrently with fuzzing.
                var fuzzNoInstrument = map[string]bool{
-                       "testing":       true,
+                       "context":       true,
                        "internal/fuzz": true,
+                       "reflect":       true,
                        "runtime":       true,
+                       "sync":          true,
+                       "sync/atomic":   true,
+                       "syscall":       true,
+                       "testing":       true,
+                       "time":          true,
                }
                for _, p := range load.TestPackageList(ctx, pkgOpts, pkgs) {
                        if fuzzNoInstrument[p.ImportPath] {
index a6c9cafada4d69f98acd69a9059d8d1f39b0860d..10e4c2926f44073d04f7b9e685bc2c5e06325468 100644 (file)
@@ -35,19 +35,27 @@ go 1.16
 -- y_test.go --
 package y
 
-import "testing"
+import (
+       "io"
+       "testing"
+)
 
 func FuzzY(f *testing.F) {
        f.Add([]byte("y"))
-       f.Fuzz(func(t *testing.T, b []byte) { Y(b) })
+       f.Fuzz(func(t *testing.T, b []byte) { Y(io.Discard, b) })
 }
 -- y.go --
 package y
 
-import "bytes"
+import (
+       "bytes"
+       "io"
+)
 
-func Y(b []byte) bool {
-       return bytes.Equal(b, []byte("y"))
+func Y(w io.Writer, b []byte) {
+       if !bytes.Equal(b, []byte("y")) {
+               w.Write([]byte("not equal"))
+       }
 }
 -- empty/empty.go --
 package empty