bpf: add various jit test cases
authorDaniel Borkmann <daniel@iogearbox.net>
Sat, 24 Feb 2018 00:08:03 +0000 (01:08 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 24 Feb 2018 06:50:00 +0000 (22:50 -0800)
Add few test cases that check the rnu-time results under JIT.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/test_verifier.c

index 2971ba2829acef46a92f7cd4bc869175801d6c23..c987d3a2426f93b2a1fe1aec1e99e19cb5d65c06 100644 (file)
@@ -11140,6 +11140,95 @@ static struct bpf_test tests[] = {
                .result = REJECT,
                .prog_type = BPF_PROG_TYPE_TRACEPOINT,
        },
+       {
+               "jit: lsh, rsh, arsh by 1",
+               .insns = {
+                       BPF_MOV64_IMM(BPF_REG_0, 1),
+                       BPF_MOV64_IMM(BPF_REG_1, 0xff),
+                       BPF_ALU64_IMM(BPF_LSH, BPF_REG_1, 1),
+                       BPF_ALU32_IMM(BPF_LSH, BPF_REG_1, 1),
+                       BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0x3fc, 1),
+                       BPF_EXIT_INSN(),
+                       BPF_ALU64_IMM(BPF_RSH, BPF_REG_1, 1),
+                       BPF_ALU32_IMM(BPF_RSH, BPF_REG_1, 1),
+                       BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0xff, 1),
+                       BPF_EXIT_INSN(),
+                       BPF_ALU64_IMM(BPF_ARSH, BPF_REG_1, 1),
+                       BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0x7f, 1),
+                       BPF_EXIT_INSN(),
+                       BPF_MOV64_IMM(BPF_REG_0, 2),
+                       BPF_EXIT_INSN(),
+               },
+               .result = ACCEPT,
+               .retval = 2,
+       },
+       {
+               "jit: mov32 for ldimm64, 1",
+               .insns = {
+                       BPF_MOV64_IMM(BPF_REG_0, 2),
+                       BPF_LD_IMM64(BPF_REG_1, 0xfeffffffffffffffULL),
+                       BPF_ALU64_IMM(BPF_RSH, BPF_REG_1, 32),
+                       BPF_LD_IMM64(BPF_REG_2, 0xfeffffffULL),
+                       BPF_JMP_REG(BPF_JEQ, BPF_REG_1, BPF_REG_2, 1),
+                       BPF_MOV64_IMM(BPF_REG_0, 1),
+                       BPF_EXIT_INSN(),
+               },
+               .result = ACCEPT,
+               .retval = 2,
+       },
+       {
+               "jit: mov32 for ldimm64, 2",
+               .insns = {
+                       BPF_MOV64_IMM(BPF_REG_0, 1),
+                       BPF_LD_IMM64(BPF_REG_1, 0x1ffffffffULL),
+                       BPF_LD_IMM64(BPF_REG_2, 0xffffffffULL),
+                       BPF_JMP_REG(BPF_JEQ, BPF_REG_1, BPF_REG_2, 1),
+                       BPF_MOV64_IMM(BPF_REG_0, 2),
+                       BPF_EXIT_INSN(),
+               },
+               .result = ACCEPT,
+               .retval = 2,
+       },
+       {
+               "jit: various mul tests",
+               .insns = {
+                       BPF_LD_IMM64(BPF_REG_2, 0xeeff0d413122ULL),
+                       BPF_LD_IMM64(BPF_REG_0, 0xfefefeULL),
+                       BPF_LD_IMM64(BPF_REG_1, 0xefefefULL),
+                       BPF_ALU64_REG(BPF_MUL, BPF_REG_0, BPF_REG_1),
+                       BPF_JMP_REG(BPF_JEQ, BPF_REG_0, BPF_REG_2, 2),
+                       BPF_MOV64_IMM(BPF_REG_0, 1),
+                       BPF_EXIT_INSN(),
+                       BPF_LD_IMM64(BPF_REG_3, 0xfefefeULL),
+                       BPF_ALU64_REG(BPF_MUL, BPF_REG_3, BPF_REG_1),
+                       BPF_JMP_REG(BPF_JEQ, BPF_REG_3, BPF_REG_2, 2),
+                       BPF_MOV64_IMM(BPF_REG_0, 1),
+                       BPF_EXIT_INSN(),
+                       BPF_MOV32_REG(BPF_REG_2, BPF_REG_2),
+                       BPF_LD_IMM64(BPF_REG_0, 0xfefefeULL),
+                       BPF_ALU32_REG(BPF_MUL, BPF_REG_0, BPF_REG_1),
+                       BPF_JMP_REG(BPF_JEQ, BPF_REG_0, BPF_REG_2, 2),
+                       BPF_MOV64_IMM(BPF_REG_0, 1),
+                       BPF_EXIT_INSN(),
+                       BPF_LD_IMM64(BPF_REG_3, 0xfefefeULL),
+                       BPF_ALU32_REG(BPF_MUL, BPF_REG_3, BPF_REG_1),
+                       BPF_JMP_REG(BPF_JEQ, BPF_REG_3, BPF_REG_2, 2),
+                       BPF_MOV64_IMM(BPF_REG_0, 1),
+                       BPF_EXIT_INSN(),
+                       BPF_LD_IMM64(BPF_REG_0, 0x952a7bbcULL),
+                       BPF_LD_IMM64(BPF_REG_1, 0xfefefeULL),
+                       BPF_LD_IMM64(BPF_REG_2, 0xeeff0d413122ULL),
+                       BPF_ALU32_REG(BPF_MUL, BPF_REG_2, BPF_REG_1),
+                       BPF_JMP_REG(BPF_JEQ, BPF_REG_2, BPF_REG_0, 2),
+                       BPF_MOV64_IMM(BPF_REG_0, 1),
+                       BPF_EXIT_INSN(),
+                       BPF_MOV64_IMM(BPF_REG_0, 2),
+                       BPF_EXIT_INSN(),
+               },
+               .result = ACCEPT,
+               .retval = 2,
+       },
+
 };
 
 static int probe_filter_length(const struct bpf_insn *fp)