All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yonghong Song <yonghong.song@linux.dev>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	kernel-team@fb.com, Martin KaFai Lau <martin.lau@kernel.org>
Subject: Re: [PATCH bpf-next 1/4] selftests/bpf: Replace CHECK with ASSERT macros for ksyms test
Date: Mon, 4 Mar 2024 23:21:07 -0800	[thread overview]
Message-ID: <5474994c-4c9e-4633-a189-b3dfe98906e4@linux.dev> (raw)
In-Reply-To: <CAEf4Bzad8b4ZxNjx_sK=pxGrEdz_M1-2VJAj6bsg7ZLA+5s_fg@mail.gmail.com>


On 3/4/24 4:17 PM, Andrii Nakryiko wrote:
> On Sat, Mar 2, 2024 at 8:50 AM Yonghong Song <yonghong.song@linux.dev> wrote:
>> I am going to modify ksyms test later so take this opportunity
>> to replace old CHECK macros with new ASSERT macros.
>> No functionality change.
>>
>> Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
>> ---
>>   .../testing/selftests/bpf/prog_tests/ksyms.c  | 38 +++++++++----------
>>   1 file changed, 19 insertions(+), 19 deletions(-)
>>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/ksyms.c b/tools/testing/selftests/bpf/prog_tests/ksyms.c
>> index b295969b263b..e081f8bf3f17 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/ksyms.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/ksyms.c
>> @@ -5,8 +5,6 @@
>>   #include "test_ksyms.skel.h"
>>   #include <sys/stat.h>
>>
>> -static int duration;
>> -
>>   void test_ksyms(void)
>>   {
>>          const char *btf_path = "/sys/kernel/btf/vmlinux";
>> @@ -18,43 +16,45 @@ void test_ksyms(void)
>>          int err;
>>
>>          err = kallsyms_find("bpf_link_fops", &link_fops_addr);
>> -       if (CHECK(err == -EINVAL, "kallsyms_fopen", "failed to open: %d\n", errno))
>> +       if (err == -EINVAL) {
>> +               ASSERT_TRUE(false, "kallsyms_fopen for bpf_link_fops");
> should this (and few other cases below) be ASSERT_EQ()/ASSERT_NEQ()
> (whichever makes sense, I can't reason about CHECK() conditions).

The below 'err == -ENOENT' case will later be modified in Patch 3 where I cannot
do ASSERT_EQ(err, -ENOENT) which is why I do 'err == -EINVAL' here. But you have
a good point that ASSERT_EQ/NEQ is easier to understand. Will fix it in the next
revision.

>
> ASSERT_TRUE(false) is a last resort way, we have more meaningful checks.
>
>>                  return;
>> -       if (CHECK(err == -ENOENT, "ksym_find", "symbol 'bpf_link_fops' not found\n"))
>> +       }
>> +       if (err == -ENOENT) {
>> +               ASSERT_TRUE(false, "ksym_find for bpf_link_fops");
>>                  return;
>> +       }
>>
>>          err = kallsyms_find("__per_cpu_start", &per_cpu_start_addr);
>> -       if (CHECK(err == -EINVAL, "kallsyms_fopen", "failed to open: %d\n", errno))
>> +       if (err == -EINVAL) {
>> +               ASSERT_TRUE(false, "kallsyms_fopen for __per_cpu_start");
>>                  return;
>> -       if (CHECK(err == -ENOENT, "ksym_find", "symbol 'per_cpu_start' not found\n"))
>> +       }
>> +       if (err == -ENOENT) {
>> +               ASSERT_TRUE(false, "ksym_find for __per_cpu_start");
>>                  return;
>> +       }
[...]


  reply	other threads:[~2024-03-05  7:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-02 16:50 [PATCH bpf-next 0/4] selftests/bpf: Fix a couple of test failures with LTO kernel Yonghong Song
2024-03-02 16:50 ` [PATCH bpf-next 1/4] selftests/bpf: Replace CHECK with ASSERT macros for ksyms test Yonghong Song
2024-03-05  0:17   ` Andrii Nakryiko
2024-03-05  7:21     ` Yonghong Song [this message]
2024-03-02 16:50 ` [PATCH bpf-next 2/4] selftests/bpf: Add check_lto_kernel() helper Yonghong Song
2024-03-02 16:50 ` [PATCH bpf-next 3/4] selftests/bpf: Fix possible ksyms test failure with LTO kernel Yonghong Song
2024-03-05  5:37   ` Alexei Starovoitov
2024-03-05  7:24     ` Yonghong Song
2024-03-02 16:50 ` [PATCH bpf-next 4/4] selftests/bpf: Fix possible kprobe_multi_bench_attach " Yonghong Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5474994c-4c9e-4633-a189-b3dfe98906e4@linux.dev \
    --to=yonghong.song@linux.dev \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.