More opcode tests
This commit is contained in:
@@ -65,3 +65,91 @@ functions:
|
|||||||
|
|
||||||
expectGlobalMemory(t, state, 0, 15)
|
expectGlobalMemory(t, state, 0, 15)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSub(t *testing.T) {
|
||||||
|
state := assembleAndExecute(t, `
|
||||||
|
functions:
|
||||||
|
- - [sub, g0, 2]
|
||||||
|
- [sub, g0, -5]
|
||||||
|
- [sub, f0, 4]
|
||||||
|
- [sub, g0, f0]
|
||||||
|
`)
|
||||||
|
|
||||||
|
expectGlobalMemory(t, state, 0, 7)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMul(t *testing.T) {
|
||||||
|
state := assembleAndExecute(t, `
|
||||||
|
functions:
|
||||||
|
- - [mov, g0, 5]
|
||||||
|
- [mul, g0, 3]
|
||||||
|
- [mul, g0, g0]
|
||||||
|
- [mov, g1, 5]
|
||||||
|
- [mul, g1, -3]
|
||||||
|
`)
|
||||||
|
|
||||||
|
expectGlobalMemory(t, state, 0, 225)
|
||||||
|
expectGlobalMemorySigned(t, state, 1, -15)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDivU(t *testing.T) {
|
||||||
|
state := assembleAndExecute(t, `
|
||||||
|
functions:
|
||||||
|
- - [mov, g0, 15]
|
||||||
|
- [divu, g0, 3]
|
||||||
|
- [mov, g1, 4]
|
||||||
|
- [divu, g1, g1]
|
||||||
|
`)
|
||||||
|
|
||||||
|
expectGlobalMemory(t, state, 0, 5)
|
||||||
|
expectGlobalMemory(t, state, 1, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDivS(t *testing.T) {
|
||||||
|
state := assembleAndExecute(t, `
|
||||||
|
functions:
|
||||||
|
- - [mov, g0, 15]
|
||||||
|
- [divs, g0, -3]
|
||||||
|
- [mov, g1, -15]
|
||||||
|
- [divs, g1, -3]
|
||||||
|
- [mov, g2, -4]
|
||||||
|
- [divs, g2, g2]
|
||||||
|
`)
|
||||||
|
|
||||||
|
expectGlobalMemorySigned(t, state, 0, -5)
|
||||||
|
expectGlobalMemorySigned(t, state, 1, 5)
|
||||||
|
expectGlobalMemorySigned(t, state, 2, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEq(t *testing.T) {
|
||||||
|
state := assembleAndExecute(t, `
|
||||||
|
functions:
|
||||||
|
- - [mov, g0, 5]
|
||||||
|
- [eq, g0, 5]
|
||||||
|
- [jmpt, +2]
|
||||||
|
- [add, g1, 1]
|
||||||
|
- [eq, g0, 6]
|
||||||
|
- [jmpt, +2]
|
||||||
|
- [add, g1, 2]
|
||||||
|
`)
|
||||||
|
|
||||||
|
expectGlobalMemory(t, state, 1, 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLTU(t *testing.T) {
|
||||||
|
state := assembleAndExecute(t, `
|
||||||
|
functions:
|
||||||
|
- - [mov, g0, 5]
|
||||||
|
- [ltu, g0, 4]
|
||||||
|
- [jmpt, +2]
|
||||||
|
- [add, g1, 1]
|
||||||
|
- [ltu, g0, 5]
|
||||||
|
- [jmpt, +2]
|
||||||
|
- [add, g1, 2]
|
||||||
|
- [ltu, g0, 6]
|
||||||
|
- [jmpt, +2]
|
||||||
|
- [add, g1, 4]
|
||||||
|
`)
|
||||||
|
|
||||||
|
expectGlobalMemory(t, state, 1, 3)
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,3 +30,10 @@ func expectGlobalMemory(t *testing.T, state *vm.State, i uint64, expected uint64
|
|||||||
t.Fatalf("Global memory index %d: expected=%d actual=%d\n", i, expected, actual)
|
t.Fatalf("Global memory index %d: expected=%d actual=%d\n", i, expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func expectGlobalMemorySigned(t *testing.T, state *vm.State, i uint64, expected int64) {
|
||||||
|
actual := int64(state.GlobalMemory().MustReadUnsigned(i))
|
||||||
|
if actual != expected {
|
||||||
|
t.Fatalf("Global memory index %d: expected=%d actual=%d\n", i, expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user