Skip to content

Commit

Permalink
bpf: add mod default A and X test cases
Browse files Browse the repository at this point in the history
When running "mod X" operation, if X is 0 the filter has to be halt.
Add new test cases to cover A = A mod X if X is 0, and A = A mod 1.

CC: Xi Wang <[email protected]>
CC: Zi Shen Lim <[email protected]>
Signed-off-by: Yang Shi <[email protected]>
Acked-by: Daniel Borkmann <[email protected]>
Acked-by: Alexei Starovoitov <[email protected]>
Acked-by: Zi Shen Lim <[email protected]>
Acked-by: Xi Wang <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Yang Shi authored and davem330 committed Nov 5, 2015
1 parent df761ea commit d4e4bc1
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/test_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -5055,6 +5055,36 @@ static struct bpf_test tests[] = {
{},
{ {0x1, 0x0 } },
},
{
"MOD default X",
.u.insns = {
/*
* A = 0x42
* A = A mod X ; this halt the filter execution if X is 0
* ret 0x42
*/
BPF_STMT(BPF_LD | BPF_IMM, 0x42),
BPF_STMT(BPF_ALU | BPF_MOD | BPF_X, 0),
BPF_STMT(BPF_RET | BPF_K, 0x42),
},
CLASSIC | FLAG_NO_DATA,
{},
{ {0x1, 0x0 } },
},
{
"MOD default A",
.u.insns = {
/*
* A = A mod 1
* ret A
*/
BPF_STMT(BPF_ALU | BPF_MOD | BPF_K, 0x1),
BPF_STMT(BPF_RET | BPF_A, 0x0),
},
CLASSIC | FLAG_NO_DATA,
{},
{ {0x1, 0x0 } },
},
{
"JMP EQ default A",
.u.insns = {
Expand Down

0 comments on commit d4e4bc1

Please sign in to comment.