2022-04-06 08:43:35

by Yuntao Wang

[permalink] [raw]
Subject: [PATCH bpf-next] selftests/bpf: Remove redundant checks in get_stack_print_output()

The checks preceding CHECK macro are redundant, remove them.

Signed-off-by: Yuntao Wang <[email protected]>
---
tools/testing/selftests/bpf/prog_tests/get_stack_raw_tp.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/get_stack_raw_tp.c b/tools/testing/selftests/bpf/prog_tests/get_stack_raw_tp.c
index 16048978a1ef..5f2ab720dabd 100644
--- a/tools/testing/selftests/bpf/prog_tests/get_stack_raw_tp.c
+++ b/tools/testing/selftests/bpf/prog_tests/get_stack_raw_tp.c
@@ -76,10 +76,8 @@ static void get_stack_print_output(void *ctx, int cpu, void *data, __u32 size)
good_user_stack = true;
}

- if (!good_kern_stack)
- CHECK(!good_kern_stack, "kern_stack", "corrupted kernel stack\n");
- if (!good_user_stack)
- CHECK(!good_user_stack, "user_stack", "corrupted user stack\n");
+ CHECK(!good_kern_stack, "kern_stack", "corrupted kernel stack\n");
+ CHECK(!good_user_stack, "user_stack", "corrupted user stack\n");
}

void test_get_stack_raw_tp(void)
--
2.35.1


2022-04-06 13:48:36

by Andrii Nakryiko

[permalink] [raw]
Subject: Re: [PATCH bpf-next] selftests/bpf: Remove redundant checks in get_stack_print_output()

On Tue, Apr 5, 2022 at 9:39 AM Yuntao Wang <[email protected]> wrote:
>
> The checks preceding CHECK macro are redundant, remove them.
>
> Signed-off-by: Yuntao Wang <[email protected]>
> ---
> tools/testing/selftests/bpf/prog_tests/get_stack_raw_tp.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/get_stack_raw_tp.c b/tools/testing/selftests/bpf/prog_tests/get_stack_raw_tp.c
> index 16048978a1ef..5f2ab720dabd 100644
> --- a/tools/testing/selftests/bpf/prog_tests/get_stack_raw_tp.c
> +++ b/tools/testing/selftests/bpf/prog_tests/get_stack_raw_tp.c
> @@ -76,10 +76,8 @@ static void get_stack_print_output(void *ctx, int cpu, void *data, __u32 size)
> good_user_stack = true;
> }
>
> - if (!good_kern_stack)
> - CHECK(!good_kern_stack, "kern_stack", "corrupted kernel stack\n");
> - if (!good_user_stack)
> - CHECK(!good_user_stack, "user_stack", "corrupted user stack\n");
> + CHECK(!good_kern_stack, "kern_stack", "corrupted kernel stack\n");
> + CHECK(!good_user_stack, "user_stack", "corrupted user stack\n");

I suspect it was to avoid super long verbose logs, as each CHECK()
emits one line into output and here we might be getting a lot of
samples. So let's keep it as is. But for the future let's try getting
rid of CHECK()s as much as possible in favor of ASSERT_xxx(). Thanks.

> }
>
> void test_get_stack_raw_tp(void)
> --
> 2.35.1
>