Extended Berkeley Packet Filter (eBPF) assembler and virtual machine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

83 lines
1.4 KiB

package ebpf
import (
"testing"
)
func TestJump(t *testing.T) {
testInstruction{
Test: Jump{
Offset: 0x23a2,
},
WantRaw: RawInstruction{
Op: opClassJump | jumpOp,
Offset: 0x23a2,
},
WantString: "ja +9122",
}.Run(t)
}
func TestJumpIf(t *testing.T) {
tests := testInstructionSuite{
{
Test: JumpIf{
Cond: JumpEqual,
Dst: R1,
Value: 0x2a,
Offset: 666,
},
WantRaw: RawInstruction{
Op: opClassJump | jumpOpEqual,
Dst: R1,
Offset: 0x29a,
Immediate: 0x2a,
},
WantString: "jeq R1, 42, +666",
},
{
Test: JumpIf{
Cond: JumpSignedLessOrEqual,
Dst: R2,
Value: 1,
Offset: 2,
},
WantRaw: RawInstruction{
Op: opClassJump | jumpOpSignedLessOrEqual,
Dst: R2,
Offset: 2,
Immediate: 1,
},
WantString: "jsle R2, 1, +2",
},
}
tests.Run(t)
}
func TestJumpIfX(t *testing.T) {
tests := testInstructionSuite{
{
Test: JumpIfX{
Cond: JumpEqual,
Src: R2,
Dst: R1,
Offset: 666,
},
WantRaw: RawInstruction{
Op: opClassJump | jumpOpEqual | jumpSourceX,
Src: R2,
Dst: R1,
Offset: 0x29a,
},
WantString: "jeq R1, R2, +666",
},
}
tests.Run(t)
}
func TestExit(t *testing.T) {
testInstruction{
Test: Exit{},
WantRaw: RawInstruction{Op: opClassJump | jumpOpExit},
WantString: "exit",
}.Run(t)
}