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 'all good here'
|
||||||
! stdout FAIL
|
! 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 --
|
-- chatty_error_fuzz_test.go --
|
||||||
package chatty_error_fuzz
|
package chatty_error_fuzz
|
||||||
|
|
||||||
@ -79,3 +90,17 @@ func Fuzz(f *testing.F) {
|
|||||||
f.Log("all good here")
|
f.Log("all good here")
|
||||||
f.Fuzz(func(*testing.T, []byte) {})
|
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()
|
m.before()
|
||||||
defer m.after()
|
defer m.after()
|
||||||
deadline := m.startAlarm()
|
if !*isFuzzWorker {
|
||||||
haveExamples = len(m.examples) > 0
|
// The fuzzing coordinator will already run all tests, examples,
|
||||||
testRan, testOk := runTests(m.deps.MatchString, m.tests, deadline)
|
// and benchmarks. Don't make the workers do redundant work.
|
||||||
fuzzTargetsRan, fuzzTargetsOk := runFuzzTargets(m.deps, m.fuzzTargets)
|
deadline := m.startAlarm()
|
||||||
exampleRan, exampleOk := runExamples(m.deps.MatchString, m.examples)
|
haveExamples = len(m.examples) > 0
|
||||||
m.stopAlarm()
|
testRan, testOk := runTests(m.deps.MatchString, m.tests, deadline)
|
||||||
if !testRan && !exampleRan && !fuzzTargetsRan && *matchBenchmarks == "" && *matchFuzz == "" {
|
fuzzTargetsRan, fuzzTargetsOk := runFuzzTargets(m.deps, m.fuzzTargets)
|
||||||
fmt.Fprintln(os.Stderr, "testing: warning: no tests to run")
|
exampleRan, exampleOk := runExamples(m.deps.MatchString, m.examples)
|
||||||
}
|
m.stopAlarm()
|
||||||
if !testOk || !exampleOk || !fuzzTargetsOk || !runBenchmarks(m.deps.ImportPath(), m.deps.MatchString, m.benchmarks) || race.Errors() > 0 {
|
if !testRan && !exampleRan && !fuzzTargetsRan && *matchBenchmarks == "" && *matchFuzz == "" {
|
||||||
fmt.Println("FAIL")
|
fmt.Fprintln(os.Stderr, "testing: warning: no tests to run")
|
||||||
m.exitCode = 1
|
}
|
||||||
return
|
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)
|
fuzzingRan, fuzzingOk := runFuzzing(m.deps, m.fuzzTargets)
|
||||||
if *matchFuzz != "" && !fuzzingRan {
|
if *matchFuzz != "" && !fuzzingRan {
|
||||||
fmt.Fprintln(os.Stderr, "testing: warning: no targets to fuzz")
|
fmt.Fprintln(os.Stderr, "testing: warning: no targets to fuzz")
|
||||||
}
|
}
|
||||||
if !fuzzingOk && !*isFuzzWorker {
|
if !*isFuzzWorker && !fuzzingOk {
|
||||||
fmt.Println("FAIL")
|
fmt.Println("FAIL")
|
||||||
m.exitCode = 1
|
m.exitCode = 1
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user