]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix broken fuzz test
authorKatie Hockman <katie@golang.org>
Mon, 18 Oct 2021 14:24:00 +0000 (10:24 -0400)
committerRoland Shoemaker <roland@golang.org>
Mon, 18 Oct 2021 16:06:08 +0000 (16:06 +0000)
Fixes test breakage caused by CL 355691.

Change-Id: I85fcb1491dc39c45342f4cae91fdfda6aedecd1a
Reviewed-on: https://go-review.googlesource.com/c/go/+/356530
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/testdata/script/test_fuzz_minimize.txt
src/cmd/go/testdata/script/test_fuzz_minimize_interesting.txt

index 56abc681042fda8890f8d6f0da0dbffc48be38ac..8b11621bbda9c182a583fba4d89c058b98c7e8a8 100644 (file)
@@ -34,21 +34,6 @@ stdout FAIL
 stdout 'there was an Error'
 stdout FAIL
 
-# Test that minimization occurs for a crash that appears while minimizing a
-# newly found interesting input. There must be only one worker for this test to
-# be flaky like we want.
-! go test -fuzz=FuzzMinimizerCrashInMinimization -run=FuzzMinimizerCrashInMinimization -fuzztime=10000x -parallel=1 .
-! stdout '^ok'
-stdout 'got the minimum size!'
-stdout 'flaky failure'
-stdout FAIL
-
-# Make sure the crash that was written will fail when run with go test
-! go test -run=FuzzMinimizerCrashInMinimization .
-
-# Clear testdata.
-rm testdata
-
 # Test that minimization is working for recoverable errors.
 ! go test -fuzz=FuzzMinimizerRecoverable -run=FuzzMinimizerRecoverable -fuzztime=10000x .
 ! stdout '^ok'
@@ -97,25 +82,10 @@ stdout FAIL
 module example.com/y
 
 go 1.16
--- y.go --
-package y
-
-import (
-       "bytes"
-       "io"
-)
-
-func Y(w io.Writer, b []byte) {
-       if !bytes.Equal(b, []byte("y")) {
-               w.Write([]byte("not equal"))
-       }
-}
 -- y_test.go --
 package y
 
 import (
-       "bytes"
-       "io"
        "os"
        "testing"
 )
@@ -161,28 +131,6 @@ func FuzzMinimizerNonrecoverable(f *testing.F) {
                os.Exit(99)
        })
 }
-
-func FuzzMinimizerCrashInMinimization(f *testing.F) {
-       seed := make([]byte, 1000)
-       f.Add(seed)
-       f.Fuzz(func(t *testing.T, b []byte) {
-               if len(b) < 50 || len(b) > 1100 {
-                       // Make sure that b is large enough that it can be minimized
-                       return
-               }
-               if !bytes.Equal(b, seed) {
-                       // This should have hit a new edge, and the interesting input
-                       // should be attempting minimization
-                       Y(io.Discard, b)
-               }
-               if len(b) < 350 {
-                       t.Error("flaky failure")
-               }
-               if len(b) == 50 {
-                       t.Log("got the minimum size!")
-               }
-       })
-}
 -- empty/empty.go --
 package empty
 -- check_testdata/check_testdata.go --
index 5e1d90d8d9b3aabe70c6fc3aa3ebd291b07c4626..fc66201eb3fac361298a365f84dd15dc04cd751e 100644 (file)
 
 go test -c -fuzz=.  # Build using shared build cache for speed.
 env GOCACHE=$WORK/gocache
-exec ./fuzz.test$GOEXE -test.fuzzcachedir=$GOCACHE/fuzz -test.fuzz=. -test.fuzztime=1000x
-go run check_cache.go $GOCACHE/fuzz/FuzzMin
+exec ./fuzz.test$GOEXE -test.fuzzcachedir=$GOCACHE/fuzz -test.fuzz=FuzzMinCache -test.fuzztime=1000x
+go run check_cache.go $GOCACHE/fuzz/FuzzMinCache
+
+# Test that minimization occurs for a crash that appears while minimizing a
+# newly found interesting input. There must be only one worker for this test to
+# be flaky like we want.
+go test -c -fuzz=.  # Build using shared build cache for speed.
+env GOCACHE=$WORK/gocache
+! exec ./fuzz.test$GOEXE -test.fuzzcachedir=$GOCACHE/fuzz -test.fuzz=FuzzMinimizerCrashInMinimization -test.fuzztime=10000x -test.parallel=1
+! stdout '^ok'
+stdout 'got the minimum size!'
+stdout 'flaky failure'
+stdout FAIL
+
+# Make sure the crash that was written will fail when run with go test
+! go test -run=FuzzMinimizerCrashInMinimization .
 
 -- go.mod --
 module fuzz
 
 go 1.17
+-- y.go --
+package fuzz
+
+import (
+       "bytes"
+       "io"
+)
+
+func Y(w io.Writer, b []byte) {
+       if !bytes.Equal(b, []byte("y")) {
+               w.Write([]byte("not equal"))
+       }
+}
 -- fuzz_test.go --
 package fuzz
 
 import (
        "bytes"
+       "io"
        "testing"
 )
 
-func FuzzMin(f *testing.F) {
+func FuzzMinimizerCrashInMinimization(f *testing.F) {
+       seed := make([]byte, 1000)
+       f.Add(seed)
+       f.Fuzz(func(t *testing.T, b []byte) {
+               if len(b) < 50 || len(b) > 1100 {
+                       // Make sure that b is large enough that it can be minimized
+                       return
+               }
+               if !bytes.Equal(b, seed) {
+                       // This should have hit a new edge, and the interesting input
+                       // should be attempting minimization
+                       Y(io.Discard, b)
+               }
+               if len(b) < 350 {
+                       t.Error("flaky failure")
+               }
+               if len(b) == 50 {
+                       t.Log("got the minimum size!")
+               }
+       })
+}
+
+func FuzzMinCache(f *testing.F) {
        seed := bytes.Repeat([]byte("a"), 20)
        f.Add(seed)
        f.Fuzz(func(t *testing.T, buf []byte) {