Skip to content

Commit bc0915e

Browse files
authored
integration test: adds memmov regression tests (#2203)
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
1 parent 3403dd3 commit bc0915e

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

internal/integration_test/engine/adhoc_test.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,35 @@ func testHugeStack(t *testing.T, r wazero.Runtime) {
253253
require.NoError(t, module.Close(testCtx))
254254
}()
255255

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

259-
res, err := fn.Call(testCtx, 0, 0, 0, 0, 0, 0) // params ignored by wasm
260-
require.NoError(t, err)
264+
t.Run("main", func(t *testing.T) {
265+
fn := module.ExportedFunction("main")
266+
require.NotNil(t, fn)
267+
res, err := fn.Call(testCtx, 0, 0, 0, 0, 0, 0) // params ignored by wasm
268+
require.NoError(t, err)
269+
verifyResult(t, res)
270+
})
261271

262-
const resultNumInUint64 = 180
263-
require.Equal(t, resultNumInUint64, len(res))
264-
for i := uint64(1); i <= resultNumInUint64; i++ {
265-
require.Equal(t, i, res[i-1])
266-
}
272+
t.Run("memory_fill_after_main", func(t *testing.T) {
273+
fn := module.ExportedFunction("memory_fill_after_main")
274+
require.NotNil(t, fn)
275+
for _, offset := range []uint64{0, 2, 4, 8, 16, 32, 48, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768} {
276+
for _, size := range []uint64{0, 2, 4, 8, 16, 32, 48, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384} {
277+
t.Run(fmt.Sprintf("offset=%d,size=%d", offset, size), func(t *testing.T) {
278+
res, err := fn.Call(testCtx, offset, 0xff, size)
279+
require.NoError(t, err)
280+
verifyResult(t, res)
281+
})
282+
}
283+
}
284+
})
267285
}
268286

269287
// testOverflow ensures that adding one into the maximum integer results in the
Binary file not shown.

internal/integration_test/engine/testdata/hugestack.wat

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(module
22
(func (export "main")
3-
(param f32 v128 i32 f64 i64) ;; unused params -> wazeroir always emits the drop operation on this.
3+
(param f32 v128 i32 f64 i64)
44
(result
55
;; 180 results (in terms of uint64 representations) which use up all all the possible unreserved registers
66
;; of both general purpose and vector types on the function return.
@@ -39,4 +39,33 @@
3939
(f64.const 8.84e-322) ;; math.Float64frombits(179)
4040
(f64.const 8.9e-322) ;; math.Float64frombits(180)
4141
)
42+
(func (export "memory_fill_after_main") (param i32 i32 i32)
43+
(result
44+
;; 180 results (in terms of uint64 representations) which use up all all the possible unreserved registers
45+
;; of both general purpose and vector types on the function return.
46+
v128 f64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 ;; 20
47+
v128 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 ;; 40
48+
i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 ;; 60
49+
i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 ;; 80
50+
i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 f64 v128 ;; 100
51+
v128 v128 v128 v128 v128 v128 v128 v128 v128 v128 ;; 120
52+
v128 v128 v128 v128 v128 v128 v128 v128 v128 v128 ;; 140
53+
v128 v128 v128 v128 v128 v128 v128 v128 v128 v128 ;; 160
54+
v128 v128 v128 v128 v128 v128 v128 v128 v128 f64 f64 ;; 180
55+
)
56+
f32.const 0
57+
v128.const i64x2 0 0
58+
i32.const 0
59+
f64.const 0
60+
i64.const 0
61+
call 0
62+
;; Call memory.fill with params. memory.fill/copy internally calls the Go runtime's runtime.memmove,
63+
;; which has a slightly tricky calling convention. This ensures that across the call to memory.fill
64+
;; the registers are preserved. https://github.com/tetratelabs/wazero/pull/2202
65+
local.get 0
66+
local.get 1
67+
local.get 2
68+
memory.fill
69+
)
70+
(memory 1)
4271
)

0 commit comments

Comments
 (0)