...
1
2
3
4
5
6 package fuzztest
7
8 import (
9 "flag"
10 "io/ioutil"
11 "os"
12 "path/filepath"
13 "sort"
14 "testing"
15 )
16
17 var corpus = flag.String("corpus", "corpus", "directory containing the fuzzer corpus")
18
19
20 func Test(t *testing.T, fuzz func(b []byte) int) {
21 dir, err := os.Open(*corpus)
22 if err != nil {
23 t.Fatal(err)
24 }
25 infos, err := dir.Readdir(0)
26 if err != nil {
27 t.Fatal(err)
28
29 }
30 var names []string
31 for _, info := range infos {
32 names = append(names, info.Name())
33 }
34 sort.Strings(names)
35 for _, name := range names {
36 t.Run(name, func(t *testing.T) {
37 b, err := ioutil.ReadFile(filepath.Join(*corpus, name))
38 if err != nil {
39 t.Fatal(err)
40 }
41 b = b[:len(b):len(b)]
42 fuzz(b)
43 })
44 }
45 }
46
View as plain text