File size: 1,977 Bytes
e36aeda | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | [!fuzz-instrumented] skip
[short] skip
env GOCACHE=$WORK/cache
# Fuzz cache should not exist after a regular test run.
go test .
exists $GOCACHE
! exists $GOCACHE/fuzz
# Fuzzing should write interesting values to the cache.
go test -fuzz=FuzzY -fuzztime=100x .
go run ./contains_files $GOCACHE/fuzz/example.com/y/FuzzY
# 'go clean -cache' should not delete the fuzz cache.
go clean -cache
exists $GOCACHE/fuzz
# 'go clean -fuzzcache' should delete the fuzz cache but not the build cache.
go build -x ./empty
stderr '(compile|gccgo)( |\.exe).*empty.go'
go clean -fuzzcache
! exists $GOCACHE/fuzz
go build -x ./empty
! stderr '(compile|gccgo)( |\.exe).*empty.go'
# Fuzzing indicates that one new interesting value was found with an empty
# corpus, and the total size of the cache is now 1.
go clean -fuzzcache
go test -fuzz=FuzzEmpty -fuzztime=10000x .
stdout 'new interesting: 1'
stdout 'total: 1'
# Fuzzing again with a small fuzztime does not find any other interesting
# values but still indicates that the cache size is 1.
go test -fuzz=FuzzEmpty -fuzztime=2x .
stdout 'new interesting: 0'
stdout 'total: 1'
! go clean -fuzzcache example.com/y
stderr 'go: clean -fuzzcache cannot be used with package arguments'
-- go.mod --
module example.com/y
go 1.16
-- y_test.go --
package y
import (
"io"
"testing"
)
func FuzzEmpty(f *testing.F) {
f.Fuzz(func (*testing.T, []byte) {})
}
func FuzzY(f *testing.F) {
f.Add([]byte("y"))
f.Fuzz(func(t *testing.T, b []byte) { Y(io.Discard, b) })
}
-- 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"))
}
}
-- empty/empty.go --
package empty
-- contains_files/contains_files.go --
package main
import (
"fmt"
"path/filepath"
"io/ioutil"
"os"
)
func main() {
infos, err := ioutil.ReadDir(filepath.Clean(os.Args[1]))
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if len(infos) == 0 {
os.Exit(1)
}
}
|