MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime-go / TestFuncArgs

Function TestFuncArgs

func_test.go:69–88  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

67}
68
69func TestFuncArgs(t *testing.T) {
70 store := NewStore(NewEngine())
71 cb := func(caller *Caller, args []Val) ([]Val, *Trap) {
72 require.Len(t, args, 2, "wrong argument size")
73 require.Equal(t, int32(1), args[0].I32(), "bad first argument")
74 require.Equal(t, int64(2), args[1].I64(), "bad second argument")
75 return []Val{ValF32(3), ValF64(4)}, nil
76 }
77 i32 := NewValType(KindI32)
78 i64 := NewValType(KindI64)
79 f32 := NewValType(KindF32)
80 f64 := NewValType(KindF64)
81 f := NewFunc(store, NewFuncType([]*ValType{i32, i64}, []*ValType{f32, f64}), cb)
82 results, trap := f.Call(store, int32(1), int64(2))
83 require.Nil(t, trap)
84 list := results.([]Val)
85 require.Len(t, list, 2, "bad results")
86 require.Equal(t, float32(3), list[0].F32(), "bad result[0]")
87 require.Equal(t, float64(4), list[1].F64(), "bad result[1]")
88}
89
90func TestFuncOneRet(t *testing.T) {
91 store := NewStore(NewEngine())

Callers

nothing calls this directly

Calls 12

CallMethod · 0.95
NewStoreFunction · 0.85
NewEngineFunction · 0.85
ValF32Function · 0.85
ValF64Function · 0.85
NewValTypeFunction · 0.85
NewFuncFunction · 0.85
NewFuncTypeFunction · 0.85
I32Method · 0.80
I64Method · 0.80
F32Method · 0.80
F64Method · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…