bpf: add selftests for lsh, rsh, arsh with reg operand
authorJie Meng <jmeng@fb.com>
Fri, 7 Oct 2022 20:23:49 +0000 (13:23 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 19 Oct 2022 23:53:51 +0000 (16:53 -0700)
Current tests cover only shifts with an immediate as the source
operand/shift counts; add a new test case to cover register operand.

Signed-off-by: Jie Meng <jmeng@fb.com>
Link: https://lore.kernel.org/r/20221007202348.1118830-4-jmeng@fb.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/verifier/jit.c

index 79021c3..8bf37e5 100644 (file)
        .retval = 2,
 },
 {
+       "jit: lsh, rsh, arsh by reg",
+       .insns = {
+       BPF_MOV64_IMM(BPF_REG_0, 1),
+       BPF_MOV64_IMM(BPF_REG_4, 1),
+       BPF_MOV64_IMM(BPF_REG_1, 0xff),
+       BPF_ALU64_REG(BPF_LSH, BPF_REG_1, BPF_REG_0),
+       BPF_ALU32_REG(BPF_LSH, BPF_REG_1, BPF_REG_4),
+       BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0x3fc, 1),
+       BPF_EXIT_INSN(),
+       BPF_ALU64_REG(BPF_RSH, BPF_REG_1, BPF_REG_4),
+       BPF_MOV64_REG(BPF_REG_4, BPF_REG_1),
+       BPF_ALU32_REG(BPF_RSH, BPF_REG_4, BPF_REG_0),
+       BPF_JMP_IMM(BPF_JEQ, BPF_REG_4, 0xff, 1),
+       BPF_EXIT_INSN(),
+       BPF_ALU64_REG(BPF_ARSH, BPF_REG_4, BPF_REG_4),
+       BPF_JMP_IMM(BPF_JEQ, BPF_REG_4, 0, 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),