mirror of
https://github.com/golang/go
synced 2024-11-17 13:44:43 -07:00
[dev.fuzz] cmd/go: in 'go test' don't allow multiple packages with -fuzz
Until we have a system for managing load across multiple fuzz targets in multiple test executables, we'll only support fuzzing one target in one package at a time. Users can still run multiple 'go test -fuzz' commands concurrently, but this may overwhelm some systems unless -parallel and -p are set carefully. For #46312 Change-Id: If84c58d1b3e60498ce955eae5ad4d52100dbd4b7 Reviewed-on: https://go-review.googlesource.com/c/go/+/350156 Trust: Jay Conrod <jayconrod@google.com> Trust: Katie Hockman <katie@golang.org> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Katie Hockman <katie@golang.org>
This commit is contained in:
parent
24e25afff4
commit
51ca5706ab
@ -671,6 +671,9 @@ func runTest(ctx context.Context, cmd *base.Command, args []string) {
|
||||
if testO != "" && len(pkgs) != 1 {
|
||||
base.Fatalf("cannot use -o flag with multiple packages")
|
||||
}
|
||||
if testFuzz != "" && len(pkgs) != 1 {
|
||||
base.Fatalf("cannot use -fuzz flag with multiple packages")
|
||||
}
|
||||
if testProfile() != "" && len(pkgs) != 1 {
|
||||
base.Fatalf("cannot use %s flag with multiple packages", testProfile())
|
||||
}
|
||||
|
20
src/cmd/go/testdata/script/test_fuzz_match.txt
vendored
20
src/cmd/go/testdata/script/test_fuzz_match.txt
vendored
@ -29,13 +29,6 @@ go test -run ThisWillNotMatch standalone_fuzz_test.go
|
||||
stdout '^ok.*no tests to run'
|
||||
! stdout 'no targets to fuzz'
|
||||
|
||||
# Matches more than one fuzz target for fuzzing.
|
||||
! go test -fuzz Fuzz -fuzztime 1x multiple_fuzz_test.go
|
||||
! stdout 'no tests to run'
|
||||
! stdout 'no targets to fuzz'
|
||||
stdout FAIL
|
||||
stdout 'will not fuzz, -fuzz matches more than one target'
|
||||
|
||||
-- standalone_fuzz_test.go --
|
||||
package standalone_fuzz
|
||||
|
||||
@ -44,16 +37,3 @@ import "testing"
|
||||
func Fuzz(f *testing.F) {
|
||||
f.Fuzz(func (*testing.T, []byte) {})
|
||||
}
|
||||
|
||||
-- multiple_fuzz_test.go --
|
||||
package multiple_fuzz
|
||||
|
||||
import "testing"
|
||||
|
||||
func FuzzA(f *testing.F) {
|
||||
f.Fuzz(func (*testing.T, []byte) {})
|
||||
}
|
||||
|
||||
func FuzzB(f *testing.F) {
|
||||
f.Fuzz(func (*testing.T, []byte) {})
|
||||
}
|
||||
|
51
src/cmd/go/testdata/script/test_fuzz_multiple.txt
vendored
Normal file
51
src/cmd/go/testdata/script/test_fuzz_multiple.txt
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
# This test checks that 'go test' prints a reasonable error when fuzzing is
|
||||
# enabled, and multiple package or multiple fuzz targets match.
|
||||
# TODO(#46312): support fuzzing multiple targets in multiple packages.
|
||||
|
||||
# TODO(jayconrod): support shared memory on more platforms.
|
||||
[!darwin] [!linux] [!windows] skip
|
||||
|
||||
[short] skip
|
||||
|
||||
# With fuzzing disabled, multiple targets can be tested.
|
||||
go test ./...
|
||||
|
||||
# With fuzzing enabled, at most one package may be tested,
|
||||
# even if only one package contains fuzz targets.
|
||||
! go test -fuzz=. ./...
|
||||
stderr '^cannot use -fuzz flag with multiple packages$'
|
||||
! go test -fuzz=. ./zero ./one
|
||||
stderr '^cannot use -fuzz flag with multiple packages$'
|
||||
go test -fuzz=. -fuzztime=1x ./one
|
||||
|
||||
# With fuzzing enabled, at most one target in the same package may match.
|
||||
! go test -fuzz=. ./two
|
||||
stdout '^testing: will not fuzz, -fuzz matches more than one target: \[FuzzOne FuzzTwo\]$'
|
||||
go test -fuzz=FuzzTwo -fuzztime=1x ./two
|
||||
|
||||
-- go.mod --
|
||||
module fuzz
|
||||
|
||||
go 1.18
|
||||
-- zero/zero.go --
|
||||
package zero
|
||||
-- one/one_test.go --
|
||||
package one
|
||||
|
||||
import "testing"
|
||||
|
||||
func FuzzOne(f *testing.F) {
|
||||
f.Fuzz(func(*testing.T, []byte) {})
|
||||
}
|
||||
-- two/two_test.go --
|
||||
package two
|
||||
|
||||
import "testing"
|
||||
|
||||
func FuzzOne(f *testing.F) {
|
||||
f.Fuzz(func(*testing.T, []byte) {})
|
||||
}
|
||||
|
||||
func FuzzTwo(f *testing.F) {
|
||||
f.Fuzz(func(*testing.T, []byte) {})
|
||||
}
|
Loading…
Reference in New Issue
Block a user