forked from bytecodealliance/wasmtime-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store_test.go
103 lines (85 loc) · 2.09 KB
/
store_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package wasmtime
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestStore(t *testing.T) {
engine := NewEngine()
defer engine.Close()
store := NewStore(engine)
defer store.Close()
}
func TestInterruptWasm(t *testing.T) {
config := NewConfig()
config.SetEpochInterruption(true)
store := NewStore(NewEngineWithConfig(config))
store.SetEpochDeadline(1)
wasm, err := Wat2Wasm(`
(import "" "" (func))
(func
call 0
(loop br 0))
(start 1)
`)
require.NoError(t, err)
module, err := NewModule(store.Engine, wasm)
require.NoError(t, err)
engine := store.Engine
f := WrapFunc(store, func() {
engine.IncrementEpoch()
})
instance, err := NewInstance(store, module, []AsExtern{f})
require.Nil(t, instance)
require.Error(t, err)
trap := err.(*Trap)
require.NotNil(t, trap)
}
func TestFuelConsumed(t *testing.T) {
engine := NewEngine()
store := NewStore(engine)
fuel, enable := store.GetFuel()
require.Error(t, enable)
require.Equal(t, fuel, uint64(0))
}
func TestAddFuel(t *testing.T) {
config := NewConfig()
config.SetConsumeFuel(true)
engine := NewEngineWithConfig(config)
store := NewStore(engine)
fuel, enable := store.GetFuel()
require.NoError(t, enable)
require.Equal(t, fuel, uint64(0))
const add_fuel = 3
err := store.SetFuel(add_fuel)
require.NoError(t, err)
}
func TestLimiterMemorySizeFail(t *testing.T) {
engine := NewEngine()
store := NewStore(engine)
store.Limiter(2*64*1024, -1, -1, -1, -1)
wasm, err := Wat2Wasm(`
(module
(memory 3)
)
`)
require.NoError(t, err)
module, err := NewModule(store.Engine, wasm)
require.NoError(t, err)
_, err = NewInstance(store, module, []AsExtern{})
require.Error(t, err, "memory minimum size of 3 pages exceeds memory limits")
}
func TestLimiterMemorySizeSuccess(t *testing.T) {
engine := NewEngine()
store := NewStore(engine)
store.Limiter(4*64*1024, -1, -1, -1, -1)
wasm, err := Wat2Wasm(`
(module
(memory 3)
)
`)
require.NoError(t, err)
module, err := NewModule(store.Engine, wasm)
require.NoError(t, err)
_, err = NewInstance(store, module, []AsExtern{})
require.NoError(t, err)
}