On 6/18/25 16:40, Alexei Starovoitov wrote: > On Wed, Jun 18, 2025 at 6:32 AM Viktor Malik <vmalik@xxxxxxxxxx> 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@xxxxxxxxxx> >> --- >> 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 >