-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuzz_test.go
59 lines (48 loc) · 817 Bytes
/
fuzz_test.go
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
// +build gofuzz
package plua
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
func TestFuzz(t *testing.T) {
processFile := func(path string) (err error) {
f, err := os.Open(path)
if err != nil {
t.Fatal(err)
}
defer f.Close()
data, err := ioutil.ReadAll(f)
if err != nil {
t.Fatal(err)
}
defer func() {
if r := recover(); r != nil {
if rerr, ok := r.(error); ok {
err = rerr
} else {
err = fmt.Errorf("%v", r)
}
}
}()
Fuzz(data)
return nil
}
dir := filepath.Join("_fuzz", "corpus")
d, err := os.Open(dir)
if err != nil {
t.Fatal(err)
}
names, err := d.Readdirnames(-1)
if err != nil {
t.Fatal(err)
}
for _, name := range names {
err := processFile(filepath.Join(dir, name))
if err != nil {
t.Error(err)
}
}
}