Separate interpreter and engine per wazero.cache impl (#1022)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
@@ -9,7 +9,9 @@ import (
|
||||
goruntime "runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/tetratelabs/wazero/internal/platform"
|
||||
"github.com/tetratelabs/wazero/internal/testing/require"
|
||||
"github.com/tetratelabs/wazero/internal/wasm"
|
||||
)
|
||||
|
||||
//go:embed internal/integration_test/vs/testdata/fac.wasm
|
||||
@@ -22,11 +24,17 @@ func TestCompilationCache(t *testing.T) {
|
||||
foo, bar := getCacheSharedRuntimes(ctx, t)
|
||||
cacheInst := foo.cache
|
||||
|
||||
// add interpreter first, to ensure compiler support isn't order dependent
|
||||
eng := foo.cache.engs[engineKindInterpreter]
|
||||
if platform.CompilerSupported() {
|
||||
eng = foo.cache.engs[engineKindCompiler]
|
||||
}
|
||||
|
||||
// Try compiling.
|
||||
compiled, err := foo.CompileModule(ctx, facWasm)
|
||||
require.NoError(t, err)
|
||||
// Also check it is actually cached.
|
||||
require.Equal(t, uint32(1), cacheInst.eng.CompiledModuleCount())
|
||||
require.Equal(t, uint32(1), eng.CompiledModuleCount())
|
||||
barCompiled, err := bar.CompileModule(ctx, facWasm)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -47,12 +55,12 @@ func TestCompilationCache(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
err = bar.Close(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint32(1), cacheInst.eng.CompiledModuleCount())
|
||||
require.Equal(t, uint32(1), eng.CompiledModuleCount())
|
||||
|
||||
// Close the cache, and ensure the engine is closed.
|
||||
err = cacheInst.Close(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint32(0), cacheInst.eng.CompiledModuleCount())
|
||||
require.Equal(t, uint32(0), eng.CompiledModuleCount())
|
||||
})
|
||||
|
||||
// Even when cache is configured, compiled host modules must be different as that's the way
|
||||
@@ -162,3 +170,26 @@ func requireChdirToTemp(t *testing.T) (string, string) {
|
||||
require.NoError(t, os.Chdir(tmpDir))
|
||||
return tmpDir, oldwd
|
||||
}
|
||||
|
||||
func TestCache_Close(t *testing.T) {
|
||||
t.Run("all engines", func(t *testing.T) {
|
||||
c := &cache{engs: [engineKindCount]wasm.Engine{&mockEngine{}, &mockEngine{}}}
|
||||
err := c.Close(testCtx)
|
||||
require.NoError(t, err)
|
||||
for i := engineKind(0); i < engineKindCount; i++ {
|
||||
require.True(t, c.engs[i].(*mockEngine).closed)
|
||||
}
|
||||
})
|
||||
t.Run("only interp", func(t *testing.T) {
|
||||
c := &cache{engs: [engineKindCount]wasm.Engine{nil, &mockEngine{}}}
|
||||
err := c.Close(testCtx)
|
||||
require.NoError(t, err)
|
||||
require.True(t, c.engs[engineKindInterpreter].(*mockEngine).closed)
|
||||
})
|
||||
t.Run("only compiler", func(t *testing.T) {
|
||||
c := &cache{engs: [engineKindCount]wasm.Engine{&mockEngine{}, nil}}
|
||||
err := c.Close(testCtx)
|
||||
require.NoError(t, err)
|
||||
require.True(t, c.engs[engineKindCompiler].(*mockEngine).closed)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user