...
1 package vs
2
3 import (
4 _ "embed"
5 "testing"
6
7 "github.com/tetratelabs/wazero/internal/testing/require"
8 )
9
10 var (
11
12
13 factorialWasm []byte
14 factorialParam = uint64(30)
15 factorialResult = uint64(9682165104862298112)
16 factorialConfig *RuntimeConfig
17 )
18
19 func init() {
20 factorialConfig = &RuntimeConfig{
21 ModuleName: "math",
22 ModuleWasm: factorialWasm,
23 FuncNames: []string{"fac-ssa"},
24 }
25 }
26
27 func factorialCall(m Module, _ int) error {
28 _, err := m.CallI64_I64(testCtx, "fac-ssa", factorialParam)
29 return err
30 }
31
32 func RunTestFactorial(t *testing.T, runtime func() Runtime) {
33 testCall(t, runtime, factorialConfig, testFactorialCall)
34 }
35
36 func testFactorialCall(t *testing.T, m Module, instantiation, iteration int) {
37 res, err := m.CallI64_I64(testCtx, "fac-ssa", factorialParam)
38 require.NoError(t, err, "instantiation[%d] iteration[%d] failed", instantiation, iteration)
39 require.Equal(t, factorialResult, res)
40 }
41
42 func RunTestBenchmarkFactorial_Call_CompilerFastest(t *testing.T, vsRuntime Runtime) {
43 runTestBenchmark_Call_CompilerFastest(t, factorialConfig, "Factorial", factorialCall, vsRuntime)
44 }
45
46 func RunBenchmarkFactorial(b *testing.B, runtime func() Runtime) {
47 benchmark(b, runtime, factorialConfig, factorialCall)
48 }
49
View as plain text