diff --git a/README.md b/README.md index d33b658..6be214a 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,10 @@ $ go install golang.org/dl/gotip@latest $ gotip download ``` -Download, compile, and install the fzgen binary from source: +Download and install the fzgen binary from source, as well as add its fuzzer to our go.mod: ``` $ go install github.com/thepudds/fzgen/cmd/fzgen@latest +$ go get github.com/thepudds/fzgen/fuzzer ``` Use fzgen to automatically create a set of fuzz targets -- in this case for the encoding/ascii85 package from the Go standard library: @@ -56,10 +57,10 @@ That's enough for you to get started on your own, but let's also briefly look at ## Example: Easily Finding a Data Race -Again starting from an empty directory, we'll set up a module, and this time also add fzgen to the go.mod: +Again starting from an empty directory, we'll set up a module, and add the fzgen fuzzer to go.mod: ``` $ go mod init temp -$ go get go get github.com/thepudds/fzgen +$ go get github.com/thepudds/fzgen/fuzzer ``` Next, we automatically create a new fuzz target. This time: diff --git a/examples/inputs/race-xsync-mpmcqueue/go.mod b/examples/inputs/race-xsync-mpmcqueue/go.mod deleted file mode 100644 index 8dfaf48..0000000 --- a/examples/inputs/race-xsync-mpmcqueue/go.mod +++ /dev/null @@ -1,15 +0,0 @@ -module github.com/thepudds/fzgen/examples/inputs/race-xsyncmap - -go 1.17 - -require ( - github.com/puzpuzpuz/xsync v1.0.1-0.20210823092703-32778049b5f5 - github.com/thepudds/fzgen v0.0.0-00010101000000-000000000000 -) - -require ( - github.com/google/gofuzz v1.2.0 // indirect - github.com/sanity-io/litter v1.5.1 // indirect -) - -replace github.com/thepudds/fzgen => ./../../.. diff --git a/examples/inputs/race-xsync-mpmcqueue/go.sum b/examples/inputs/race-xsync-mpmcqueue/go.sum deleted file mode 100644 index d30d801..0000000 --- a/examples/inputs/race-xsync-mpmcqueue/go.sum +++ /dev/null @@ -1,49 +0,0 @@ -github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= -github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= -github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0 h1:GD+A8+e+wFkqje55/2fOVnZPkoDIu1VooBWfNrnY8Uo= -github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/puzpuzpuz/xsync v0.0.0-20210815074145-06f072a152a8 h1:bAvbvlslJkn5r/JnGkDOoZ5/N1I6zBiDBcCpsZ8an/Q= -github.com/puzpuzpuz/xsync v0.0.0-20210815074145-06f072a152a8/go.mod h1:GF6mnc4fZ1Vit0eWBHPcthv2l1nE81+iZvLsexB/HM4= -github.com/puzpuzpuz/xsync v1.0.1-0.20210823092703-32778049b5f5 h1:ZoUoiy+1+jwi9B2+5F0Mh4HMlI/q01Nqt+qN9T2h5lA= -github.com/puzpuzpuz/xsync v1.0.1-0.20210823092703-32778049b5f5/go.mod h1:GF6mnc4fZ1Vit0eWBHPcthv2l1nE81+iZvLsexB/HM4= -github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= -github.com/sanity-io/litter v1.5.1 h1:dwnrSypP6q56o3lFxTU+t2fwQ9A+U5qrXVO4Qg9KwVU= -github.com/sanity-io/litter v1.5.1/go.mod h1:5Z71SvaYy5kcGtyglXOC9rrUi3c1E8CamFWjQsazTh0= -github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312 h1:UsFdQ3ZmlzS0BqZYGxvYaXvFGUbCmPGy8DM7qWJJiIQ= -github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/thepudds/fzgo v0.2.3-0.20211028225222-cdf4f1cc8ee2/go.mod h1:ZgigL1toyKrar3rWdXz7Fuv7bUpKZ4BAYN49TpEFMCI= -github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/examples/inputs/race-xsync-mpmcqueue/xsyncqueue.go b/examples/inputs/race-xsync-mpmcqueue/xsyncqueue.go deleted file mode 100644 index 68d5532..0000000 --- a/examples/inputs/race-xsync-mpmcqueue/xsyncqueue.go +++ /dev/null @@ -1,33 +0,0 @@ -// xsyncqueue is a thin wrapper over github.com/puzpuzpuz/xsync.MPMCQueue. - -package xsyncqueue - -import "github.com/puzpuzpuz/xsync" - -type XSyncMPMCQueue struct { - xsyncq *xsync.MPMCQueue -} - -func NewMPMCQueue(capacity int) *XSyncMPMCQueue { - return &XSyncMPMCQueue{xsync.NewMPMCQueue(capacity)} -} - -func (q *XSyncMPMCQueue) Dequeue() int8 { - return q.xsyncq.Dequeue().(int8) -} - -func (q *XSyncMPMCQueue) Enqueue(item int8) { - q.xsyncq.Enqueue(item) -} - -func (q *XSyncMPMCQueue) TryDequeue() (item int8, ok bool) { - v, ok := q.xsyncq.TryDequeue() - if !ok { - return 0, false - } - return v.(int8), true -} - -func (q *XSyncMPMCQueue) TryEnqueue(item int8) bool { - return q.xsyncq.TryEnqueue(item) -} diff --git a/examples/inputs/race/race.go b/examples/inputs/race/race.go index 3c23a68..093d127 100644 --- a/examples/inputs/race/race.go +++ b/examples/inputs/race/race.go @@ -7,7 +7,7 @@ // 3. The two Loads must happen concurrently. // 4. Prior to the two Loads, no other Store can update the key to have a non-matching payload. // -// Using the fzgen/fuzzer.Chain created by default via 'fzgen -chain -parallel -pkg=github.com/thepudds/fzgen/examples/inputs/race', +// Using the fzgen/fuzzer.Chain created by default via 'fzgen -chain -parallel github.com/thepudds/fzgen/examples/inputs/race', // this data race is typically caught after a few minutes of fuzzing with '-race' when starting from scratch. package raceexample @@ -32,7 +32,7 @@ func (m *MySafeMap) Load(key [16]byte) *Request { if ok { req := r.(*Request) if req.Answer == 42 { - // DATA RACE (but requires: matching store/load keys, and concurrent matching load keys, and certain payload data) + // DATA RACE (but detection requires: matching store/load keys, and concurrent matching load keys, and certain payload data) req.deepQuestion++ } return req diff --git a/examples/outputs/go-fuzz-perf/cmd-go/fuzz_test.go b/examples/outputs/go-fuzz-perf/cmd-go/fuzz_test.go deleted file mode 100644 index 58f3c17..0000000 --- a/examples/outputs/go-fuzz-perf/cmd-go/fuzz_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package fuzzperf - -import ( - "encoding/binary" - "testing" -) - -func findInt(i int) { - if 1337 == i { - panic("Found int") - } -} - -// FuzzIntegerLittleEndian shows how sonar can discover integers to use as inputs to increase coverage -func FuzzIntegerLittleEndian(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - // interpret data as little-endian encoded - if len(data) < 8 { - return - } - findInt(int(binary.LittleEndian.Uint64(data))) - }) - -} diff --git a/examples/outputs/go-fuzz-perf/go-fuzz/fuzz.go b/examples/outputs/go-fuzz-perf/go-fuzz/fuzz.go deleted file mode 100644 index fe9464a..0000000 --- a/examples/outputs/go-fuzz-perf/go-fuzz/fuzz.go +++ /dev/null @@ -1,52 +0,0 @@ -package fuzzperf - -import ( - "encoding/binary" - "strconv" -) - -func findInt(i int) { - if 1337 == i { - panic("Found int") - } -} - -// FuzzIntegerBigEndian shows how sonar can discover integers to use as inputs to increase coverage -func FuzzIntegerBigEndian(data []byte) int { - // interpret data as big-endian encoded - if len(data) < 8 { - return 0 - } - findInt(int(binary.BigEndian.Uint64(data))) - return 1 -} - -// FuzzIntegerLittleEndian shows how sonar can discover integers to use as inputs to increase coverage -func FuzzIntegerLittleEndian(data []byte) int { - // interpret data as little-endian encoded - if len(data) < 8 { - return 0 - } - findInt(int(binary.LittleEndian.Uint64(data))) - return 1 -} - -// FuzzIntegerDecimalString interprets input as a decimal string -func FuzzIntegerDecimalString(data []byte) int { - i, err := strconv.Atoi(string(data)) - if err != nil { - return 0 - } - findInt(i) - return 1 -} - -// FuzzIntegerHexString interprets input as a hexadecimal string -func FuzzIntegerHexString(data []byte) int { - i, err := strconv.ParseInt(string(data), 16, 64) - if err != nil { - return 0 - } - findInt(int(i)) - return 1 -} \ No newline at end of file diff --git a/examples/outputs/goroar/autofuzzchain_test.go b/examples/outputs/goroar/autofuzzchain_test.go deleted file mode 100644 index 42b492c..0000000 --- a/examples/outputs/goroar/autofuzzchain_test.go +++ /dev/null @@ -1,101 +0,0 @@ -package goroarfuzz // rename if needed - -// if needed, fill in imports or run 'goimports' -import ( - "testing" - - "github.com/fzandona/goroar" - "github.com/thepudds/fzgen/fuzzer" -) - -func Fuzz_New_Chain(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - fz := fuzzer.NewFuzzer(data) - - target := goroar.New() - other := goroar.New() - - steps := []fuzzer.Step{ - fuzzer.Step{ - Name: "Fuzz_RoaringBitmap_Add", - Func: func(x uint32) { - target.Add(x) - }}, - fuzzer.Step{ - Name: "Fuzz_RoaringBitmap_Add_Other", - Func: func(x uint32) { - other.Add(x) - }}, - fuzzer.Step{ - Name: "Fuzz_RoaringBitmap_And", - Func: func() { - target.And(other) - }}, - fuzzer.Step{ - Name: "Fuzz_RoaringBitmap_AndNot", - Func: func() { - target.AndNot(other) - }}, - fuzzer.Step{ - Name: "Fuzz_RoaringBitmap_Cardinality", - Func: func() int { - return target.Cardinality() - }}, - fuzzer.Step{ - Name: "Fuzz_RoaringBitmap_Cardinality_Other", - Func: func() int { - return other.Cardinality() - }}, - fuzzer.Step{ - Name: "Fuzz_RoaringBitmap_Clone", - Func: func() *goroar.RoaringBitmap { - return target.Clone() - }}, - fuzzer.Step{ - Name: "Fuzz_RoaringBitmap_Clone_Other", - Func: func() *goroar.RoaringBitmap { - return other.Clone() - }}, - fuzzer.Step{ - Name: "Fuzz_RoaringBitmap_Contains", - Func: func(i uint32) bool { - return target.Contains(i) - }}, -/* - fuzzer.Step{ - Name: "Fuzz_RoaringBitmap_Iterator", - Func: func() <-chan uint32 { - return target.Iterator() - }}, -*/ - fuzzer.Step{ - Name: "Fuzz_RoaringBitmap_Or", - Func: func() { - target.Or(other) - }}, - fuzzer.Step{ - Name: "Fuzz_RoaringBitmap_SizeInBytes", - Func: func() int { - return target.SizeInBytes() - }}, - fuzzer.Step{ - Name: "Fuzz_RoaringBitmap_Stats", - Func: func() { - target.Stats() - }}, - fuzzer.Step{ - Name: "Fuzz_RoaringBitmap_String", - Func: func() string { - return target.String() - }}, - fuzzer.Step{ - Name: "Fuzz_RoaringBitmap_Xor", - Func: func() { - target.Xor(other) - }}, - } - - // Execute a specific chain of steps, with the count, sequence and arguments controlled by fz.Chain - fz.Chain(steps) - }) -} diff --git a/examples/outputs/lz4/autofuzz_test.go b/examples/outputs/lz4/autofuzz_test.go deleted file mode 100644 index 3ac8a0d..0000000 --- a/examples/outputs/lz4/autofuzz_test.go +++ /dev/null @@ -1,282 +0,0 @@ -package lz4fuzz // rename if needed - -// if needed, fill in imports or run 'goimports' -import ( - "io" - "testing" - - "github.com/pierrec/lz4/v4" - "github.com/thepudds/fzgen/fuzzer" -) - -func Fuzz_Compressor_CompressBlock(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var c *lz4.Compressor - var src []byte - var dst []byte - fz := fuzzer.NewFuzzer(data) - fz.Fill(&c, &src, &dst) - if c == nil { - return - } - - c.CompressBlock(src, dst) - }) -} - -func Fuzz_CompressorHC_CompressBlock(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var c *lz4.CompressorHC - var src []byte - var dst []byte - fz := fuzzer.NewFuzzer(data) - fz.Fill(&c, &src, &dst) - if c == nil { - return - } - - c.CompressBlock(src, dst) - }) -} - -// skipping Fuzz_Reader_Apply because parameters include unsupported func or chan: []github.com/pierrec/lz4/v4.Option - -func Fuzz_Reader_Read(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var r io.Reader - var buf []byte - fz := fuzzer.NewFuzzer(data) - fz.Fill(&r, &buf) - - r1 := lz4.NewReader(r) - r1.Read(buf) - }) -} - -func Fuzz_Reader_Reset(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var r io.Reader - var reader io.Reader - fz := fuzzer.NewFuzzer(data) - fz.Fill(&r, &reader) - - r1 := lz4.NewReader(r) - r1.Reset(reader) - }) -} - -func Fuzz_Reader_Size(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var r io.Reader - fz := fuzzer.NewFuzzer(data) - fz.Fill(&r) - - r1 := lz4.NewReader(r) - r1.Size() - }) -} - -func Fuzz_Reader_WriteTo(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var r io.Reader - var w io.Writer - fz := fuzzer.NewFuzzer(data) - fz.Fill(&r, &w) - - r1 := lz4.NewReader(r) - r1.WriteTo(w) - }) -} - -// skipping Fuzz_Writer_Apply because parameters include unsupported func or chan: []github.com/pierrec/lz4/v4.Option - -func Fuzz_Writer_Close(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var w io.Writer - fz := fuzzer.NewFuzzer(data) - fz.Fill(&w) - - w1 := lz4.NewWriter(w) - w1.Close() - }) -} - -func Fuzz_Writer_ReadFrom(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var w io.Writer - var r io.Reader - fz := fuzzer.NewFuzzer(data) - fz.Fill(&w, &r) - - w1 := lz4.NewWriter(w) - w1.ReadFrom(r) - }) -} - -func Fuzz_Writer_Reset(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var w io.Writer - var writer io.Writer - fz := fuzzer.NewFuzzer(data) - fz.Fill(&w, &writer) - - w1 := lz4.NewWriter(w) - w1.Reset(writer) - }) -} - -func Fuzz_Writer_Write(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var w io.Writer - var buf []byte - fz := fuzzer.NewFuzzer(data) - fz.Fill(&w, &buf) - - w1 := lz4.NewWriter(w) - w1.Write(buf) - }) -} - -func Fuzz_BlockSize_String(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var i lz4.BlockSize - fz := fuzzer.NewFuzzer(data) - fz.Fill(&i) - - i.String() - }) -} - -func Fuzz_CompressionLevel_String(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var i lz4.CompressionLevel - fz := fuzzer.NewFuzzer(data) - fz.Fill(&i) - - i.String() - }) -} - -// skipping Fuzz_Option_String because parameters include unsupported func or chan: github.com/pierrec/lz4/v4.Option - -func Fuzz_BlockChecksumOption(f *testing.F) { - f.Fuzz(func(t *testing.T, flag bool) { - lz4.BlockChecksumOption(flag) - }) -} - -func Fuzz_BlockSizeOption(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var size lz4.BlockSize - fz := fuzzer.NewFuzzer(data) - fz.Fill(&size) - - lz4.BlockSizeOption(size) - }) -} - -func Fuzz_ChecksumOption(f *testing.F) { - f.Fuzz(func(t *testing.T, flag bool) { - lz4.ChecksumOption(flag) - }) -} - -func Fuzz_CompressBlock(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var src []byte - var dst []byte - var _x3 []int - fz := fuzzer.NewFuzzer(data) - fz.Fill(&src, &dst, &_x3) - - lz4.CompressBlock(src, dst, _x3) - }) -} - -func Fuzz_CompressBlockBound(f *testing.F) { - f.Fuzz(func(t *testing.T, n int) { - lz4.CompressBlockBound(n) - }) -} - -func Fuzz_CompressBlockHC(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var src []byte - var dst []byte - var depth lz4.CompressionLevel - var _x4 []int - var _x5 []int - fz := fuzzer.NewFuzzer(data) - fz.Fill(&src, &dst, &depth, &_x4, &_x5) - - lz4.CompressBlockHC(src, dst, depth, _x4, _x5) - }) -} - -func Fuzz_CompressionLevelOption(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var level lz4.CompressionLevel - fz := fuzzer.NewFuzzer(data) - fz.Fill(&level) - - lz4.CompressionLevelOption(level) - }) -} - -func Fuzz_ConcurrencyOption(f *testing.F) { - f.Fuzz(func(t *testing.T, n int) { - lz4.ConcurrencyOption(n) - }) -} - -func Fuzz_LegacyOption(f *testing.F) { - f.Fuzz(func(t *testing.T, legacy bool) { - lz4.LegacyOption(legacy) - }) -} - -func Fuzz_NewReader(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var r io.Reader - fz := fuzzer.NewFuzzer(data) - fz.Fill(&r) - - lz4.NewReader(r) - }) -} - -func Fuzz_NewWriter(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var w io.Writer - fz := fuzzer.NewFuzzer(data) - fz.Fill(&w) - - lz4.NewWriter(w) - }) -} - -// skipping Fuzz_OnBlockDoneOption because parameters include unsupported func or chan: func(size int) - -func Fuzz_SizeOption(f *testing.F) { - f.Fuzz(func(t *testing.T, size uint64) { - lz4.SizeOption(size) - }) -} - -func Fuzz_UncompressBlock(f *testing.F) { - f.Fuzz(func(t *testing.T, src []byte, dst []byte) { - lz4.UncompressBlock(src, dst) - }) -} - -func Fuzz_UncompressBlockWithDict(f *testing.F) { - f.Fuzz(func(t *testing.T, src []byte, dst []byte, dict []byte) { - lz4.UncompressBlockWithDict(src, dst, dict) - }) -} - -func Fuzz_ValidFrameHeader(f *testing.F) { - f.Fuzz(func(t *testing.T, in []byte) { - lz4.ValidFrameHeader(in) - }) -} diff --git a/examples/outputs/netlink/autofuzzchain_test.go b/examples/outputs/netlink/autofuzzchain_test.go deleted file mode 100644 index 2084f61..0000000 --- a/examples/outputs/netlink/autofuzzchain_test.go +++ /dev/null @@ -1,112 +0,0 @@ -package netlinkfuzz // rename if needed - -// if needed, fill in imports or run 'goimports' -import ( - "testing" - - "github.com/mdlayher/netlink" - "github.com/thepudds/fzgen/fuzzer" -) - -func Fuzz_NewAttributeDecoder_Chain(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var b []byte - fz := fuzzer.NewFuzzer(data) - fz.Fill(&b) - - target, err := netlink.NewAttributeDecoder(b) - if err != nil { - return - } - - steps := []fuzzer.Step{ - fuzzer.Step{ - Name: "Fuzz_AttributeDecoder_Bytes", - Func: func() []byte { - return target.Bytes() - }}, - // skipping Fuzz_AttributeDecoder_Do because parameters include unsupported func or chan: func(b []byte) error - - fuzzer.Step{ - Name: "Fuzz_AttributeDecoder_Err", - Func: func() { - target.Err() - }}, - fuzzer.Step{ - Name: "Fuzz_AttributeDecoder_Flag", - Func: func() bool { - return target.Flag() - }}, - fuzzer.Step{ - Name: "Fuzz_AttributeDecoder_Int16", - Func: func() int16 { - return target.Int16() - }}, - fuzzer.Step{ - Name: "Fuzz_AttributeDecoder_Int32", - Func: func() int32 { - return target.Int32() - }}, - fuzzer.Step{ - Name: "Fuzz_AttributeDecoder_Int64", - Func: func() int64 { - return target.Int64() - }}, - fuzzer.Step{ - Name: "Fuzz_AttributeDecoder_Int8", - Func: func() int8 { - return target.Int8() - }}, - fuzzer.Step{ - Name: "Fuzz_AttributeDecoder_Len", - Func: func() int { - return target.Len() - }}, - // skipping Fuzz_AttributeDecoder_Nested because parameters include unsupported func or chan: func(nad *github.com/mdlayher/netlink.AttributeDecoder) error - - fuzzer.Step{ - Name: "Fuzz_AttributeDecoder_Next", - Func: func() bool { - return target.Next() - }}, - fuzzer.Step{ - Name: "Fuzz_AttributeDecoder_String", - Func: func() string { - return target.String() - }}, - fuzzer.Step{ - Name: "Fuzz_AttributeDecoder_Type", - Func: func() uint16 { - return target.Type() - }}, - fuzzer.Step{ - Name: "Fuzz_AttributeDecoder_TypeFlags", - Func: func() uint16 { - return target.TypeFlags() - }}, - fuzzer.Step{ - Name: "Fuzz_AttributeDecoder_Uint16", - Func: func() uint16 { - return target.Uint16() - }}, - fuzzer.Step{ - Name: "Fuzz_AttributeDecoder_Uint32", - Func: func() uint32 { - return target.Uint32() - }}, - fuzzer.Step{ - Name: "Fuzz_AttributeDecoder_Uint64", - Func: func() uint64 { - return target.Uint64() - }}, - fuzzer.Step{ - Name: "Fuzz_AttributeDecoder_Uint8", - Func: func() uint8 { - return target.Uint8() - }}, - } - - // Execute a specific chain of steps, with the count, sequence and arguments controlled by fz.Chain - fz.Chain(steps) - }) -} diff --git a/examples/outputs/race-xsync-mpmcqueue-repro/repro_test.go b/examples/outputs/race-xsync-mpmcqueue-repro/repro_test.go deleted file mode 100644 index 7a61ec3..0000000 --- a/examples/outputs/race-xsync-mpmcqueue-repro/repro_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package xsyncmapfuzz - -// repro extracted from: -// fzgen -chain -parallel -pkg=github.com/thepudds/fzgen/examples/inputs/race-xsyncmap - -import ( - "testing" - - xsyncqueue "github.com/thepudds/fzgen/examples/inputs/race-xsync-mpmcqueue" -) - -func TestRepro_NewMPMCQueue_Chain(t *testing.T) { - - target := xsyncqueue.NewMPMCQueue(1) - - Fuzz_XSyncMPMCQueue_TryEnqueue := func(item int8) bool { - return target.TryEnqueue(item) - } - Fuzz_XSyncMPMCQueue_Enqueue_Dequeue := func(item int8) int8 { - target.Enqueue(item) - return target.Dequeue() - } - - Fuzz_XSyncMPMCQueue_TryEnqueue(0) - Fuzz_XSyncMPMCQueue_Enqueue_Dequeue(0) -} diff --git a/examples/outputs/race-xsync-mpmcqueue/autofuzzchain_test.go b/examples/outputs/race-xsync-mpmcqueue/autofuzzchain_test.go deleted file mode 100644 index 4c70c50..0000000 --- a/examples/outputs/race-xsync-mpmcqueue/autofuzzchain_test.go +++ /dev/null @@ -1,90 +0,0 @@ -package xsyncqueuefuzz - -// generated by: -// fzgen -chain -parallel -pkg github.com/thepudds/fzgen/examples/inputs/race-xsync-mpmcqueue -// and then modified as follows: -// 1. restricted the capacity to be in the interval [1,4096]. -// 2. enforce a large enough capacity prior to any Enqueue. -// 2. placed an Enqueue prior to every Dequeue and TryDequeue, to avoid possibly blocking on Dequeue. -import ( - "testing" - - xsyncqueue "github.com/thepudds/fzgen/examples/inputs/race-xsync-mpmcqueue" - "github.com/thepudds/fzgen/fuzzer" -) - -func Fuzz_NewMPMCQueue_Chain(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var capacity int - fz := fuzzer.NewFuzzer(data) - fz.Fill(&capacity) - - if capacity < 0 { - capacity = -capacity - } - if capacity%2 == 0 { - capacity = 1 - } else { - capacity = 1 + capacity%4096 - } - - target := xsyncqueue.NewMPMCQueue(capacity) - - var allowDequeue, allowEnqueue bool - if capacity > 256*10 { - // We should have enough capacity to avoid blocking on an Enqueue. - // This check relies on current knowledge of fzgen.Fuzzer implementation. - // Worst case is a loop of 256 with 10 steps being executed in parallel that - // are all Enqueue or TryEnqueue without any Dequeue or TryDequeue, - // which would place 256*10 elements into the queue. - allowEnqueue = true - } - - fz.Fill(&allowDequeue) - if !allowEnqueue { - // For Dequeue, we only allow it if we always proceed every Dequeue and TryDequeue - // with an Enqueue so that it is not possible to have more Dequeues than elements inserted so far, - // so if Enqueue is disallowed, we disallow Dequeue. - allowDequeue = false - } - - steps := []fuzzer.Step{ - fuzzer.Step{ - Name: "Fuzz_XSyncMPMCQueue_Enqueue", - Func: func(item int8) { - if allowEnqueue { - target.Enqueue(item) - } - }}, - fuzzer.Step{ - Name: "Fuzz_XSyncMPMCQueue_Enqueue_Dequeue", - Func: func(item int8) int8 { - if allowEnqueue && allowDequeue { - // We should have enough capacity to avoid blocking. See comment above. - target.Enqueue(item) - return target.Dequeue() - } - return 0 - }}, - fuzzer.Step{ - Name: "Fuzz_XSyncMPMCQueue_TryDequeue", - Func: func() (int8, bool) { - if allowDequeue { - // To avoid a later Dequeue from possibly blocking, TryDequeue here - // must have a paired Enqueue to ensure there is always at least 1 elem - // for a subsequent Dequeue. - target.Enqueue(0) - } - return target.TryDequeue() - }}, - fuzzer.Step{ - Name: "Fuzz_XSyncMPMCQueue_TryEnqueue", - Func: func(item int8) bool { - return target.TryEnqueue(item) - }}, - } - - // Execute a specific chain of steps, with the count, sequence and arguments controlled by fz.Chain - fz.Chain(steps, fuzzer.ChainOptParallel) - }) -} diff --git a/examples/outputs/race/autofuzzchain_test.go b/examples/outputs/race/autofuzzchain_test.go index 0971d94..16bce6e 100644 --- a/examples/outputs/race/autofuzzchain_test.go +++ b/examples/outputs/race/autofuzzchain_test.go @@ -1,6 +1,6 @@ package raceexamplefuzz -// generated by: +// Automatically generated by: // fzgen -chain -parallel github.com/thepudds/fzgen/examples/inputs/race import ( @@ -26,15 +26,12 @@ func Fuzz_NewMySafeMap_Chain(f *testing.F) { { Name: "Fuzz_MySafeMap_Store", Func: func(key [16]byte, req *raceexample.Request) { - if req == nil { - return - } target.Store(key, req) }, }, } // Execute a specific chain of steps, with the count, sequence and arguments controlled by fz.Chain - fz.Chain(steps, fuzzer.ChainOptParallel) + fz.Chain(steps, fuzzer.ChainParallel) }) } diff --git a/examples/outputs/randpanic/autofuzz_test.go b/examples/outputs/randpanic/autofuzz_test.go deleted file mode 100644 index 872f346..0000000 --- a/examples/outputs/randpanic/autofuzz_test.go +++ /dev/null @@ -1,36 +0,0 @@ -package myrand - -// if needed, fill in imports or run 'goimports' -import ( - "testing" -) - -func Fuzz_PanicOn10(f *testing.F) { - f.Fuzz(func(t *testing.T, a int) { - PanicOn10(a) - }) -} - -func Fuzz_PanicOn10000(f *testing.F) { - f.Fuzz(func(t *testing.T, a int) { - PanicOn10000(a) - }) -} - -func Fuzz_PanicRandomly1000(f *testing.F) { - f.Fuzz(func(t *testing.T, a int) { - PanicRandomly1000(a) - }) -} - -func Fuzz_PanicRandomly10000(f *testing.F) { - f.Fuzz(func(t *testing.T, a int) { - PanicRandomly10000(a) - }) -} - -func Fuzz_PanicRandomly100000(f *testing.F) { - f.Fuzz(func(t *testing.T, a int) { - PanicRandomly100000(a) - }) -} diff --git a/examples/outputs/randpanic/rand.go b/examples/outputs/randpanic/rand.go deleted file mode 100644 index 0cc15e8..0000000 --- a/examples/outputs/randpanic/rand.go +++ /dev/null @@ -1,34 +0,0 @@ -package myrand - -import "math/rand" - -func PanicRandomly1000(a int) { - if rand.Int31n(1000) == 0 { - panic("1 in a 1000") - } -} - -func PanicRandomly10000(a int) { - if rand.Int31n(10000) == 0 { - panic("1 in a 10000") - } -} - -func PanicRandomly100000(a int) { - if rand.Int31n(100000) == 0 { - panic("1 in a 100000") - } -} - -func PanicOn10(a int) { - if a == 10 { - panic("sent 10") - } -} - -func PanicOn10000(a int) { - if a == 10000 { - panic("sent 10000") - } -} - diff --git a/examples/outputs/stdlib-net-url/autofuzzchain_test.go b/examples/outputs/stdlib-net-url/autofuzzchain_test.go deleted file mode 100644 index 42086a8..0000000 --- a/examples/outputs/stdlib-net-url/autofuzzchain_test.go +++ /dev/null @@ -1,96 +0,0 @@ -package urlfuzz // rename if needed - -// if needed, fill in imports or run 'goimports' -import ( - "net/url" - "testing" - - "github.com/thepudds/fzgen/fuzzer" -) - -func Fuzz_ParseRequestURI_Chain(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var rawURL string - fz := fuzzer.NewFuzzer(data) - fz.Fill(&rawURL) - - target, err := url.ParseRequestURI(rawURL) - if err != nil { - return - } - - steps := []fuzzer.Step{ - fuzzer.Step{ - Name: "Fuzz_URL_EscapedFragment", - Func: func() string { - return target.EscapedFragment() - }}, - fuzzer.Step{ - Name: "Fuzz_URL_EscapedPath", - Func: func() string { - return target.EscapedPath() - }}, - fuzzer.Step{ - Name: "Fuzz_URL_Hostname", - Func: func() string { - return target.Hostname() - }}, - fuzzer.Step{ - Name: "Fuzz_URL_IsAbs", - Func: func() bool { - return target.IsAbs() - }}, - fuzzer.Step{ - Name: "Fuzz_URL_MarshalBinary", - Func: func() ([]byte, error) { - return target.MarshalBinary() - }}, - fuzzer.Step{ - Name: "Fuzz_URL_Parse", - Func: func(ref string) (*url.URL, error) { - return target.Parse(ref) - }}, - fuzzer.Step{ - Name: "Fuzz_URL_Port", - Func: func() string { - return target.Port() - }}, - fuzzer.Step{ - Name: "Fuzz_URL_Query", - Func: func() url.Values { - return target.Query() - }}, - fuzzer.Step{ - Name: "Fuzz_URL_Redacted", - Func: func() string { - return target.Redacted() - }}, - fuzzer.Step{ - Name: "Fuzz_URL_RequestURI", - Func: func() string { - return target.RequestURI() - }}, - fuzzer.Step{ - Name: "Fuzz_URL_ResolveReference", - Func: func(ref *url.URL) *url.URL { - if ref == nil { - return nil - } - return target.ResolveReference(ref) - }}, - fuzzer.Step{ - Name: "Fuzz_URL_String", - Func: func() string { - return target.String() - }}, - fuzzer.Step{ - Name: "Fuzz_URL_UnmarshalBinary", - Func: func(text []byte) { - target.UnmarshalBinary(text) - }}, - } - - // Execute a specific chain of steps, with the count, sequence and arguments controlled by fz.Chain - fz.Chain(steps) - }) -} diff --git a/examples/outputs/stdlib-netip/autofuzz_test.go b/examples/outputs/stdlib-netip/autofuzz_test.go deleted file mode 100644 index e2b8230..0000000 --- a/examples/outputs/stdlib-netip/autofuzz_test.go +++ /dev/null @@ -1,656 +0,0 @@ -package netipfuzz // rename if needed - -// if needed, fill in imports or run 'goimports' -import ( - "testing" - - "github.com/thepudds/fzgen/fuzzer" - "golang.zx2c4.com/go118/netip" -) - -func Fuzz_Addr_UnmarshalBinary(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip *netip.Addr - var b []byte - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip, &b) - if ip == nil { - return - } - - ip.UnmarshalBinary(b) - }) -} - -func Fuzz_Addr_UnmarshalText(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip *netip.Addr - var text []byte - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip, &text) - if ip == nil { - return - } - - ip.UnmarshalText(text) - }) -} - -func Fuzz_AddrPort_UnmarshalBinary(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p *netip.AddrPort - var b []byte - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p, &b) - if p == nil { - return - } - - p.UnmarshalBinary(b) - }) -} - -func Fuzz_AddrPort_UnmarshalText(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p *netip.AddrPort - var text []byte - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p, &text) - if p == nil { - return - } - - p.UnmarshalText(text) - }) -} - -func Fuzz_Prefix_UnmarshalBinary(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p *netip.Prefix - var b []byte - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p, &b) - if p == nil { - return - } - - p.UnmarshalBinary(b) - }) -} - -func Fuzz_Prefix_UnmarshalText(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p *netip.Prefix - var text []byte - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p, &text) - if p == nil { - return - } - - p.UnmarshalText(text) - }) -} - -func Fuzz_Addr_AppendTo(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - var b []byte - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip, &b) - - ip.AppendTo(b) - }) -} - -func Fuzz_Addr_As16(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.As16() - }) -} - -func Fuzz_Addr_As4(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.As4() - }) -} - -func Fuzz_Addr_AsSlice(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.AsSlice() - }) -} - -func Fuzz_Addr_BitLen(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.BitLen() - }) -} - -func Fuzz_Addr_Compare(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - var ip2 netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip, &ip2) - - ip.Compare(ip2) - }) -} - -func Fuzz_Addr_Is4(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.Is4() - }) -} - -func Fuzz_Addr_Is4In6(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.Is4In6() - }) -} - -func Fuzz_Addr_Is6(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.Is6() - }) -} - -func Fuzz_Addr_IsGlobalUnicast(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.IsGlobalUnicast() - }) -} - -func Fuzz_Addr_IsInterfaceLocalMulticast(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.IsInterfaceLocalMulticast() - }) -} - -func Fuzz_Addr_IsLinkLocalMulticast(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.IsLinkLocalMulticast() - }) -} - -func Fuzz_Addr_IsLinkLocalUnicast(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.IsLinkLocalUnicast() - }) -} - -func Fuzz_Addr_IsLoopback(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.IsLoopback() - }) -} - -func Fuzz_Addr_IsMulticast(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.IsMulticast() - }) -} - -func Fuzz_Addr_IsPrivate(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.IsPrivate() - }) -} - -func Fuzz_Addr_IsUnspecified(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.IsUnspecified() - }) -} - -func Fuzz_Addr_IsValid(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.IsValid() - }) -} - -func Fuzz_Addr_Less(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - var ip2 netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip, &ip2) - - ip.Less(ip2) - }) -} - -func Fuzz_Addr_MarshalBinary(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.MarshalBinary() - }) -} - -func Fuzz_Addr_MarshalText(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.MarshalText() - }) -} - -func Fuzz_Addr_Next(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.Next() - }) -} - -func Fuzz_Addr_Prefix(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - var b int - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip, &b) - - ip.Prefix(b) - }) -} - -func Fuzz_Addr_Prev(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.Prev() - }) -} - -func Fuzz_Addr_String(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.String() - }) -} - -func Fuzz_Addr_StringExpanded(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.StringExpanded() - }) -} - -func Fuzz_Addr_Unmap(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.Unmap() - }) -} - -func Fuzz_Addr_WithZone(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - var zone string - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip, &zone) - - ip.WithZone(zone) - }) -} - -func Fuzz_Addr_Zone(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip) - - ip.Zone() - }) -} - -func Fuzz_AddrPort_Addr(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.AddrPort - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p) - - p.Addr() - }) -} - -func Fuzz_AddrPort_AppendTo(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.AddrPort - var b []byte - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p, &b) - - p.AppendTo(b) - }) -} - -func Fuzz_AddrPort_IsValid(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.AddrPort - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p) - - p.IsValid() - }) -} - -func Fuzz_AddrPort_MarshalBinary(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.AddrPort - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p) - - p.MarshalBinary() - }) -} - -func Fuzz_AddrPort_MarshalText(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.AddrPort - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p) - - p.MarshalText() - }) -} - -func Fuzz_AddrPort_Port(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.AddrPort - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p) - - p.Port() - }) -} - -func Fuzz_AddrPort_String(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.AddrPort - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p) - - p.String() - }) -} - -func Fuzz_Prefix_Addr(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.Prefix - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p) - - p.Addr() - }) -} - -func Fuzz_Prefix_AppendTo(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.Prefix - var b []byte - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p, &b) - - p.AppendTo(b) - }) -} - -func Fuzz_Prefix_Bits(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.Prefix - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p) - - p.Bits() - }) -} - -func Fuzz_Prefix_Contains(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.Prefix - var ip netip.Addr - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p, &ip) - - p.Contains(ip) - }) -} - -func Fuzz_Prefix_IsSingleIP(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.Prefix - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p) - - p.IsSingleIP() - }) -} - -func Fuzz_Prefix_IsValid(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.Prefix - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p) - - p.IsValid() - }) -} - -func Fuzz_Prefix_MarshalBinary(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.Prefix - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p) - - p.MarshalBinary() - }) -} - -func Fuzz_Prefix_MarshalText(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.Prefix - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p) - - p.MarshalText() - }) -} - -func Fuzz_Prefix_Masked(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.Prefix - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p) - - p.Masked() - }) -} - -func Fuzz_Prefix_Overlaps(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.Prefix - var o netip.Prefix - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p, &o) - - p.Overlaps(o) - }) -} - -func Fuzz_Prefix_String(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var p netip.Prefix - fz := fuzzer.NewFuzzer(data) - fz.Fill(&p) - - p.String() - }) -} - -func Fuzz_AddrFrom16(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var addr [16]byte - fz := fuzzer.NewFuzzer(data) - fz.Fill(&addr) - - netip.AddrFrom16(addr) - }) -} - -func Fuzz_AddrFrom4(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var addr [4]byte - fz := fuzzer.NewFuzzer(data) - fz.Fill(&addr) - - netip.AddrFrom4(addr) - }) -} - -func Fuzz_AddrFromSlice(f *testing.F) { - f.Fuzz(func(t *testing.T, slice []byte) { - netip.AddrFromSlice(slice) - }) -} - -func Fuzz_AddrPortFrom(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - var port uint16 - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip, &port) - - netip.AddrPortFrom(ip, port) - }) -} - -func Fuzz_MustParseAddr(f *testing.F) { - f.Fuzz(func(t *testing.T, s string) { - netip.MustParseAddr(s) - }) -} - -func Fuzz_MustParseAddrPort(f *testing.F) { - f.Fuzz(func(t *testing.T, s string) { - netip.MustParseAddrPort(s) - }) -} - -func Fuzz_MustParsePrefix(f *testing.F) { - f.Fuzz(func(t *testing.T, s string) { - netip.MustParsePrefix(s) - }) -} - -func Fuzz_ParseAddr(f *testing.F) { - f.Fuzz(func(t *testing.T, s string) { - netip.ParseAddr(s) - }) -} - -func Fuzz_ParseAddrPort(f *testing.F) { - f.Fuzz(func(t *testing.T, s string) { - netip.ParseAddrPort(s) - }) -} - -func Fuzz_ParsePrefix(f *testing.F) { - f.Fuzz(func(t *testing.T, s string) { - netip.ParsePrefix(s) - }) -} - -func Fuzz_PrefixFrom(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var ip netip.Addr - var bits int - fz := fuzzer.NewFuzzer(data) - fz.Fill(&ip, &bits) - - netip.PrefixFrom(ip, bits) - }) -} diff --git a/examples/outputs/stdlib-strconv/autofuzz_test.go b/examples/outputs/stdlib-strconv/autofuzz_test.go deleted file mode 100644 index 2f6cb2f..0000000 --- a/examples/outputs/stdlib-strconv/autofuzz_test.go +++ /dev/null @@ -1,246 +0,0 @@ -package strconvfuzz // rename if needed - -// if needed, fill in imports or run 'goimports' -import ( - "strconv" - "testing" - - "github.com/thepudds/fzgen/fuzzer" -) - -func Fuzz_NumError_Error(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var e *strconv.NumError - fz := fuzzer.NewFuzzer(data) - fz.Fill(&e) - if e == nil { - return - } - - e.Error() - }) -} - -func Fuzz_NumError_Unwrap(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var e *strconv.NumError - fz := fuzzer.NewFuzzer(data) - fz.Fill(&e) - if e == nil { - return - } - - e.Unwrap() - }) -} - -func Fuzz_AppendBool(f *testing.F) { - f.Fuzz(func(t *testing.T, dst []byte, b bool) { - strconv.AppendBool(dst, b) - }) -} - -func Fuzz_AppendFloat(f *testing.F) { - f.Fuzz(func(t *testing.T, dst []byte, f2 float64, fmt byte, prec int, bitSize int) { - strconv.AppendFloat(dst, f2, fmt, prec, bitSize) - }) -} - -func Fuzz_AppendInt(f *testing.F) { - f.Fuzz(func(t *testing.T, dst []byte, i int64, base int) { - strconv.AppendInt(dst, i, base) - }) -} - -func Fuzz_AppendQuote(f *testing.F) { - f.Fuzz(func(t *testing.T, dst []byte, s string) { - strconv.AppendQuote(dst, s) - }) -} - -func Fuzz_AppendQuoteRune(f *testing.F) { - f.Fuzz(func(t *testing.T, dst []byte, r rune) { - strconv.AppendQuoteRune(dst, r) - }) -} - -func Fuzz_AppendQuoteRuneToASCII(f *testing.F) { - f.Fuzz(func(t *testing.T, dst []byte, r rune) { - strconv.AppendQuoteRuneToASCII(dst, r) - }) -} - -func Fuzz_AppendQuoteRuneToGraphic(f *testing.F) { - f.Fuzz(func(t *testing.T, dst []byte, r rune) { - strconv.AppendQuoteRuneToGraphic(dst, r) - }) -} - -func Fuzz_AppendQuoteToASCII(f *testing.F) { - f.Fuzz(func(t *testing.T, dst []byte, s string) { - strconv.AppendQuoteToASCII(dst, s) - }) -} - -func Fuzz_AppendQuoteToGraphic(f *testing.F) { - f.Fuzz(func(t *testing.T, dst []byte, s string) { - strconv.AppendQuoteToGraphic(dst, s) - }) -} - -func Fuzz_AppendUint(f *testing.F) { - f.Fuzz(func(t *testing.T, dst []byte, i uint64, base int) { - strconv.AppendUint(dst, i, base) - }) -} - -func Fuzz_Atoi(f *testing.F) { - f.Fuzz(func(t *testing.T, s string) { - strconv.Atoi(s) - }) -} - -func Fuzz_CanBackquote(f *testing.F) { - f.Fuzz(func(t *testing.T, s string) { - strconv.CanBackquote(s) - }) -} - -func Fuzz_FormatBool(f *testing.F) { - f.Fuzz(func(t *testing.T, b bool) { - strconv.FormatBool(b) - }) -} - -func Fuzz_FormatComplex(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { - var c complex128 - var fmt byte - var prec int - var bitSize int - fz := fuzzer.NewFuzzer(data) - fz.Fill(&c, &fmt, &prec, &bitSize) - - strconv.FormatComplex(c, fmt, prec, bitSize) - }) -} - -func Fuzz_FormatFloat(f *testing.F) { - f.Fuzz(func(t *testing.T, f1 float64, fmt byte, prec int, bitSize int) { - strconv.FormatFloat(f1, fmt, prec, bitSize) - }) -} - -func Fuzz_FormatInt(f *testing.F) { - f.Fuzz(func(t *testing.T, i int64, base int) { - strconv.FormatInt(i, base) - }) -} - -func Fuzz_FormatUint(f *testing.F) { - f.Fuzz(func(t *testing.T, i uint64, base int) { - strconv.FormatUint(i, base) - }) -} - -func Fuzz_IsGraphic(f *testing.F) { - f.Fuzz(func(t *testing.T, r rune) { - strconv.IsGraphic(r) - }) -} - -func Fuzz_IsPrint(f *testing.F) { - f.Fuzz(func(t *testing.T, r rune) { - strconv.IsPrint(r) - }) -} - -func Fuzz_Itoa(f *testing.F) { - f.Fuzz(func(t *testing.T, i int) { - strconv.Itoa(i) - }) -} - -func Fuzz_ParseBool(f *testing.F) { - f.Fuzz(func(t *testing.T, str string) { - strconv.ParseBool(str) - }) -} - -func Fuzz_ParseComplex(f *testing.F) { - f.Fuzz(func(t *testing.T, s string, bitSize int) { - strconv.ParseComplex(s, bitSize) - }) -} - -func Fuzz_ParseFloat(f *testing.F) { - f.Fuzz(func(t *testing.T, s string, bitSize int) { - strconv.ParseFloat(s, bitSize) - }) -} - -func Fuzz_ParseInt(f *testing.F) { - f.Fuzz(func(t *testing.T, s string, base int, bitSize int) { - strconv.ParseInt(s, base, bitSize) - }) -} - -func Fuzz_ParseUint(f *testing.F) { - f.Fuzz(func(t *testing.T, s string, base int, bitSize int) { - strconv.ParseUint(s, base, bitSize) - }) -} - -func Fuzz_Quote(f *testing.F) { - f.Fuzz(func(t *testing.T, s string) { - strconv.Quote(s) - }) -} - -func Fuzz_QuoteRune(f *testing.F) { - f.Fuzz(func(t *testing.T, r rune) { - strconv.QuoteRune(r) - }) -} - -func Fuzz_QuoteRuneToASCII(f *testing.F) { - f.Fuzz(func(t *testing.T, r rune) { - strconv.QuoteRuneToASCII(r) - }) -} - -func Fuzz_QuoteRuneToGraphic(f *testing.F) { - f.Fuzz(func(t *testing.T, r rune) { - strconv.QuoteRuneToGraphic(r) - }) -} - -func Fuzz_QuoteToASCII(f *testing.F) { - f.Fuzz(func(t *testing.T, s string) { - strconv.QuoteToASCII(s) - }) -} - -func Fuzz_QuoteToGraphic(f *testing.F) { - f.Fuzz(func(t *testing.T, s string) { - strconv.QuoteToGraphic(s) - }) -} - -func Fuzz_QuotedPrefix(f *testing.F) { - f.Fuzz(func(t *testing.T, s string) { - strconv.QuotedPrefix(s) - }) -} - -func Fuzz_Unquote(f *testing.F) { - f.Fuzz(func(t *testing.T, s string) { - strconv.Unquote(s) - }) -} - -func Fuzz_UnquoteChar(f *testing.F) { - f.Fuzz(func(t *testing.T, s string, quote byte) { - strconv.UnquoteChar(s, quote) - }) -} diff --git a/fuzzer/fuzzer.go b/fuzzer/fuzzer.go index 40f58a4..c71b33f 100644 --- a/fuzzer/fuzzer.go +++ b/fuzzer/fuzzer.go @@ -477,7 +477,39 @@ func (fz *Fuzzer) callStep(ec execCall) []reflect.Value { // This contains the input values we previously created. reflectArgs := []reflect.Value{} for i := range ec.args { - reflectArgs = append(reflectArgs, *ec.args[i].val) + v := *ec.args[i].val + + // For map, pointer, or slice, we disallow nil values to + // be passed in as args by creating a new object here if nil. Note that we are not setting up + // for example a map completely -- just making sure it is not nil. + // In older versions, this arg nil check was emitted code someone could choose to delete. + // We could return and skip this call (closer to older emitted logic), but + // if we do that, we need to handle the outputslot broadcast channels for this call in case someone + // is waiting or will be waiting on a return value from this call. + // TODO: this is likely useful for Ptr, but less sure how useful this is for the other types here. + // TODO: test this better. inputs/race/race.go tests this for Ptr, but this is slightly annoying to test + // because fz.Fill avoids this. This occurs for example when the plan decides to reuse a call return + // value and that function under test returns a nil. In that case, fz.Fill is not the one creating the value. + // TODO: if we keep this, consider showing equivalent logic in the emitted repro logic, or maybe only when it matters. + // TODO: consider skipping this instead, and emit the nil check logic in the repro. + // TODO: make this configurable, including because people no longer have option of deleting the emitted nil checks. + switch v.Kind() { + case reflect.Ptr: + if v.IsNil() { + v = reflect.New(v.Type().Elem()) + } + case reflect.Slice: + if v.IsNil() { + v = reflect.MakeSlice(v.Type(), 0, 0) + } + case reflect.Map: + if v.IsNil() { + v = reflect.MakeMapWithSize(v.Type(), 0) + } + case reflect.Interface: + // TODO: consider checking Interface too. Or better to keep passing the code under test a nil? + } + reflectArgs = append(reflectArgs, v) } // Call the user's func.