mirror of
https://github.com/golang/go.git
synced 2025-05-28 19:02:22 +00:00
[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 <katie@golang.org> Run-TryBot: Katie Hockman <katie@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
354c77a108
commit
b89483497a
25
src/cmd/go/testdata/script/test_fuzz_chatty.txt
vendored
25
src/cmd/go/testdata/script/test_fuzz_chatty.txt
vendored
@ -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) {})
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user