forked from tetratelabs/wazero
/
bench_hostcall.go
48 lines (39 loc) · 1.27 KB
/
bench_hostcall.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
package vs
import (
_ "embed"
"testing"
"github.com/AR1011/wazero/internal/testing/require"
)
var (
//go:embed testdata/hostcall.wasm
hostCallWasm []byte
hostCallConfig *RuntimeConfig
hostCallFunction = "call_host_func"
hostCallParam = uint64(12345)
)
func init() {
hostCallConfig = &RuntimeConfig{
ModuleName: "hostcall",
ModuleWasm: hostCallWasm,
FuncNames: []string{hostCallFunction},
EnvFReturnValue: 0xffff,
}
}
func RunTestHostCall(t *testing.T, runtime func() Runtime) {
testCall(t, runtime, hostCallConfig, testHostCall)
}
func testHostCall(t *testing.T, m Module, instantiation, iteration int) {
res, err := m.CallI64_I64(testCtx, hostCallFunction, hostCallParam)
require.NoError(t, err, "instantiation[%d] iteration[%d] failed", instantiation, iteration)
require.Equal(t, hostCallConfig.EnvFReturnValue, res)
}
func RunTestBenchmarkHostCall_CompilerFastest(t *testing.T, vsRuntime Runtime) {
runTestBenchmark_Call_CompilerFastest(t, hostCallConfig, "HostCall_CrossBoundary", hostCall, vsRuntime)
}
func RunBenchmarkHostCall(b *testing.B, runtime func() Runtime) {
benchmark(b, runtime, hostCallConfig, hostCall)
}
func hostCall(m Module, _ int) error {
_, err := m.CallI64_I64(testCtx, hostCallFunction, hostCallParam)
return err
}