Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integration test: adds memmov regression tests #2203

Merged
merged 2 commits into from
May 7, 2024
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
36 changes: 27 additions & 9 deletions internal/integration_test/engine/adhoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,35 @@ func testHugeStack(t *testing.T, r wazero.Runtime) {
require.NoError(t, module.Close(testCtx))
}()

fn := module.ExportedFunction("main")
require.NotNil(t, fn)
verifyResult := func(t *testing.T, res []uint64) {
const resultNumInUint64 = 180
require.Equal(t, resultNumInUint64, len(res))
for i := uint64(1); i <= resultNumInUint64; i++ {
require.Equal(t, i, res[i-1])
}
}

res, err := fn.Call(testCtx, 0, 0, 0, 0, 0, 0) // params ignored by wasm
require.NoError(t, err)
t.Run("main", func(t *testing.T) {
fn := module.ExportedFunction("main")
require.NotNil(t, fn)
res, err := fn.Call(testCtx, 0, 0, 0, 0, 0, 0) // params ignored by wasm
require.NoError(t, err)
verifyResult(t, res)
})

const resultNumInUint64 = 180
require.Equal(t, resultNumInUint64, len(res))
for i := uint64(1); i <= resultNumInUint64; i++ {
require.Equal(t, i, res[i-1])
}
t.Run("memory_fill_after_main", func(t *testing.T) {
fn := module.ExportedFunction("memory_fill_after_main")
require.NotNil(t, fn)
for _, offset := range []uint64{0, 2, 4, 8, 16, 32, 48, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768} {
for _, size := range []uint64{0, 2, 4, 8, 16, 32, 48, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384} {
t.Run(fmt.Sprintf("offset=%d,size=%d", offset, size), func(t *testing.T) {
res, err := fn.Call(testCtx, offset, 0xff, size)
require.NoError(t, err)
verifyResult(t, res)
})
}
}
})
}

// testOverflow ensures that adding one into the maximum integer results in the
Expand Down
Binary file modified internal/integration_test/engine/testdata/hugestack.wasm
Binary file not shown.
31 changes: 30 additions & 1 deletion internal/integration_test/engine/testdata/hugestack.wat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(module
(func (export "main")
(param f32 v128 i32 f64 i64) ;; unused params -> wazeroir always emits the drop operation on this.
(param f32 v128 i32 f64 i64)
(result
;; 180 results (in terms of uint64 representations) which use up all all the possible unreserved registers
;; of both general purpose and vector types on the function return.
Expand Down Expand Up @@ -39,4 +39,33 @@
(f64.const 8.84e-322) ;; math.Float64frombits(179)
(f64.const 8.9e-322) ;; math.Float64frombits(180)
)
(func (export "memory_fill_after_main") (param i32 i32 i32)
(result
;; 180 results (in terms of uint64 representations) which use up all all the possible unreserved registers
;; of both general purpose and vector types on the function return.
v128 f64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 ;; 20
v128 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 ;; 40
i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 ;; 60
i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 ;; 80
i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 f64 v128 ;; 100
v128 v128 v128 v128 v128 v128 v128 v128 v128 v128 ;; 120
v128 v128 v128 v128 v128 v128 v128 v128 v128 v128 ;; 140
v128 v128 v128 v128 v128 v128 v128 v128 v128 v128 ;; 160
v128 v128 v128 v128 v128 v128 v128 v128 v128 f64 f64 ;; 180
)
f32.const 0
v128.const i64x2 0 0
i32.const 0
f64.const 0
i64.const 0
call 0
;; Call memory.fill with params. memory.fill/copy internally calls the Go runtime's runtime.memmove,
;; which has a slightly tricky calling convention. This ensures that across the call to memory.fill
;; the registers are preserved. https://github.com/tetratelabs/wazero/pull/2202
local.get 0
local.get 1
local.get 2
memory.fill
)
(memory 1)
)
Loading