...

Text file src/cmd/go/testdata/script/test_fuzz_limit_dup_entry.txt

Documentation: cmd/go/testdata/script

     1[!fuzz] skip
     2[short] skip
     3env GOCACHE=$WORK/cache
     4
     5# FuzzA attempts to cause the mutator to create duplicate inputs that generate
     6# new coverage. Previously this would trigger a corner case when the fuzzer
     7# had an execution limit, causing it to deadlock and sit in the coordinator
     8# loop indefinitely, failing to exit once the limit had been exhausted.
     9
    10go test -fuzz=FuzzA -fuzztime=100x -parallel=1
    11
    12-- go.mod --
    13module m
    14
    15go 1.16
    16-- fuzz_test.go --
    17package fuzz_test
    18
    19import (
    20	"fmt"
    21	"testing"
    22)
    23
    24func FuzzA(f *testing.F) {
    25	f.Add([]byte("seed"))
    26	i := 0
    27	f.Fuzz(func(t *testing.T, b []byte) {
    28		i++
    29		if string(b) == "seed" {
    30			if i == 0 {
    31				fmt.Println("a")
    32			} else if i > 1 {
    33				fmt.Println("b")
    34			}
    35		}
    36	})
    37}

View as plain text