bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Viktor Malik <vmalik@redhat.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>
Subject: Re: [PATCH bpf-next v5 3/4] selftests/bpf: Allow macros in __retval
Date: Thu, 19 Jun 2025 06:51:53 +0200	[thread overview]
Message-ID: <095ccb13-7970-456b-9176-7f0c30a8b35c@redhat.com> (raw)
In-Reply-To: <CAADnVQLwxwLo5RqBPy=-Rr30nni5ZL8X5on-LenFMHqArZ6XFg@mail.gmail.com>

On 6/18/25 16:40, Alexei Starovoitov wrote:
> On Wed, Jun 18, 2025 at 6:32 AM Viktor Malik <vmalik@redhat.com> wrote:
>>
>> Allow macro expansion for values passed to the `__retval` and
>> `__retval_unpriv` attributes. This is especially useful for testing
>> programs which return various error codes.
>>
>> With this change, the code for parsing special literals is made
>> redundant (as the literals are defined via macros) so drop it.
>>
>> Signed-off-by: Viktor Malik <vmalik@redhat.com>
>> ---
>>  tools/testing/selftests/bpf/progs/bpf_misc.h | 11 ++++++-----
>>  tools/testing/selftests/bpf/test_loader.c    | 17 -----------------
>>  2 files changed, 6 insertions(+), 22 deletions(-)
>>
>> diff --git a/tools/testing/selftests/bpf/progs/bpf_misc.h b/tools/testing/selftests/bpf/progs/bpf_misc.h
>> index a678463e972c..1758265f5905 100644
>> --- a/tools/testing/selftests/bpf/progs/bpf_misc.h
>> +++ b/tools/testing/selftests/bpf/progs/bpf_misc.h
>> @@ -83,9 +83,10 @@
>>   *                   expect return value to match passed parameter:
>>   *                   - a decimal number
>>   *                   - a hexadecimal number, when starts from 0x
>> - *                   - literal INT_MIN
>> - *                   - literal POINTER_VALUE (see definition below)
>> - *                   - literal TEST_DATA_LEN (see definition below)
>> + *                   - a macro which expands to one of the above
>> + *                   In addition, two special macros are defined:
>> + *                   - POINTER_VALUE (see definition below)
>> + *                   - TEST_DATA_LEN (see definition below)
>>   * __retval_unpriv   Same, but load program in unprivileged mode.
>>   *
>>   * __description     Text to be used instead of a program name for display
>> @@ -125,8 +126,8 @@
>>  #define __success_unpriv       __attribute__((btf_decl_tag("comment:test_expect_success_unpriv")))
>>  #define __log_level(lvl)       __attribute__((btf_decl_tag("comment:test_log_level="#lvl)))
>>  #define __flag(flag)           __attribute__((btf_decl_tag("comment:test_prog_flags="#flag)))
>> -#define __retval(val)          __attribute__((btf_decl_tag("comment:test_retval="#val)))
>> -#define __retval_unpriv(val)   __attribute__((btf_decl_tag("comment:test_retval_unpriv="#val)))
>> +#define __retval(val)          __attribute__((btf_decl_tag("comment:test_retval="XSTR(val))))
>> +#define __retval_unpriv(val)   __attribute__((btf_decl_tag("comment:test_retval_unpriv="XSTR(val))))
>>  #define __auxiliary            __attribute__((btf_decl_tag("comment:test_auxiliary")))
>>  #define __auxiliary_unpriv     __attribute__((btf_decl_tag("comment:test_auxiliary_unpriv")))
>>  #define __btf_path(path)       __attribute__((btf_decl_tag("comment:test_btf_path=" path)))
>> diff --git a/tools/testing/selftests/bpf/test_loader.c b/tools/testing/selftests/bpf/test_loader.c
>> index 9551d8d5f8f9..28d2d366a8ae 100644
>> --- a/tools/testing/selftests/bpf/test_loader.c
>> +++ b/tools/testing/selftests/bpf/test_loader.c
>> @@ -318,23 +318,6 @@ static int parse_caps(const char *str, __u64 *val, const char *name)
>>
>>  static int parse_retval(const char *str, int *val, const char *name)
>>  {
>> -       struct {
>> -               char *name;
>> -               int val;
>> -       } named_values[] = {
>> -               { "INT_MIN"      , INT_MIN },
>> -               { "POINTER_VALUE", POINTER_VALUE },
>> -               { "TEST_DATA_LEN", TEST_DATA_LEN },
>> -       };
>> -       int i;
>> -
>> -       for (i = 0; i < ARRAY_SIZE(named_values); ++i) {
>> -               if (strcmp(str, named_values[i].name) != 0)
>> -                       continue;
>> -               *val = named_values[i].val;
>> -               return 0;
>> -       }
>> -
> 
> and this broke a bunch of tests.

Right, sorry about that. I'll fix it and send v6 shortly.

Viktor

> 
> pw-bot: cr
> 


  reply	other threads:[~2025-06-19  4:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-18 13:32 [PATCH bpf-next v5 0/4] bpf: Add kfuncs for read-only string operations Viktor Malik
2025-06-18 13:32 ` [PATCH bpf-next v5 1/4] uaccess: Define pagefault lock guard Viktor Malik
2025-06-18 13:32 ` [PATCH bpf-next v5 2/4] bpf: Add kfuncs for read-only string operations Viktor Malik
2025-06-18 13:32 ` [PATCH bpf-next v5 3/4] selftests/bpf: Allow macros in __retval Viktor Malik
2025-06-18 14:40   ` Alexei Starovoitov
2025-06-19  4:51     ` Viktor Malik [this message]
2025-06-18 13:32 ` [PATCH bpf-next v5 4/4] selftests/bpf: Add tests for string kfuncs Viktor Malik

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=095ccb13-7970-456b-9176-7f0c30a8b35c@redhat.com \
    --to=vmalik@redhat.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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 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).