Skip to content

Commit

Permalink
selftests: bpf: functional and min/max reasoning unit tests for JMP32
Browse files Browse the repository at this point in the history
This patch adds unit tests for new JMP32 instructions.

This patch also added the new BPF_JMP32_REG and BPF_JMP32_IMM macros to
samples/bpf/bpf_insn.h so that JMP32 insn builders are available to tests
under 'samples' directory.

Reviewed-by: Jakub Kicinski <[email protected]>
Signed-off-by: Jiong Wang <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
  • Loading branch information
Jiong Wang authored and Alexei Starovoitov committed Jan 26, 2019
1 parent 4614483 commit 6ea848b
Show file tree
Hide file tree
Showing 2 changed files with 782 additions and 24 deletions.
20 changes: 20 additions & 0 deletions samples/bpf/bpf_insn.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ struct bpf_insn;
.off = OFF, \
.imm = 0 })

/* Like BPF_JMP_REG, but with 32-bit wide operands for comparison. */

#define BPF_JMP32_REG(OP, DST, SRC, OFF) \
((struct bpf_insn) { \
.code = BPF_JMP32 | BPF_OP(OP) | BPF_X, \
.dst_reg = DST, \
.src_reg = SRC, \
.off = OFF, \
.imm = 0 })

/* Conditional jumps against immediates, if (dst_reg 'op' imm32) goto pc + off16 */

#define BPF_JMP_IMM(OP, DST, IMM, OFF) \
Expand All @@ -174,6 +184,16 @@ struct bpf_insn;
.off = OFF, \
.imm = IMM })

/* Like BPF_JMP_IMM, but with 32-bit wide operands for comparison. */

#define BPF_JMP32_IMM(OP, DST, IMM, OFF) \
((struct bpf_insn) { \
.code = BPF_JMP32 | BPF_OP(OP) | BPF_K, \
.dst_reg = DST, \
.src_reg = 0, \
.off = OFF, \
.imm = IMM })

/* Raw code statement block */

#define BPF_RAW_INSN(CODE, DST, SRC, OFF, IMM) \
Expand Down
Loading

0 comments on commit 6ea848b

Please sign in to comment.