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

     1  [!fuzz] skip
     2  [short] skip
     3  
     4  # This test checks that cached corpus loading properly handles duplicate entries (this can
     5  # happen when a f.Add value has a duplicate entry in the cached corpus.) Duplicate entries
     6  # should be discarded, and the rest of the cache should be loaded as normal.
     7  
     8  env GOCACHE=$WORK/cache
     9  env GODEBUG=fuzzdebug=1
    10  
    11  mkdir -p $GOCACHE/fuzz/fuzztest/FuzzTarget
    12  go run ./populate $GOCACHE/fuzz/fuzztest/FuzzTarget
    13  
    14  go test -fuzz=FuzzTarget -fuzztime=10x .
    15  stdout 'entries: 5'
    16  
    17  -- go.mod --
    18  module fuzztest
    19  
    20  go 1.17
    21  
    22  -- fuzz_test.go --
    23  package fuzz
    24  
    25  import "testing"
    26  
    27  func FuzzTarget(f *testing.F) {
    28      f.Add(int(0))
    29      f.Fuzz(func(t *testing.T, _ int) {})
    30  }
    31  
    32  -- populate/main.go --
    33  package main
    34  
    35  import (
    36      "path/filepath"
    37  	"fmt"
    38  	"os"
    39  )
    40  
    41  func main() {
    42  	for i := 0; i < 10; i++ {
    43  		b := byte(0)
    44  		if i > 5 {
    45  			b = byte(i)
    46  		}
    47          tmpl := "go test fuzz v1\nint(%d)\n"
    48  		if err := os.WriteFile(filepath.Join(os.Args[1], fmt.Sprint(i)), []byte(fmt.Sprintf(tmpl, b)), 0777); err != nil {
    49  			panic(err)
    50  		}
    51  	}
    52  }

View as plain text