github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/integration_test/vs/bench_hostcall.go (about) 1 package vs 2 3 import ( 4 _ "embed" 5 "testing" 6 7 "github.com/bananabytelabs/wazero/internal/testing/require" 8 ) 9 10 var ( 11 //go:embed testdata/hostcall.wasm 12 hostCallWasm []byte 13 hostCallConfig *RuntimeConfig 14 hostCallFunction = "call_host_func" 15 hostCallParam = uint64(12345) 16 ) 17 18 func init() { 19 hostCallConfig = &RuntimeConfig{ 20 ModuleName: "hostcall", 21 ModuleWasm: hostCallWasm, 22 FuncNames: []string{hostCallFunction}, 23 EnvFReturnValue: 0xffff, 24 } 25 } 26 27 func RunTestHostCall(t *testing.T, runtime func() Runtime) { 28 testCall(t, runtime, hostCallConfig, testHostCall) 29 } 30 31 func testHostCall(t *testing.T, m Module, instantiation, iteration int) { 32 res, err := m.CallI64_I64(testCtx, hostCallFunction, hostCallParam) 33 require.NoError(t, err, "instantiation[%d] iteration[%d] failed", instantiation, iteration) 34 require.Equal(t, hostCallConfig.EnvFReturnValue, res) 35 } 36 37 func RunTestBenchmarkHostCall_CompilerFastest(t *testing.T, vsRuntime Runtime) { 38 runTestBenchmark_Call_CompilerFastest(t, hostCallConfig, "HostCall_CrossBoundary", hostCall, vsRuntime) 39 } 40 41 func RunBenchmarkHostCall(b *testing.B, runtime func() Runtime) { 42 benchmark(b, runtime, hostCallConfig, hostCall) 43 } 44 45 func hostCall(m Module, _ int) error { 46 _, err := m.CallI64_I64(testCtx, hostCallFunction, hostCallParam) 47 return err 48 }