Hides internal logging (#956)
This makes it easier to do maintenance by hiding the implementation details of using a proxy module to test host modules. What happens is we skip logging of these proxy modules, which makes it easier to see what log affects a change has. Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
@@ -15,7 +15,6 @@ import (
|
||||
"github.com/tetratelabs/wazero"
|
||||
"github.com/tetratelabs/wazero/api"
|
||||
. "github.com/tetratelabs/wazero/experimental"
|
||||
"github.com/tetratelabs/wazero/experimental/logging"
|
||||
"github.com/tetratelabs/wazero/internal/testing/proxy"
|
||||
"github.com/tetratelabs/wazero/internal/testing/require"
|
||||
"github.com/tetratelabs/wazero/internal/u64"
|
||||
@@ -61,8 +60,7 @@ func TestAbort(t *testing.T) {
|
||||
require.True(t, ok, err)
|
||||
require.Equal(t, uint32(255), sysErr.ExitCode())
|
||||
require.Equal(t, `
|
||||
--> proxy.abort(message=4,fileName=22,lineNumber=1,columnNumber=2)
|
||||
==> env.~lib/builtins/abort(message=4,fileName=22,lineNumber=1,columnNumber=2)
|
||||
==> env.~lib/builtins/abort(message=4,fileName=22,lineNumber=1,columnNumber=2)
|
||||
`, "\n"+log.String())
|
||||
|
||||
require.Equal(t, tc.expected, stderr.String())
|
||||
@@ -86,8 +84,7 @@ func TestAbort_Error(t *testing.T) {
|
||||
messageUTF16: encodeUTF16("message")[:5],
|
||||
fileNameUTF16: encodeUTF16("filename"),
|
||||
expectedLog: `
|
||||
--> proxy.abort(message=4,fileName=13,lineNumber=1,columnNumber=2)
|
||||
==> env.~lib/builtins/abort(message=4,fileName=13,lineNumber=1,columnNumber=2)
|
||||
==> env.~lib/builtins/abort(message=4,fileName=13,lineNumber=1,columnNumber=2)
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -95,8 +92,7 @@ func TestAbort_Error(t *testing.T) {
|
||||
messageUTF16: encodeUTF16("message"),
|
||||
fileNameUTF16: encodeUTF16("filename")[:5],
|
||||
expectedLog: `
|
||||
--> proxy.abort(message=4,fileName=22,lineNumber=1,columnNumber=2)
|
||||
==> env.~lib/builtins/abort(message=4,fileName=22,lineNumber=1,columnNumber=2)
|
||||
==> env.~lib/builtins/abort(message=4,fileName=22,lineNumber=1,columnNumber=2)
|
||||
`,
|
||||
},
|
||||
}
|
||||
@@ -130,10 +126,8 @@ func TestSeed(t *testing.T) {
|
||||
ret, err := mod.ExportedFunction(functionSeed).Call(testCtx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, `
|
||||
--> proxy.seed()
|
||||
==> env.~lib/builtins/seed()
|
||||
<== rand=4.958153677776298e-175
|
||||
<-- 4.958153677776298e-175
|
||||
==> env.~lib/builtins/seed()
|
||||
<== rand=4.958153677776298e-175
|
||||
`, "\n"+log.String())
|
||||
|
||||
require.Equal(t, "538c7f96b164bf1b", hex.EncodeToString(u64.LeBytes(ret[0])))
|
||||
@@ -151,7 +145,7 @@ func TestSeed_error(t *testing.T) {
|
||||
expectedErr: `error reading random seed: unexpected EOF (recovered by wazero)
|
||||
wasm stack trace:
|
||||
env.~lib/builtins/seed() f64
|
||||
proxy.seed() f64`,
|
||||
internal/testing/proxy/proxy.go.seed() f64`,
|
||||
},
|
||||
{
|
||||
name: "error reading",
|
||||
@@ -159,7 +153,7 @@ wasm stack trace:
|
||||
expectedErr: `error reading random seed: ice cream (recovered by wazero)
|
||||
wasm stack trace:
|
||||
env.~lib/builtins/seed() f64
|
||||
proxy.seed() f64`,
|
||||
internal/testing/proxy/proxy.go.seed() f64`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -173,8 +167,7 @@ wasm stack trace:
|
||||
_, err := mod.ExportedFunction(functionSeed).Call(testCtx)
|
||||
require.EqualError(t, err, tc.expectedErr)
|
||||
require.Equal(t, `
|
||||
--> proxy.seed()
|
||||
==> env.~lib/builtins/seed()
|
||||
==> env.~lib/builtins/seed()
|
||||
`, "\n"+log.String())
|
||||
})
|
||||
}
|
||||
@@ -184,10 +177,8 @@ wasm stack trace:
|
||||
func TestFunctionExporter_Trace(t *testing.T) {
|
||||
noArgs := []uint64{4, 0, 0, 0, 0, 0, 0}
|
||||
noArgsLog := `
|
||||
--> proxy.trace(message=4,nArgs=0,arg0=0,arg1=0,arg2=0,arg3=0,arg4=0)
|
||||
==> env.~lib/builtins/trace(message=4,nArgs=0,arg0=0,arg1=0,arg2=0,arg3=0,arg4=0)
|
||||
<==
|
||||
<--
|
||||
==> env.~lib/builtins/trace(message=4,nArgs=0,arg0=0,arg1=0,arg2=0,arg3=0,arg4=0)
|
||||
<==
|
||||
`
|
||||
|
||||
tests := []struct {
|
||||
@@ -226,10 +217,8 @@ func TestFunctionExporter_Trace(t *testing.T) {
|
||||
params: []uint64{4, 1, api.EncodeF64(1), 0, 0, 0, 0},
|
||||
expected: "trace: hello 1\n",
|
||||
expectedLog: `
|
||||
--> proxy.trace(message=4,nArgs=1,arg0=1,arg1=0,arg2=0,arg3=0,arg4=0)
|
||||
==> env.~lib/builtins/trace(message=4,nArgs=1,arg0=1,arg1=0,arg2=0,arg3=0,arg4=0)
|
||||
<==
|
||||
<--
|
||||
==> env.~lib/builtins/trace(message=4,nArgs=1,arg0=1,arg1=0,arg2=0,arg3=0,arg4=0)
|
||||
<==
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -238,10 +227,8 @@ func TestFunctionExporter_Trace(t *testing.T) {
|
||||
params: []uint64{4, 2, api.EncodeF64(1), api.EncodeF64(2), 0, 0, 0},
|
||||
expected: "trace: hello 1,2\n",
|
||||
expectedLog: `
|
||||
--> proxy.trace(message=4,nArgs=2,arg0=1,arg1=2,arg2=0,arg3=0,arg4=0)
|
||||
==> env.~lib/builtins/trace(message=4,nArgs=2,arg0=1,arg1=2,arg2=0,arg3=0,arg4=0)
|
||||
<==
|
||||
<--
|
||||
==> env.~lib/builtins/trace(message=4,nArgs=2,arg0=1,arg1=2,arg2=0,arg3=0,arg4=0)
|
||||
<==
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -258,10 +245,8 @@ func TestFunctionExporter_Trace(t *testing.T) {
|
||||
},
|
||||
expected: "trace: hello 1,2,3.3,4.4,5\n",
|
||||
expectedLog: `
|
||||
--> proxy.trace(message=4,nArgs=5,arg0=1,arg1=2,arg2=3.3,arg3=4.4,arg4=5)
|
||||
==> env.~lib/builtins/trace(message=4,nArgs=5,arg0=1,arg1=2,arg2=3.3,arg3=4.4,arg4=5)
|
||||
<==
|
||||
<--
|
||||
==> env.~lib/builtins/trace(message=4,nArgs=5,arg0=1,arg1=2,arg2=3.3,arg3=4.4,arg4=5)
|
||||
<==
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -420,7 +405,7 @@ func requireProxyModule(t *testing.T, fns FunctionExporter, config wazero.Module
|
||||
var log bytes.Buffer
|
||||
|
||||
// Set context to one that has an experimental listener
|
||||
ctx := context.WithValue(testCtx, FunctionListenerFactoryKey{}, logging.NewLoggingListenerFactory(&log))
|
||||
ctx := context.WithValue(testCtx, FunctionListenerFactoryKey{}, proxy.NewLoggingListenerFactory(&log))
|
||||
|
||||
r := wazero.NewRuntime(ctx)
|
||||
|
||||
@@ -433,7 +418,7 @@ func requireProxyModule(t *testing.T, fns FunctionExporter, config wazero.Module
|
||||
_, err = r.InstantiateModule(ctx, envCompiled, config)
|
||||
require.NoError(t, err)
|
||||
|
||||
proxyBin := proxy.GetProxyModuleBinary("env", envCompiled)
|
||||
proxyBin := proxy.NewModuleBinary("env", envCompiled)
|
||||
|
||||
proxyCompiled, err := r.CompileModule(ctx, proxyBin)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -27,10 +27,8 @@ func Test_argsGet(t *testing.T) {
|
||||
// Invoke argsGet and check the memory side effects.
|
||||
requireErrno(t, ErrnoSuccess, mod, argsGetName, uint64(argv), uint64(argvBuf))
|
||||
require.Equal(t, `
|
||||
--> proxy.args_get(argv=22,argv_buf=16)
|
||||
==> wasi_snapshot_preview1.args_get(argv=22,argv_buf=16)
|
||||
<== ESUCCESS
|
||||
<-- 0
|
||||
==> wasi_snapshot_preview1.args_get(argv=22,argv_buf=16)
|
||||
<== ESUCCESS
|
||||
`, "\n"+log.String())
|
||||
|
||||
actual, ok := mod.Memory().Read(argvBuf-1, uint32(len(expectedMemory)))
|
||||
@@ -55,10 +53,8 @@ func Test_argsGet_Errors(t *testing.T) {
|
||||
argv: memorySize,
|
||||
argvBuf: validAddress,
|
||||
expectedLog: `
|
||||
--> proxy.args_get(argv=65536,argv_buf=0)
|
||||
==> wasi_snapshot_preview1.args_get(argv=65536,argv_buf=0)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.args_get(argv=65536,argv_buf=0)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -66,10 +62,8 @@ func Test_argsGet_Errors(t *testing.T) {
|
||||
argv: validAddress,
|
||||
argvBuf: memorySize,
|
||||
expectedLog: `
|
||||
--> proxy.args_get(argv=0,argv_buf=65536)
|
||||
==> wasi_snapshot_preview1.args_get(argv=0,argv_buf=65536)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.args_get(argv=0,argv_buf=65536)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -78,10 +72,8 @@ func Test_argsGet_Errors(t *testing.T) {
|
||||
argv: memorySize - 4*2 + 1,
|
||||
argvBuf: validAddress,
|
||||
expectedLog: `
|
||||
--> proxy.args_get(argv=65529,argv_buf=0)
|
||||
==> wasi_snapshot_preview1.args_get(argv=65529,argv_buf=0)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.args_get(argv=65529,argv_buf=0)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -90,10 +82,8 @@ func Test_argsGet_Errors(t *testing.T) {
|
||||
// "a", "bc" size = size of "a0bc0" = 5
|
||||
argvBuf: memorySize - 5 + 1,
|
||||
expectedLog: `
|
||||
--> proxy.args_get(argv=0,argv_buf=65532)
|
||||
==> wasi_snapshot_preview1.args_get(argv=0,argv_buf=65532)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.args_get(argv=0,argv_buf=65532)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
}
|
||||
@@ -129,10 +119,8 @@ func Test_argsSizesGet(t *testing.T) {
|
||||
// Invoke argsSizesGet and check the memory side effects.
|
||||
requireErrno(t, ErrnoSuccess, mod, argsSizesGetName, uint64(resultArgc), uint64(resultArgvLen))
|
||||
require.Equal(t, `
|
||||
--> proxy.args_sizes_get(result.argc=16,result.argv_len=21)
|
||||
==> wasi_snapshot_preview1.args_sizes_get(result.argc=16,result.argv_len=21)
|
||||
<== ESUCCESS
|
||||
<-- 0
|
||||
==> wasi_snapshot_preview1.args_sizes_get(result.argc=16,result.argv_len=21)
|
||||
<== ESUCCESS
|
||||
`, "\n"+log.String())
|
||||
|
||||
actual, ok := mod.Memory().Read(resultArgc-1, uint32(len(expectedMemory)))
|
||||
@@ -157,10 +145,8 @@ func Test_argsSizesGet_Errors(t *testing.T) {
|
||||
argc: memorySize,
|
||||
argvLen: validAddress,
|
||||
expectedLog: `
|
||||
--> proxy.args_sizes_get(result.argc=65536,result.argv_len=0)
|
||||
==> wasi_snapshot_preview1.args_sizes_get(result.argc=65536,result.argv_len=0)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.args_sizes_get(result.argc=65536,result.argv_len=0)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -168,10 +154,8 @@ func Test_argsSizesGet_Errors(t *testing.T) {
|
||||
argc: validAddress,
|
||||
argvLen: memorySize,
|
||||
expectedLog: `
|
||||
--> proxy.args_sizes_get(result.argc=0,result.argv_len=65536)
|
||||
==> wasi_snapshot_preview1.args_sizes_get(result.argc=0,result.argv_len=65536)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.args_sizes_get(result.argc=0,result.argv_len=65536)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -179,10 +163,8 @@ func Test_argsSizesGet_Errors(t *testing.T) {
|
||||
argc: memorySize - 4 + 1, // 4 is the size of uint32, the type of the count of args
|
||||
argvLen: validAddress,
|
||||
expectedLog: `
|
||||
--> proxy.args_sizes_get(result.argc=65533,result.argv_len=0)
|
||||
==> wasi_snapshot_preview1.args_sizes_get(result.argc=65533,result.argv_len=0)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.args_sizes_get(result.argc=65533,result.argv_len=0)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -190,10 +172,8 @@ func Test_argsSizesGet_Errors(t *testing.T) {
|
||||
argc: validAddress,
|
||||
argvLen: memorySize - 4 + 1, // 4 is count of bytes to encode uint32le
|
||||
expectedLog: `
|
||||
--> proxy.args_sizes_get(result.argc=0,result.argv_len=65533)
|
||||
==> wasi_snapshot_preview1.args_sizes_get(result.argc=0,result.argv_len=65533)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.args_sizes_get(result.argc=0,result.argv_len=65533)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -35,10 +35,8 @@ func Test_clockResGet(t *testing.T) {
|
||||
clockID: clockIDRealtime,
|
||||
expectedMemory: expectedMemoryMicro,
|
||||
expectedLog: `
|
||||
--> proxy.clock_res_get(id=0,result.resolution=16)
|
||||
==> wasi_snapshot_preview1.clock_res_get(id=0,result.resolution=16)
|
||||
<== ESUCCESS
|
||||
<-- 0
|
||||
==> wasi_snapshot_preview1.clock_res_get(id=0,result.resolution=16)
|
||||
<== ESUCCESS
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -46,10 +44,8 @@ func Test_clockResGet(t *testing.T) {
|
||||
clockID: clockIDMonotonic,
|
||||
expectedMemory: expectedMemoryNano,
|
||||
expectedLog: `
|
||||
--> proxy.clock_res_get(id=1,result.resolution=16)
|
||||
==> wasi_snapshot_preview1.clock_res_get(id=1,result.resolution=16)
|
||||
<== ESUCCESS
|
||||
<-- 0
|
||||
==> wasi_snapshot_preview1.clock_res_get(id=1,result.resolution=16)
|
||||
<== ESUCCESS
|
||||
`,
|
||||
},
|
||||
}
|
||||
@@ -88,10 +84,8 @@ func Test_clockResGet_Unsupported(t *testing.T) {
|
||||
clockID: 2,
|
||||
expectedErrno: ErrnoInval,
|
||||
expectedLog: `
|
||||
--> proxy.clock_res_get(id=2,result.resolution=16)
|
||||
==> wasi_snapshot_preview1.clock_res_get(id=2,result.resolution=16)
|
||||
<== EINVAL
|
||||
<-- 28
|
||||
==> wasi_snapshot_preview1.clock_res_get(id=2,result.resolution=16)
|
||||
<== EINVAL
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -99,10 +93,8 @@ func Test_clockResGet_Unsupported(t *testing.T) {
|
||||
clockID: 3,
|
||||
expectedErrno: ErrnoInval,
|
||||
expectedLog: `
|
||||
--> proxy.clock_res_get(id=3,result.resolution=16)
|
||||
==> wasi_snapshot_preview1.clock_res_get(id=3,result.resolution=16)
|
||||
<== EINVAL
|
||||
<-- 28
|
||||
==> wasi_snapshot_preview1.clock_res_get(id=3,result.resolution=16)
|
||||
<== EINVAL
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -110,10 +102,8 @@ func Test_clockResGet_Unsupported(t *testing.T) {
|
||||
clockID: 100,
|
||||
expectedErrno: ErrnoInval,
|
||||
expectedLog: `
|
||||
--> proxy.clock_res_get(id=100,result.resolution=16)
|
||||
==> wasi_snapshot_preview1.clock_res_get(id=100,result.resolution=16)
|
||||
<== EINVAL
|
||||
<-- 28
|
||||
==> wasi_snapshot_preview1.clock_res_get(id=100,result.resolution=16)
|
||||
<== EINVAL
|
||||
`,
|
||||
},
|
||||
}
|
||||
@@ -150,10 +140,8 @@ func Test_clockTimeGet(t *testing.T) {
|
||||
'?', // stopped after encoding
|
||||
},
|
||||
expectedLog: `
|
||||
--> proxy.clock_time_get(id=0,precision=0,result.timestamp=16)
|
||||
==> wasi_snapshot_preview1.clock_time_get(id=0,precision=0,result.timestamp=16)
|
||||
<== ESUCCESS
|
||||
<-- 0
|
||||
==> wasi_snapshot_preview1.clock_time_get(id=0,precision=0,result.timestamp=16)
|
||||
<== ESUCCESS
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -165,10 +153,8 @@ func Test_clockTimeGet(t *testing.T) {
|
||||
'?', // stopped after encoding
|
||||
},
|
||||
expectedLog: `
|
||||
--> proxy.clock_time_get(id=1,precision=0,result.timestamp=16)
|
||||
==> wasi_snapshot_preview1.clock_time_get(id=1,precision=0,result.timestamp=16)
|
||||
<== ESUCCESS
|
||||
<-- 0
|
||||
==> wasi_snapshot_preview1.clock_time_get(id=1,precision=0,result.timestamp=16)
|
||||
<== ESUCCESS
|
||||
`,
|
||||
},
|
||||
}
|
||||
@@ -206,10 +192,8 @@ func Test_clockTimeGet_Unsupported(t *testing.T) {
|
||||
clockID: 2,
|
||||
expectedErrno: ErrnoInval,
|
||||
expectedLog: `
|
||||
--> proxy.clock_time_get(id=2,precision=0,result.timestamp=16)
|
||||
==> wasi_snapshot_preview1.clock_time_get(id=2,precision=0,result.timestamp=16)
|
||||
<== EINVAL
|
||||
<-- 28
|
||||
==> wasi_snapshot_preview1.clock_time_get(id=2,precision=0,result.timestamp=16)
|
||||
<== EINVAL
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -217,10 +201,8 @@ func Test_clockTimeGet_Unsupported(t *testing.T) {
|
||||
clockID: 3,
|
||||
expectedErrno: ErrnoInval,
|
||||
expectedLog: `
|
||||
--> proxy.clock_time_get(id=3,precision=0,result.timestamp=16)
|
||||
==> wasi_snapshot_preview1.clock_time_get(id=3,precision=0,result.timestamp=16)
|
||||
<== EINVAL
|
||||
<-- 28
|
||||
==> wasi_snapshot_preview1.clock_time_get(id=3,precision=0,result.timestamp=16)
|
||||
<== EINVAL
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -228,10 +210,8 @@ func Test_clockTimeGet_Unsupported(t *testing.T) {
|
||||
clockID: 100,
|
||||
expectedErrno: ErrnoInval,
|
||||
expectedLog: `
|
||||
--> proxy.clock_time_get(id=100,precision=0,result.timestamp=16)
|
||||
==> wasi_snapshot_preview1.clock_time_get(id=100,precision=0,result.timestamp=16)
|
||||
<== EINVAL
|
||||
<-- 28
|
||||
==> wasi_snapshot_preview1.clock_time_get(id=100,precision=0,result.timestamp=16)
|
||||
<== EINVAL
|
||||
`,
|
||||
},
|
||||
}
|
||||
@@ -264,20 +244,16 @@ func Test_clockTimeGet_Errors(t *testing.T) {
|
||||
name: "resultTimestamp out-of-memory",
|
||||
resultTimestamp: memorySize,
|
||||
expectedLog: `
|
||||
--> proxy.clock_time_get(id=0,precision=0,result.timestamp=65536)
|
||||
==> wasi_snapshot_preview1.clock_time_get(id=0,precision=0,result.timestamp=65536)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.clock_time_get(id=0,precision=0,result.timestamp=65536)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "resultTimestamp exceeds the maximum valid address by 1",
|
||||
resultTimestamp: memorySize - 4 + 1, // 4 is the size of uint32, the type of the count of args
|
||||
expectedLog: `
|
||||
--> proxy.clock_time_get(id=0,precision=0,result.timestamp=65533)
|
||||
==> wasi_snapshot_preview1.clock_time_get(id=0,precision=0,result.timestamp=65533)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.clock_time_get(id=0,precision=0,result.timestamp=65533)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -29,10 +29,8 @@ func Test_environGet(t *testing.T) {
|
||||
// Invoke environGet and check the memory side effects.
|
||||
requireErrno(t, ErrnoSuccess, mod, environGetName, uint64(resultEnviron), uint64(resultEnvironBuf))
|
||||
require.Equal(t, `
|
||||
--> proxy.environ_get(environ=26,environ_buf=16)
|
||||
==> wasi_snapshot_preview1.environ_get(environ=26,environ_buf=16)
|
||||
<== ESUCCESS
|
||||
<-- 0
|
||||
==> wasi_snapshot_preview1.environ_get(environ=26,environ_buf=16)
|
||||
<== ESUCCESS
|
||||
`, "\n"+log.String())
|
||||
|
||||
actual, ok := mod.Memory().Read(resultEnvironBuf-1, uint32(len(expectedMemory)))
|
||||
@@ -58,10 +56,8 @@ func Test_environGet_Errors(t *testing.T) {
|
||||
environ: memorySize,
|
||||
environBuf: validAddress,
|
||||
expectedLog: `
|
||||
--> proxy.environ_get(environ=65536,environ_buf=0)
|
||||
==> wasi_snapshot_preview1.environ_get(environ=65536,environ_buf=0)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.environ_get(environ=65536,environ_buf=0)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -69,10 +65,8 @@ func Test_environGet_Errors(t *testing.T) {
|
||||
environ: validAddress,
|
||||
environBuf: memorySize,
|
||||
expectedLog: `
|
||||
--> proxy.environ_get(environ=0,environ_buf=65536)
|
||||
==> wasi_snapshot_preview1.environ_get(environ=0,environ_buf=65536)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.environ_get(environ=0,environ_buf=65536)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -81,10 +75,8 @@ func Test_environGet_Errors(t *testing.T) {
|
||||
environ: memorySize - 4*2 + 1,
|
||||
environBuf: validAddress,
|
||||
expectedLog: `
|
||||
--> proxy.environ_get(environ=65529,environ_buf=0)
|
||||
==> wasi_snapshot_preview1.environ_get(environ=65529,environ_buf=0)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.environ_get(environ=65529,environ_buf=0)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -93,10 +85,8 @@ func Test_environGet_Errors(t *testing.T) {
|
||||
// "a=bc", "b=cd" size = size of "a=bc0b=cd0" = 10
|
||||
environBuf: memorySize - 10 + 1,
|
||||
expectedLog: `
|
||||
--> proxy.environ_get(environ=0,environ_buf=65527)
|
||||
==> wasi_snapshot_preview1.environ_get(environ=0,environ_buf=65527)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.environ_get(environ=0,environ_buf=65527)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
}
|
||||
@@ -133,10 +123,8 @@ func Test_environSizesGet(t *testing.T) {
|
||||
// Invoke environSizesGet and check the memory side effects.
|
||||
requireErrno(t, ErrnoSuccess, mod, environSizesGetName, uint64(resultEnvironc), uint64(resultEnvironvLen))
|
||||
require.Equal(t, `
|
||||
--> proxy.environ_sizes_get(result.environc=16,result.environv_len=21)
|
||||
==> wasi_snapshot_preview1.environ_sizes_get(result.environc=16,result.environv_len=21)
|
||||
<== ESUCCESS
|
||||
<-- 0
|
||||
==> wasi_snapshot_preview1.environ_sizes_get(result.environc=16,result.environv_len=21)
|
||||
<== ESUCCESS
|
||||
`, "\n"+log.String())
|
||||
|
||||
actual, ok := mod.Memory().Read(resultEnvironc-1, uint32(len(expectedMemory)))
|
||||
@@ -162,10 +150,8 @@ func Test_environSizesGet_Errors(t *testing.T) {
|
||||
environc: memorySize,
|
||||
environLen: validAddress,
|
||||
expectedLog: `
|
||||
--> proxy.environ_sizes_get(result.environc=65536,result.environv_len=0)
|
||||
==> wasi_snapshot_preview1.environ_sizes_get(result.environc=65536,result.environv_len=0)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.environ_sizes_get(result.environc=65536,result.environv_len=0)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -173,10 +159,8 @@ func Test_environSizesGet_Errors(t *testing.T) {
|
||||
environc: validAddress,
|
||||
environLen: memorySize,
|
||||
expectedLog: `
|
||||
--> proxy.environ_sizes_get(result.environc=0,result.environv_len=65536)
|
||||
==> wasi_snapshot_preview1.environ_sizes_get(result.environc=0,result.environv_len=65536)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.environ_sizes_get(result.environc=0,result.environv_len=65536)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -184,10 +168,8 @@ func Test_environSizesGet_Errors(t *testing.T) {
|
||||
environc: memorySize - 4 + 1, // 4 is the size of uint32, the type of the count of environ
|
||||
environLen: validAddress,
|
||||
expectedLog: `
|
||||
--> proxy.environ_sizes_get(result.environc=65533,result.environv_len=0)
|
||||
==> wasi_snapshot_preview1.environ_sizes_get(result.environc=65533,result.environv_len=0)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.environ_sizes_get(result.environc=65533,result.environv_len=0)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -195,10 +177,8 @@ func Test_environSizesGet_Errors(t *testing.T) {
|
||||
environc: validAddress,
|
||||
environLen: memorySize - 4 + 1, // 4 is count of bytes to encode uint32le
|
||||
expectedLog: `
|
||||
--> proxy.environ_sizes_get(result.environc=0,result.environv_len=65533)
|
||||
==> wasi_snapshot_preview1.environ_sizes_get(result.environc=0,result.environv_len=65533)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.environ_sizes_get(result.environc=0,result.environv_len=65533)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -41,10 +41,8 @@ func Test_pollOneoff(t *testing.T) {
|
||||
requireErrno(t, ErrnoSuccess, mod, pollOneoffName, uint64(in), uint64(out), uint64(nsubscriptions),
|
||||
uint64(resultNevents))
|
||||
require.Equal(t, `
|
||||
--> proxy.poll_oneoff(in=0,out=128,nsubscriptions=1,result.nevents=512)
|
||||
==> wasi_snapshot_preview1.poll_oneoff(in=0,out=128,nsubscriptions=1,result.nevents=512)
|
||||
<== ESUCCESS
|
||||
<-- 0
|
||||
==> wasi_snapshot_preview1.poll_oneoff(in=0,out=128,nsubscriptions=1,result.nevents=512)
|
||||
<== ESUCCESS
|
||||
`, "\n"+log.String())
|
||||
|
||||
outMem, ok := mod.Memory().Read(out, uint32(len(expectedMem)))
|
||||
@@ -76,10 +74,8 @@ func Test_pollOneoff_Errors(t *testing.T) {
|
||||
resultNevents: 512, // past out
|
||||
expectedErrno: ErrnoFault,
|
||||
expectedLog: `
|
||||
--> proxy.poll_oneoff(in=65536,out=128,nsubscriptions=1,result.nevents=512)
|
||||
==> wasi_snapshot_preview1.poll_oneoff(in=65536,out=128,nsubscriptions=1,result.nevents=512)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.poll_oneoff(in=65536,out=128,nsubscriptions=1,result.nevents=512)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -89,10 +85,8 @@ func Test_pollOneoff_Errors(t *testing.T) {
|
||||
nsubscriptions: 1,
|
||||
expectedErrno: ErrnoFault,
|
||||
expectedLog: `
|
||||
--> proxy.poll_oneoff(in=0,out=65536,nsubscriptions=1,result.nevents=512)
|
||||
==> wasi_snapshot_preview1.poll_oneoff(in=0,out=65536,nsubscriptions=1,result.nevents=512)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.poll_oneoff(in=0,out=65536,nsubscriptions=1,result.nevents=512)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -101,10 +95,8 @@ func Test_pollOneoff_Errors(t *testing.T) {
|
||||
nsubscriptions: 1,
|
||||
expectedErrno: ErrnoFault,
|
||||
expectedLog: `
|
||||
--> proxy.poll_oneoff(in=0,out=0,nsubscriptions=1,result.nevents=65536)
|
||||
==> wasi_snapshot_preview1.poll_oneoff(in=0,out=0,nsubscriptions=1,result.nevents=65536)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.poll_oneoff(in=0,out=0,nsubscriptions=1,result.nevents=65536)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -113,10 +105,8 @@ func Test_pollOneoff_Errors(t *testing.T) {
|
||||
resultNevents: 512, // past out
|
||||
expectedErrno: ErrnoInval,
|
||||
expectedLog: `
|
||||
--> proxy.poll_oneoff(in=0,out=128,nsubscriptions=0,result.nevents=512)
|
||||
==> wasi_snapshot_preview1.poll_oneoff(in=0,out=128,nsubscriptions=0,result.nevents=512)
|
||||
<== EINVAL
|
||||
<-- 28
|
||||
==> wasi_snapshot_preview1.poll_oneoff(in=0,out=128,nsubscriptions=0,result.nevents=512)
|
||||
<== EINVAL
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -138,10 +128,8 @@ func Test_pollOneoff_Errors(t *testing.T) {
|
||||
'?', // stopped after encoding
|
||||
},
|
||||
expectedLog: `
|
||||
--> proxy.poll_oneoff(in=0,out=128,nsubscriptions=1,result.nevents=512)
|
||||
==> wasi_snapshot_preview1.poll_oneoff(in=0,out=128,nsubscriptions=1,result.nevents=512)
|
||||
<== ESUCCESS
|
||||
<-- 0
|
||||
==> wasi_snapshot_preview1.poll_oneoff(in=0,out=128,nsubscriptions=1,result.nevents=512)
|
||||
<== ESUCCESS
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -21,16 +21,14 @@ func Test_procExit(t *testing.T) {
|
||||
name: "success (exitcode 0)",
|
||||
exitCode: 0,
|
||||
expectedLog: `
|
||||
--> proxy.proc_exit(rval=0)
|
||||
==> wasi_snapshot_preview1.proc_exit(rval=0)
|
||||
==> wasi_snapshot_preview1.proc_exit(rval=0)
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "arbitrary non-zero exitcode",
|
||||
exitCode: 42,
|
||||
expectedLog: `
|
||||
--> proxy.proc_exit(rval=42)
|
||||
==> wasi_snapshot_preview1.proc_exit(rval=42)
|
||||
==> wasi_snapshot_preview1.proc_exit(rval=42)
|
||||
`,
|
||||
},
|
||||
}
|
||||
@@ -56,9 +54,7 @@ func Test_procExit(t *testing.T) {
|
||||
func Test_procRaise(t *testing.T) {
|
||||
log := requireErrnoNosys(t, procRaiseName, 0)
|
||||
require.Equal(t, `
|
||||
--> proxy.proc_raise(sig=0)
|
||||
--> wasi_snapshot_preview1.proc_raise(sig=0)
|
||||
<-- ENOSYS
|
||||
<-- 52
|
||||
--> wasi_snapshot_preview1.proc_raise(sig=0)
|
||||
<-- ENOSYS
|
||||
`, log)
|
||||
}
|
||||
|
||||
@@ -29,10 +29,8 @@ func Test_randomGet(t *testing.T) {
|
||||
// Invoke randomGet and check the memory side effects!
|
||||
requireErrno(t, ErrnoSuccess, mod, randomGetName, uint64(offset), uint64(length))
|
||||
require.Equal(t, `
|
||||
--> proxy.random_get(buf=1,buf_len=5)
|
||||
==> wasi_snapshot_preview1.random_get(buf=1,buf_len=5)
|
||||
<== ESUCCESS
|
||||
<-- 0
|
||||
==> wasi_snapshot_preview1.random_get(buf=1,buf_len=5)
|
||||
<== ESUCCESS
|
||||
`, "\n"+log.String())
|
||||
|
||||
actual, ok := mod.Memory().Read(0, offset+length+1)
|
||||
@@ -56,10 +54,8 @@ func Test_randomGet_Errors(t *testing.T) {
|
||||
offset: memorySize,
|
||||
length: 1,
|
||||
expectedLog: `
|
||||
--> proxy.random_get(buf=65536,buf_len=1)
|
||||
==> wasi_snapshot_preview1.random_get(buf=65536,buf_len=1)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.random_get(buf=65536,buf_len=1)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
{
|
||||
@@ -67,10 +63,8 @@ func Test_randomGet_Errors(t *testing.T) {
|
||||
offset: 0, // arbitrary valid offset
|
||||
length: memorySize + 1,
|
||||
expectedLog: `
|
||||
--> proxy.random_get(buf=0,buf_len=65537)
|
||||
==> wasi_snapshot_preview1.random_get(buf=0,buf_len=65537)
|
||||
<== EFAULT
|
||||
<-- 21
|
||||
==> wasi_snapshot_preview1.random_get(buf=0,buf_len=65537)
|
||||
<== EFAULT
|
||||
`,
|
||||
},
|
||||
}
|
||||
@@ -97,20 +91,16 @@ func Test_randomGet_SourceError(t *testing.T) {
|
||||
name: "error",
|
||||
randSource: iotest.ErrReader(errors.New("RandSource error")),
|
||||
expectedLog: `
|
||||
--> proxy.random_get(buf=1,buf_len=5)
|
||||
==> wasi_snapshot_preview1.random_get(buf=1,buf_len=5)
|
||||
<== EIO
|
||||
<-- 29
|
||||
==> wasi_snapshot_preview1.random_get(buf=1,buf_len=5)
|
||||
<== EIO
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "incomplete",
|
||||
randSource: bytes.NewReader([]byte{1, 2}),
|
||||
expectedLog: `
|
||||
--> proxy.random_get(buf=1,buf_len=5)
|
||||
==> wasi_snapshot_preview1.random_get(buf=1,buf_len=5)
|
||||
<== EIO
|
||||
<-- 29
|
||||
==> wasi_snapshot_preview1.random_get(buf=1,buf_len=5)
|
||||
<== EIO
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -10,9 +10,7 @@ import (
|
||||
func Test_schedYield(t *testing.T) {
|
||||
log := requireErrnoNosys(t, schedYieldName)
|
||||
require.Equal(t, `
|
||||
--> proxy.sched_yield()
|
||||
--> wasi_snapshot_preview1.sched_yield()
|
||||
<-- ENOSYS
|
||||
<-- 52
|
||||
--> wasi_snapshot_preview1.sched_yield()
|
||||
<-- ENOSYS
|
||||
`, log)
|
||||
}
|
||||
|
||||
@@ -10,10 +10,8 @@ import (
|
||||
func Test_sockAccept(t *testing.T) {
|
||||
log := requireErrnoNosys(t, sockAcceptName, 0, 0, 0)
|
||||
require.Equal(t, `
|
||||
--> proxy.sock_accept(fd=0,flags=0,result.fd=0)
|
||||
--> wasi_snapshot_preview1.sock_accept(fd=0,flags=0,result.fd=0)
|
||||
<-- ENOSYS
|
||||
<-- 52
|
||||
--> wasi_snapshot_preview1.sock_accept(fd=0,flags=0,result.fd=0)
|
||||
<-- ENOSYS
|
||||
`, log)
|
||||
}
|
||||
|
||||
@@ -21,10 +19,8 @@ func Test_sockAccept(t *testing.T) {
|
||||
func Test_sockRecv(t *testing.T) {
|
||||
log := requireErrnoNosys(t, sockRecvName, 0, 0, 0, 0, 0, 0)
|
||||
require.Equal(t, `
|
||||
--> proxy.sock_recv(fd=0,ri_data=0,ri_data_count=0,ri_flags=0,result.ro_datalen=0,result.ro_flags=0)
|
||||
--> wasi_snapshot_preview1.sock_recv(fd=0,ri_data=0,ri_data_count=0,ri_flags=0,result.ro_datalen=0,result.ro_flags=0)
|
||||
<-- ENOSYS
|
||||
<-- 52
|
||||
--> wasi_snapshot_preview1.sock_recv(fd=0,ri_data=0,ri_data_count=0,ri_flags=0,result.ro_datalen=0,result.ro_flags=0)
|
||||
<-- ENOSYS
|
||||
`, log)
|
||||
}
|
||||
|
||||
@@ -32,10 +28,8 @@ func Test_sockRecv(t *testing.T) {
|
||||
func Test_sockSend(t *testing.T) {
|
||||
log := requireErrnoNosys(t, sockSendName, 0, 0, 0, 0, 0)
|
||||
require.Equal(t, `
|
||||
--> proxy.sock_send(fd=0,si_data=0,si_data_count=0,si_flags=0,result.so_datalen=0)
|
||||
--> wasi_snapshot_preview1.sock_send(fd=0,si_data=0,si_data_count=0,si_flags=0,result.so_datalen=0)
|
||||
<-- ENOSYS
|
||||
<-- 52
|
||||
--> wasi_snapshot_preview1.sock_send(fd=0,si_data=0,si_data_count=0,si_flags=0,result.so_datalen=0)
|
||||
<-- ENOSYS
|
||||
`, log)
|
||||
}
|
||||
|
||||
@@ -43,9 +37,7 @@ func Test_sockSend(t *testing.T) {
|
||||
func Test_sockShutdown(t *testing.T) {
|
||||
log := requireErrnoNosys(t, sockShutdownName, 0, 0)
|
||||
require.Equal(t, `
|
||||
--> proxy.sock_shutdown(fd=0,how=0)
|
||||
--> wasi_snapshot_preview1.sock_shutdown(fd=0,how=0)
|
||||
<-- ENOSYS
|
||||
<-- 52
|
||||
--> wasi_snapshot_preview1.sock_shutdown(fd=0,how=0)
|
||||
<-- ENOSYS
|
||||
`, log)
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ func instantiateProxyModule(r wazero.Runtime, config wazero.ModuleConfig) (api.M
|
||||
return nil, err
|
||||
}
|
||||
|
||||
proxyBin := proxy.GetProxyModuleBinary(ModuleName, wasiModuleCompiled)
|
||||
proxyBin := proxy.NewModuleBinary(ModuleName, wasiModuleCompiled)
|
||||
|
||||
proxyCompiled, err := r.CompileModule(testCtx, proxyBin)
|
||||
if err != nil {
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/tetratelabs/wazero"
|
||||
"github.com/tetratelabs/wazero/api"
|
||||
. "github.com/tetratelabs/wazero/experimental"
|
||||
"github.com/tetratelabs/wazero/experimental/logging"
|
||||
"github.com/tetratelabs/wazero/internal/testing/proxy"
|
||||
"github.com/tetratelabs/wazero/internal/testing/require"
|
||||
"github.com/tetratelabs/wazero/sys"
|
||||
@@ -85,7 +84,7 @@ func requireProxyModule(t *testing.T, config wazero.ModuleConfig) (api.Module, a
|
||||
var log bytes.Buffer
|
||||
|
||||
// Set context to one that has an experimental listener
|
||||
ctx := context.WithValue(testCtx, FunctionListenerFactoryKey{}, logging.NewLoggingListenerFactory(&log))
|
||||
ctx := context.WithValue(testCtx, FunctionListenerFactoryKey{}, proxy.NewLoggingListenerFactory(&log))
|
||||
|
||||
r := wazero.NewRuntime(ctx)
|
||||
|
||||
@@ -95,7 +94,7 @@ func requireProxyModule(t *testing.T, config wazero.ModuleConfig) (api.Module, a
|
||||
_, err = r.InstantiateModule(ctx, wasiModuleCompiled, config)
|
||||
require.NoError(t, err)
|
||||
|
||||
proxyBin := proxy.GetProxyModuleBinary(ModuleName, wasiModuleCompiled)
|
||||
proxyBin := proxy.NewModuleBinary(ModuleName, wasiModuleCompiled)
|
||||
|
||||
proxyCompiled, err := r.CompileModule(ctx, proxyBin)
|
||||
require.NoError(t, err)
|
||||
@@ -113,7 +112,7 @@ func requireErrnoNosys(t *testing.T, funcName string, params ...uint64) string {
|
||||
var log bytes.Buffer
|
||||
|
||||
// Set context to one that has an experimental listener
|
||||
ctx := context.WithValue(testCtx, FunctionListenerFactoryKey{}, logging.NewHostLoggingListenerFactory(&log))
|
||||
ctx := context.WithValue(testCtx, FunctionListenerFactoryKey{}, proxy.NewLoggingListenerFactory(&log))
|
||||
|
||||
r := wazero.NewRuntime(ctx)
|
||||
defer r.Close(ctx)
|
||||
@@ -125,7 +124,7 @@ func requireErrnoNosys(t *testing.T, funcName string, params ...uint64) string {
|
||||
_, err = r.InstantiateModule(ctx, wasiModuleCompiled, wazero.NewModuleConfig())
|
||||
require.NoError(t, err)
|
||||
|
||||
proxyBin := proxy.GetProxyModuleBinary(ModuleName, wasiModuleCompiled)
|
||||
proxyBin := proxy.NewModuleBinary(ModuleName, wasiModuleCompiled)
|
||||
|
||||
proxyCompiled, err := r.CompileModule(ctx, proxyBin)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -1,26 +1,52 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/tetratelabs/wazero"
|
||||
"github.com/tetratelabs/wazero/api"
|
||||
"github.com/tetratelabs/wazero/experimental"
|
||||
"github.com/tetratelabs/wazero/experimental/logging"
|
||||
"github.com/tetratelabs/wazero/internal/leb128"
|
||||
"github.com/tetratelabs/wazero/internal/wasm"
|
||||
binaryformat "github.com/tetratelabs/wazero/internal/wasm/binary"
|
||||
)
|
||||
|
||||
// GetProxyModuleBinary creates the proxy module to proxy a function call against
|
||||
const proxyModuleName = "internal/testing/proxy/proxy.go"
|
||||
|
||||
// NewLoggingListenerFactory is like logging.NewHostLoggingListenerFactory,
|
||||
// except it skips logging proxying functions from NewModuleBinary.
|
||||
func NewLoggingListenerFactory(writer io.Writer) experimental.FunctionListenerFactory {
|
||||
return &loggingListenerFactory{logging.NewHostLoggingListenerFactory(writer)}
|
||||
}
|
||||
|
||||
type loggingListenerFactory struct {
|
||||
delegate experimental.FunctionListenerFactory
|
||||
}
|
||||
|
||||
// NewListener implements the same method as documented on
|
||||
// experimental.FunctionListener.
|
||||
func (f *loggingListenerFactory) NewListener(fnd api.FunctionDefinition) experimental.FunctionListener {
|
||||
if fnd.ModuleName() == proxyModuleName {
|
||||
return nil // don't log proxy stuff
|
||||
}
|
||||
return f.delegate.NewListener(fnd)
|
||||
}
|
||||
|
||||
// NewModuleBinary creates the proxy module to proxy a function call against
|
||||
// all the exported functions in `proxyTarget`, and returns its encoded binary.
|
||||
// The resulting module exports the proxy functions whose names are exactly the same
|
||||
// as the proxy destination.
|
||||
//
|
||||
// This is used to test host call implementations.
|
||||
func GetProxyModuleBinary(moduleName string, proxyTarget wazero.CompiledModule) []byte {
|
||||
// This is used to test host call implementations. If logging, use
|
||||
// NewLoggingListenerFactory to avoid messages from the proxying module.
|
||||
func NewModuleBinary(moduleName string, proxyTarget wazero.CompiledModule) []byte {
|
||||
funcDefs := proxyTarget.ExportedFunctions()
|
||||
funcNum := uint32(len(funcDefs))
|
||||
proxyModule := &wasm.Module{
|
||||
MemorySection: &wasm.Memory{Min: 1},
|
||||
ExportSection: []*wasm.Export{{Name: "memory", Type: api.ExternTypeMemory}},
|
||||
NameSection: &wasm.NameSection{ModuleName: "proxy"},
|
||||
NameSection: &wasm.NameSection{ModuleName: proxyModuleName},
|
||||
}
|
||||
var cnt wasm.Index
|
||||
for _, def := range funcDefs {
|
||||
|
||||
@@ -102,7 +102,8 @@ func equal(expected, actual interface{}) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// EqualError fails if the err is nil or its `Error()` value is not equal to the expected.
|
||||
// EqualError fails if the error is nil or its `Error()` value is not equal to
|
||||
// the expected string.
|
||||
//
|
||||
// - formatWithArgs are optional. When the first is a string that contains '%', it is treated like fmt.Sprintf.
|
||||
func EqualError(t TestingT, err error, expected string, formatWithArgs ...interface{}) {
|
||||
|
||||
Reference in New Issue
Block a user