From f89b4c8d82c028d635eb8e685dd92dceb0027438 Mon Sep 17 00:00:00 2001 From: Jay Conrod Date: Mon, 16 Aug 2021 15:09:05 -0700 Subject: [PATCH] [dev.fuzz] cmd/go: exclude additional packages from fuzzing instrumentation 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 Run-TryBot: Jay Conrod Reviewed-by: Roland Shoemaker --- src/cmd/go/internal/test/test.go | 11 +++++++++-- src/cmd/go/testdata/script/test_fuzz_cache.txt | 18 +++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go index 012a75123b..75345a8223 100644 --- a/src/cmd/go/internal/test/test.go +++ b/src/cmd/go/internal/test/test.go @@ -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] { diff --git a/src/cmd/go/testdata/script/test_fuzz_cache.txt b/src/cmd/go/testdata/script/test_fuzz_cache.txt index a6c9cafada..10e4c2926f 100644 --- a/src/cmd/go/testdata/script/test_fuzz_cache.txt +++ b/src/cmd/go/testdata/script/test_fuzz_cache.txt @@ -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 -- 2.50.0