|
|
|
|
@@ -54,14 +54,13 @@ func TestSnapshotPreview1_ArgsGet(t *testing.T) {
|
|
|
|
|
'?', // stopped after encoding
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionArgsGet, ImportArgsGet, moduleName, args)
|
|
|
|
|
mem := mod.Memory("memory")
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionArgsGet, ImportArgsGet, moduleName, args)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.ArgsGet", func(t *testing.T) {
|
|
|
|
|
maskMemory(t, mem, len(expectedMemory))
|
|
|
|
|
|
|
|
|
|
// Invoke ArgsGet directly and check the memory side effects.
|
|
|
|
|
errno := NewAPI(args).ArgsGet(mod.Instance.Ctx, argv, argvBuf)
|
|
|
|
|
errno := NewAPI(args).ArgsGet(ctx(mem), argv, argvBuf)
|
|
|
|
|
require.Equal(t, wasi.ErrnoSuccess, errno)
|
|
|
|
|
|
|
|
|
|
actual, ok := mem.Read(0, uint32(len(expectedMemory)))
|
|
|
|
|
@@ -82,12 +81,17 @@ func TestSnapshotPreview1_ArgsGet(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ctx(mem publicwasm.Memory) *wasm.ModuleContext {
|
|
|
|
|
ctx := (&wasm.ModuleContext{}).WithMemory(mem.(*wasm.MemoryInstance))
|
|
|
|
|
return ctx
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestSnapshotPreview1_ArgsGet_Errors(t *testing.T) {
|
|
|
|
|
args, err := Args("a", "bc")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionArgsGet, ImportArgsGet, moduleName, args)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionArgsGet, ImportArgsGet, moduleName, args)
|
|
|
|
|
|
|
|
|
|
memorySize := mod.Memory("memory").Size()
|
|
|
|
|
memorySize := mem.Size()
|
|
|
|
|
validAddress := uint32(0) // arbitrary valid address as arguments to args_get. We chose 0 here.
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
@@ -143,15 +147,13 @@ func TestSnapshotPreview1_ArgsSizesGet(t *testing.T) {
|
|
|
|
|
'?', // stopped after encoding
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionArgsSizesGet, ImportArgsSizesGet, moduleName, args)
|
|
|
|
|
|
|
|
|
|
mem := mod.Memory("memory")
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionArgsSizesGet, ImportArgsSizesGet, moduleName, args)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.ArgsSizesGet", func(t *testing.T) {
|
|
|
|
|
maskMemory(t, mem, len(expectedMemory))
|
|
|
|
|
|
|
|
|
|
// Invoke ArgsSizesGet directly and check the memory side effects.
|
|
|
|
|
errno := NewAPI(args).ArgsSizesGet(mod.Instance.Ctx, resultArgc, resultArgvBufSize)
|
|
|
|
|
errno := NewAPI(args).ArgsSizesGet(ctx(mem), resultArgc, resultArgvBufSize)
|
|
|
|
|
require.Equal(t, wasi.ErrnoSuccess, errno)
|
|
|
|
|
|
|
|
|
|
actual, ok := mem.Read(0, uint32(len(expectedMemory)))
|
|
|
|
|
@@ -176,9 +178,9 @@ func TestSnapshotPreview1_ArgsSizesGet_Errors(t *testing.T) {
|
|
|
|
|
args, err := Args("a", "bc")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionArgsSizesGet, ImportArgsSizesGet, moduleName, args)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionArgsSizesGet, ImportArgsSizesGet, moduleName, args)
|
|
|
|
|
|
|
|
|
|
memorySize := mod.Memory("memory").Size()
|
|
|
|
|
memorySize := mem.Size()
|
|
|
|
|
validAddress := uint32(0) // arbitrary valid address as arguments to args_sizes_get. We chose 0 here.
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
@@ -270,14 +272,13 @@ func TestSnapshotPreview1_EnvironGet(t *testing.T) {
|
|
|
|
|
'?', // stopped after encoding
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionEnvironGet, ImportEnvironGet, moduleName, envOpt)
|
|
|
|
|
mem := mod.Memory("memory")
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionEnvironGet, ImportEnvironGet, moduleName, envOpt)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.EnvironGet", func(t *testing.T) {
|
|
|
|
|
maskMemory(t, mem, len(expectedMemory))
|
|
|
|
|
|
|
|
|
|
// Invoke EnvironGet directly and check the memory side effects.
|
|
|
|
|
errno := NewAPI(envOpt).EnvironGet(mod.Instance.Ctx, resultEnviron, resultEnvironBuf)
|
|
|
|
|
errno := NewAPI(envOpt).EnvironGet(ctx(mem), resultEnviron, resultEnvironBuf)
|
|
|
|
|
require.Equal(t, wasi.ErrnoSuccess, errno)
|
|
|
|
|
|
|
|
|
|
actual, ok := mem.Read(0, uint32(len(expectedMemory)))
|
|
|
|
|
@@ -302,9 +303,9 @@ func TestSnapshotPreview1_EnvironGet_Errors(t *testing.T) {
|
|
|
|
|
envOpt, err := Environ("a=bc", "b=cd")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionEnvironGet, ImportEnvironGet, moduleName, envOpt)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionEnvironGet, ImportEnvironGet, moduleName, envOpt)
|
|
|
|
|
|
|
|
|
|
memorySize := mod.Memory("memory").Size()
|
|
|
|
|
memorySize := mem.Size()
|
|
|
|
|
validAddress := uint32(0) // arbitrary valid address as arguments to environ_get. We chose 0 here.
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
@@ -360,14 +361,13 @@ func TestSnapshotPreview1_EnvironSizesGet(t *testing.T) {
|
|
|
|
|
'?', // stopped after encoding
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionEnvironSizesGet, ImportEnvironSizesGet, moduleName, envOpt)
|
|
|
|
|
mem := mod.Memory("memory")
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionEnvironSizesGet, ImportEnvironSizesGet, moduleName, envOpt)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.EnvironSizesGet", func(t *testing.T) {
|
|
|
|
|
maskMemory(t, mem, len(expectedMemory))
|
|
|
|
|
|
|
|
|
|
// Invoke EnvironSizesGet directly and check the memory side effects.
|
|
|
|
|
errno := NewAPI(envOpt).EnvironSizesGet(mod.Instance.Ctx, resultEnvironc, resultEnvironBufSize)
|
|
|
|
|
errno := NewAPI(envOpt).EnvironSizesGet(ctx(mem), resultEnvironc, resultEnvironBufSize)
|
|
|
|
|
require.Equal(t, wasi.ErrnoSuccess, errno)
|
|
|
|
|
|
|
|
|
|
actual, ok := mem.Read(0, uint32(len(expectedMemory)))
|
|
|
|
|
@@ -392,9 +392,9 @@ func TestSnapshotPreview1_EnvironSizesGet_Errors(t *testing.T) {
|
|
|
|
|
envOpt, err := Environ("a=b", "b=cd")
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionEnvironSizesGet, ImportEnvironSizesGet, moduleName, envOpt)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionEnvironSizesGet, ImportEnvironSizesGet, moduleName, envOpt)
|
|
|
|
|
|
|
|
|
|
memorySize := mod.Memory("memory").Size()
|
|
|
|
|
memorySize := mem.Size()
|
|
|
|
|
validAddress := uint32(0) // arbitrary valid address as arguments to environ_sizes_get. We chose 0 here.
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
@@ -437,10 +437,10 @@ func TestSnapshotPreview1_EnvironSizesGet_Errors(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_ClockResGet only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_ClockResGet(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionClockResGet, ImportClockResGet, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionClockResGet, ImportClockResGet, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.ClockResGet", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().ClockResGet(mod.Instance.Ctx, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().ClockResGet(ctx(mem), 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionClockResGet, func(t *testing.T) {
|
|
|
|
|
@@ -462,14 +462,13 @@ func TestSnapshotPreview1_ClockTimeGet(t *testing.T) {
|
|
|
|
|
clockOpt := func(api *wasiAPI) {
|
|
|
|
|
api.timeNowUnixNano = func() uint64 { return epochNanos }
|
|
|
|
|
}
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionClockTimeGet, ImportClockTimeGet, moduleName, clockOpt)
|
|
|
|
|
mem := mod.Memory("memory")
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionClockTimeGet, ImportClockTimeGet, moduleName, clockOpt)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.ClockTimeGet", func(t *testing.T) {
|
|
|
|
|
maskMemory(t, mem, len(expectedMemory))
|
|
|
|
|
|
|
|
|
|
// invoke ClockTimeGet directly and check the memory side effects!
|
|
|
|
|
errno := NewAPI(clockOpt).ClockTimeGet(mod.Instance.Ctx, 0 /* TODO: id */, 0 /* TODO: precision */, resultTimestamp)
|
|
|
|
|
errno := NewAPI(clockOpt).ClockTimeGet(ctx(mem), 0 /* TODO: id */, 0 /* TODO: precision */, resultTimestamp)
|
|
|
|
|
require.Equal(t, wasi.ErrnoSuccess, errno)
|
|
|
|
|
|
|
|
|
|
actual, ok := mem.Read(0, uint32(len(expectedMemory)))
|
|
|
|
|
@@ -493,11 +492,11 @@ func TestSnapshotPreview1_ClockTimeGet(t *testing.T) {
|
|
|
|
|
func TestSnapshotPreview1_ClockTimeGet_Errors(t *testing.T) {
|
|
|
|
|
epochNanos := uint64(1640995200000000000) // midnight UTC 2022-01-01
|
|
|
|
|
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionClockTimeGet, ImportClockTimeGet, moduleName, func(api *wasiAPI) {
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionClockTimeGet, ImportClockTimeGet, moduleName, func(api *wasiAPI) {
|
|
|
|
|
api.timeNowUnixNano = func() uint64 { return epochNanos }
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
memorySize := mod.Memory("memory").Size()
|
|
|
|
|
memorySize := mem.Size()
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
@@ -528,10 +527,10 @@ func TestSnapshotPreview1_ClockTimeGet_Errors(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdAdvise only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_FdAdvise(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdAdvise, ImportFdAdvise, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdAdvise, ImportFdAdvise, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.FdAdvise", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdAdvise(mod.Instance.Ctx, 0, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdAdvise(ctx(mem), 0, 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionFdAdvise, func(t *testing.T) {
|
|
|
|
|
@@ -543,10 +542,10 @@ func TestSnapshotPreview1_FdAdvise(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdAllocate only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_FdAllocate(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdAllocate, ImportFdAllocate, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdAllocate, ImportFdAllocate, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.FdAllocate", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdAllocate(mod.Instance.Ctx, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdAllocate(ctx(mem), 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionFdAllocate, func(t *testing.T) {
|
|
|
|
|
@@ -560,9 +559,9 @@ func TestSnapshotPreview1_FdClose(t *testing.T) {
|
|
|
|
|
fdToClose := uint32(3) // arbitrary fd
|
|
|
|
|
fdToKeep := uint32(4) // another arbitrary fd
|
|
|
|
|
|
|
|
|
|
setupFD := func() (*wasm.PublicModule, publicwasm.Function, *wasiAPI) {
|
|
|
|
|
setupFD := func() (publicwasm.Memory, publicwasm.Function, *wasiAPI) {
|
|
|
|
|
var api *wasiAPI
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdClose, ImportFdClose, moduleName, func(a *wasiAPI) {
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdClose, ImportFdClose, moduleName, func(a *wasiAPI) {
|
|
|
|
|
memFs := &MemFS{}
|
|
|
|
|
a.opened = map[uint32]fileEntry{
|
|
|
|
|
fdToClose: {
|
|
|
|
|
@@ -576,13 +575,13 @@ func TestSnapshotPreview1_FdClose(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
api = a // for later tests
|
|
|
|
|
})
|
|
|
|
|
return mod, fn, api
|
|
|
|
|
return mem, fn, api
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.FdClose", func(t *testing.T) {
|
|
|
|
|
mod, _, api := setupFD()
|
|
|
|
|
mem, _, api := setupFD()
|
|
|
|
|
|
|
|
|
|
errno := api.FdClose(mod.Instance.Ctx, fdToClose)
|
|
|
|
|
errno := api.FdClose(ctx(mem), fdToClose)
|
|
|
|
|
require.Equal(t, wasi.ErrnoSuccess, errno)
|
|
|
|
|
require.NotContains(t, api.opened, fdToClose) // Fd is closed and removed from the opened FDs.
|
|
|
|
|
require.Contains(t, api.opened, fdToKeep)
|
|
|
|
|
@@ -597,18 +596,19 @@ func TestSnapshotPreview1_FdClose(t *testing.T) {
|
|
|
|
|
require.Contains(t, api.opened, fdToKeep)
|
|
|
|
|
})
|
|
|
|
|
t.Run("ErrnoBadF for an invalid FD", func(t *testing.T) {
|
|
|
|
|
mod, _, api := setupFD()
|
|
|
|
|
errno := api.FdClose(mod.Instance.Ctx, 42) // 42 is an arbitrary invalid FD
|
|
|
|
|
mem, _, api := setupFD()
|
|
|
|
|
|
|
|
|
|
errno := api.FdClose(ctx(mem), 42) // 42 is an arbitrary invalid FD
|
|
|
|
|
require.Equal(t, wasi.ErrnoBadf, errno)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdDatasync only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_FdDatasync(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdDatasync, ImportFdDatasync, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdDatasync, ImportFdDatasync, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.FdDatasync", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdDatasync(mod.Instance.Ctx, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdDatasync(ctx(mem), 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionFdDatasync, func(t *testing.T) {
|
|
|
|
|
@@ -622,10 +622,10 @@ func TestSnapshotPreview1_FdDatasync(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdFdstatSetFlags only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_FdFdstatSetFlags(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdFdstatSetFlags, ImportFdFdstatSetFlags, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdFdstatSetFlags, ImportFdFdstatSetFlags, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.FdFdstatSetFlags", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdFdstatSetFlags(mod.Instance.Ctx, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdFdstatSetFlags(ctx(mem), 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionFdFdstatSetFlags, func(t *testing.T) {
|
|
|
|
|
@@ -637,10 +637,10 @@ func TestSnapshotPreview1_FdFdstatSetFlags(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdFdstatSetRights only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_FdFdstatSetRights(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdFdstatSetRights, ImportFdFdstatSetRights, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdFdstatSetRights, ImportFdFdstatSetRights, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.FdFdstatSetRights", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdFdstatSetRights(mod.Instance.Ctx, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdFdstatSetRights(ctx(mem), 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionFdFdstatSetRights, func(t *testing.T) {
|
|
|
|
|
@@ -652,10 +652,10 @@ func TestSnapshotPreview1_FdFdstatSetRights(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdFilestatGet only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_FdFilestatGet(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdFilestatGet, ImportFdFilestatGet, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdFilestatGet, ImportFdFilestatGet, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.FdFilestatGet", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdFilestatGet(mod.Instance.Ctx, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdFilestatGet(ctx(mem), 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionFdFilestatGet, func(t *testing.T) {
|
|
|
|
|
@@ -667,10 +667,10 @@ func TestSnapshotPreview1_FdFilestatGet(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdFilestatSetSize only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_FdFilestatSetSize(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdFilestatSetSize, ImportFdFilestatSetSize, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdFilestatSetSize, ImportFdFilestatSetSize, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.FdFilestatSetSize", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdFilestatSetSize(mod.Instance.Ctx, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdFilestatSetSize(ctx(mem), 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionFdFilestatSetSize, func(t *testing.T) {
|
|
|
|
|
@@ -682,10 +682,10 @@ func TestSnapshotPreview1_FdFilestatSetSize(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdFilestatSetTimes only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_FdFilestatSetTimes(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdFilestatSetTimes, ImportFdFilestatSetTimes, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdFilestatSetTimes, ImportFdFilestatSetTimes, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.FdFilestatSetTimes", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdFilestatSetTimes(mod.Instance.Ctx, 0, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdFilestatSetTimes(ctx(mem), 0, 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionFdFilestatSetTimes, func(t *testing.T) {
|
|
|
|
|
@@ -697,10 +697,10 @@ func TestSnapshotPreview1_FdFilestatSetTimes(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdPread only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_FdPread(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdPread, ImportFdPread, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdPread, ImportFdPread, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.FdPread", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdPread(mod.Instance.Ctx, 0, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdPread(ctx(mem), 0, 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionFdPread, func(t *testing.T) {
|
|
|
|
|
@@ -715,14 +715,13 @@ func TestSnapshotPreview1_FdPread(t *testing.T) {
|
|
|
|
|
func TestSnapshotPreview1_FdPrestatDirName(t *testing.T) {
|
|
|
|
|
fd := uint32(3) // arbitrary fd after 0, 1, and 2, that are stdin/out/err
|
|
|
|
|
var api *wasiAPI
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdPrestatDirName, ImportFdPrestatDirName, moduleName, func(a *wasiAPI) {
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdPrestatDirName, ImportFdPrestatDirName, moduleName, func(a *wasiAPI) {
|
|
|
|
|
a.opened[fd] = fileEntry{
|
|
|
|
|
path: "/tmp",
|
|
|
|
|
fileSys: &MemFS{},
|
|
|
|
|
}
|
|
|
|
|
api = a // for later tests
|
|
|
|
|
})
|
|
|
|
|
mem := mod.Memory("memory")
|
|
|
|
|
|
|
|
|
|
path := uint32(1) // arbitrary offset
|
|
|
|
|
pathLen := uint32(3) // shorter than len("/tmp") to test the path is written for the length of pathLen
|
|
|
|
|
@@ -735,7 +734,7 @@ func TestSnapshotPreview1_FdPrestatDirName(t *testing.T) {
|
|
|
|
|
t.Run("SnapshotPreview1.FdPrestatDirName", func(t *testing.T) {
|
|
|
|
|
maskMemory(t, mem, len(expectedMemory))
|
|
|
|
|
|
|
|
|
|
errno := api.FdPrestatDirName(mod.Instance.Ctx, fd, path, pathLen)
|
|
|
|
|
errno := api.FdPrestatDirName(ctx(mem), fd, path, pathLen)
|
|
|
|
|
require.Equal(t, wasi.ErrnoSuccess, errno)
|
|
|
|
|
|
|
|
|
|
actual, ok := mem.Read(0, uint32(len(expectedMemory)))
|
|
|
|
|
@@ -759,9 +758,7 @@ func TestSnapshotPreview1_FdPrestatDirName(t *testing.T) {
|
|
|
|
|
func TestSnapshotPreview1_FdPrestatDirName_Errors(t *testing.T) {
|
|
|
|
|
dirName := "/tmp"
|
|
|
|
|
opt := Preopen(dirName, &MemFS{})
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdPrestatDirName, ImportFdPrestatDirName, moduleName, opt)
|
|
|
|
|
|
|
|
|
|
mem := mod.Memory("memory")
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdPrestatDirName, ImportFdPrestatDirName, moduleName, opt)
|
|
|
|
|
|
|
|
|
|
memorySize := mem.Size()
|
|
|
|
|
validAddress := uint32(0) // Arbitrary valid address as arguments to fd_prestat_dir_name. We chose 0 here.
|
|
|
|
|
@@ -817,10 +814,10 @@ func TestSnapshotPreview1_FdPrestatDirName_Errors(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdPwrite only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_FdPwrite(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdPwrite, ImportFdPwrite, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdPwrite, ImportFdPwrite, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.FdPwrite", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdPwrite(mod.Instance.Ctx, 0, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdPwrite(ctx(mem), 0, 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionFdPwrite, func(t *testing.T) {
|
|
|
|
|
@@ -854,12 +851,10 @@ func TestSnapshotPreview1_FdRead(t *testing.T) {
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var api *wasiAPI
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdRead, ImportFdRead, moduleName, func(a *wasiAPI) {
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdRead, ImportFdRead, moduleName, func(a *wasiAPI) {
|
|
|
|
|
api = a // for later tests
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
mem := mod.Memory("memory")
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdRead uses a matrix because setting up test files is complicated and has to be clean each time.
|
|
|
|
|
type fdReadFn func(ctx publicwasm.ModuleContext, fd, iovs, iovsCount, resultSize uint32) wasi.Errno
|
|
|
|
|
tests := []struct {
|
|
|
|
|
@@ -893,7 +888,7 @@ func TestSnapshotPreview1_FdRead(t *testing.T) {
|
|
|
|
|
ok := mem.Write(0, initialMemory)
|
|
|
|
|
require.True(t, ok)
|
|
|
|
|
|
|
|
|
|
errno := tc.fdRead()(mod.Instance.Ctx, fd, iovs, iovsCount, resultSize)
|
|
|
|
|
errno := tc.fdRead()(ctx(mem), fd, iovs, iovsCount, resultSize)
|
|
|
|
|
require.Equal(t, wasi.ErrnoSuccess, errno)
|
|
|
|
|
|
|
|
|
|
actual, ok := mem.Read(0, uint32(len(expectedMemory)))
|
|
|
|
|
@@ -906,7 +901,7 @@ func TestSnapshotPreview1_FdRead(t *testing.T) {
|
|
|
|
|
func TestSnapshotPreview1_FdRead_Errors(t *testing.T) {
|
|
|
|
|
validFD := uint64(3) // arbitrary valid fd after 0, 1, and 2, that are stdin/out/err
|
|
|
|
|
file, memFS := createFile(t, "test_path", []byte{}) // file with empty contents
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdRead, ImportFdRead, moduleName, func(a *wasiAPI) {
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdRead, ImportFdRead, moduleName, func(a *wasiAPI) {
|
|
|
|
|
a.opened[uint32(validFD)] = fileEntry{
|
|
|
|
|
path: "test_path",
|
|
|
|
|
fileSys: memFS,
|
|
|
|
|
@@ -914,8 +909,6 @@ func TestSnapshotPreview1_FdRead_Errors(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
mem := mod.Memory("memory")
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
fd, iovs, iovsCount, resultSize uint64
|
|
|
|
|
@@ -999,10 +992,10 @@ func TestSnapshotPreview1_FdRead_Errors(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdReaddir only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_FdReaddir(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdReaddir, ImportFdReaddir, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdReaddir, ImportFdReaddir, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.FdReaddir", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdReaddir(mod.Instance.Ctx, 0, 0, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdReaddir(ctx(mem), 0, 0, 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionFdReaddir, func(t *testing.T) {
|
|
|
|
|
@@ -1014,10 +1007,10 @@ func TestSnapshotPreview1_FdReaddir(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdRenumber only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_FdRenumber(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdRenumber, ImportFdRenumber, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdRenumber, ImportFdRenumber, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.FdRenumber", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdRenumber(mod.Instance.Ctx, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdRenumber(ctx(mem), 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionFdRenumber, func(t *testing.T) {
|
|
|
|
|
@@ -1029,10 +1022,10 @@ func TestSnapshotPreview1_FdRenumber(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdSeek only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_FdSeek(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdSeek, ImportFdSeek, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdSeek, ImportFdSeek, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.FdSeek", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdSeek(mod.Instance.Ctx, 0, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdSeek(ctx(mem), 0, 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionFdSeek, func(t *testing.T) {
|
|
|
|
|
@@ -1044,10 +1037,10 @@ func TestSnapshotPreview1_FdSeek(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdSync only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_FdSync(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdSync, ImportFdSync, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdSync, ImportFdSync, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.FdSync", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdSync(mod.Instance.Ctx, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdSync(ctx(mem), 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionFdSync, func(t *testing.T) {
|
|
|
|
|
@@ -1059,10 +1052,10 @@ func TestSnapshotPreview1_FdSync(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdTell only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_FdTell(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdTell, ImportFdTell, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdTell, ImportFdTell, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.FdTell", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdTell(mod.Instance.Ctx, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().FdTell(ctx(mem), 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionFdTell, func(t *testing.T) {
|
|
|
|
|
@@ -1096,12 +1089,10 @@ func TestSnapshotPreview1_FdWrite(t *testing.T) {
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var api *wasiAPI
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdWrite, ImportFdWrite, moduleName, func(a *wasiAPI) {
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdWrite, ImportFdWrite, moduleName, func(a *wasiAPI) {
|
|
|
|
|
api = a // for later tests
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
mem := mod.Memory("memory")
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_FdWrite uses a matrix because setting up test files is complicated and has to be clean each time.
|
|
|
|
|
type fdWriteFn func(ctx publicwasm.ModuleContext, fd, iovs, iovsCount, resultSize uint32) wasi.Errno
|
|
|
|
|
tests := []struct {
|
|
|
|
|
@@ -1134,7 +1125,7 @@ func TestSnapshotPreview1_FdWrite(t *testing.T) {
|
|
|
|
|
ok := mem.Write(0, initialMemory)
|
|
|
|
|
require.True(t, ok)
|
|
|
|
|
|
|
|
|
|
errno := tc.fdWrite()(mod.Instance.Ctx, fd, iovs, iovsCount, resultSize)
|
|
|
|
|
errno := tc.fdWrite()(ctx(mem), fd, iovs, iovsCount, resultSize)
|
|
|
|
|
require.Equal(t, wasi.ErrnoSuccess, errno)
|
|
|
|
|
|
|
|
|
|
actual, ok := mem.Read(0, uint32(len(expectedMemory)))
|
|
|
|
|
@@ -1148,7 +1139,7 @@ func TestSnapshotPreview1_FdWrite(t *testing.T) {
|
|
|
|
|
func TestSnapshotPreview1_FdWrite_Errors(t *testing.T) {
|
|
|
|
|
validFD := uint64(3) // arbitrary valid fd after 0, 1, and 2, that are stdin/out/err
|
|
|
|
|
file, memFS := createFile(t, "test_path", []byte{}) // file with empty contents
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionFdWrite, ImportFdWrite, moduleName, func(a *wasiAPI) {
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionFdWrite, ImportFdWrite, moduleName, func(a *wasiAPI) {
|
|
|
|
|
a.opened[uint32(validFD)] = fileEntry{
|
|
|
|
|
path: "test_path",
|
|
|
|
|
fileSys: memFS,
|
|
|
|
|
@@ -1156,8 +1147,6 @@ func TestSnapshotPreview1_FdWrite_Errors(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
mem := mod.Memory("memory")
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
fd, iovs, iovsCount, resultSize uint64
|
|
|
|
|
@@ -1253,10 +1242,10 @@ func createFile(t *testing.T, path string, contents []byte) (*memFile, *MemFS) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_PathCreateDirectory only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_PathCreateDirectory(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionPathCreateDirectory, ImportPathCreateDirectory, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionPathCreateDirectory, ImportPathCreateDirectory, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.PathCreateDirectory", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathCreateDirectory(mod.Instance.Ctx, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathCreateDirectory(ctx(mem), 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionPathCreateDirectory, func(t *testing.T) {
|
|
|
|
|
@@ -1268,10 +1257,10 @@ func TestSnapshotPreview1_PathCreateDirectory(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_PathFilestatGet only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_PathFilestatGet(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionPathFilestatGet, ImportPathFilestatGet, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionPathFilestatGet, ImportPathFilestatGet, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.PathFilestatGet", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathFilestatGet(mod.Instance.Ctx, 0, 0, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathFilestatGet(ctx(mem), 0, 0, 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionPathFilestatGet, func(t *testing.T) {
|
|
|
|
|
@@ -1283,10 +1272,10 @@ func TestSnapshotPreview1_PathFilestatGet(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_PathFilestatSetTimes only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_PathFilestatSetTimes(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionPathFilestatSetTimes, ImportPathFilestatSetTimes, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionPathFilestatSetTimes, ImportPathFilestatSetTimes, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.PathFilestatSetTimes", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathFilestatSetTimes(mod.Instance.Ctx, 0, 0, 0, 0, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathFilestatSetTimes(ctx(mem), 0, 0, 0, 0, 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionPathFilestatSetTimes, func(t *testing.T) {
|
|
|
|
|
@@ -1298,10 +1287,10 @@ func TestSnapshotPreview1_PathFilestatSetTimes(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_PathLink only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_PathLink(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionPathLink, ImportPathLink, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionPathLink, ImportPathLink, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.PathLink", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathLink(mod.Instance.Ctx, 0, 0, 0, 0, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathLink(ctx(mem), 0, 0, 0, 0, 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionPathLink, func(t *testing.T) {
|
|
|
|
|
@@ -1315,10 +1304,10 @@ func TestSnapshotPreview1_PathLink(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_PathReadlink only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_PathReadlink(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionPathReadlink, ImportPathReadlink, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionPathReadlink, ImportPathReadlink, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.PathLink", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathReadlink(mod.Instance.Ctx, 0, 0, 0, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathReadlink(ctx(mem), 0, 0, 0, 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionPathReadlink, func(t *testing.T) {
|
|
|
|
|
@@ -1330,10 +1319,10 @@ func TestSnapshotPreview1_PathReadlink(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_PathRemoveDirectory only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_PathRemoveDirectory(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionPathRemoveDirectory, ImportPathRemoveDirectory, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionPathRemoveDirectory, ImportPathRemoveDirectory, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.PathRemoveDirectory", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathRemoveDirectory(mod.Instance.Ctx, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathRemoveDirectory(ctx(mem), 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionPathRemoveDirectory, func(t *testing.T) {
|
|
|
|
|
@@ -1345,10 +1334,10 @@ func TestSnapshotPreview1_PathRemoveDirectory(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_PathRename only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_PathRename(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionPathRename, ImportPathRename, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionPathRename, ImportPathRename, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.PathRename", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathRename(mod.Instance.Ctx, 0, 0, 0, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathRename(ctx(mem), 0, 0, 0, 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionPathRename, func(t *testing.T) {
|
|
|
|
|
@@ -1360,10 +1349,10 @@ func TestSnapshotPreview1_PathRename(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_PathSymlink only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_PathSymlink(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionPathSymlink, ImportPathSymlink, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionPathSymlink, ImportPathSymlink, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.PathSymlink", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathSymlink(mod.Instance.Ctx, 0, 0, 0, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathSymlink(ctx(mem), 0, 0, 0, 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionPathSymlink, func(t *testing.T) {
|
|
|
|
|
@@ -1375,10 +1364,10 @@ func TestSnapshotPreview1_PathSymlink(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_PathUnlinkFile only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_PathUnlinkFile(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionPathUnlinkFile, ImportPathUnlinkFile, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionPathUnlinkFile, ImportPathUnlinkFile, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.PathUnlinkFile", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathUnlinkFile(mod.Instance.Ctx, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PathUnlinkFile(ctx(mem), 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionPathUnlinkFile, func(t *testing.T) {
|
|
|
|
|
@@ -1390,10 +1379,10 @@ func TestSnapshotPreview1_PathUnlinkFile(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_PollOneoff only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_PollOneoff(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionPollOneoff, ImportPollOneoff, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionPollOneoff, ImportPollOneoff, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.PollOneoff", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PollOneoff(mod.Instance.Ctx, 0, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().PollOneoff(ctx(mem), 0, 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionPollOneoff, func(t *testing.T) {
|
|
|
|
|
@@ -1436,10 +1425,10 @@ func TestSnapshotPreview1_ProcExit(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_ProcRaise only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_ProcRaise(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionProcRaise, ImportProcRaise, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionProcRaise, ImportProcRaise, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.ProcRaise", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().ProcRaise(mod.Instance.Ctx, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().ProcRaise(ctx(mem), 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionProcRaise, func(t *testing.T) {
|
|
|
|
|
@@ -1451,10 +1440,10 @@ func TestSnapshotPreview1_ProcRaise(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_SchedYield only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_SchedYield(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionSchedYield, ImportSchedYield, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionSchedYield, ImportSchedYield, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.SchedYield", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().SchedYield(mod.Instance.Ctx))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().SchedYield(ctx(mem)))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionSchedYield, func(t *testing.T) {
|
|
|
|
|
@@ -1485,13 +1474,12 @@ func TestSnapshotPreview1_RandomGet(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionRandomGet, ImportRandomGet, moduleName, randOpt)
|
|
|
|
|
mem := mod.Memory("memory")
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionRandomGet, ImportRandomGet, moduleName, randOpt)
|
|
|
|
|
t.Run("SnapshotPreview1.RandomGet", func(t *testing.T) {
|
|
|
|
|
maskMemory(t, mem, len(expectedMemory))
|
|
|
|
|
|
|
|
|
|
// Invoke RandomGet directly and check the memory side effects!
|
|
|
|
|
errno := NewAPI(randOpt).RandomGet(mod.Instance.Ctx, offset, length)
|
|
|
|
|
errno := NewAPI(randOpt).RandomGet(ctx(mem), offset, length)
|
|
|
|
|
require.Equal(t, wasi.ErrnoSuccess, errno)
|
|
|
|
|
|
|
|
|
|
actual, ok := mem.Read(0, offset+length+1)
|
|
|
|
|
@@ -1515,8 +1503,8 @@ func TestSnapshotPreview1_RandomGet(t *testing.T) {
|
|
|
|
|
func TestSnapshotPreview1_RandomGet_Errors(t *testing.T) {
|
|
|
|
|
validAddress := uint32(0) // arbitrary valid address
|
|
|
|
|
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionRandomGet, ImportRandomGet, moduleName)
|
|
|
|
|
memorySize := mod.Memory("memory").Size()
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionRandomGet, ImportRandomGet, moduleName)
|
|
|
|
|
memorySize := mem.Size()
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
@@ -1561,10 +1549,10 @@ func TestSnapshotPreview1_RandomGet_SourceError(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_SockRecv only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_SockRecv(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionSockRecv, ImportSockRecv, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionSockRecv, ImportSockRecv, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.SockRecv", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().SockRecv(mod.Instance.Ctx, 0, 0, 0, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().SockRecv(ctx(mem), 0, 0, 0, 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionSockRecv, func(t *testing.T) {
|
|
|
|
|
@@ -1576,10 +1564,10 @@ func TestSnapshotPreview1_SockRecv(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_SockSend only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_SockSend(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionSockSend, ImportSockSend, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionSockSend, ImportSockSend, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.SockSend", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().SockSend(mod.Instance.Ctx, 0, 0, 0, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().SockSend(ctx(mem), 0, 0, 0, 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionSockSend, func(t *testing.T) {
|
|
|
|
|
@@ -1591,10 +1579,10 @@ func TestSnapshotPreview1_SockSend(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// TestSnapshotPreview1_SockShutdown only tests it is stubbed for GrainLang per #271
|
|
|
|
|
func TestSnapshotPreview1_SockShutdown(t *testing.T) {
|
|
|
|
|
mod, fn := instantiateModule(t, FunctionSockShutdown, ImportSockShutdown, moduleName)
|
|
|
|
|
mem, fn := instantiateModule(t, FunctionSockShutdown, ImportSockShutdown, moduleName)
|
|
|
|
|
|
|
|
|
|
t.Run("SnapshotPreview1.SockShutdown", func(t *testing.T) {
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().SockShutdown(mod.Instance.Ctx, 0, 0))
|
|
|
|
|
require.Equal(t, wasi.ErrnoNosys, NewAPI().SockShutdown(ctx(mem), 0, 0))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run(FunctionSockShutdown, func(t *testing.T) {
|
|
|
|
|
@@ -1606,9 +1594,9 @@ func TestSnapshotPreview1_SockShutdown(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
const testMemoryPageSize = 1
|
|
|
|
|
|
|
|
|
|
func instantiateModule(t *testing.T, wasiFunction, wasiImport, moduleName string, opts ...Option) (*wasm.PublicModule, publicwasm.Function) {
|
|
|
|
|
func instantiateModule(t *testing.T, wasiFunction, wasiImport, moduleName string, opts ...Option) (publicwasm.Memory, publicwasm.Function) {
|
|
|
|
|
enabledFeatures := wasm.Features20191205
|
|
|
|
|
mod, err := text.DecodeModule([]byte(fmt.Sprintf(`(module
|
|
|
|
|
mem, err := text.DecodeModule([]byte(fmt.Sprintf(`(module
|
|
|
|
|
%[2]s
|
|
|
|
|
(memory 1) ;; just an arbitrary size big enough for tests
|
|
|
|
|
(export "memory" (memory 0))
|
|
|
|
|
@@ -1616,18 +1604,18 @@ func instantiateModule(t *testing.T, wasiFunction, wasiImport, moduleName string
|
|
|
|
|
)`, wasiFunction, wasiImport)), enabledFeatures)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
// The package `wazero` has a simpler interface for adding host modules, but we can't use that as it would create an
|
|
|
|
|
// import cycle. Instead, we export Store.NewHostModule and use it here.
|
|
|
|
|
store := wasm.NewStore(context.Background(), interpreter.NewEngine(), enabledFeatures)
|
|
|
|
|
|
|
|
|
|
snapshotPreview1Functions := SnapshotPreview1Functions(opts...)
|
|
|
|
|
_, err = store.NewHostModule(wasi.ModuleSnapshotPreview1, snapshotPreview1Functions)
|
|
|
|
|
_, err = store.NewHostModule(wasi.ModuleSnapshotPreview1, SnapshotPreview1Functions(opts...))
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
instantiated, err := store.Instantiate(mod, moduleName)
|
|
|
|
|
instantiated, err := store.Instantiate(mem, moduleName)
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
|
|
fn := instantiated.Function(wasiFunction)
|
|
|
|
|
require.NotNil(t, fn)
|
|
|
|
|
return instantiated, fn
|
|
|
|
|
return instantiated.Memory("memory"), fn
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// maskMemory sets the first memory in the store to '?' * size, so tests can see what's written.
|
|
|
|
|
|