Skip to content

Commit 69aa7ac

Browse files
hickfordgopherbot
authored andcommitted
sumdb/tlog: fuzz tests for parsers
Future fuzz tests could test round trip properties Change-Id: If195b82998ebedaeca68a7723c2558369e68f716 GitHub-Last-Rev: 6fff4e6 GitHub-Pull-Request: #18 Reviewed-on: https://go-review.googlesource.com/c/mod/+/470155 Run-TryBot: Matthew Hickford <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Matthew Hickford <[email protected]> Run-TryBot: Bryan Mills <[email protected]>
1 parent b710602 commit 69aa7ac

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

sumdb/tlog/note_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,19 @@ func TestParseRecord(t *testing.T) {
115115
}
116116
}
117117
}
118+
119+
// FuzzParseTree tests that ParseTree never crashes
120+
func FuzzParseTree(f *testing.F) {
121+
f.Add([]byte("go.sum database tree\n123456789012\nTszzRgjTG6xce+z2AG31kAXYKBgQVtCSCE40HmuwBb0=\n"))
122+
f.Fuzz(func(t *testing.T, text []byte) {
123+
ParseTree(text)
124+
})
125+
}
126+
127+
// FuzzParseRecord tests that ParseRecord never crashes
128+
func FuzzParseRecord(f *testing.F) {
129+
f.Add([]byte("12345\nhello\n\n"))
130+
f.Fuzz(func(t *testing.T, msg []byte) {
131+
ParseRecord(msg)
132+
})
133+
}

sumdb/tlog/tile_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2019 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package tlog
6+
7+
import (
8+
"testing"
9+
)
10+
11+
// FuzzParseTilePath tests that ParseTilePath never crashes
12+
func FuzzParseTilePath(f *testing.F) {
13+
f.Add("tile/4/0/001")
14+
f.Add("tile/4/0/001.p/5")
15+
f.Add("tile/3/5/x123/x456/078")
16+
f.Add("tile/3/5/x123/x456/078.p/2")
17+
f.Add("tile/1/0/x003/x057/500")
18+
f.Add("tile/3/5/123/456/078")
19+
f.Add("tile/3/-1/123/456/078")
20+
f.Add("tile/1/data/x003/x057/500")
21+
f.Fuzz(func(t *testing.T, path string) {
22+
ParseTilePath(path)
23+
})
24+
}

0 commit comments

Comments
 (0)