]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: disallow profile flags when using -fuzz
authorRoland Shoemaker <roland@golang.org>
Mon, 1 Nov 2021 17:28:52 +0000 (10:28 -0700)
committerRoland Shoemaker <roland@golang.org>
Tue, 2 Nov 2021 18:01:20 +0000 (18:01 +0000)
Disallow the usage of coverprofile, blockprofile, cpuprofile, memprofile,
mutexprofile, and trace when fuzzing, since these currently do not work
as the user would expect.

Fixes #48178

Change-Id: Ibe6dfaef9b28a91c60c26fcad38c33a2a959d869
Reviewed-on: https://go-review.googlesource.com/c/go/+/360395
Trust: Roland Shoemaker <roland@golang.org>
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Katie Hockman <katie@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/go/internal/test/test.go
src/cmd/go/testdata/script/test_fuzz_profile_flags.txt [new file with mode: 0644]

index cfb0a1465fbc91ff0ebfdff88b3c288728d2ae58..7dca6b531ca33fbe8c5f67014232ed77b1ce80fa 100644 (file)
@@ -666,6 +666,12 @@ func runTest(ctx context.Context, cmd *base.Command, args []string) {
                if len(pkgs) != 1 {
                        base.Fatalf("cannot use -fuzz flag with multiple packages")
                }
+               if testCoverProfile != "" {
+                       base.Fatalf("cannot use -coverprofile flag with -fuzz flag")
+               }
+               if profileFlag := testProfile(); profileFlag != "" {
+                       base.Fatalf("cannot use %s flag with -fuzz flag", profileFlag)
+               }
 
                // Reject the '-fuzz' flag if the package is outside the main module.
                // Otherwise, if fuzzing identifies a failure it could corrupt checksums in
diff --git a/src/cmd/go/testdata/script/test_fuzz_profile_flags.txt b/src/cmd/go/testdata/script/test_fuzz_profile_flags.txt
new file mode 100644 (file)
index 0000000..5434c72
--- /dev/null
@@ -0,0 +1,38 @@
+[!fuzz] skip
+
+! go test -fuzz=FuzzTrivial -coverprofile=prof
+! stdout .
+stderr '^cannot use -coverprofile flag with -fuzz flag$'
+
+! go test -fuzz=FuzzTrivial -blockprofile=prof
+! stdout .
+stderr '^cannot use -blockprofile flag with -fuzz flag$'
+
+! go test -fuzz=FuzzTrivial -cpuprofile=prof
+! stdout .
+stderr '^cannot use -cpuprofile flag with -fuzz flag$'
+
+! go test -fuzz=FuzzTrivial -memprofile=prof
+! stdout .
+stderr '^cannot use -memprofile flag with -fuzz flag$'
+
+! go test -fuzz=FuzzTrivial -mutexprofile=prof
+! stdout .
+stderr '^cannot use -mutexprofile flag with -fuzz flag$'
+
+! go test -fuzz=FuzzTrivial -trace=prof
+! stdout .
+stderr '^cannot use -trace flag with -fuzz flag$'
+
+-- go.mod --
+module example
+
+go 1.18
+-- fuzz_test.go --
+package example
+
+import "testing"
+
+func FuzzTrivial(f *testing.F) {
+       f.Fuzz(func(t *testing.T, _ []byte) {})
+}