-
Notifications
You must be signed in to change notification settings - Fork 297
/
fuzz_test.go
44 lines (40 loc) · 901 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
package fse
import (
"bytes"
"fmt"
"testing"
"github.com/klauspost/compress/internal/fuzz"
)
func FuzzCompress(f *testing.F) {
fuzz.AddFromZip(f, "testdata/fse_compress.zip", fuzz.TypeRaw, false)
f.Fuzz(func(t *testing.T, buf0 []byte) {
var s, s2 Scratch
b, err := Compress(buf0, &s)
if err != nil || b == nil {
return
}
err = s.validateNorm()
if err != nil {
return
}
//Decompress
got, err := Decompress(b, &s2)
if err != nil || len(got) == 0 {
return
}
if !bytes.Equal(buf0, got) {
t.Fatal(fmt.Sprintln("FuzzCompress output mismatch\n", len(got), "org: \n", len(buf0)))
}
})
}
func FuzzDecompress(f *testing.F) {
fuzz.AddFromZip(f, "testdata/fse_decompress.zip", fuzz.TypeRaw, false)
f.Fuzz(func(t *testing.T, buf0 []byte) {
var s2 Scratch
//Decompress
got, err := Decompress(buf0, &s2)
if err != nil || len(got) == 0 {
return
}
})
}