-
Notifications
You must be signed in to change notification settings - Fork 16
/
fuzz_test.go
55 lines (47 loc) · 1.14 KB
/
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
// Copyright (c) 2021 Timo Savola. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package wag
import (
"bytes"
"os"
"path/filepath"
"testing"
"gate.computer/wag/buffer"
werrors "gate.computer/wag/errors"
)
func FuzzCompile(f *testing.F) {
filenames, err := filepath.Glob("testsuite/testdata/specdata/*.wasm")
if err != nil {
f.Fatal(err)
}
for _, filename := range filenames {
wasm, err := os.ReadFile(filename)
if err != nil {
f.Fatal(err)
}
f.Add(wasm, "", uint8(255), uint8(255))
}
f.Fuzz(func(t *testing.T, wasm []byte, entry string, text, data uint8) {
config := &Config{
Text: buffer.NewLimited(nil, (int(text)+1)*4096),
GlobalsMemory: buffer.NewLimited(nil, (int(data)+1)*4096),
MemoryAlignment: 4096,
Entry: entry,
}
if data == 0 { // Only one page.
config.MemoryAlignment = 0
}
_, err := Compile(config, bytes.NewReader(wasm), testlib)
if err == nil {
return
}
if werrors.AsModuleError(err) != nil {
return
}
if werrors.AsResourceLimit(err) != nil {
return
}
t.Error(err)
})
}