forked from cilium/ebpf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsl_test.go
46 lines (43 loc) · 1.35 KB
/
dsl_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
package asm
import (
"testing"
)
func TestDSL(t *testing.T) {
testcases := []struct {
name string
have Instruction
want Instruction
}{
{"Call", FnMapLookupElem.Call(), Instruction{OpCode: 0x85, Constant: 1}},
{"Exit", Return(), Instruction{OpCode: 0x95}},
{"LoadAbs", LoadAbs(2, Byte), Instruction{OpCode: 0x30, Constant: 2}},
{"Store", StoreMem(RFP, -4, R0, Word), Instruction{
OpCode: 0x63,
Dst: RFP,
Src: R0,
Offset: -4,
}},
{"Add.Imm", Add.Imm(R1, 22), Instruction{OpCode: 0x07, Dst: R1, Constant: 22}},
{"Add.Reg", Add.Reg(R1, R2), Instruction{OpCode: 0x0f, Dst: R1, Src: R2}},
{"Add.Imm32", Add.Imm32(R1, 22), Instruction{
OpCode: 0x04, Dst: R1, Constant: 22,
}},
{"JSGT.Imm", JSGT.Imm(R1, 4, "foo"), Instruction{
OpCode: 0x65, Dst: R1, Constant: 4, Offset: -1,
}.WithReference("foo")},
{"JSGT.Imm32", JSGT.Imm32(R1, -2, "foo"), Instruction{
OpCode: 0x66, Dst: R1, Constant: -2, Offset: -1,
}.WithReference("foo")},
{"JSLT.Reg", JSLT.Reg(R1, R2, "foo"), Instruction{
OpCode: 0xcd, Dst: R1, Src: R2, Offset: -1,
}.WithReference("foo")},
{"JSLT.Reg32", JSLT.Reg32(R1, R3, "foo"), Instruction{
OpCode: 0xce, Dst: R1, Src: R3, Offset: -1,
}.WithReference("foo")},
}
for _, tc := range testcases {
if !tc.have.equal(tc.want) {
t.Errorf("%s: have %v, want %v", tc.name, tc.have, tc.want)
}
}
}