forked from cilium/ebpf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opcode_test.go
52 lines (45 loc) · 988 Bytes
/
opcode_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package asm
import (
"fmt"
"testing"
qt "github.com/frankban/quicktest"
)
func TestGetSetJumpOp(t *testing.T) {
test := func(class Class, op JumpOp, valid bool) {
t.Run(fmt.Sprintf("%s-%s", class, op), func(t *testing.T) {
opcode := OpCode(class).SetJumpOp(op)
if valid {
qt.Assert(t, opcode, qt.Not(qt.Equals), InvalidOpCode)
qt.Assert(t, opcode.JumpOp(), qt.Equals, op)
} else {
qt.Assert(t, opcode, qt.Equals, InvalidOpCode)
qt.Assert(t, opcode.JumpOp(), qt.Equals, InvalidJumpOp)
}
})
}
// Exit, call and JA aren't allowed with Jump32
test(Jump32Class, Exit, false)
test(Jump32Class, Call, false)
test(Jump32Class, Ja, false)
// But are with Jump
test(JumpClass, Exit, true)
test(JumpClass, Call, true)
test(JumpClass, Ja, true)
// All other ops work
for _, op := range []JumpOp{
JEq,
JGT,
JGE,
JSet,
JNE,
JSGT,
JSGE,
JLT,
JLE,
JSLT,
JSLE,
} {
test(Jump32Class, op, true)
test(JumpClass, op, true)
}
}