MCPcopy
hub / github.com/dgraph-io/dgraph / FuzzTestParser

Function FuzzTestParser

dql/parser_fuzz_test.go:21–73  ·  view source on GitHub ↗
(f *testing.F)

Source from the content-addressed store, hash-verified

19)
20
21func FuzzTestParser(f *testing.F) {
22 // add the corpus data to the test
23 fd, err := os.Open(corpusTarFile)
24 if err != nil {
25 f.Fatalf("error opening corpus tar file: %v", err)
26 }
27 defer func() {
28 if err := fd.Close(); err != nil {
29 f.Logf("error closing corpus tar file: %v", err)
30 }
31 }()
32
33 gzr, err := gzip.NewReader(fd)
34 if err != nil {
35 f.Fatalf("error reading corpus tar file: %v", err)
36 }
37 defer func() {
38 if err := gzr.Close(); err != nil {
39 f.Logf("error closing corpus tar file: %v", err)
40 }
41 }()
42 tr := tar.NewReader(gzr)
43
44 for {
45 header, err := tr.Next()
46 if err == io.EOF {
47 break
48 }
49 if err != nil {
50 f.Fatalf("error while reading corpus tar file: %v", err)
51 }
52
53 switch header.Typeflag {
54 case tar.TypeReg:
55 buf := new(bytes.Buffer)
56 if _, err := io.Copy(buf, tr); err != nil {
57 f.Fatalf("error while copying file [%v]: %v", header.Name, err)
58 }
59 f.Add(buf.Bytes())
60 f.Logf("adding input: %v", buf.String())
61 }
62 }
63
64 f.Fuzz(func(t *testing.T, in []byte) {
65 defer func() {
66 if err := recover(); err != nil {
67 t.Errorf("DQL parsing failed for input [%x] with error: [%v]", in, err)
68 }
69 }()
70
71 _, _ = Parse(Request{Str: string(in)})
72 })
73}

Callers

nothing calls this directly

Calls 8

FatalfMethod · 0.80
ParseFunction · 0.70
OpenMethod · 0.65
CloseMethod · 0.65
NextMethod · 0.45
AddMethod · 0.45
StringMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected