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