-
Notifications
You must be signed in to change notification settings - Fork 243
/
emscripten_test.go
48 lines (37 loc) · 1.47 KB
/
emscripten_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package emscripten
import (
"bytes"
"context"
_ "embed"
"testing"
"github.com/tetratelabs/wazero"
. "github.com/tetratelabs/wazero/experimental"
"github.com/tetratelabs/wazero/experimental/logging"
"github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
"github.com/tetratelabs/wazero/internal/testing/require"
"github.com/tetratelabs/wazero/sys"
)
// growWasm was compiled from testdata/grow.cc
//
//go:embed testdata/grow.wasm
var growWasm []byte
// testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors.
var testCtx = context.WithValue(context.Background(), struct{}{}, "arbitrary")
// TestGrow is an integration test until we have an Emscripten example.
func TestGrow(t *testing.T) {
var log bytes.Buffer
// Set context to one that has an experimental listener
ctx := context.WithValue(testCtx, FunctionListenerFactoryKey{}, logging.NewLoggingListenerFactory(&log))
r := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfigInterpreter())
defer r.Close(ctx)
_, err := wasi_snapshot_preview1.Instantiate(ctx, r)
require.NoError(t, err)
_, err = Instantiate(ctx, r)
require.NoError(t, err)
// Emscripten exits main with zero by default
_, err = r.InstantiateModuleFromBinary(ctx, growWasm)
require.Error(t, err)
require.Zero(t, err.(*sys.ExitError).ExitCode())
// We expect the memory no-op memory growth hook to be invoked as wasm.
require.Contains(t, log.String(), "--> env.emscripten_notify_memory_growth(memory_index=0)")
}