1 package logging
2
3 import (
4 "testing"
5
6 "github.com/tetratelabs/wazero/api"
7 "github.com/tetratelabs/wazero/internal/gojs/custom"
8 "github.com/tetratelabs/wazero/internal/logging"
9 "github.com/tetratelabs/wazero/internal/testing/require"
10 "github.com/tetratelabs/wazero/internal/wasm"
11 )
12
13 type testFunctionDefinition struct {
14 name string
15 *wasm.FunctionDefinition
16 }
17
18
19 func (f *testFunctionDefinition) Name() string {
20 return f.name
21 }
22
23 func TestIsInLogScope(t *testing.T) {
24 runtimeGetRandomData := &testFunctionDefinition{name: custom.NameRuntimeGetRandomData}
25 runtimeResetMemoryDataView := &testFunctionDefinition{name: custom.NameRuntimeResetMemoryDataView}
26 runtimeWasmExit := &testFunctionDefinition{name: custom.NameRuntimeWasmExit}
27 syscallValueCall := &testFunctionDefinition{name: custom.NameSyscallValueCall}
28 tests := []struct {
29 name string
30 fnd api.FunctionDefinition
31 scopes logging.LogScopes
32 expected bool
33 }{
34 {
35 name: "runtimeWasmExit in LogScopeProc",
36 fnd: runtimeWasmExit,
37 scopes: logging.LogScopeProc,
38 expected: true,
39 },
40 {
41 name: "runtimeWasmExit not in LogScopeFilesystem",
42 fnd: runtimeWasmExit,
43 scopes: logging.LogScopeFilesystem,
44 expected: false,
45 },
46 {
47 name: "runtimeWasmExit in LogScopeProc|LogScopeFilesystem",
48 fnd: runtimeWasmExit,
49 scopes: logging.LogScopeProc | logging.LogScopeFilesystem,
50 expected: true,
51 },
52 {
53 name: "runtimeWasmExit not in LogScopeNone",
54 fnd: runtimeWasmExit,
55 scopes: logging.LogScopeNone,
56 expected: false,
57 },
58 {
59 name: "runtimeWasmExit in LogScopeAll",
60 fnd: runtimeWasmExit,
61 scopes: logging.LogScopeAll,
62 expected: true,
63 },
64 {
65 name: "runtimeResetMemoryDataView in LogScopeMemory",
66 fnd: runtimeResetMemoryDataView,
67 scopes: logging.LogScopeMemory,
68 expected: true,
69 },
70 {
71 name: "runtimeResetMemoryDataView not in LogScopeFilesystem",
72 fnd: runtimeResetMemoryDataView,
73 scopes: logging.LogScopeFilesystem,
74 expected: false,
75 },
76 {
77 name: "runtimeResetMemoryDataView in LogScopeMemory|LogScopeFilesystem",
78 fnd: runtimeResetMemoryDataView,
79 scopes: logging.LogScopeMemory | logging.LogScopeFilesystem,
80 expected: true,
81 },
82 {
83 name: "runtimeResetMemoryDataView not in LogScopeNone",
84 fnd: runtimeResetMemoryDataView,
85 scopes: logging.LogScopeNone,
86 expected: false,
87 },
88 {
89 name: "runtimeResetMemoryDataView in LogScopeAll",
90 fnd: runtimeResetMemoryDataView,
91 scopes: logging.LogScopeAll,
92 expected: true,
93 },
94 {
95 name: "runtimeGetRandomData not in LogScopeFilesystem",
96 fnd: runtimeGetRandomData,
97 scopes: logging.LogScopeFilesystem,
98 expected: false,
99 },
100 {
101 name: "runtimeGetRandomData in LogScopeRandom|LogScopeFilesystem",
102 fnd: runtimeGetRandomData,
103 scopes: logging.LogScopeRandom | logging.LogScopeFilesystem,
104 expected: true,
105 },
106 {
107 name: "runtimeGetRandomData not in LogScopeNone",
108 fnd: runtimeGetRandomData,
109 scopes: logging.LogScopeNone,
110 expected: false,
111 },
112 {
113 name: "runtimeGetRandomData in LogScopeAll",
114 fnd: runtimeGetRandomData,
115 scopes: logging.LogScopeAll,
116 expected: true,
117 },
118 {
119 name: "syscallValueCall in LogScopeFilesystem",
120 fnd: syscallValueCall,
121 scopes: logging.LogScopeFilesystem,
122 expected: true,
123 },
124 {
125 name: "syscallValueCall in LogScopeRandom",
126 fnd: syscallValueCall,
127 scopes: logging.LogScopeRandom,
128 expected: true,
129 },
130 {
131 name: "syscallValueCall in LogScopeRandom|LogScopeFilesystem",
132 fnd: syscallValueCall,
133 scopes: logging.LogScopeRandom | logging.LogScopeFilesystem,
134 expected: true,
135 },
136 {
137 name: "syscallValueCall in LogScopeAll",
138 fnd: syscallValueCall,
139 scopes: logging.LogScopeAll,
140 expected: true,
141 },
142 {
143 name: "syscallValueCall not in LogScopeNone",
144 fnd: syscallValueCall,
145 scopes: logging.LogScopeNone,
146 expected: false,
147 },
148 }
149
150 for _, tt := range tests {
151 tc := tt
152
153 t.Run(tc.name, func(t *testing.T) {
154 require.Equal(t, tc.expected, IsInLogScope(tc.fnd, tc.scopes))
155 })
156 }
157 }
158
View as plain text