Many tests failed in gojs due to needing to be resolved against the CWD,
which is atypically stored host side. This fixes that and renames the
"exit" scope to "proc" so we can use it for other proc concerns besides
exit.
This reduces known failures on GOOS=js from 23 to 14:
```bash
$ wazero run -mount=/usr/local/go/src/os:/:ro -mount=/tmp:/tmp -mount=/etc:/etc:ro -mount=/usr:/usr:ro -mount=/dev:/dev:ro os.wasm |grep '^--- FAIL'|wc -l
14
```
See #1222
Signed-off-by: Adrian Cole <adrian@tetrate.io>
158 lines
4.2 KiB
Go
158 lines
4.2 KiB
Go
package logging
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/tetratelabs/wazero/api"
|
|
"github.com/tetratelabs/wazero/internal/gojs/custom"
|
|
"github.com/tetratelabs/wazero/internal/logging"
|
|
"github.com/tetratelabs/wazero/internal/testing/require"
|
|
"github.com/tetratelabs/wazero/internal/wasm"
|
|
)
|
|
|
|
type testFunctionDefinition struct {
|
|
name string
|
|
*wasm.FunctionDefinition
|
|
}
|
|
|
|
// Name implements the same method as documented on api.FunctionDefinition.
|
|
func (f *testFunctionDefinition) Name() string {
|
|
return f.name
|
|
}
|
|
|
|
func TestIsInLogScope(t *testing.T) {
|
|
runtimeGetRandomData := &testFunctionDefinition{name: custom.NameRuntimeGetRandomData}
|
|
runtimeResetMemoryDataView := &testFunctionDefinition{name: custom.NameRuntimeResetMemoryDataView}
|
|
runtimeWasmExit := &testFunctionDefinition{name: custom.NameRuntimeWasmExit}
|
|
syscallValueCall := &testFunctionDefinition{name: custom.NameSyscallValueCall}
|
|
tests := []struct {
|
|
name string
|
|
fnd api.FunctionDefinition
|
|
scopes logging.LogScopes
|
|
expected bool
|
|
}{
|
|
{
|
|
name: "runtimeWasmExit in LogScopeProc",
|
|
fnd: runtimeWasmExit,
|
|
scopes: logging.LogScopeProc,
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "runtimeWasmExit not in LogScopeFilesystem",
|
|
fnd: runtimeWasmExit,
|
|
scopes: logging.LogScopeFilesystem,
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "runtimeWasmExit in LogScopeProc|LogScopeFilesystem",
|
|
fnd: runtimeWasmExit,
|
|
scopes: logging.LogScopeProc | logging.LogScopeFilesystem,
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "runtimeWasmExit not in LogScopeNone",
|
|
fnd: runtimeWasmExit,
|
|
scopes: logging.LogScopeNone,
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "runtimeWasmExit in LogScopeAll",
|
|
fnd: runtimeWasmExit,
|
|
scopes: logging.LogScopeAll,
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "runtimeResetMemoryDataView in LogScopeMemory",
|
|
fnd: runtimeResetMemoryDataView,
|
|
scopes: logging.LogScopeMemory,
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "runtimeResetMemoryDataView not in LogScopeFilesystem",
|
|
fnd: runtimeResetMemoryDataView,
|
|
scopes: logging.LogScopeFilesystem,
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "runtimeResetMemoryDataView in LogScopeMemory|LogScopeFilesystem",
|
|
fnd: runtimeResetMemoryDataView,
|
|
scopes: logging.LogScopeMemory | logging.LogScopeFilesystem,
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "runtimeResetMemoryDataView not in LogScopeNone",
|
|
fnd: runtimeResetMemoryDataView,
|
|
scopes: logging.LogScopeNone,
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "runtimeResetMemoryDataView in LogScopeAll",
|
|
fnd: runtimeResetMemoryDataView,
|
|
scopes: logging.LogScopeAll,
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "runtimeGetRandomData not in LogScopeFilesystem",
|
|
fnd: runtimeGetRandomData,
|
|
scopes: logging.LogScopeFilesystem,
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "runtimeGetRandomData in LogScopeRandom|LogScopeFilesystem",
|
|
fnd: runtimeGetRandomData,
|
|
scopes: logging.LogScopeRandom | logging.LogScopeFilesystem,
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "runtimeGetRandomData not in LogScopeNone",
|
|
fnd: runtimeGetRandomData,
|
|
scopes: logging.LogScopeNone,
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "runtimeGetRandomData in LogScopeAll",
|
|
fnd: runtimeGetRandomData,
|
|
scopes: logging.LogScopeAll,
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "syscallValueCall in LogScopeFilesystem",
|
|
fnd: syscallValueCall,
|
|
scopes: logging.LogScopeFilesystem,
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "syscallValueCall in LogScopeRandom",
|
|
fnd: syscallValueCall,
|
|
scopes: logging.LogScopeRandom,
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "syscallValueCall in LogScopeRandom|LogScopeFilesystem",
|
|
fnd: syscallValueCall,
|
|
scopes: logging.LogScopeRandom | logging.LogScopeFilesystem,
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "syscallValueCall in LogScopeAll",
|
|
fnd: syscallValueCall,
|
|
scopes: logging.LogScopeAll,
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "syscallValueCall not in LogScopeNone",
|
|
fnd: syscallValueCall,
|
|
scopes: logging.LogScopeNone,
|
|
expected: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tc := tt
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
require.Equal(t, tc.expected, IsInLogScope(tc.fnd, tc.scopes))
|
|
})
|
|
}
|
|
}
|