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 b25e7fe9e1..bb6360aa83 100644 Binary files a/internal/integration_test/engine/testdata/hugestack.wasm and b/internal/integration_test/engine/testdata/hugestack.wasm differ diff --git a/internal/integration_test/engine/testdata/hugestack.wat b/internal/integration_test/engine/testdata/hugestack.wat index 46efac0535..841d1f7752 100644 --- a/internal/integration_test/engine/testdata/hugestack.wat +++ b/internal/integration_test/engine/testdata/hugestack.wat @@ -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. @@ -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) )