diff mbox series

selftests/bpf: Add valid flag to bpf_cookie selftest's res

Message ID 20240904115510.67480-1-chenyuan_fl@163.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series selftests/bpf: Add valid flag to bpf_cookie selftest's res | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-17 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-18 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 fail Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc

Commit Message

Yuan Chen Sept. 4, 2024, 11:55 a.m. UTC
From: Yuan Chen <chenyuan@kylinos.cn>

This patch identifies whether a test item is valid by adding a valid flag to res.

When we test the bpf_cookies/perf_event sub-test item of test_progs, there is a
probability failure of the test item. In fact, this is not a problem, because
the corresponding perf event is not collected. This should not output the test
failure, and it is more reasonable to output SKIP. Therefore, add a valid
identifier to res to distinguish whether the test item is valid, and skip the
test item if it is invalid.

Signed-off-by: Yuan Chen <chenyuan@kylinos.cn>
---
 .../testing/selftests/bpf/prog_tests/bpf_cookie.c | 15 +++++++++++++++
 .../testing/selftests/bpf/progs/test_bpf_cookie.c |  2 ++
 2 files changed, 17 insertions(+)

Comments

Andrii Nakryiko Sept. 5, 2024, 8:43 p.m. UTC | #1
On Wed, Sep 4, 2024 at 9:10 PM Yuan Chen <chenyuan_fl@163.com> wrote:
>
> From: Yuan Chen <chenyuan@kylinos.cn>
>
> This patch identifies whether a test item is valid by adding a valid flag to res.
>
> When we test the bpf_cookies/perf_event sub-test item of test_progs, there is a
> probability failure of the test item. In fact, this is not a problem, because
> the corresponding perf event is not collected. This should not output the test
> failure, and it is more reasonable to output SKIP. Therefore, add a valid
> identifier to res to distinguish whether the test item is valid, and skip the
> test item if it is invalid.
>
> Signed-off-by: Yuan Chen <chenyuan@kylinos.cn>
> ---
>  .../testing/selftests/bpf/prog_tests/bpf_cookie.c | 15 +++++++++++++++
>  .../testing/selftests/bpf/progs/test_bpf_cookie.c |  2 ++
>  2 files changed, 17 insertions(+)
>

I'm not following the proposal. We expect BPF program to fire, and if
it fires, then we should get a valid BPF cookie value. If perf event
didn't fire, then it's flakiness in the test setup, but adding this
SKIP behavior for such a case is just papering over the real issue,
no?

> diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
> index 070c52c312e5..e5bf4b385501 100644
> --- a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
> +++ b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
> @@ -456,6 +456,7 @@ static void pe_subtest(struct test_bpf_cookie *skel)
>         if (!ASSERT_GE(pfd, 0, "perf_fd"))
>                 goto cleanup;
>
> +       skel->bss->res_valid = false;
>         opts.bpf_cookie = 0x100000;
>         link = bpf_program__attach_perf_event_opts(skel->progs.handle_pe, pfd, &opts);
>         if (!ASSERT_OK_PTR(link, "link1"))
> @@ -463,6 +464,12 @@ static void pe_subtest(struct test_bpf_cookie *skel)
>
>         burn_cpu(); /* trigger BPF prog */
>
> +       if (!skel->bss->res_valid) {
> +               printf("%s:SKIP:the corresponding perf event was not sampled.\n",
> +                       __func__);
> +               test__skip();
> +               goto cleanup;
> +       }
>         ASSERT_EQ(skel->bss->pe_res, 0x100000, "pe_res1");
>
>         /* prevent bpf_link__destroy() closing pfd itself */
> @@ -474,6 +481,7 @@ static void pe_subtest(struct test_bpf_cookie *skel)
>         link = NULL;
>         kern_sync_rcu();
>         skel->bss->pe_res = 0;
> +       skel->bss->res_valid = false;
>
>         opts.bpf_cookie = 0x200000;
>         link = bpf_program__attach_perf_event_opts(skel->progs.handle_pe, pfd, &opts);
> @@ -482,6 +490,13 @@ static void pe_subtest(struct test_bpf_cookie *skel)
>
>         burn_cpu(); /* trigger BPF prog */
>
> +       if (!skel->bss->res_valid) {
> +               printf("%s:SKIP:the corresponding perf event was not sampled.\n",
> +                       __func__);
> +               test__skip();
> +               goto cleanup;
> +       }
> +
>         ASSERT_EQ(skel->bss->pe_res, 0x200000, "pe_res2");
>
>  cleanup:
> diff --git a/tools/testing/selftests/bpf/progs/test_bpf_cookie.c b/tools/testing/selftests/bpf/progs/test_bpf_cookie.c
> index c83142b55f47..28d0ae6810d9 100644
> --- a/tools/testing/selftests/bpf/progs/test_bpf_cookie.c
> +++ b/tools/testing/selftests/bpf/progs/test_bpf_cookie.c
> @@ -7,6 +7,7 @@
>  #include <errno.h>
>
>  int my_tid;
> +bool res_valid;
>
>  __u64 kprobe_res;
>  __u64 kprobe_multi_res;
> @@ -27,6 +28,7 @@ static void update(void *ctx, __u64 *res)
>         if (my_tid != (u32)bpf_get_current_pid_tgid())
>                 return;
>
> +       res_valid = true;
>         *res |= bpf_get_attach_cookie(ctx);
>  }
>
> --
> 2.46.0
>
Yuan Chen Sept. 6, 2024, 6:54 a.m. UTC | #2
What you said is reasonable,but it would confuse the test personnel, as there is
no clear reminders. Is it possible to modify it to without SKIP,will give exact 
reminders when it is failed?
Andrii Nakryiko Sept. 6, 2024, 5:31 p.m. UTC | #3
On Thu, Sep 5, 2024 at 11:55 PM Yuan Chen <chenyuan_fl@163.com> wrote:
>
> What you said is reasonable,but it would confuse the test personnel, as there is
> no clear reminders. Is it possible to modify it to without SKIP,will give exact
> reminders when it is failed?
>

You'll get a test failure, I don't think we can provide a guess as to
why any given check failed in selftests for every selftest's
ASSERT_xxx() call. So I'd just leave it as is, I'm not sure what
problem we are trying to solve here, tbh.
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
index 070c52c312e5..e5bf4b385501 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
@@ -456,6 +456,7 @@  static void pe_subtest(struct test_bpf_cookie *skel)
 	if (!ASSERT_GE(pfd, 0, "perf_fd"))
 		goto cleanup;
 
+	skel->bss->res_valid = false;
 	opts.bpf_cookie = 0x100000;
 	link = bpf_program__attach_perf_event_opts(skel->progs.handle_pe, pfd, &opts);
 	if (!ASSERT_OK_PTR(link, "link1"))
@@ -463,6 +464,12 @@  static void pe_subtest(struct test_bpf_cookie *skel)
 
 	burn_cpu(); /* trigger BPF prog */
 
+	if (!skel->bss->res_valid) {
+		printf("%s:SKIP:the corresponding perf event was not sampled.\n",
+		        __func__);
+		test__skip();
+		goto cleanup;
+	}
 	ASSERT_EQ(skel->bss->pe_res, 0x100000, "pe_res1");
 
 	/* prevent bpf_link__destroy() closing pfd itself */
@@ -474,6 +481,7 @@  static void pe_subtest(struct test_bpf_cookie *skel)
 	link = NULL;
 	kern_sync_rcu();
 	skel->bss->pe_res = 0;
+	skel->bss->res_valid = false;
 
 	opts.bpf_cookie = 0x200000;
 	link = bpf_program__attach_perf_event_opts(skel->progs.handle_pe, pfd, &opts);
@@ -482,6 +490,13 @@  static void pe_subtest(struct test_bpf_cookie *skel)
 
 	burn_cpu(); /* trigger BPF prog */
 
+	if (!skel->bss->res_valid) {
+		printf("%s:SKIP:the corresponding perf event was not sampled.\n",
+		        __func__);
+		test__skip();
+		goto cleanup;
+	}
+
 	ASSERT_EQ(skel->bss->pe_res, 0x200000, "pe_res2");
 
 cleanup:
diff --git a/tools/testing/selftests/bpf/progs/test_bpf_cookie.c b/tools/testing/selftests/bpf/progs/test_bpf_cookie.c
index c83142b55f47..28d0ae6810d9 100644
--- a/tools/testing/selftests/bpf/progs/test_bpf_cookie.c
+++ b/tools/testing/selftests/bpf/progs/test_bpf_cookie.c
@@ -7,6 +7,7 @@ 
 #include <errno.h>
 
 int my_tid;
+bool res_valid;
 
 __u64 kprobe_res;
 __u64 kprobe_multi_res;
@@ -27,6 +28,7 @@  static void update(void *ctx, __u64 *res)
 	if (my_tid != (u32)bpf_get_current_pid_tgid())
 		return;
 
+	res_valid = true;
 	*res |= bpf_get_attach_cookie(ctx);
 }