Skip to content

Commit 272fbc7

Browse files
authored
tests: Tweak fuzz tests (#719)
1 parent b2d7bff commit 272fbc7

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

flate/fuzz_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ func FuzzEncoding(f *testing.F) {
2222
startFuzz = HuffmanOnly
2323
endFuzz = BestCompression
2424

25-
// Also tests with dictionaries...
26-
testDicts = true
27-
2825
// Max input size:
2926
maxSize = 1 << 20
3027
)
3128
decoder := NewReader(nil)
3229
buf := new(bytes.Buffer)
30+
encs := make([]*Writer, endFuzz-startFuzz+1)
31+
for i := range encs {
32+
var err error
33+
encs[i], err = NewWriter(nil, i+startFuzz)
34+
if err != nil {
35+
f.Fatal(err.Error())
36+
}
37+
}
3338

3439
f.Fuzz(func(t *testing.T, data []byte) {
3540
if len(data) > maxSize {
@@ -38,10 +43,8 @@ func FuzzEncoding(f *testing.F) {
3843
for level := startFuzz; level <= endFuzz; level++ {
3944
msg := "level " + strconv.Itoa(level) + ":"
4045
buf.Reset()
41-
fw, err := NewWriter(buf, level)
42-
if err != nil {
43-
t.Fatal(msg + err.Error())
44-
}
46+
fw := encs[level-startFuzz]
47+
fw.Reset(buf)
4548
n, err := fw.Write(data)
4649
if n != len(data) {
4750
t.Fatal(msg + "short write")

flate/testdata/fuzz/FuzzEncoding.zip

159 KB
Binary file not shown.

zstd/fuzz_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ func FuzzEncoding(f *testing.F) {
146146

147147
initEnc := func() func() {
148148
var err error
149-
dec, err = NewReader(nil, WithDecoderConcurrency(2), WithDecoderDicts(dicts...), WithDecoderMaxWindow(128<<10), WithDecoderMaxMemory(maxSize))
149+
dec, err = NewReader(nil, WithDecoderConcurrency(2), WithDecoderDicts(dicts...), WithDecoderMaxWindow(64<<10), WithDecoderMaxMemory(maxSize))
150150
if err != nil {
151151
panic(err)
152152
}
153153
for level := startFuzz; level <= endFuzz; level++ {
154-
encs[level], err = NewWriter(nil, WithEncoderCRC(true), WithEncoderLevel(level), WithEncoderConcurrency(2), WithWindowSize(128<<10), WithZeroFrames(true), WithLowerEncoderMem(true))
154+
encs[level], err = NewWriter(nil, WithEncoderCRC(true), WithEncoderLevel(level), WithEncoderConcurrency(2), WithWindowSize(64<<10), WithZeroFrames(true), WithLowerEncoderMem(true))
155155
if testDicts {
156-
encsD[level], err = NewWriter(nil, WithEncoderCRC(true), WithEncoderLevel(level), WithEncoderConcurrency(2), WithWindowSize(128<<10), WithZeroFrames(true), WithEncoderDict(dicts[0]), WithLowerEncoderMem(true), WithLowerEncoderMem(true))
156+
encsD[level], err = NewWriter(nil, WithEncoderCRC(true), WithEncoderLevel(level), WithEncoderConcurrency(2), WithWindowSize(64<<10), WithZeroFrames(true), WithEncoderDict(dicts[level]), WithLowerEncoderMem(true), WithLowerEncoderMem(true))
157157
}
158158
}
159159
return func() {

0 commit comments

Comments
 (0)