github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/asm/opcode_test.go (about) 1 package asm 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/go-quicktest/qt" 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, qt.Not(qt.Equals(opcode, InvalidOpCode))) 17 qt.Assert(t, qt.Equals(opcode.JumpOp(), op)) 18 } else { 19 qt.Assert(t, qt.Equals(opcode, InvalidOpCode)) 20 qt.Assert(t, qt.Equals(opcode.JumpOp(), InvalidJumpOp)) 21 } 22 }) 23 } 24 25 // Exit and call aren't allowed with Jump32 26 test(Jump32Class, Exit, false) 27 test(Jump32Class, Call, false) 28 29 // But are with Jump 30 test(JumpClass, Exit, true) 31 test(JumpClass, Call, true) 32 33 // All other ops work 34 for _, op := range []JumpOp{ 35 Ja, 36 JEq, 37 JGT, 38 JGE, 39 JSet, 40 JNE, 41 JSGT, 42 JSGE, 43 JLT, 44 JLE, 45 JSLT, 46 JSLE, 47 } { 48 test(Jump32Class, op, true) 49 test(JumpClass, op, true) 50 } 51 }