Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] bpf/tests: do not PASS tests without actually testing the result
@ 2021-07-21 10:38 Johan Almbladh
  2021-07-24  0:23 ` Andrii Nakryiko
  2021-07-24  0:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Johan Almbladh @ 2021-07-21 10:38 UTC (permalink / raw)
  To: ast, daniel, andrii
  Cc: kafai, songliubraving, yhs, john.fastabend, kpsingh,
	Tony.Ambardar, netdev, bpf, Johan Almbladh

Each test case can have a set of sub-tests, where each sub-test can
run the cBPF/eBPF test snippet with its own data_size and expected
result. Before, the end of the sub-test array was indicated by both
data_size and result being zero. However, most or all of the internal
eBPF tests has a data_size of zero already. When such a test also had
an expected value of zero, the test was never run but reported as
PASS anyway.

Now the test runner always runs the first sub-test, regardless of the
data_size and result values. The sub-test array zero-termination only
applies for any additional sub-tests.

There are other ways fix it of course, but this solution at least
removes the surprise of eBPF tests with a zero result always succeeding.

Signed-off-by: Johan Almbladh <johan.almbladh@anyfinetworks.com>
---
 lib/test_bpf.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index d500320778c7..baff847a02da 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -6659,7 +6659,14 @@ static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
 		u64 duration;
 		u32 ret;
 
-		if (test->test[i].data_size == 0 &&
+		/*
+		 * NOTE: Several sub-tests may be present, in which case
+		 * a zero {data_size, result} tuple indicates the end of
+		 * the sub-test array. The first test is always run,
+		 * even if both data_size and result happen to be zero.
+		 */
+		if (i > 0 &&
+		    test->test[i].data_size == 0 &&
 		    test->test[i].result == 0)
 			break;
 
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] bpf/tests: do not PASS tests without actually testing the result
  2021-07-21 10:38 [PATCH] bpf/tests: do not PASS tests without actually testing the result Johan Almbladh
@ 2021-07-24  0:23 ` Andrii Nakryiko
  2021-07-24  0:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2021-07-24  0:23 UTC (permalink / raw)
  To: Johan Almbladh
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Martin Lau,
	Song Liu, Yonghong Song, john fastabend, KP Singh, Tony Ambardar,
	Networking, bpf

On Wed, Jul 21, 2021 at 3:39 AM Johan Almbladh
<johan.almbladh@anyfinetworks.com> wrote:
>
> Each test case can have a set of sub-tests, where each sub-test can
> run the cBPF/eBPF test snippet with its own data_size and expected
> result. Before, the end of the sub-test array was indicated by both
> data_size and result being zero. However, most or all of the internal
> eBPF tests has a data_size of zero already. When such a test also had
> an expected value of zero, the test was never run but reported as
> PASS anyway.
>
> Now the test runner always runs the first sub-test, regardless of the
> data_size and result values. The sub-test array zero-termination only
> applies for any additional sub-tests.
>
> There are other ways fix it of course, but this solution at least
> removes the surprise of eBPF tests with a zero result always succeeding.
>
> Signed-off-by: Johan Almbladh <johan.almbladh@anyfinetworks.com>
> ---
>  lib/test_bpf.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/lib/test_bpf.c b/lib/test_bpf.c
> index d500320778c7..baff847a02da 100644
> --- a/lib/test_bpf.c
> +++ b/lib/test_bpf.c
> @@ -6659,7 +6659,14 @@ static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
>                 u64 duration;
>                 u32 ret;
>
> -               if (test->test[i].data_size == 0 &&
> +               /*
> +                * NOTE: Several sub-tests may be present, in which case
> +                * a zero {data_size, result} tuple indicates the end of
> +                * the sub-test array. The first test is always run,
> +                * even if both data_size and result happen to be zero.
> +                */
> +               if (i > 0 &&

This feels pretty arbitrary, of course, but I don't see how to improve
this easily without tons of code churn for each test specification.
Applied to bpf-next, thanks!

> +                   test->test[i].data_size == 0 &&
>                     test->test[i].result == 0)
>                         break;
>
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] bpf/tests: do not PASS tests without actually testing the result
  2021-07-21 10:38 [PATCH] bpf/tests: do not PASS tests without actually testing the result Johan Almbladh
  2021-07-24  0:23 ` Andrii Nakryiko
@ 2021-07-24  0:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-07-24  0:30 UTC (permalink / raw)
  To: Johan Almbladh
  Cc: ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend,
	kpsingh, Tony.Ambardar, netdev, bpf

Hello:

This patch was applied to bpf/bpf-next.git (refs/heads/master):

On Wed, 21 Jul 2021 12:38:22 +0200 you wrote:
> Each test case can have a set of sub-tests, where each sub-test can
> run the cBPF/eBPF test snippet with its own data_size and expected
> result. Before, the end of the sub-test array was indicated by both
> data_size and result being zero. However, most or all of the internal
> eBPF tests has a data_size of zero already. When such a test also had
> an expected value of zero, the test was never run but reported as
> PASS anyway.
> 
> [...]

Here is the summary with links:
  - bpf/tests: do not PASS tests without actually testing the result
    https://git.kernel.org/bpf/bpf-next/c/2b7e9f25e590

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-24  0:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-21 10:38 [PATCH] bpf/tests: do not PASS tests without actually testing the result Johan Almbladh
2021-07-24  0:23 ` Andrii Nakryiko
2021-07-24  0:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).