2015-11-04 19:54:54

by Shi, Yang

[permalink] [raw]
Subject: [PATCH] bpf: add mod default A and X test cases

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]>
---
lib/test_bpf.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)

diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index d137739..10cd186 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -5056,6 +5056,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 = {
/*
--
2.0.2


2015-11-04 20:15:34

by Daniel Borkmann

[permalink] [raw]
Subject: Re: [PATCH] bpf: add mod default A and X test cases

On 11/04/2015 08:36 PM, Yang Shi wrote:
> 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]>

LGTM!

Acked-by: Daniel Borkmann <[email protected]>

2015-11-04 20:25:54

by Alexei Starovoitov

[permalink] [raw]
Subject: Re: [PATCH] bpf: add mod default A and X test cases

On Wed, Nov 04, 2015 at 11:36:37AM -0800, Yang Shi wrote:
> 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: Alexei Starovoitov <[email protected]>

2015-11-04 22:05:08

by Z Lim

[permalink] [raw]
Subject: Re: [PATCH] bpf: add mod default A and X test cases

On Wed, Nov 4, 2015 at 11:36 AM, Yang Shi <[email protected]> wrote:
> 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: Zi Shen Lim <[email protected]>

2015-11-04 22:44:31

by Xi Wang

[permalink] [raw]
Subject: Re: [PATCH] bpf: add mod default A and X test cases

On Wed, Nov 4, 2015 at 11:36 AM, Yang Shi <[email protected]> wrote:
> 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: Xi Wang <[email protected]>

2015-11-05 05:06:12

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] bpf: add mod default A and X test cases

From: Yang Shi <[email protected]>
Date: Wed, 4 Nov 2015 11:36:37 -0800

> 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]>

Applied, thank you.