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