Skip to content

Commit c099f3f

Browse files
Jiong WangAlexei Starovoitov
authored andcommitted
selftests: bpf: update testcases for BPF_ALU | BPF_ARSH
"arsh32 on imm" and "arsh32 on reg" now are accepted. Also added two new testcases to make sure arsh32 won't be treated as arsh64 during interpretation or JIT code-gen for which case the high bits will be moved into low halve that the testcases could catch them. Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: Jiong Wang <jiong.wang@netronome.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent c49f7db commit c099f3f

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

tools/testing/selftests/bpf/test_verifier.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,18 @@ static struct bpf_test tests[] = {
721721
BPF_ALU32_IMM(BPF_ARSH, BPF_REG_0, 5),
722722
BPF_EXIT_INSN(),
723723
},
724-
.result = REJECT,
725-
.errstr = "unknown opcode c4",
724+
.result = ACCEPT,
725+
.retval = 0,
726+
},
727+
{
728+
"arsh32 on imm 2",
729+
.insns = {
730+
BPF_LD_IMM64(BPF_REG_0, 0x1122334485667788),
731+
BPF_ALU32_IMM(BPF_ARSH, BPF_REG_0, 7),
732+
BPF_EXIT_INSN(),
733+
},
734+
.result = ACCEPT,
735+
.retval = -16069393,
726736
},
727737
{
728738
"arsh32 on reg",
@@ -732,8 +742,19 @@ static struct bpf_test tests[] = {
732742
BPF_ALU32_REG(BPF_ARSH, BPF_REG_0, BPF_REG_1),
733743
BPF_EXIT_INSN(),
734744
},
735-
.result = REJECT,
736-
.errstr = "unknown opcode cc",
745+
.result = ACCEPT,
746+
.retval = 0,
747+
},
748+
{
749+
"arsh32 on reg 2",
750+
.insns = {
751+
BPF_LD_IMM64(BPF_REG_0, 0xffff55667788),
752+
BPF_MOV64_IMM(BPF_REG_1, 15),
753+
BPF_ALU32_REG(BPF_ARSH, BPF_REG_0, BPF_REG_1),
754+
BPF_EXIT_INSN(),
755+
},
756+
.result = ACCEPT,
757+
.retval = 43724,
737758
},
738759
{
739760
"arsh64 on imm",

0 commit comments

Comments
 (0)