...
1[!fuzz] skip
2[short] skip
3env 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
9env GOCACHE=$WORK/cache
10env GODEBUG=fuzzdebug=1
11
12mkdir -p $GOCACHE/fuzz/fuzztest/FuzzTarget
13go run ./populate $GOCACHE/fuzz/fuzztest/FuzzTarget
14
15go test -fuzz=FuzzTarget -fuzztime=10x .
16stdout 'entries: 5'
17
18-- go.mod --
19module fuzztest
20
21go 1.17
22
23-- fuzz_test.go --
24package fuzz
25
26import "testing"
27
28func FuzzTarget(f *testing.F) {
29 f.Add(int(0))
30 f.Fuzz(func(t *testing.T, _ int) {})
31}
32
33-- populate/main.go --
34package main
35
36import (
37 "path/filepath"
38 "fmt"
39 "os"
40)
41
42func 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