From bc0915e051699a2485fb4c84ea7cfff9839f4b9c Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 7 May 2024 14:51:21 +0900 Subject: [PATCH] integration test: adds memmov regression tests (#2203) Signed-off-by: Takeshi Yoneda --- .../integration_test/engine/adhoc_test.go | 36 +++++++++++++----- .../engine/testdata/hugestack.wasm | Bin 1191 -> 1417 bytes .../engine/testdata/hugestack.wat | 31 ++++++++++++++- 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/internal/integration_test/engine/adhoc_test.go b/internal/integration_test/engine/adhoc_test.go index 624afda17b..770362b6ed 100644 --- a/internal/integration_test/engine/adhoc_test.go +++ b/internal/integration_test/engine/adhoc_test.go @@ -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 diff --git a/internal/integration_test/engine/testdata/hugestack.wasm b/internal/integration_test/engine/testdata/hugestack.wasm index b25e7fe9e17fb94e2bd30ff3ee489444135908eb..bb6360aa83b2c2a112367871722b81d6122bc7c6 100644 GIT binary patch delta 133 zcmZ3^*~!hrkXW3{$iTqBxRi-$BF|*j1m^ns`ia852Fy$hjI7Lz42 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. @@ -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) )