Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/guard/wasm_dispatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var labelResponseReturnsTwoWasm = []byte{
func setupRawWasmModule(t *testing.T, wasmBytes []byte, name string) (*WasmGuard, func()) {
t.Helper()
ctx := context.Background()
rt := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfigInterpreter())
rt := newTestInterpreterRuntime(ctx)
mod, err := rt.InstantiateWithConfig(ctx, wasmBytes, wazero.NewModuleConfig().WithName(name))
require.NoError(t, err, "failed to instantiate WASM module %s", name)
g := &WasmGuard{name: name, module: mod}
Expand Down
2 changes: 1 addition & 1 deletion internal/guard/wasm_parse_coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ var labelReturnsNeg1Wasm = []byte{
func setupWasmGuard(t *testing.T, wasmBytes []byte, name string) (*WasmGuard, func()) {
t.Helper()
ctx := context.Background()
rt := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfigInterpreter())
rt := newTestInterpreterRuntime(ctx)
mod, err := rt.InstantiateWithConfig(ctx, wasmBytes, wazero.NewModuleConfig().WithName(name))
require.NoError(t, err, "failed to instantiate WASM module %s", name)
g := &WasmGuard{name: name, module: mod}
Expand Down
17 changes: 12 additions & 5 deletions internal/guard/wasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ import (
"github.com/tetratelabs/wazero/sys"
)

// newTestInterpreterRuntime creates a wazero interpreter runtime for tests.
// The interpreter engine is preferred over the compiler engine in tests
// because it has faster startup and doesn't require JIT support.
func newTestInterpreterRuntime(ctx context.Context) wazero.Runtime {
return wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfigInterpreter())
}

func TestMain(m *testing.M) {
code := m.Run()
if err := globalCompilationCache.Close(context.Background()); err != nil {
Expand Down Expand Up @@ -1191,7 +1198,7 @@ func TestWasmGuardClose(t *testing.T) {

t.Run("close ignores caller cancellation during cleanup", func(t *testing.T) {
ctx := context.Background()
rt := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfigInterpreter())
rt := newTestInterpreterRuntime(ctx)
mod, err := rt.InstantiateWithConfig(ctx, minimalGuardWasm, wazero.NewModuleConfig().WithName("close-guard"))
require.NoError(t, err)

Expand Down Expand Up @@ -1318,7 +1325,7 @@ func TestBufferRetryLogic(t *testing.T) {
setupModule := func(t *testing.T, wasmBytes []byte, moduleName string) (*WasmGuard, func()) {
t.Helper()
ctx := context.Background()
rt := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfigInterpreter())
rt := newTestInterpreterRuntime(ctx)
mod, err := rt.InstantiateWithConfig(ctx, wasmBytes, wazero.NewModuleConfig().WithName(moduleName))
require.NoError(t, err)
g := &WasmGuard{name: moduleName, module: mod}
Expand All @@ -1332,7 +1339,7 @@ func TestBufferRetryLogic(t *testing.T) {
t.Run("function not exported from module", func(t *testing.T) {
// minimalGuardWasm has no exports at all; ExportedFunction returns nil.
ctx := context.Background()
rt := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfigInterpreter())
rt := newTestInterpreterRuntime(ctx)
t.Cleanup(func() { require.NoError(t, rt.Close(ctx)) })
mod, err := rt.InstantiateWithConfig(ctx, minimalGuardWasm, wazero.NewModuleConfig().WithName("minimal-retry"))
require.NoError(t, err)
Expand Down Expand Up @@ -1465,7 +1472,7 @@ func TestWasmMemoryLayout(t *testing.T) {

func TestTryCallWasmFunctionDirectMemoryFallback(t *testing.T) {
ctx := context.Background()
runtime := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfigInterpreter())
runtime := newTestInterpreterRuntime(ctx)
t.Cleanup(func() {
require.NoError(t, runtime.Close(ctx))
})
Expand Down Expand Up @@ -1598,7 +1605,7 @@ func TestJSONMarshaling(t *testing.T) {
func TestIsWasmTrap(t *testing.T) {
t.Run("actual wazero trap still uses wasm error prefix (verified with wazero v1.12.0)", func(t *testing.T) {
ctx := context.Background()
runtime := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfigInterpreter())
runtime := newTestInterpreterRuntime(ctx)
t.Cleanup(func() {
require.NoError(t, runtime.Close(ctx))
})
Expand Down
Loading