Use correct pattern for table tests everywhere (#582)

Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
This commit is contained in:
Anuraag Agrawal
2022-05-20 16:55:01 +09:00
committed by GitHub
parent 7794530d01
commit ec3ada35a0
28 changed files with 636 additions and 332 deletions

View File

@@ -29,7 +29,7 @@ func TestNodeImpl_AssignSourceConstant(t *testing.T) {
}
func TestNodeImpl_String(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
in *NodeImpl
exp string
}{
@@ -101,7 +101,10 @@ func TestNodeImpl_String(t *testing.T) {
in: &NodeImpl{Instruction: MOVQ, Types: OperandTypesConstToRegister, SrcConst: 123, DstReg: REG_AX},
exp: "MOVQ 0x7b, AX",
},
} {
}
for _, tt := range tests {
tc := tt
require.Equal(t, tc.exp, tc.in.String())
}
}
@@ -142,7 +145,7 @@ func TestAssemblerImpl_encodeNode(t *testing.T) {
}
func TestAssemblerImpl_padNOP(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
num int
expected []byte
}{
@@ -164,8 +167,10 @@ func TestAssemblerImpl_padNOP(t *testing.T) {
{num: 16, expected: append(nopOpcodes[8][:9], nopOpcodes[6][:7]...)},
{num: 17, expected: append(nopOpcodes[8][:9], nopOpcodes[7][:8]...)},
{num: 18, expected: append(nopOpcodes[8][:9], nopOpcodes[8][:9]...)},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(strconv.Itoa(tc.num), func(t *testing.T) {
a := NewAssemblerImpl()
a.padNOP(tc.num)
@@ -358,7 +363,7 @@ func TestAssemblerImpl_CompileMemoryToConst(t *testing.T) {
}
func TestAssemblerImpl_encodeNoneToNone(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
inst asm.Instruction
exp []byte
expErr bool
@@ -368,8 +373,10 @@ func TestAssemblerImpl_encodeNoneToNone(t *testing.T) {
{inst: CQO, exp: []byte{0x48, 0x99}},
{inst: NOP, exp: nil},
{inst: RET, exp: []byte{0xc3}},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(InstructionName(tc.inst), func(t *testing.T) {
a := NewAssemblerImpl()
err := a.encodeNoneToNone(&NodeImpl{Instruction: tc.inst, Types: OperandTypesNoneToNone})
@@ -385,7 +392,7 @@ func TestAssemblerImpl_encodeNoneToNone(t *testing.T) {
func TestAssemblerImpl_EncodeMemoryToRegister(t *testing.T) {
// These are not supported by golang-asm, so we test here instead of integration tests.
for _, tc := range []struct {
tests := []struct {
n *NodeImpl
exp []byte
}{
@@ -409,8 +416,10 @@ func TestAssemblerImpl_EncodeMemoryToRegister(t *testing.T) {
},
exp: []byte{0xf3, 0x41, 0xf, 0x6f, 0x5d, 0xa},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.n.String(), func(t *testing.T) {
a := NewAssemblerImpl()
err := a.EncodeMemoryToRegister(tc.n)
@@ -426,7 +435,7 @@ func TestAssemblerImpl_EncodeMemoryToRegister(t *testing.T) {
func TestAssemblerImpl_EncodeRegisterToMemory(t *testing.T) {
// These are not supported by golang-asm, so we test here instead of integration tests.
for _, tc := range []struct {
tests := []struct {
n *NodeImpl
exp []byte
}{
@@ -450,8 +459,10 @@ func TestAssemblerImpl_EncodeRegisterToMemory(t *testing.T) {
},
exp: []byte{0xf3, 0x41, 0xf, 0x7f, 0x5d, 0x0},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.n.String(), func(t *testing.T) {
a := NewAssemblerImpl()
err := a.EncodeRegisterToMemory(tc.n)
@@ -467,7 +478,7 @@ func TestAssemblerImpl_EncodeRegisterToMemory(t *testing.T) {
func TestAssemblerImpl_EncodeRegisterToRegister(t *testing.T) {
// These are not supported by golang-asm, so we test here instead of integration tests.
for _, tc := range []struct {
tests := []struct {
n *NodeImpl
exp []byte
}{
@@ -498,8 +509,10 @@ func TestAssemblerImpl_EncodeRegisterToRegister(t *testing.T) {
},
exp: []byte{0xf3, 0x45, 0xf, 0x6f, 0xfa},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.n.String(), func(t *testing.T) {
a := NewAssemblerImpl()
err := a.EncodeRegisterToRegister(tc.n)

View File

@@ -28,7 +28,7 @@ func TestNodeImpl_AssignSourceConstant(t *testing.T) {
}
func TestNodeImpl_String(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
in *NodeImpl
exp string
}{
@@ -126,7 +126,10 @@ func TestNodeImpl_String(t *testing.T) {
SrcReg: REG_V3, DstReg: REG_V29, VectorArrangement: VectorArrangement2D, VectorIndex: 1},
exp: "VCNT V3.V3, V29.V3",
},
} {
}
for _, tt := range tests {
tc := tt
require.Equal(t, tc.exp, tc.in.String())
}
}
@@ -432,7 +435,7 @@ func Test_CompileVectorRegisterToVectorRegister(t *testing.T) {
}
func Test_checkRegisterToRegisterType(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
src, dst asm.Register
requireSrcInt, requireDstInt bool
expErr string
@@ -456,7 +459,10 @@ func Test_checkRegisterToRegisterType(t *testing.T) {
{src: REG_V10, dst: REG_V30, requireSrcInt: true, requireDstInt: false, expErr: "src requires int register but got V10"},
{src: REG_V10, dst: REG_V30, requireSrcInt: true, requireDstInt: true, expErr: "src requires int register but got V10"},
{src: REG_V10, dst: REG_V30, requireSrcInt: false, requireDstInt: true, expErr: "dst requires int register but got V30"},
} {
}
for _, tt := range tests {
tc := tt
actual := checkRegisterToRegisterType(tc.src, tc.dst, tc.requireSrcInt, tc.requireDstInt)
if tc.expErr != "" {
require.EqualError(t, actual, tc.expErr)
@@ -467,14 +473,17 @@ func Test_checkRegisterToRegisterType(t *testing.T) {
}
func Test_validateMemoryOffset(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
offset int64
expErr string
}{
{offset: 0}, {offset: -256}, {offset: 255}, {offset: 123 * 8},
{offset: -257, expErr: "negative memory offset must be larget than or equal -256 but got -257"},
{offset: 257, expErr: "large memory offset (>255) must be a multiple of 8 but got 257"},
} {
}
for _, tt := range tests {
tc := tt
actual := validateMemoryOffset(tc.offset)
if tc.expErr == "" {
require.NoError(t, actual)
@@ -486,7 +495,7 @@ func Test_validateMemoryOffset(t *testing.T) {
func TestAssemblerImpl_EncodeVectorRegisterToVectorRegister(t *testing.T) {
x1, x2 := REG_V2, REG_V10
for _, tc := range []struct {
tests := []struct {
inst asm.Instruction
exp []byte
}{
@@ -497,8 +506,10 @@ func TestAssemblerImpl_EncodeVectorRegisterToVectorRegister(t *testing.T) {
{inst: VFADDS, exp: []byte{
0x4a, 0xd4, 0x2a, 0x4e, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
}},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(InstructionName(tc.inst), func(t *testing.T) {
a := NewAssemblerImpl(asm.NilRegister)
err := a.EncodeVectorRegisterToVectorRegister(&NodeImpl{

View File

@@ -67,7 +67,7 @@ func TestCompiler_compileBrIf(t *testing.T) {
thenBranchTarget := &wazeroir.BranchTargetDrop{Target: &wazeroir.BranchTarget{Label: &wazeroir.Label{Kind: wazeroir.LabelKindHeader, FrameID: 1}}}
elseBranchTarget := &wazeroir.BranchTargetDrop{Target: &wazeroir.BranchTarget{Label: &wazeroir.Label{Kind: wazeroir.LabelKindHeader, FrameID: 2}}}
for _, tc := range []struct {
tests := []struct {
name string
setupFunc func(t *testing.T, compiler compilerImpl, shouldGoElse bool)
}{
@@ -223,8 +223,10 @@ func TestCompiler_compileBrIf(t *testing.T) {
require.NoError(t, err)
},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
for _, shouldGoToElse := range []bool{false, true} {
shouldGoToElse := shouldGoToElse
@@ -308,7 +310,7 @@ func TestCompiler_compileBrTable(t *testing.T) {
}
}
for _, tc := range []struct {
tests := []struct {
name string
index int64
o *wazeroir.OperationBrTable
@@ -419,8 +421,10 @@ func TestCompiler_compileBrTable(t *testing.T) {
index: 4,
expectedValue: 5,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
env := newCompilerEnvironment()
compiler := env.requireNewCompiler(t, newCompiler, nil)

View File

@@ -140,7 +140,7 @@ func TestCompiler_compileExtend(t *testing.T) {
}
func TestCompiler_compileITruncFromF(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
outputType wazeroir.SignedInt
inputType wazeroir.Float
nonTrapping bool
@@ -161,8 +161,10 @@ func TestCompiler_compileITruncFromF(t *testing.T) {
{outputType: wazeroir.SignedUint32, inputType: wazeroir.Float64, nonTrapping: true},
{outputType: wazeroir.SignedUint64, inputType: wazeroir.Float32, nonTrapping: true},
{outputType: wazeroir.SignedUint64, inputType: wazeroir.Float64, nonTrapping: true},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(fmt.Sprintf("%s from %s (non-trapping=%v)", tc.outputType, tc.inputType, tc.nonTrapping), func(t *testing.T) {
for _, v := range []float64{
1.0, 100, -100, 1, -1, 100.01234124, -100.01234124, 200.12315,
@@ -366,7 +368,7 @@ func TestCompiler_compileITruncFromF(t *testing.T) {
}
func TestCompiler_compileFConvertFromI(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
inputType wazeroir.SignedInt
outputType wazeroir.Float
}{
@@ -378,8 +380,10 @@ func TestCompiler_compileFConvertFromI(t *testing.T) {
{inputType: wazeroir.SignedUint32, outputType: wazeroir.Float64},
{inputType: wazeroir.SignedUint64, outputType: wazeroir.Float32},
{inputType: wazeroir.SignedUint64, outputType: wazeroir.Float64},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(fmt.Sprintf("%s from %s", tc.outputType, tc.inputType), func(t *testing.T) {
for _, v := range []uint64{
0, 1, 12345, 1 << 31, 1 << 32, 1 << 54, 1 << 63,

View File

@@ -12,7 +12,7 @@ import (
)
func TestCompiler_compileModuleContextInitialization(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
moduleInstance *wasm.ModuleInstance
}{
@@ -101,8 +101,10 @@ func TestCompiler_compileModuleContextInitialization(t *testing.T) {
name: "all nil except mod engine",
moduleInstance: &wasm.ModuleInstance{},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
env := newCompilerEnvironment()
env.moduleInstance = tc.moduleInstance

View File

@@ -81,7 +81,7 @@ func TestCompiler_compileLoad(t *testing.T) {
arg := &wazeroir.MemoryImmediate{Offset: 361}
offset := baseOffset + arg.Offset
for _, tc := range []struct {
tests := []struct {
name string
isFloatTarget bool
operationSetupFn func(t *testing.T, compiler compilerImpl)
@@ -229,9 +229,10 @@ func TestCompiler_compileLoad(t *testing.T) {
require.Equal(t, uint64(uint32(loadedValueAsUint64)), loadedValueAsUint64)
},
},
} {
}
tc := tc
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
env := newCompilerEnvironment()
compiler := env.requireNewCompiler(t, newCompiler, &wazeroir.CompilationResult{HasMemory: true, Signature: &wasm.FunctionType{}})
@@ -279,7 +280,7 @@ func TestCompiler_compileStore(t *testing.T) {
arg := &wazeroir.MemoryImmediate{Offset: 361}
offset := arg.Offset + baseOffset
for _, tc := range []struct {
tests := []struct {
name string
isFloatTarget bool
targetSizeInBytes uint32
@@ -365,8 +366,10 @@ func TestCompiler_compileStore(t *testing.T) {
require.Equal(t, uint32(storeTargetValue), binary.LittleEndian.Uint32(mem[offset:]))
},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
env := newCompilerEnvironment()
compiler := env.requireNewCompiler(t, newCompiler, &wazeroir.CompilationResult{HasMemory: true, Signature: &wasm.FunctionType{}})

View File

@@ -824,7 +824,7 @@ func TestCompiler_compile_Clz_Ctz_Popcnt(t *testing.T) {
}
func TestCompiler_compile_Min_Max_Copysign(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
is32bit bool
setupFunc func(t *testing.T, compiler compilerImpl)
@@ -932,8 +932,10 @@ func TestCompiler_compile_Min_Max_Copysign(t *testing.T) {
}
},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
for _, vs := range [][2]float64{
{100, -1.1}, {100, 0}, {0, 0}, {1, 1},
@@ -1000,7 +1002,7 @@ func TestCompiler_compile_Min_Max_Copysign(t *testing.T) {
}
func TestCompiler_compile_Abs_Neg_Ceil_Floor_Trunc_Nearest_Sqrt(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
is32bit bool
setupFunc func(t *testing.T, compiler compilerImpl)
@@ -1244,8 +1246,10 @@ func TestCompiler_compile_Abs_Neg_Ceil_Floor_Trunc_Nearest_Sqrt(t *testing.T) {
}
},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
for _, v := range []float64{
0, 1 << 63, 1<<63 | 12345, 1 << 31,

View File

@@ -16,7 +16,7 @@ func TestCompiler_compileSignExtend(t *testing.T) {
from8, from16, from32 := fromKind(0), fromKind(1), fromKind(2)
t.Run("32bit", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
in int32
expected int32
fromKind fromKind
@@ -38,8 +38,10 @@ func TestCompiler_compileSignExtend(t *testing.T) {
{in: 0x0123_0000, expected: 0, fromKind: from16},
{in: -19103744 /* = 0xfedc_8000 bit pattern */, expected: -0x8000, fromKind: from16},
{in: -1, expected: -1, fromKind: from16},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(fmt.Sprintf("0x%x", tc.in), func(t *testing.T) {
env := newCompilerEnvironment()
compiler := env.requireNewCompiler(t, newCompiler, nil)
@@ -73,7 +75,7 @@ func TestCompiler_compileSignExtend(t *testing.T) {
}
})
t.Run("64bit", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
in int64
expected int64
fromKind fromKind
@@ -107,8 +109,10 @@ func TestCompiler_compileSignExtend(t *testing.T) {
{in: 0x01234567_00000000, expected: 0, fromKind: from32},
{in: -81985529054232576 /* = 0xfedcba98_80000000 bit pattern */, expected: -0x80000000, fromKind: from32},
{in: -1, expected: -1, fromKind: from32},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(fmt.Sprintf("0x%x", tc.in), func(t *testing.T) {
env := newCompilerEnvironment()
compiler := env.requireNewCompiler(t, newCompiler, nil)
@@ -147,7 +151,7 @@ func TestCompiler_compileSignExtend(t *testing.T) {
func TestCompiler_compileMemoryCopy(t *testing.T) {
const checkCeil = 100
for i, tc := range []struct {
tests := []struct {
sourceOffset, destOffset, size uint32
requireOutOfBoundsError bool
}{
@@ -179,8 +183,10 @@ func TestCompiler_compileMemoryCopy(t *testing.T) {
{sourceOffset: 0, destOffset: defaultMemoryPageNumInTest*wasm.MemoryPageSize + 1, size: 0, requireOutOfBoundsError: true},
{sourceOffset: defaultMemoryPageNumInTest*wasm.MemoryPageSize - 99, destOffset: 0, size: 100, requireOutOfBoundsError: true},
{sourceOffset: 0, destOffset: defaultMemoryPageNumInTest*wasm.MemoryPageSize - 99, size: 100, requireOutOfBoundsError: true},
} {
tc := tc
}
for i, tt := range tests {
tc := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
env := newCompilerEnvironment()
compiler := env.requireNewCompiler(t, newCompiler, &wazeroir.CompilationResult{HasMemory: true, Signature: &wasm.FunctionType{}})
@@ -235,7 +241,7 @@ func TestCompiler_compileMemoryCopy(t *testing.T) {
func TestCompiler_compileMemoryFill(t *testing.T) {
const checkCeil = 50
for i, tc := range []struct {
tests := []struct {
v, destOffset uint32
size uint32
requireOutOfBoundsError bool
@@ -256,8 +262,10 @@ func TestCompiler_compileMemoryFill(t *testing.T) {
{v: 10, destOffset: defaultMemoryPageNumInTest * wasm.MemoryPageSize, size: 5, requireOutOfBoundsError: true},
{v: 10, destOffset: defaultMemoryPageNumInTest * wasm.MemoryPageSize, size: 1, requireOutOfBoundsError: true},
{v: 10, destOffset: defaultMemoryPageNumInTest*wasm.MemoryPageSize + 1, size: 0, requireOutOfBoundsError: true},
} {
tc := tc
}
for i, tt := range tests {
tc := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
env := newCompilerEnvironment()
compiler := env.requireNewCompiler(t, newCompiler, &wazeroir.CompilationResult{HasMemory: true, Signature: &wasm.FunctionType{}})
@@ -362,7 +370,7 @@ func TestCompiler_compileMemoryInit(t *testing.T) {
nil, {1, 2, 3, 4, 5},
}
for i, tc := range []struct {
tests := []struct {
sourceOffset, destOffset uint32
dataIndex uint32
copySize uint32
@@ -389,8 +397,10 @@ func TestCompiler_compileMemoryInit(t *testing.T) {
{sourceOffset: 0, destOffset: defaultMemoryPageNumInTest * wasm.MemoryPageSize, copySize: 5, dataIndex: 1, expOutOfBounds: true},
{sourceOffset: 0, destOffset: defaultMemoryPageNumInTest*wasm.MemoryPageSize - 3, copySize: 5, dataIndex: 1, expOutOfBounds: true},
{sourceOffset: 6, destOffset: 0, copySize: 0, dataIndex: 1, expOutOfBounds: true},
} {
tc := tc
}
for i, tt := range tests {
tc := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
env := newCompilerEnvironment()
env.module().DataInstances = dataInstances
@@ -495,7 +505,7 @@ func TestCompiler_compileElemDrop(t *testing.T) {
func TestCompiler_compileTableCopy(t *testing.T) {
const tableSize = 100
for i, tc := range []struct {
tests := []struct {
sourceOffset, destOffset, size uint32
requireOutOfBoundsError bool
}{
@@ -527,8 +537,10 @@ func TestCompiler_compileTableCopy(t *testing.T) {
{sourceOffset: 0, destOffset: tableSize + 1, size: 0, requireOutOfBoundsError: true},
{sourceOffset: tableSize - 99, destOffset: 0, size: 100, requireOutOfBoundsError: true},
{sourceOffset: 0, destOffset: tableSize - 99, size: 100, requireOutOfBoundsError: true},
} {
tc := tc
}
for i, tt := range tests {
tc := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
env := newCompilerEnvironment()
compiler := env.requireNewCompiler(t, newCompiler, &wazeroir.CompilationResult{HasTable: true, Signature: &wasm.FunctionType{}})
@@ -587,7 +599,7 @@ func TestCompiler_compileTableInit(t *testing.T) {
}
const tableSize = 100
for i, tc := range []struct {
tests := []struct {
sourceOffset, destOffset uint32
elemIndex uint32
copySize uint32
@@ -612,8 +624,10 @@ func TestCompiler_compileTableInit(t *testing.T) {
{sourceOffset: 0, destOffset: 10, copySize: 5, elemIndex: 1},
{sourceOffset: 0, destOffset: 0, copySize: 6, elemIndex: 1, expOutOfBounds: true},
{sourceOffset: 6, destOffset: 0, copySize: 0, elemIndex: 1, expOutOfBounds: true},
} {
tc := tc
}
for i, tt := range tests {
tc := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
env := newCompilerEnvironment()
env.module().ElementInstances = elementInstances
@@ -683,7 +697,7 @@ func TestCompiler_compileTableSet(t *testing.T) {
funcrefTable := &wasm.TableInstance{Type: wasm.RefTypeFuncref, References: []wasm.Reference{0, 0, 0, 0, funcrefOpaque}}
tables := []*wasm.TableInstance{externTable, funcrefTable}
for _, tc := range []struct {
tests := []struct {
name string
tableIndex uint32
offset uint32
@@ -733,8 +747,10 @@ func TestCompiler_compileTableSet(t *testing.T) {
in: 0,
expError: true,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
env := newCompilerEnvironment()
@@ -820,7 +836,7 @@ func TestCompiler_compileTableGet(t *testing.T) {
{Type: wasm.RefTypeFuncref, References: []wasm.Reference{0, 0, 0, 0, funcrefOpaque}},
}
for _, tc := range []struct {
tests := []struct {
name string
tableIndex uint32
offset uint32
@@ -863,8 +879,10 @@ func TestCompiler_compileTableGet(t *testing.T) {
offset: 1000,
expError: true,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
env := newCompilerEnvironment()

View File

@@ -12,7 +12,7 @@ import (
func TestCompiler_releaseRegisterToStack(t *testing.T) {
const val = 10000
for _, tc := range []struct {
tests := []struct {
name string
stackPointer uint64
isFloat bool
@@ -21,8 +21,10 @@ func TestCompiler_releaseRegisterToStack(t *testing.T) {
{name: "float", stackPointer: 10, isFloat: true},
{name: "int-huge-height", stackPointer: math.MaxInt16 + 1, isFloat: false},
{name: "float-huge-height", stackPointer: math.MaxInt16 + 1, isFloat: true},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
env := newCompilerEnvironment()
@@ -74,7 +76,7 @@ func TestCompiler_releaseRegisterToStack(t *testing.T) {
func TestCompiler_compileLoadValueOnStackToRegister(t *testing.T) {
const val = 123
for _, tc := range []struct {
tests := []struct {
name string
stackPointer uint64
isFloat bool
@@ -83,8 +85,10 @@ func TestCompiler_compileLoadValueOnStackToRegister(t *testing.T) {
{name: "float", stackPointer: 10, isFloat: true},
{name: "int-huge-height", stackPointer: math.MaxInt16 + 1, isFloat: false},
{name: "float-huge-height", stackPointer: math.MaxInt16 + 1, isFloat: true},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
env := newCompilerEnvironment()
@@ -158,14 +162,16 @@ func TestCompiler_compilePick_v128(t *testing.T) {
const pickTargetLo, pickTargetHi uint64 = 12345, 6789
op := &wazeroir.OperationPick{Depth: 2, IsTargetVector: true}
for _, tc := range []struct {
tests := []struct {
name string
isPickTargetOnRegister bool
}{
{name: "target on register", isPickTargetOnRegister: false},
{name: "target on stack", isPickTargetOnRegister: true},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
env := newCompilerEnvironment()
compiler := env.requireNewCompiler(t, newCompiler, nil)
@@ -227,7 +233,7 @@ func TestCompiler_compilePick_v128(t *testing.T) {
func TestCompiler_compilePick(t *testing.T) {
const pickTargetValue uint64 = 12345
op := &wazeroir.OperationPick{Depth: 1}
for _, tc := range []struct {
tests := []struct {
name string
pickTargetSetupFunc func(compiler compilerImpl, ce *callEngine) error
isPickTargetFloat, isPickTargetOnRegister bool
@@ -270,8 +276,10 @@ func TestCompiler_compilePick(t *testing.T) {
isPickTargetFloat: false,
isPickTargetOnRegister: false,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
env := newCompilerEnvironment()
compiler := env.requireNewCompiler(t, newCompiler, nil)
@@ -466,7 +474,7 @@ func TestCompiler_compileSelect(t *testing.T) {
// And for each case, we have to test with
// three conditional value location: stack, gp register, conditional register.
// So in total we have 24 cases.
for i, tc := range []struct {
tests := []struct {
x1OnRegister, x2OnRegister bool
selectX1 bool
condlValueOnStack, condValueOnGPRegister, condValueOnCondRegister bool
@@ -498,7 +506,10 @@ func TestCompiler_compileSelect(t *testing.T) {
{x1OnRegister: false, x2OnRegister: true, selectX1: false, condValueOnCondRegister: true},
{x1OnRegister: false, x2OnRegister: false, selectX1: true, condValueOnCondRegister: true},
{x1OnRegister: false, x2OnRegister: false, selectX1: false, condValueOnCondRegister: true},
} {
}
for i, tt := range tests {
tc := tt
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
for _, vals := range [][2]uint64{
{1, 2}, {0, 1}, {1, 0},
@@ -589,15 +600,17 @@ func TestCompiler_compileSwap_v128(t *testing.T) {
const x1Lo, x1Hi uint64 = 100000, 200000
const x2Lo, x2Hi uint64 = 1, 2
for _, tc := range []struct {
tests := []struct {
x1OnRegister, x2OnRegister bool
}{
{x1OnRegister: true, x2OnRegister: true},
{x1OnRegister: true, x2OnRegister: false},
{x1OnRegister: false, x2OnRegister: true},
{x1OnRegister: false, x2OnRegister: false},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(fmt.Sprintf("x1_register=%v, x2_register=%v", tc.x1OnRegister, tc.x2OnRegister), func(t *testing.T) {
env := newCompilerEnvironment()
compiler := env.requireNewCompiler(t, newCompiler, nil)
@@ -657,7 +670,7 @@ func TestCompiler_compileSwap_v128(t *testing.T) {
func TestCompiler_compileSwap(t *testing.T) {
var x1Value, x2Value int64 = 100, 200
for i, tc := range []struct {
tests := []struct {
x1OnConditionalRegister, x1OnRegister, x2OnRegister bool
}{
{x1OnRegister: true, x2OnRegister: true},
@@ -667,7 +680,10 @@ func TestCompiler_compileSwap(t *testing.T) {
// x1 on conditional register
{x1OnConditionalRegister: true, x2OnRegister: false},
{x1OnConditionalRegister: true, x2OnRegister: true},
} {
}
for i, tt := range tests {
tc := tt
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
env := newCompilerEnvironment()
compiler := env.requireNewCompiler(t, newCompiler, nil)

View File

@@ -18,7 +18,7 @@ func TestAmd64Compiler_compile_Mul_Div_Rem(t *testing.T) {
kind := kind
t.Run(kind.String(), func(t *testing.T) {
t.Run("int32", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
x1Reg, x2Reg asm.Register
}{
@@ -62,8 +62,10 @@ func TestAmd64Compiler_compile_Mul_Div_Rem(t *testing.T) {
x1Reg: asm.NilRegister,
x2Reg: asm.NilRegister,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
env := newCompilerEnvironment()
@@ -141,7 +143,7 @@ func TestAmd64Compiler_compile_Mul_Div_Rem(t *testing.T) {
}
})
t.Run("int64", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
x1Reg, x2Reg asm.Register
}{
@@ -185,8 +187,10 @@ func TestAmd64Compiler_compile_Mul_Div_Rem(t *testing.T) {
x1Reg: asm.NilRegister,
x2Reg: asm.NilRegister,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
const x1Value uint64 = 1 << 35
const x2Value uint64 = 51

View File

@@ -119,7 +119,7 @@ func TestInterpreter_NonTrappingFloatToIntConversion(t *testing.T) {
_0x8000000000000000 := uint64(0x8000000000000000)
_0xffffffffffffffff := uint64(0xffffffffffffffff)
for _, tc := range []struct {
tests := []struct {
op wasm.OpcodeMisc
inputType wazeroir.Float
outputType wazeroir.SignedInt
@@ -257,8 +257,10 @@ func TestInterpreter_NonTrappingFloatToIntConversion(t *testing.T) {
0x0000000000000000, 0, 0, 0, 0,
},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(wasm.MiscInstructionName(tc.op), func(t *testing.T) {
in32bit := len(tc.input32bit) > 0
casenum := len(tc.input32bit)
@@ -325,7 +327,7 @@ func TestInterpreter_CallEngine_callNativeFunc_signExtend(t *testing.T) {
return
}
t.Run("32bit", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
in int32
expected int32
opcode wasm.Opcode
@@ -347,8 +349,10 @@ func TestInterpreter_CallEngine_callNativeFunc_signExtend(t *testing.T) {
{in: 0x0123_0000, expected: 0, opcode: wasm.OpcodeI32Extend16S},
{in: -19103744 /* = 0xfedc_8000 bit pattern */, expected: -0x8000, opcode: wasm.OpcodeI32Extend16S},
{in: -1, expected: -1, opcode: wasm.OpcodeI32Extend16S},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(fmt.Sprintf("%s(i32.const(0x%x))", wasm.InstructionName(tc.opcode), tc.in), func(t *testing.T) {
ce := &callEngine{}
f := &function{
@@ -365,7 +369,7 @@ func TestInterpreter_CallEngine_callNativeFunc_signExtend(t *testing.T) {
}
})
t.Run("64bit", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
in int64
expected int64
opcode wasm.Opcode
@@ -399,8 +403,10 @@ func TestInterpreter_CallEngine_callNativeFunc_signExtend(t *testing.T) {
{in: 0x01234567_00000000, expected: 0, opcode: wasm.OpcodeI64Extend32S},
{in: -81985529054232576 /* = 0xfedcba98_80000000 bit pattern */, expected: -0x80000000, opcode: wasm.OpcodeI64Extend32S},
{in: -1, expected: -1, opcode: wasm.OpcodeI64Extend32S},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(fmt.Sprintf("%s(i64.const(0x%x))", wasm.InstructionName(tc.opcode), tc.in), func(t *testing.T) {
ce := &callEngine{}
f := &function{

View File

@@ -80,7 +80,7 @@ func TestAssemblerImpl_Assemble(t *testing.T) {
func TestAssemblerImpl_Assemble_NOPPadding(t *testing.T) {
t.Run("non relative jumps", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
setupFn func(assembler amd64.Assembler)
}{
@@ -116,8 +116,10 @@ func TestAssemblerImpl_Assemble_NOPPadding(t *testing.T) {
}
},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
// TODO: remove golang-asm dependency in tests.
goasm, err := newGolangAsmAssembler()
@@ -183,7 +185,7 @@ func TestAssemblerImpl_Assemble_NOPPadding(t *testing.T) {
}
func TestAssemblerImpl_Assemble_NOPPadding_fusedJumps(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
setupFn func(assembler amd64.Assembler)
}{
@@ -307,8 +309,10 @@ func TestAssemblerImpl_Assemble_NOPPadding_fusedJumps(t *testing.T) {
assembler.CompileNoneToMemory(amd64.DECQ, amd64.REG_R10, 0)
},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
for _, jmpInst := range []asm.Instruction{amd64.JCC, amd64.JCS, amd64.JEQ, amd64.JGE, amd64.JGT, amd64.JHI, amd64.JLE, amd64.JLS, amd64.JLT, amd64.JMI, amd64.JNE, amd64.JPC, amd64.JPS} {
t.Run(amd64.InstructionName(jmpInst), func(t *testing.T) {
@@ -363,7 +367,7 @@ func TestAssemblerImpl_EncodeNoneToRegister(t *testing.T) {
require.Error(t, err)
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *amd64.NodeImpl
expErr string
}{
@@ -375,7 +379,10 @@ func TestAssemblerImpl_EncodeNoneToRegister(t *testing.T) {
n: &amd64.NodeImpl{Instruction: amd64.JMP, Types: amd64.OperandTypesNoneToRegister},
expErr: "invalid register [nil]",
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.expErr, func(t *testing.T) {
tc := tc
a := amd64.NewAssemblerImpl()
@@ -416,7 +423,7 @@ func TestAssemblerImpl_EncodeNoneToRegister(t *testing.T) {
func TestAssemblerImpl_EncodeNoneToMemory(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *amd64.NodeImpl
expErr string
}{
@@ -424,7 +431,10 @@ func TestAssemblerImpl_EncodeNoneToMemory(t *testing.T) {
n: &amd64.NodeImpl{Instruction: amd64.ADDL, Types: amd64.OperandTypesNoneToMemory, DstReg: amd64.REG_AX},
expErr: "ADDL is unsupported for from:none,to:memory type",
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.expErr, func(t *testing.T) {
tc := tc
a := amd64.NewAssemblerImpl()
@@ -476,7 +486,7 @@ func TestAssemblerImpl_ResolveForwardRelativeJumps(t *testing.T) {
})
t.Run("ok", func(t *testing.T) {
originOffset := uint64(0)
for _, tc := range []struct {
tests := []struct {
instruction asm.Instruction
targetOffset uint64
expectedOffsetFromEIP int32
@@ -492,7 +502,10 @@ func TestAssemblerImpl_ResolveForwardRelativeJumps(t *testing.T) {
writtenOffsetIndexInBinary: 2, // Conditional jumps has two opcode for long jump.
expectedOffsetFromEIP: 1234 - 6, // the instruction length of long relative amd64.JCC
},
} {
}
for _, tt := range tests {
tc := tt
origin := &amd64.NodeImpl{Instruction: tc.instruction, OffsetInBinaryField: originOffset}
target := &amd64.NodeImpl{OffsetInBinaryField: tc.targetOffset, JumpOrigins: map[*amd64.NodeImpl]struct{}{origin: {}}}
a := amd64.NewAssemblerImpl()
@@ -511,7 +524,7 @@ func TestAssemblerImpl_ResolveForwardRelativeJumps(t *testing.T) {
t.Run("short jump", func(t *testing.T) {
t.Run("reassemble", func(t *testing.T) {
originOffset := uint64(0)
for _, tc := range []struct {
tests := []struct {
instruction asm.Instruction
targetOffset uint64
}{
@@ -533,7 +546,10 @@ func TestAssemblerImpl_ResolveForwardRelativeJumps(t *testing.T) {
// Relative jump offset = 130 - len(amd64.JCC instruction bytes) = 130 -2 = 128 > math.MaxInt8.
targetOffset: 130,
},
} {
}
for _, tt := range tests {
tc := tt
origin := &amd64.NodeImpl{Instruction: tc.instruction, OffsetInBinaryField: originOffset, Flag: amd64.NodeFlagShortForwardJump}
target := &amd64.NodeImpl{OffsetInBinaryField: tc.targetOffset, JumpOrigins: map[*amd64.NodeImpl]struct{}{origin: {}}}
origin.JumpTarget = target
@@ -548,7 +564,7 @@ func TestAssemblerImpl_ResolveForwardRelativeJumps(t *testing.T) {
})
t.Run("ok", func(t *testing.T) {
originOffset := uint64(0)
for _, tc := range []struct {
tests := []struct {
instruction asm.Instruction
targetOffset uint64
expectedOffsetFromEIP byte
@@ -561,7 +577,10 @@ func TestAssemblerImpl_ResolveForwardRelativeJumps(t *testing.T) {
instruction: amd64.JCC, targetOffset: 129,
expectedOffsetFromEIP: 129 - 2, // short jumps are of 2 bytes.
},
} {
}
for _, tt := range tests {
tc := tt
origin := &amd64.NodeImpl{Instruction: tc.instruction, OffsetInBinaryField: originOffset, Flag: amd64.NodeFlagShortForwardJump}
target := &amd64.NodeImpl{OffsetInBinaryField: tc.targetOffset, JumpOrigins: map[*amd64.NodeImpl]struct{}{origin: {}}}
origin.JumpTarget = target
@@ -583,7 +602,7 @@ func TestAssemblerImpl_ResolveForwardRelativeJumps(t *testing.T) {
func TestAssemblerImpl_encodeNoneToBranch(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *amd64.NodeImpl
expErr string
}{
@@ -591,7 +610,10 @@ func TestAssemblerImpl_encodeNoneToBranch(t *testing.T) {
n: &amd64.NodeImpl{Types: amd64.OperandTypesNoneToBranch, Instruction: amd64.JMP},
expErr: "jump target must not be nil for relative JMP",
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.expErr, func(t *testing.T) {
tc := tc
a := amd64.NewAssemblerImpl()
@@ -695,7 +717,7 @@ func TestAssemblerImpl_encodeNoneToBranch(t *testing.T) {
func TestAssemblerImpl_EncodeRegisterToNone(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *amd64.NodeImpl
expErr string
}{
@@ -707,7 +729,10 @@ func TestAssemblerImpl_EncodeRegisterToNone(t *testing.T) {
n: &amd64.NodeImpl{Instruction: amd64.DIVQ, Types: amd64.OperandTypesRegisterToNone},
expErr: "invalid register [nil]",
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.expErr, func(t *testing.T) {
tc := tc
a := amd64.NewAssemblerImpl()
@@ -745,7 +770,7 @@ func TestAssemblerImpl_EncodeRegisterToNone(t *testing.T) {
func TestAssemblerImpl_EncodeRegisterToRegister(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *amd64.NodeImpl
expErr string
}{
@@ -764,7 +789,10 @@ func TestAssemblerImpl_EncodeRegisterToRegister(t *testing.T) {
n: &amd64.NodeImpl{Instruction: amd64.MOVL, Types: amd64.OperandTypesRegisterToRegister, SrcReg: amd64.REG_X0, DstReg: amd64.REG_X1},
expErr: "MOVL for float to float is undefined",
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.expErr, func(t *testing.T) {
tc := tc
a := amd64.NewAssemblerImpl()
@@ -777,7 +805,7 @@ func TestAssemblerImpl_EncodeRegisterToRegister(t *testing.T) {
intRegisters := []asm.Register{amd64.REG_AX, amd64.REG_R8}
floatRegisters := []asm.Register{amd64.REG_X0, amd64.REG_X8}
allRegisters := append(intRegisters, floatRegisters...)
for _, tc := range []struct {
tests := []struct {
instruction asm.Instruction
srcRegs, DstRegs []asm.Register
arg byte
@@ -877,8 +905,10 @@ func TestAssemblerImpl_EncodeRegisterToRegister(t *testing.T) {
{instruction: amd64.XORPD, srcRegs: floatRegisters, DstRegs: floatRegisters},
{instruction: amd64.XORPS, srcRegs: floatRegisters, DstRegs: floatRegisters},
{instruction: amd64.XORQ, srcRegs: intRegisters, DstRegs: intRegisters},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(amd64.InstructionName(tc.instruction), func(t *testing.T) {
t.Run("error", func(t *testing.T) {
srcFloat, dstFloat := amd64.IsVectorRegister(tc.srcRegs[0]), amd64.IsVectorRegister(tc.DstRegs[0])
@@ -957,7 +987,7 @@ func TestAssemblerImpl_EncodeRegisterToRegister(t *testing.T) {
func TestAssemblerImpl_EncodeRegisterToMemory(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *amd64.NodeImpl
expErr string
}{
@@ -973,7 +1003,10 @@ func TestAssemblerImpl_EncodeRegisterToMemory(t *testing.T) {
SrcReg: amd64.REG_AX, DstReg: amd64.REG_AX},
expErr: "shifting instruction SHLQ require CX register as src but got AX",
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.expErr, func(t *testing.T) {
a := amd64.NewAssemblerImpl()
@@ -1101,7 +1134,7 @@ func TestAssemblerImpl_EncodeRegisterToMemory(t *testing.T) {
func TestAssemblerImpl_encodeRegisterToConst(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *amd64.NodeImpl
expErr string
}{
@@ -1113,7 +1146,10 @@ func TestAssemblerImpl_encodeRegisterToConst(t *testing.T) {
n: &amd64.NodeImpl{Instruction: amd64.DIVQ, Types: amd64.OperandTypesRegisterToConst},
expErr: "invalid register [nil]",
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.expErr, func(t *testing.T) {
tc := tc
a := amd64.NewAssemblerImpl()
@@ -1223,7 +1259,7 @@ func TestAssemblerImpl_EncodeMemoryToRegister(t *testing.T) {
intRegs := []asm.Register{amd64.REG_AX, amd64.REG_BP, amd64.REG_SI, amd64.REG_DI, amd64.REG_R10}
floatRegs := []asm.Register{amd64.REG_X0, amd64.REG_X8}
scales := []byte{1, 4}
for _, tc := range []struct {
tests := []struct {
instruction asm.Instruction
isFloatInst bool
}{
@@ -1249,8 +1285,10 @@ func TestAssemblerImpl_EncodeMemoryToRegister(t *testing.T) {
{instruction: amd64.SUBSS, isFloatInst: true},
{instruction: amd64.UCOMISD, isFloatInst: true},
{instruction: amd64.UCOMISS, isFloatInst: true},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
for _, srcReg := range intRegs {
srcReg := srcReg
DstRegs := intRegs
@@ -1311,7 +1349,7 @@ func TestAssemblerImpl_EncodeMemoryToRegister(t *testing.T) {
func TestAssemblerImpl_encodeConstToRegister(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *amd64.NodeImpl
expErr string
}{
@@ -1343,7 +1381,10 @@ func TestAssemblerImpl_encodeConstToRegister(t *testing.T) {
n: &amd64.NodeImpl{Instruction: amd64.PSRLQ, Types: amd64.OperandTypesConstToRegister, DstReg: amd64.REG_X0, SrcConst: 32768},
expErr: "constant must fit in signed 8-bit integer for PSRLQ, but got 32768",
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.expErr, func(t *testing.T) {
tc := tc
a := amd64.NewAssemblerImpl()
@@ -1422,7 +1463,7 @@ func TestAssemblerImpl_encodeConstToRegister(t *testing.T) {
func TestAssemblerImpl_EncodeMemoryToConst(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *amd64.NodeImpl
expErr string
}{
@@ -1430,7 +1471,10 @@ func TestAssemblerImpl_EncodeMemoryToConst(t *testing.T) {
n: &amd64.NodeImpl{Instruction: amd64.ADDL, Types: amd64.OperandTypesMemoryToConst, DstReg: amd64.REG_AX},
expErr: "ADDL is unsupported for from:memory,to:const type",
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.expErr, func(t *testing.T) {
tc := tc
a := amd64.NewAssemblerImpl()
@@ -1477,7 +1521,7 @@ func TestAssemblerImpl_EncodeMemoryToConst(t *testing.T) {
func TestAssemblerImpl_EncodeConstToMemory(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *amd64.NodeImpl
expErr string
}{
@@ -1497,7 +1541,10 @@ func TestAssemblerImpl_EncodeConstToMemory(t *testing.T) {
DstReg: amd64.REG_AX, DstConst: 0xff_ff},
expErr: "too large load target const 9223372036854775807 for MOVL",
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.expErr, func(t *testing.T) {
tc := tc
a := amd64.NewAssemblerImpl()
@@ -1558,7 +1605,7 @@ func TestAssemblerImpl_EncodeConstToMemory(t *testing.T) {
func TestNodeImpl_GetMemoryLocation(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *amd64.NodeImpl
expErr string
}{
@@ -1581,7 +1628,10 @@ func TestNodeImpl_GetMemoryLocation(t *testing.T) {
SrcConst: 10, SrcReg: amd64.REG_AX, SrcMemIndex: amd64.REG_R9, SrcMemScale: 3, DstReg: amd64.REG_R10},
expErr: "scale in SIB must be one of 1, 2, 4, 8 but got 3",
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.expErr, func(t *testing.T) {
tc := tc
_, _, _, _, err := tc.n.GetMemoryLocation()

View File

@@ -46,7 +46,7 @@ var intRegisters = []asm.Register{
func TestAssemblerImpl_EncodeJumpToRegister(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -62,7 +62,10 @@ func TestAssemblerImpl_EncodeJumpToRegister(t *testing.T) {
n: &arm64.NodeImpl{Instruction: arm64.RET, DstReg: arm64.REG_V0},
expErr: "invalid destination register: V0 is not integer",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeJumpToRegister(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -103,7 +106,7 @@ func TestAssemblerImpl_EncodeJumpToRegister(t *testing.T) {
func TestAssemblerImpl_EncodeLeftShiftedRegisterToRegister(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -132,7 +135,10 @@ func TestAssemblerImpl_EncodeLeftShiftedRegisterToRegister(t *testing.T) {
SrcConst: -1, SrcReg: arm64.REG_R0, SrcReg2: arm64.REG_R0, DstReg: arm64.REG_V0},
expErr: "V0 is not integer",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeLeftShiftedRegisterToRegister(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -140,7 +146,7 @@ func TestAssemblerImpl_EncodeLeftShiftedRegisterToRegister(t *testing.T) {
})
const inst = arm64.ADD
for _, tc := range []struct {
tests := []struct {
srcReg, shiftedSrcReg, dstReg asm.Register
shiftNum int64
}{
@@ -192,8 +198,10 @@ func TestAssemblerImpl_EncodeLeftShiftedRegisterToRegister(t *testing.T) {
shiftNum: 64,
dstReg: arm64.REGZERO,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(fmt.Sprintf("src=%s,shifted_src=%s,shift_num=%d,dst=%s",
arm64.RegisterName(tc.srcReg), arm64.RegisterName(tc.shiftedSrcReg),
tc.shiftNum, arm64.RegisterName(tc.srcReg)), func(t *testing.T) {
@@ -219,7 +227,7 @@ func TestAssemblerImpl_EncodeLeftShiftedRegisterToRegister(t *testing.T) {
func TestAssemblerImpl_EncodeTwoRegistersToNone(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -238,7 +246,10 @@ func TestAssemblerImpl_EncodeTwoRegistersToNone(t *testing.T) {
SrcReg: arm64.REG_R0, SrcReg2: arm64.REG_V0},
expErr: "R0 is not float",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeTwoRegistersToNone(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -247,7 +258,7 @@ func TestAssemblerImpl_EncodeTwoRegistersToNone(t *testing.T) {
intRegs := []asm.Register{arm64.REGZERO, arm64.REG_R0, arm64.REG_R10, arm64.REG_R30}
floatRegs := []asm.Register{arm64.REG_V0, arm64.REG_V12, arm64.REG_V31}
for _, tc := range []struct {
tests := []struct {
instruction asm.Instruction
regs []asm.Register
}{
@@ -255,7 +266,10 @@ func TestAssemblerImpl_EncodeTwoRegistersToNone(t *testing.T) {
{instruction: arm64.CMPW, regs: intRegs},
{instruction: arm64.FCMPD, regs: floatRegs},
{instruction: arm64.FCMPS, regs: floatRegs},
} {
}
for _, tt := range tests {
tc := tt
t.Run(arm64.InstructionName(tc.instruction), func(t *testing.T) {
for _, src := range tc.regs {
for _, src2 := range tc.regs {
@@ -314,7 +328,7 @@ func TestAssemblerImpl_EncodeThreeRegistersToRegister(t *testing.T) {
func TestAssemblerImpl_EncodeRegisterToRegister(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -323,7 +337,10 @@ func TestAssemblerImpl_EncodeRegisterToRegister(t *testing.T) {
SrcReg: arm64.REG_R0, SrcReg2: arm64.REG_R0, DstReg: arm64.REG_R0},
expErr: "ADR is unsupported for from:register,to:register type",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeRegisterToRegister(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -335,7 +352,7 @@ func TestAssemblerImpl_EncodeRegisterToRegister(t *testing.T) {
conditionalRegs := []asm.Register{arm64.REG_COND_EQ, arm64.REG_COND_NE, arm64.REG_COND_HS, arm64.REG_COND_LO, arm64.REG_COND_MI, arm64.REG_COND_PL, arm64.REG_COND_VS, arm64.REG_COND_VC, arm64.REG_COND_HI, arm64.REG_COND_LS, arm64.REG_COND_GE, arm64.REG_COND_LT, arm64.REG_COND_GT, arm64.REG_COND_LE, arm64.REG_COND_AL, arm64.REG_COND_NV}
floatRegs := []asm.Register{arm64.REG_V0, arm64.REG_V15, arm64.REG_V31}
for _, tc := range []struct {
tests := []struct {
inst asm.Instruction
srcRegs, dstRegs []asm.Register
}{
@@ -412,9 +429,10 @@ func TestAssemblerImpl_EncodeRegisterToRegister(t *testing.T) {
{inst: arm64.SXTH, srcRegs: intRegs, dstRegs: intRegs},
{inst: arm64.SXTHW, srcRegs: intRegs, dstRegs: intRegs},
{inst: arm64.SXTW, srcRegs: intRegs, dstRegs: intRegs},
} {
}
tc := tc
for _, tt := range tests {
tc := tt
t.Run(arm64.InstructionName(tc.inst), func(t *testing.T) {
for _, src := range tc.srcRegs {
for _, dst := range tc.dstRegs {
@@ -446,7 +464,7 @@ func TestAssemblerImpl_EncodeRegisterToRegister(t *testing.T) {
func TestAssemblerImpl_EncodeTwoRegistersToRegister(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -455,7 +473,10 @@ func TestAssemblerImpl_EncodeTwoRegistersToRegister(t *testing.T) {
SrcReg: arm64.REG_R0, SrcReg2: arm64.REG_R0, DstReg: arm64.REG_R0},
expErr: "ADR is unsupported for from:two-registers,to:register type",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeThreeRegistersToRegister(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -465,7 +486,7 @@ func TestAssemblerImpl_EncodeTwoRegistersToRegister(t *testing.T) {
intRegs := []asm.Register{arm64.REGZERO, arm64.REG_R1, arm64.REG_R10, arm64.REG_R30}
floatRegs := []asm.Register{arm64.REG_V0, arm64.REG_V15, arm64.REG_V31}
for _, tc := range []struct {
tests := []struct {
inst asm.Instruction
srcRegs, dstRegs []asm.Register
}{
@@ -491,8 +512,10 @@ func TestAssemblerImpl_EncodeTwoRegistersToRegister(t *testing.T) {
{inst: arm64.SUBW, srcRegs: intRegs, dstRegs: intRegs},
{inst: arm64.FSUBD, srcRegs: floatRegs, dstRegs: floatRegs},
{inst: arm64.FSUBS, srcRegs: floatRegs, dstRegs: floatRegs},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(arm64.InstructionName(tc.inst), func(t *testing.T) {
for _, src := range tc.srcRegs {
for _, src2 := range tc.srcRegs {
@@ -520,7 +543,7 @@ func TestAssemblerImpl_EncodeTwoRegistersToRegister(t *testing.T) {
func TestAssemblerImpl_EncodeRegisterAndConstToNone(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -539,7 +562,10 @@ func TestAssemblerImpl_EncodeRegisterAndConstToNone(t *testing.T) {
SrcReg: arm64.REGZERO, SrcConst: 123},
expErr: "zero register is not supported for CMP (immediate)",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeRegisterAndConstToNone(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -573,7 +599,7 @@ func TestAssemblerImpl_EncodeRegisterAndConstToNone(t *testing.T) {
func TestAssemblerImpl_EncodeConstToRegister(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -590,7 +616,10 @@ func TestAssemblerImpl_EncodeConstToRegister(t *testing.T) {
n: &arm64.NodeImpl{Instruction: arm64.LSL, Types: arm64.OperandTypesConstToRegister, DstReg: arm64.REG_R0},
expErr: "LSL with zero constant should be optimized out",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeConstToRegister(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -644,7 +673,7 @@ func TestAssemblerImpl_EncodeConstToRegister(t *testing.T) {
0xffffff,
}
for _, tc := range []struct {
tests := []struct {
inst asm.Instruction
consts []int64
}{
@@ -696,8 +725,10 @@ func TestAssemblerImpl_EncodeConstToRegister(t *testing.T) {
inst: arm64.LSR,
consts: []int64{1, 2, 4, 16, 31, 32, 63},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(arm64.InstructionName(tc.inst), func(t *testing.T) {
for _, r := range []asm.Register{
arm64.REG_R0, arm64.REG_R10,
@@ -734,7 +765,7 @@ func TestAssemblerImpl_EncodeConstToRegister(t *testing.T) {
func TestAssemblerImpl_EncodeSIMDByteToSIMDByte(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -742,7 +773,10 @@ func TestAssemblerImpl_EncodeSIMDByteToSIMDByte(t *testing.T) {
n: &arm64.NodeImpl{Instruction: arm64.ADR, Types: arm64.OperandTypesSIMDByteToSIMDByte},
expErr: "ADR is unsupported for from:simd-byte,to:simd-byte type",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeSIMDByteToSIMDByte(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -776,7 +810,7 @@ func TestAssemblerImpl_EncodeSIMDByteToSIMDByte(t *testing.T) {
func TestAssemblerImpl_EncodeSIMDByteToRegister(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -784,7 +818,10 @@ func TestAssemblerImpl_EncodeSIMDByteToRegister(t *testing.T) {
n: &arm64.NodeImpl{Instruction: arm64.ADR, Types: arm64.OperandTypesSIMDByteToRegister},
expErr: "ADR is unsupported for from:simd-byte,to:register type",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeSIMDByteToRegister(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -818,7 +855,7 @@ func TestAssemblerImpl_EncodeSIMDByteToRegister(t *testing.T) {
func TestAssemblerImpl_EncodeRegisterToMemory(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -826,7 +863,10 @@ func TestAssemblerImpl_EncodeRegisterToMemory(t *testing.T) {
n: &arm64.NodeImpl{Instruction: arm64.ADR, Types: arm64.OperandTypesRegisterToMemory},
expErr: "ADR is unsupported for from:register,to:memory type",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeRegisterToMemory(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -846,7 +886,7 @@ func TestAssemblerImpl_EncodeRegisterToMemory(t *testing.T) {
arm64.REG_V0, arm64.REG_V10,
arm64.REG_V30,
}
for _, tc := range []struct {
tests := []struct {
inst asm.Instruction
srcRegs []asm.Register
offsets []int64
@@ -858,8 +898,10 @@ func TestAssemblerImpl_EncodeRegisterToMemory(t *testing.T) {
{inst: arm64.MOVB, srcRegs: intRegs, offsets: offsets},
{inst: arm64.FMOVD, srcRegs: floatRegs, offsets: offsets},
{inst: arm64.FMOVS, srcRegs: floatRegs, offsets: offsets},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(arm64.InstructionName(tc.inst), func(t *testing.T) {
for _, srcReg := range tc.srcRegs {
for _, baseReg := range intRegs {
@@ -911,7 +953,7 @@ func TestAssemblerImpl_EncodeRegisterToMemory(t *testing.T) {
func TestAssemblerImpl_EncodeMemoryToRegister(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -919,7 +961,10 @@ func TestAssemblerImpl_EncodeMemoryToRegister(t *testing.T) {
n: &arm64.NodeImpl{Instruction: arm64.SUB, Types: arm64.OperandTypesMemoryToRegister},
expErr: "SUB is unsupported for from:memory,to:register type",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeMemoryToRegister(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -941,7 +986,7 @@ func TestAssemblerImpl_EncodeMemoryToRegister(t *testing.T) {
arm64.REG_V0, arm64.REG_V10,
arm64.REG_V30,
}
for _, tc := range []struct {
tests := []struct {
inst asm.Instruction
dstRegs []asm.Register
offsets []int64
@@ -955,8 +1000,10 @@ func TestAssemblerImpl_EncodeMemoryToRegister(t *testing.T) {
{inst: arm64.MOVBU, dstRegs: intRegs, offsets: offsets},
{inst: arm64.FMOVD, dstRegs: floatRegs, offsets: offsets},
{inst: arm64.FMOVS, dstRegs: floatRegs, offsets: offsets},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(arm64.InstructionName(tc.inst), func(t *testing.T) {
for _, dstReg := range tc.dstRegs {
for _, baseReg := range intRegs {
@@ -1063,7 +1110,7 @@ func TestAssemblerImpl_encodeReadInstructionAddress(t *testing.T) {
func TestAssemblerImpl_EncodeRelativeJump(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -1075,7 +1122,10 @@ func TestAssemblerImpl_EncodeRelativeJump(t *testing.T) {
n: &arm64.NodeImpl{Instruction: arm64.SUB, Types: arm64.OperandTypesNoneToBranch},
expErr: "SUB is unsupported for from:none,to:branch type",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeRelativeBranch(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -1089,7 +1139,7 @@ func TestAssemblerImpl_EncodeRelativeJump(t *testing.T) {
} {
inst := inst
t.Run(arm64.InstructionName(inst), func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
forward bool
instructionsInPreamble, instructionsBeforeBranch, instructionsAfterBranch int
}{
@@ -1113,7 +1163,10 @@ func TestAssemblerImpl_EncodeRelativeJump(t *testing.T) {
{forward: false, instructionsInPreamble: 123, instructionsBeforeBranch: 1234, instructionsAfterBranch: 1234},
{forward: true, instructionsInPreamble: 123, instructionsBeforeBranch: 123, instructionsAfterBranch: 65536},
{forward: false, instructionsInPreamble: 123, instructionsBeforeBranch: 65536, instructionsAfterBranch: 0},
} {
}
for _, tt := range tests {
tc := tt
t.Run(fmt.Sprintf("foward=%v(before=%d,after=%d)", tc.forward,
tc.instructionsBeforeBranch, tc.instructionsAfterBranch), func(t *testing.T) {
goasm := newGoasmAssembler(t, asm.NilRegister)
@@ -1175,7 +1228,7 @@ func TestAssemblerImpl_multipleLargeOffest(t *testing.T) {
func TestAssemblerImpl_EncodeTwoSIMDBytesToSIMDByteRegister(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -1183,7 +1236,10 @@ func TestAssemblerImpl_EncodeTwoSIMDBytesToSIMDByteRegister(t *testing.T) {
n: &arm64.NodeImpl{Instruction: arm64.B, Types: arm64.OperandTypesTwoSIMDBytesToSIMDByteRegister},
expErr: "B is unsupported for from:two-simd-bytes,to:simd-byte type",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeTwoSIMDBytesToSIMDByteRegister(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -1217,7 +1273,7 @@ func TestAssemblerImpl_EncodeTwoSIMDBytesToSIMDByteRegister(t *testing.T) {
func TestAssemblerImpl_EncodeVectorRegisterToVectorRegister(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -1254,7 +1310,10 @@ func TestAssemblerImpl_EncodeVectorRegisterToVectorRegister(t *testing.T) {
},
expErr: "unsupported arrangement for VADD: 1D",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeVectorRegisterToVectorRegister(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -1262,7 +1321,7 @@ func TestAssemblerImpl_EncodeVectorRegisterToVectorRegister(t *testing.T) {
})
vectorRegs := []asm.Register{arm64.REG_V10, arm64.REG_V2, arm64.REG_V30}
for _, tc := range []struct {
tests := []struct {
inst asm.Instruction
arr arm64.VectorArrangement
}{
@@ -1271,8 +1330,10 @@ func TestAssemblerImpl_EncodeVectorRegisterToVectorRegister(t *testing.T) {
{inst: arm64.VADD, arr: arm64.VectorArrangement4S},
{inst: arm64.VADD, arr: arm64.VectorArrangement8H},
{inst: arm64.VADD, arr: arm64.VectorArrangement16B},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(fmt.Sprintf("%s.%s", arm64.InstructionName(tc.inst), tc.arr), func(t *testing.T) {
for _, src := range vectorRegs {
for _, dst := range vectorRegs {
@@ -1301,7 +1362,7 @@ func TestAssemblerImpl_EncodeVectorRegisterToVectorRegister(t *testing.T) {
func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -1321,7 +1382,10 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
},
expErr: "unsupported arrangement for VLD1: unknown",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeMemoryToVectorRegister(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -1373,7 +1437,7 @@ func TestAssemblerImpl_EncodeMemoryToVectorRegister(t *testing.T) {
func TestAssemblerImpl_EncodeVectorRegisterToMemory(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -1393,7 +1457,10 @@ func TestAssemblerImpl_EncodeVectorRegisterToMemory(t *testing.T) {
},
expErr: "unsupported arrangement for VST1: unknown",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeVectorRegisterToMemory(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -1446,7 +1513,7 @@ func TestAssemblerImpl_EncodeVectorRegisterToMemory(t *testing.T) {
func TestAssemblerImpl_EncodeRegisterToVectorRegister(t *testing.T) {
t.Run("error", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
n *arm64.NodeImpl
expErr string
}{
@@ -1470,7 +1537,10 @@ func TestAssemblerImpl_EncodeRegisterToVectorRegister(t *testing.T) {
},
expErr: "unsupported arrangement for VMOV: 1D",
},
} {
}
for _, tt := range tests {
tc := tt
a := arm64.NewAssemblerImpl(asm.NilRegister)
err := a.EncodeRegisterToVectorRegister(tc.n)
require.EqualError(t, err, tc.expErr)
@@ -1480,7 +1550,7 @@ func TestAssemblerImpl_EncodeRegisterToVectorRegister(t *testing.T) {
regs := []asm.Register{arm64.REG_R0, arm64.REG_R10, arm64.REG_R30}
vectorRegs := []asm.Register{arm64.REG_V0, arm64.REG_V10, arm64.REG_V30}
for _, tc := range []struct {
tests := []struct {
inst asm.Instruction
arrangement arm64.VectorArrangement
index arm64.VectorIndex
@@ -1515,8 +1585,10 @@ func TestAssemblerImpl_EncodeRegisterToVectorRegister(t *testing.T) {
arrangement: arm64.VectorArrangementH,
index: 4,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(arm64.InstructionName(tc.inst), func(t *testing.T) {
for _, r := range regs {
for _, vr := range vectorRegs {

View File

@@ -89,7 +89,7 @@ func newGenerator(size int, ints []int, bufs [][]byte) *generator {
}
func TestGenerator_newFunctionType(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
params, results int
exp *wasm.FunctionType
}{
@@ -108,7 +108,10 @@ func TestGenerator_newFunctionType(t *testing.T) {
Results: []wasm.ValueType{i64, f32, f64, i32, i32, i64},
},
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.exp.String(), func(t *testing.T) {
g := newGenerator(0, []int{0, 1, 2, 3, 4}, nil)
actual := g.newFunctionType(tc.params, tc.results)
@@ -152,7 +155,7 @@ func TestGenerator_typeSection(t *testing.T) {
func TestGenerator_importSection(t *testing.T) {
five := uint32(5)
for i, tc := range []struct {
tests := []struct {
ints []int
numImports uint32
types []*wasm.FunctionType
@@ -255,7 +258,10 @@ func TestGenerator_importSection(t *testing.T) {
{Type: wasm.ExternTypeFunc, DescFunc: 1, Module: "module-2", Name: "2"},
},
},
} {
}
for i, tt := range tests {
tc := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
g := newGenerator(100, tc.ints, nil)
g.numImports = uint32(tc.numImports)
@@ -321,7 +327,7 @@ func TestGenerator_memorySection(t *testing.T) {
}
func TestGenerator_newConstExpr(t *testing.T) {
for i, tc := range []struct {
tests := []struct {
ints []int
bufs [][]byte
imports []*wasm.Import
@@ -413,8 +419,10 @@ func TestGenerator_newConstExpr(t *testing.T) {
exp: &wasm.ConstantExpression{Opcode: wasm.OpcodeI32Const, Data: leb128.EncodeInt32(100)},
expType: i32,
},
} {
tc := tc
}
for i, tt := range tests {
tc := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
g := newGenerator(100, tc.ints, tc.bufs)
g.m.ImportSection = tc.imports
@@ -540,7 +548,7 @@ func TestGenerator_startSection(t *testing.T) {
takePtr := func(v uint32) *uint32 { return &v }
for i, tc := range []struct {
tests := []struct {
ints []int
exp *wasm.Index
}{
@@ -548,8 +556,10 @@ func TestGenerator_startSection(t *testing.T) {
{ints: []int{1}, exp: takePtr(3)},
{ints: []int{2}, exp: takePtr(6)},
{ints: []int{3}, exp: takePtr(1)},
} {
tc := tc
}
for i, tt := range tests {
tc := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
g := newGenerator(100, tc.ints, nil)
g.needStartSection = true
@@ -603,7 +613,7 @@ func TestGenerator_elementSection(t *testing.T) {
require.Nil(t, g.m.ElementSection)
})
t.Run("ok", func(t *testing.T) {
for i, tc := range []struct {
tests := []struct {
ints []int
numElements uint32
exps []*wasm.ElementSegment
@@ -647,8 +657,10 @@ func TestGenerator_elementSection(t *testing.T) {
},
},
},
} {
tc := tc
}
for i, tt := range tests {
tc := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
g := newGenerator(100, tc.ints, nil)
g.m = &wasm.Module{
@@ -681,7 +693,7 @@ func TestGenerator_dataSection(t *testing.T) {
require.Nil(t, g.m.DataSection)
})
t.Run("ok", func(t *testing.T) {
for i, tc := range []struct {
tests := []struct {
ints []int
bufs [][]byte
numData uint32
@@ -721,8 +733,10 @@ func TestGenerator_dataSection(t *testing.T) {
},
},
},
} {
tc := tc
}
for i, tt := range tests {
tc := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
g := newGenerator(100, tc.ints, tc.bufs)
g.m.MemorySection = &wasm.Memory{Min: 1}

View File

@@ -10,7 +10,7 @@ import (
)
func TestDecodeConstantExpression(t *testing.T) {
for i, tc := range []struct {
tests := []struct {
in []byte
exp *wasm.ConstantExpression
}{
@@ -78,8 +78,10 @@ func TestDecodeConstantExpression(t *testing.T) {
},
},
},
} {
tc := tc
}
for i, tt := range tests {
tc := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
actual, err := decodeConstantExpression(bytes.NewReader(tc.in),
wasm.FeatureBulkMemoryOperations|wasm.FeatureSIMD)
@@ -90,7 +92,7 @@ func TestDecodeConstantExpression(t *testing.T) {
}
func TestDecodeConstantExpression_errors(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
in []byte
expectedErr string
features wasm.Features
@@ -174,7 +176,10 @@ func TestDecodeConstantExpression_errors(t *testing.T) {
expectedErr: "read vector const instruction immediates: needs 16 bytes but was 8 bytes",
features: wasm.FeatureSIMD,
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.expectedErr, func(t *testing.T) {
_, err := decodeConstantExpression(bytes.NewReader(tc.in), tc.features)
require.EqualError(t, err, tc.expectedErr)

View File

@@ -10,7 +10,7 @@ import (
)
func Test_decodeDataSegment(t *testing.T) {
for i, tc := range []struct {
tests := []struct {
in []byte
exp *wasm.DataSegment
features wasm.Features
@@ -112,8 +112,10 @@ func Test_decodeDataSegment(t *testing.T) {
features: wasm.FeatureMutableGlobal,
expErr: "non-zero prefix for data segment is invalid as feature \"bulk-memory-operations\" is disabled",
},
} {
tc := tc
}
for i, tt := range tests {
tc := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
actual, err := decodeDataSegment(bytes.NewReader(tc.in), tc.features)
if tc.expErr == "" {

View File

@@ -19,7 +19,7 @@ func Test_ensureElementKindFuncRef(t *testing.T) {
}
func Test_decodeElementInitValueVector(t *testing.T) {
for i, tc := range []struct {
tests := []struct {
in []byte
exp []*wasm.Index
}{
@@ -31,7 +31,10 @@ func Test_decodeElementInitValueVector(t *testing.T) {
in: []byte{5, 1, 2, 3, 4, 5},
exp: []*wasm.Index{uint32Ptr(1), uint32Ptr(2), uint32Ptr(3), uint32Ptr(4), uint32Ptr(5)},
},
} {
}
for i, tt := range tests {
tc := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
actual, err := decodeElementInitValueVector(bytes.NewReader(tc.in))
require.NoError(t, err)
@@ -41,7 +44,7 @@ func Test_decodeElementInitValueVector(t *testing.T) {
}
func Test_decodeElementConstExprVector(t *testing.T) {
for i, tc := range []struct {
tests := []struct {
in []byte
exp []*wasm.Index
features wasm.Features
@@ -72,7 +75,10 @@ func Test_decodeElementConstExprVector(t *testing.T) {
exp: []*wasm.Index{nil, uint32Ptr(165675008), nil},
features: wasm.FeatureBulkMemoryOperations,
},
} {
}
for i, tt := range tests {
tc := tt
t.Run(strconv.Itoa(i), func(t *testing.T) {
actual, err := decodeElementConstExprVector(bytes.NewReader(tc.in), tc.features)
require.NoError(t, err)
@@ -82,7 +88,7 @@ func Test_decodeElementConstExprVector(t *testing.T) {
}
func TestDecodeElementSegment(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
in []byte
exp *wasm.ElementSegment
@@ -357,8 +363,10 @@ func TestDecodeElementSegment(t *testing.T) {
},
features: wasm.FeatureBulkMemoryOperations,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
actual, err := decodeElementSegment(bytes.NewReader(tc.in), tc.features)
if tc.expErr != "" {

View File

@@ -293,7 +293,7 @@ func TestModule_ValidateFunction_BulkMemoryOperations(t *testing.T) {
}
})
t.Run("errors", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
body []byte
dataSection []*DataSegment
elementSection []*ElementSegment
@@ -635,7 +635,10 @@ func TestModule_ValidateFunction_BulkMemoryOperations(t *testing.T) {
tables: []*Table{{}},
expectedErr: "cannot pop the operand for table.copy: i32 missing",
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.expectedErr, func(t *testing.T) {
m := &Module{
TypeSection: []*FunctionType{v_v},
@@ -2231,7 +2234,7 @@ func TestModule_funcValidation_CallIndirect(t *testing.T) {
}
func TestModule_funcValidation_RefTypes(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
body []byte
flag Features
@@ -2310,8 +2313,10 @@ func TestModule_funcValidation_RefTypes(t *testing.T) {
},
expectedErr: "ref.func invalid as feature \"reference-types\" is disabled",
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
m := &Module{
TypeSection: []*FunctionType{v_v},
@@ -2330,7 +2335,7 @@ func TestModule_funcValidation_RefTypes(t *testing.T) {
func TestModule_funcValidation_TableGrowSizeFill(t *testing.T) {
tables := []*Table{{Type: RefTypeFuncref}, {Type: RefTypeExternref}}
for _, tc := range []struct {
tests := []struct {
name string
body []byte
flag Features
@@ -2476,8 +2481,10 @@ func TestModule_funcValidation_TableGrowSizeFill(t *testing.T) {
flag: FeatureReferenceTypes,
expectedErr: `table of index 10 not found`,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
m := &Module{
TypeSection: []*FunctionType{v_v},
@@ -2496,7 +2503,7 @@ func TestModule_funcValidation_TableGrowSizeFill(t *testing.T) {
func TestModule_funcValidation_TableGetSet(t *testing.T) {
tables := []*Table{{Type: RefTypeFuncref}, {Type: RefTypeExternref}}
for _, tc := range []struct {
tests := []struct {
name string
body []byte
flag Features
@@ -2586,8 +2593,10 @@ func TestModule_funcValidation_TableGetSet(t *testing.T) {
flag: Features20191205,
expectedErr: `table.set is invalid as feature "reference-types" is disabled`,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
m := &Module{
TypeSection: []*FunctionType{v_v},
@@ -2605,7 +2614,7 @@ func TestModule_funcValidation_TableGetSet(t *testing.T) {
}
func TestModule_funcValidation_Select_error(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
body []byte
flag Features
@@ -2641,8 +2650,10 @@ func TestModule_funcValidation_Select_error(t *testing.T) {
flag: FeatureReferenceTypes,
expectedErr: `invalid type unknown for typed_select`,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
m := &Module{
TypeSection: []*FunctionType{v_v},
@@ -2656,7 +2667,7 @@ func TestModule_funcValidation_Select_error(t *testing.T) {
}
func TestModule_funcValidation_SIMD(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
body []byte
expectedErr string
@@ -2706,8 +2717,10 @@ func TestModule_funcValidation_SIMD(t *testing.T) {
OpcodeEnd,
},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
m := &Module{
TypeSection: []*FunctionType{v_v},
@@ -2721,7 +2734,7 @@ func TestModule_funcValidation_SIMD(t *testing.T) {
}
func TestModule_funcValidation_SIMD_error(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
body []byte
flag Features
@@ -2787,8 +2800,10 @@ func TestModule_funcValidation_SIMD_error(t *testing.T) {
flag: FeatureSIMD,
expectedErr: "TODO: SIMD instruction f32x4.demote_f64x2_zero will be implemented in #506",
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
m := &Module{
TypeSection: []*FunctionType{v_v},

View File

@@ -13,7 +13,7 @@ import (
)
func TestFunctionType_String(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
functype *FunctionType
exp string
}{
@@ -27,8 +27,10 @@ func TestFunctionType_String(t *testing.T) {
{functype: &FunctionType{Params: []ValueType{ValueTypeI32}, Results: []ValueType{ValueTypeI64}}, exp: "i32_i64"},
{functype: &FunctionType{Params: []ValueType{ValueTypeI64, ValueTypeF32}, Results: []ValueType{ValueTypeI64, ValueTypeF32}}, exp: "i64f32_i64f32"},
{functype: &FunctionType{Params: []ValueType{ValueTypeI64, ValueTypeF32, ValueTypeF64}, Results: []ValueType{ValueTypeF32, ValueTypeI32, ValueTypeF64}}, exp: "i64f32f64_f32i32f64"},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.functype.String(), func(t *testing.T) {
require.Equal(t, tc.exp, tc.functype.String())
require.Equal(t, tc.exp, tc.functype.key())
@@ -120,7 +122,7 @@ func TestMemory_Validate(t *testing.T) {
}
func TestModule_allDeclarations(t *testing.T) {
for i, tc := range []struct {
tests := []struct {
module *Module
expectedFunctions []Index
expectedGlobals []*GlobalType
@@ -193,8 +195,10 @@ func TestModule_allDeclarations(t *testing.T) {
},
expectedTables: []*Table{{Min: 10}},
},
} {
tc := tc
}
for i, tt := range tests {
tc := tt
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
functions, globals, memory, tables, err := tc.module.AllDeclarations()
require.NoError(t, err)
@@ -575,7 +579,7 @@ func TestModule_validateMemory(t *testing.T) {
}
func TestModule_validateImports(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
enabledFeatures Features
i *Import
@@ -618,8 +622,10 @@ func TestModule_validateImports(t *testing.T) {
DescMem: &Memory{Min: 1},
},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
m := Module{}
if tc.i != nil {
@@ -636,7 +642,7 @@ func TestModule_validateImports(t *testing.T) {
}
func TestModule_validateExports(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
enabledFeatures Features
exportSection []*Export
@@ -718,8 +724,10 @@ func TestModule_validateExports(t *testing.T) {
tables: []*Table{},
expectedErr: `memory for export["e"] out of range`,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
m := Module{ExportSection: tc.exportSection}
err := m.validateExports(tc.enabledFeatures, tc.functions, tc.globals, tc.memory, tc.tables)
@@ -840,7 +848,7 @@ func TestModule_validateDataCountSection(t *testing.T) {
}
func TestModule_declaredFunctionIndexes(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
mod *Module
exp map[Index]struct{}
@@ -943,8 +951,10 @@ func TestModule_declaredFunctionIndexes(t *testing.T) {
name: "invalid global",
expErr: `global[0] failed to initialize: EOF`,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
actual, err := tc.mod.declaredFunctionIndexes()
if tc.expErr != "" {

View File

@@ -116,7 +116,7 @@ func TestStore_CloseModule(t *testing.T) {
const importedModuleName = "imported"
const importingModuleName = "test"
for _, tc := range []struct {
tests := []struct {
name string
initializer func(t *testing.T, s *Store)
}{
@@ -147,8 +147,10 @@ func TestStore_CloseModule(t *testing.T) {
require.NoError(t, err)
},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
s := newStore()
tc.initializer(t, s)
@@ -186,7 +188,7 @@ func TestStore_CloseStore(t *testing.T) {
const importedModuleName = "imported"
const importingModuleName = "test"
for _, tc := range []struct {
tests := []struct {
name string
testClosed bool
}{
@@ -198,8 +200,10 @@ func TestStore_CloseStore(t *testing.T) {
name: "partially closed",
testClosed: true,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
s := newStore()
@@ -487,13 +491,15 @@ func TestStore_getFunctionTypeID(t *testing.T) {
require.Error(t, err)
})
t.Run("ok", func(t *testing.T) {
for _, tc := range []*FunctionType{
tests := []*FunctionType{
{Params: []ValueType{}},
{Params: []ValueType{ValueTypeF32}},
{Results: []ValueType{ValueTypeF64}},
{Params: []ValueType{ValueTypeI32}, Results: []ValueType{ValueTypeI64}},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.String(), func(t *testing.T) {
s := newStore()
actual, err := s.getFunctionTypeID(tc)
@@ -552,7 +558,7 @@ func TestExecuteConstExpression(t *testing.T) {
}
})
t.Run("reference types", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
expr *ConstantExpression
exp interface{}
@@ -581,8 +587,10 @@ func TestExecuteConstExpression(t *testing.T) {
},
exp: int32(1),
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
val := executeConstExpression(nil, tc.expr)
require.Equal(t, tc.exp, val)
@@ -590,7 +598,7 @@ func TestExecuteConstExpression(t *testing.T) {
}
})
t.Run("global expr", func(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
valueType ValueType
val, valHi uint64
}{
@@ -599,7 +607,10 @@ func TestExecuteConstExpression(t *testing.T) {
{valueType: ValueTypeF32, val: uint64(math.Float32bits(634634432.12311))},
{valueType: ValueTypeF64, val: math.Float64bits(1.12312311)},
{valueType: ValueTypeV128, val: 0x1, valHi: 0x2},
} {
}
for _, tt := range tests {
tc := tt
t.Run(ValueTypeName(tc.valueType), func(t *testing.T) {
// The index specified in Data equals zero.
expr := &ConstantExpression{Data: []byte{0}, Opcode: OpcodeGlobalGet}
@@ -774,7 +785,7 @@ func TestStore_resolveImports(t *testing.T) {
func TestModuleInstance_validateData(t *testing.T) {
m := &ModuleInstance{Memory: &MemoryInstance{Buffer: make([]byte, 5)}}
for _, tc := range []struct {
tests := []struct {
name string
data []*DataSegment
expErr bool
@@ -800,8 +811,10 @@ func TestModuleInstance_validateData(t *testing.T) {
},
expErr: true,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
err := m.validateData(tc.data)
if tc.expErr {

View File

@@ -946,7 +946,7 @@ func TestModule_buildTable_Errors(t *testing.T) {
func TestTableInstance_Grow(t *testing.T) {
expOnErr := uint32(0xffff_ffff) // -1 as signed i32.
max10 := uint32(10)
for _, tc := range []struct {
tests := []struct {
name string
currentLen int
max *uint32
@@ -991,8 +991,10 @@ func TestTableInstance_Grow(t *testing.T) {
max: &max10,
exp: expOnErr,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
table := &TableInstance{References: make([]uintptr, tc.currentLen), Max: tc.max}
actual := table.Grow(testCtx, tc.delta, 0)

View File

@@ -11,7 +11,7 @@ import (
)
func TestFuncName(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name, moduleName, funcName string
funcIdx uint32
expected string
@@ -25,8 +25,10 @@ func TestFuncName(t *testing.T) {
{name: "dots in function", moduleName: "x", funcName: "y.z", expected: "x.y.z"},
{name: "spaces in module", moduleName: "w x", funcName: "y", expected: "w x.y"},
{name: "spaces in function", moduleName: "x", funcName: "y z", expected: "x.y z"},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
funcName := FuncName(tc.moduleName, tc.funcName, tc.funcIdx)
require.Equal(t, tc.expected, funcName)
@@ -36,7 +38,7 @@ func TestFuncName(t *testing.T) {
func TestAddSignature(t *testing.T) {
i32, i64, f32, f64 := api.ValueTypeI32, api.ValueTypeI64, api.ValueTypeF32, api.ValueTypeF64
for _, tc := range []struct {
tests := []struct {
name string
paramTypes, resultTypes []api.ValueType
expected string
@@ -51,8 +53,10 @@ func TestAddSignature(t *testing.T) {
{name: "i32_i64", paramTypes: []api.ValueType{i32}, resultTypes: []api.ValueType{i64}, expected: "x.y(i32) i64"},
{name: "i64f32_i64f32", paramTypes: []api.ValueType{i64, f32}, resultTypes: []api.ValueType{i64, f32}, expected: "x.y(i64,f32) (i64,f32)"},
{name: "i64f32f64_f32i32f64", paramTypes: []api.ValueType{i64, f32, f64}, resultTypes: []api.ValueType{f32, i32, f64}, expected: "x.y(i64,f32,f64) (f32,i32,f64)"},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
withSignature := signature("x.y", tc.paramTypes, tc.resultTypes)
require.Equal(t, tc.expected, withSignature)
@@ -66,7 +70,7 @@ func TestErrorBuilder(t *testing.T) {
i32 := api.ValueTypeI32
i32i32i32i32 := []api.ValueType{i32, i32, i32, i32}
for _, tc := range []struct {
tests := []struct {
name string
build func(ErrorBuilder) error
expectedErr string
@@ -122,8 +126,10 @@ wasm stack trace:
x.y()`,
expectUnwrap: wasmruntime.ErrRuntimeCallStackOverflow,
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
withStackTrace := tc.build(NewErrorBuilder())
require.Equal(t, tc.expectUnwrap, errors.Unwrap(withStackTrace))

View File

@@ -649,7 +649,7 @@ func TestCompile_CallIndirectNonZeroTableIndex(t *testing.T) {
}
func TestCompile_Refs(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
body []byte
expected []Operation
@@ -723,8 +723,10 @@ func TestCompile_Refs(t *testing.T) {
&OperationBr{Target: &BranchTarget{}}, // return!
},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
module := &wasm.Module{
TypeSection: []*wasm.FunctionType{{}},
@@ -739,7 +741,7 @@ func TestCompile_Refs(t *testing.T) {
}
func TestCompile_TableGetOrSet(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
body []byte
expected []Operation
@@ -789,8 +791,10 @@ func TestCompile_TableGetOrSet(t *testing.T) {
&OperationBr{Target: &BranchTarget{}}, // return!
},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
module := &wasm.Module{
TypeSection: []*wasm.FunctionType{{}},
@@ -806,7 +810,7 @@ func TestCompile_TableGetOrSet(t *testing.T) {
}
func TestCompile_TableGrowFillSize(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
body []byte
expected []Operation
@@ -856,8 +860,10 @@ func TestCompile_TableGrowFillSize(t *testing.T) {
&OperationBr{Target: &BranchTarget{}}, // return!
},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
module := &wasm.Module{
TypeSection: []*wasm.FunctionType{{}},
@@ -874,7 +880,7 @@ func TestCompile_TableGrowFillSize(t *testing.T) {
}
func TestCompile_Locals(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
mod *wasm.Module
expected []Operation
@@ -1078,8 +1084,10 @@ func TestCompile_Locals(t *testing.T) {
&OperationBr{Target: &BranchTarget{}}, // return!
},
},
} {
tc := tc
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
res, err := CompileFunctions(ctx, wasm.Features20220419, tc.mod)
require.NoError(t, err)

View File

@@ -8,7 +8,7 @@ import (
)
func TestCompiler_wasmOpcodeSignature(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
body []byte
exp *signature
@@ -88,8 +88,10 @@ func TestCompiler_wasmOpcodeSignature(t *testing.T) {
body: []byte{wasm.OpcodeMiscPrefix, wasm.OpcodeMiscTableCopy},
exp: signature_I32I32I32_None,
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
c := &compiler{body: tc.body}
actual, err := c.wasmOpcodeSignature(tc.body[0], 0)

View File

@@ -18,7 +18,7 @@ func (e *notExitError) Error() string {
func TestIs(t *testing.T) {
err := NewExitError("some module", 2)
for _, tc := range []struct {
tests := []struct {
name string
target error
matches bool
@@ -51,7 +51,10 @@ func TestIs(t *testing.T) {
},
matches: false,
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
matches := errors.Is(err, tc.target)
require.Equal(t, tc.matches, matches)

View File

@@ -29,7 +29,10 @@ func TestInstantiateModule(t *testing.T) {
defer compiled.Close(testCtx)
// Re-use the same module many times.
for _, tc := range []string{"a", "b", "c"} {
tests := []string{"a", "b", "c"}
for _, tt := range tests {
tc := tt
mod, err := r.InstantiateModule(testCtx, compiled, sys.WithArgs(tc).WithName(tc))
require.NoError(t, err)

View File

@@ -2003,7 +2003,7 @@ func (d *fakeSysErr) TimeNowUnixNano() uint64 {
}
func TestSnapshotPreview1_RandomGet_SourceError(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
randSource io.Reader
}{
@@ -2015,7 +2015,10 @@ func TestSnapshotPreview1_RandomGet_SourceError(t *testing.T) {
name: "incomplete",
randSource: bytes.NewReader([]byte{1, 2}),
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
var errCtx = context.WithValue(context.Background(), experimental.SysKey{}, &fakeSysErr{})

View File

@@ -530,7 +530,7 @@ func TestInstantiateModule_ExitError(t *testing.T) {
}
func TestClose(t *testing.T) {
for _, tc := range []struct {
tests := []struct {
name string
exitCode uint32
}{
@@ -542,7 +542,10 @@ func TestClose(t *testing.T) {
name: "exit code 2",
exitCode: uint32(2),
},
} {
}
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
r := NewRuntime()