Refactors host function tests to stub with wasm (#710)

This refactors host functions with no-op or constant returns to be
implemented with wasm instead of the host function bridge. This allows
better performance.

This also breaks up and makes WASI tests consistent, in a way that shows
parameter name drifts easier.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2022-07-21 15:49:55 +08:00
committed by GitHub
parent 303b14e67c
commit b98a11e9c3
36 changed files with 3342 additions and 3839 deletions

View File

@@ -87,7 +87,7 @@ func TestGetFunctionType(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
rVal := reflect.ValueOf(tc.inputFunc)
fk, ft, err := getFunctionType(&rVal, Features20191205|FeatureMultiValue)
fk, ft, err := getFunctionType(&rVal)
require.NoError(t, err)
require.Equal(t, tc.expectedKind, fk)
require.Equal(t, tc.expectedType, ft)
@@ -122,11 +122,6 @@ func TestGetFunctionTypeErrors(t *testing.T) {
input: func() error { return nil },
expectedErr: "result[0] is an error, which is unsupported",
},
{
name: "multiple results - multi-value not enabled",
input: func() (uint64, uint32) { return 0, 0 },
expectedErr: "multiple result types invalid as feature \"multi-value\" is disabled",
},
{
name: "multiple context types",
input: func(api.Module, context.Context) error { return nil },
@@ -149,7 +144,7 @@ func TestGetFunctionTypeErrors(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
rVal := reflect.ValueOf(tc.input)
_, _, err := getFunctionType(&rVal, Features20191205)
_, _, err := getFunctionType(&rVal)
require.EqualError(t, err, tc.expectedErr)
})
}
@@ -254,7 +249,7 @@ func TestPopGoFuncParams(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
goFunc := reflect.ValueOf(tc.inputFunc)
fk, _, err := getFunctionType(&goFunc, Features20220419)
fk, _, err := getFunctionType(&goFunc)
require.NoError(t, err)
vals := PopGoFuncParams(&FunctionInstance{Kind: fk, GoFunc: &goFunc}, (&stack{stackVals}).pop)
@@ -407,7 +402,7 @@ func TestCallGoFunc(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
goFunc := reflect.ValueOf(tc.inputFunc)
fk, _, err := getFunctionType(&goFunc, Features20220419)
fk, _, err := getFunctionType(&goFunc)
require.NoError(t, err)
results := CallGoFunc(testCtx, callCtx, &FunctionInstance{Kind: fk, GoFunc: &goFunc}, tc.inputParams)