github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/engine/wazevo/backend/go_call_test.go (about)

     1  package backend
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/tetratelabs/wazero/internal/engine/wazevo/ssa"
     7  	"github.com/tetratelabs/wazero/internal/testing/require"
     8  )
     9  
    10  func Test_goFunctionCallRequiredStackSize(t *testing.T) {
    11  	for _, tc := range []struct {
    12  		name     string
    13  		sig      *ssa.Signature
    14  		argBegin int
    15  		exp      int64
    16  	}{
    17  		{
    18  			name: "no param",
    19  			sig:  &ssa.Signature{},
    20  			exp:  0,
    21  		},
    22  		{
    23  			name: "only param",
    24  			sig:  &ssa.Signature{Params: []ssa.Type{ssa.TypeI64, ssa.TypeV128}},
    25  			exp:  32,
    26  		},
    27  		{
    28  			name: "only result",
    29  			sig:  &ssa.Signature{Results: []ssa.Type{ssa.TypeI64, ssa.TypeV128, ssa.TypeI32}},
    30  			exp:  32,
    31  		},
    32  		{
    33  			name: "param < result",
    34  			sig:  &ssa.Signature{Params: []ssa.Type{ssa.TypeI64, ssa.TypeV128}, Results: []ssa.Type{ssa.TypeI64, ssa.TypeV128, ssa.TypeI32}},
    35  			exp:  32,
    36  		},
    37  		{
    38  			name: "param > result",
    39  			sig:  &ssa.Signature{Params: []ssa.Type{ssa.TypeI64, ssa.TypeV128, ssa.TypeI32}, Results: []ssa.Type{ssa.TypeI64, ssa.TypeV128}},
    40  			exp:  32,
    41  		},
    42  		{
    43  			name:     "param < result / argBegin=2",
    44  			argBegin: 2,
    45  			sig:      &ssa.Signature{Params: []ssa.Type{ssa.TypeI64, ssa.TypeV128, ssa.TypeI32}, Results: []ssa.Type{ssa.TypeI64, ssa.TypeF64}},
    46  			exp:      16,
    47  		},
    48  	} {
    49  		tc := tc
    50  		t.Run(tc.name, func(t *testing.T) {
    51  			requiredSize, _ := GoFunctionCallRequiredStackSize(tc.sig, tc.argBegin)
    52  			require.Equal(t, tc.exp, requiredSize)
    53  		})
    54  	}
    55  }