diff mbox series

[bpf-next] selftests/bpf: Fix cd_flavor_subdir() of test_progs

Message ID 20220403135245.1713283-1-ytcoode@gmail.com (mailing list archive)
State Accepted
Commit 9bbad6dab8279905c4593be69b06704b77b31403
Delegated to: BPF
Headers show
Series [bpf-next] selftests/bpf: Fix cd_flavor_subdir() of test_progs | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 12 of 12 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Yuntao Wang April 3, 2022, 1:52 p.m. UTC
Currently, when we run test_progs with just executable file name, for
example 'PATH=. test_progs-no_alu32', cd_flavor_subdir() will not check
if test_progs is running as a flavored test runner and switch into
corresponding sub-directory.

This will cause test_progs-no_alu32 executed by the
'PATH=. test_progs-no_alu32' command to run in the wrong directory and
load the wrong BPF objects.

Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
---
 tools/testing/selftests/bpf/test_progs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Andrii Nakryiko April 4, 2022, 12:02 a.m. UTC | #1
On Sun, Apr 3, 2022 at 6:53 AM Yuntao Wang <ytcoode@gmail.com> wrote:
>
> Currently, when we run test_progs with just executable file name, for
> example 'PATH=. test_progs-no_alu32', cd_flavor_subdir() will not check

First time seeing this PATH=. trick just to avoid
./test_progs-no_alu32, but sure, the fix makes sense. Applied to
bpf-next.

> if test_progs is running as a flavored test runner and switch into
> corresponding sub-directory.
>
> This will cause test_progs-no_alu32 executed by the
> 'PATH=. test_progs-no_alu32' command to run in the wrong directory and
> load the wrong BPF objects.
>
> Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
> ---
>  tools/testing/selftests/bpf/test_progs.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
> index 2ecb73a65206..0a4b45d7b515 100644
> --- a/tools/testing/selftests/bpf/test_progs.c
> +++ b/tools/testing/selftests/bpf/test_progs.c
> @@ -761,8 +761,10 @@ int cd_flavor_subdir(const char *exec_name)
>         const char *flavor = strrchr(exec_name, '/');
>
>         if (!flavor)
> -               return 0;
> -       flavor++;
> +               flavor = exec_name;
> +       else
> +               flavor++;
> +
>         flavor = strrchr(flavor, '-');
>         if (!flavor)
>                 return 0;
> --
> 2.35.1
>
patchwork-bot+netdevbpf@kernel.org April 4, 2022, 12:10 a.m. UTC | #2
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Sun,  3 Apr 2022 21:52:45 +0800 you wrote:
> Currently, when we run test_progs with just executable file name, for
> example 'PATH=. test_progs-no_alu32', cd_flavor_subdir() will not check
> if test_progs is running as a flavored test runner and switch into
> corresponding sub-directory.
> 
> This will cause test_progs-no_alu32 executed by the
> 'PATH=. test_progs-no_alu32' command to run in the wrong directory and
> load the wrong BPF objects.
> 
> [...]

Here is the summary with links:
  - [bpf-next] selftests/bpf: Fix cd_flavor_subdir() of test_progs
    https://git.kernel.org/bpf/bpf-next/c/9bbad6dab827

You are awesome, thank you!
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index 2ecb73a65206..0a4b45d7b515 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -761,8 +761,10 @@  int cd_flavor_subdir(const char *exec_name)
 	const char *flavor = strrchr(exec_name, '/');
 
 	if (!flavor)
-		return 0;
-	flavor++;
+		flavor = exec_name;
+	else
+		flavor++;
+
 	flavor = strrchr(flavor, '-');
 	if (!flavor)
 		return 0;