File: dsl_test.go

package info (click to toggle)
golang-github-cilium-ebpf 0.17.3%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,684 kB
  • sloc: ansic: 1,259; makefile: 127; python: 113; awk: 29; sh: 24
file content (46 lines) | stat: -rw-r--r-- 1,383 bytes parent folder | download | duplicates (3)
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)
		}
	}
}