From: Katie Hockman Date: Thu, 4 Mar 2021 18:02:24 +0000 (-0500) Subject: [dev.fuzz] testing: only let workers run fuzz targets X-Git-Tag: go1.18beta1~1282^2~86 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b89483497a7349bb8dba9110e765f5ff1189f69d;p=gostls13.git [dev.fuzz] testing: only let workers run fuzz targets Previously, ever worker would run all of the unit tests, benchmarks, and examples. Only the single coordinator needs to do this. Change-Id: I0dfa7f79b390b6c3220d8ea646e2d2312eee6bb1 Reviewed-on: https://go-review.googlesource.com/c/go/+/298809 Trust: Katie Hockman Run-TryBot: Katie Hockman TryBot-Result: Go Bot Reviewed-by: Jay Conrod --- diff --git a/src/cmd/go/testdata/script/test_fuzz_chatty.txt b/src/cmd/go/testdata/script/test_fuzz_chatty.txt index aaf385f293..ea81bc331d 100644 --- a/src/cmd/go/testdata/script/test_fuzz_chatty.txt +++ b/src/cmd/go/testdata/script/test_fuzz_chatty.txt @@ -34,6 +34,17 @@ stdout PASS stdout 'all good here' ! stdout FAIL +# Fuzz successful chatty fuzz target that includes a separate unit test. +go test -v chatty_with_test_fuzz_test.go -fuzz=Fuzz -fuzztime=1s +stdout ok +stdout PASS +! stdout FAIL +# TODO: It's currently the case that it's logged twice. Fix that, and change +# this check to verify it. +stdout 'all good here' +# Verify that the unit test is only run once. +! stdout '(?s)logged foo.*logged foo' + -- chatty_error_fuzz_test.go -- package chatty_error_fuzz @@ -79,3 +90,17 @@ func Fuzz(f *testing.F) { f.Log("all good here") f.Fuzz(func(*testing.T, []byte) {}) } + +-- chatty_with_test_fuzz_test.go -- +package chatty_with_test_fuzz + +import "testing" + +func TestFoo(t *testing.T) { + t.Log("logged foo") +} + +func Fuzz(f *testing.F) { + f.Log("all good here") + f.Fuzz(func(*testing.T, []byte) {}) +} diff --git a/src/testing/testing.go b/src/testing/testing.go index 152483d8ff..7ce794c5a8 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -1439,26 +1439,30 @@ func (m *M) Run() (code int) { m.before() defer m.after() - deadline := m.startAlarm() - haveExamples = len(m.examples) > 0 - testRan, testOk := runTests(m.deps.MatchString, m.tests, deadline) - fuzzTargetsRan, fuzzTargetsOk := runFuzzTargets(m.deps, m.fuzzTargets) - exampleRan, exampleOk := runExamples(m.deps.MatchString, m.examples) - m.stopAlarm() - if !testRan && !exampleRan && !fuzzTargetsRan && *matchBenchmarks == "" && *matchFuzz == "" { - fmt.Fprintln(os.Stderr, "testing: warning: no tests to run") - } - if !testOk || !exampleOk || !fuzzTargetsOk || !runBenchmarks(m.deps.ImportPath(), m.deps.MatchString, m.benchmarks) || race.Errors() > 0 { - fmt.Println("FAIL") - m.exitCode = 1 - return + if !*isFuzzWorker { + // The fuzzing coordinator will already run all tests, examples, + // and benchmarks. Don't make the workers do redundant work. + deadline := m.startAlarm() + haveExamples = len(m.examples) > 0 + testRan, testOk := runTests(m.deps.MatchString, m.tests, deadline) + fuzzTargetsRan, fuzzTargetsOk := runFuzzTargets(m.deps, m.fuzzTargets) + exampleRan, exampleOk := runExamples(m.deps.MatchString, m.examples) + m.stopAlarm() + if !testRan && !exampleRan && !fuzzTargetsRan && *matchBenchmarks == "" && *matchFuzz == "" { + fmt.Fprintln(os.Stderr, "testing: warning: no tests to run") + } + if !testOk || !exampleOk || !fuzzTargetsOk || !runBenchmarks(m.deps.ImportPath(), m.deps.MatchString, m.benchmarks) || race.Errors() > 0 { + fmt.Println("FAIL") + m.exitCode = 1 + return + } } fuzzingRan, fuzzingOk := runFuzzing(m.deps, m.fuzzTargets) if *matchFuzz != "" && !fuzzingRan { fmt.Fprintln(os.Stderr, "testing: warning: no targets to fuzz") } - if !fuzzingOk && !*isFuzzWorker { + if !*isFuzzWorker && !fuzzingOk { fmt.Println("FAIL") m.exitCode = 1 return