selftests/bpf: Fix cd_flavor_subdir() of test_progs
authorYuntao Wang <ytcoode@gmail.com>
Sun, 3 Apr 2022 13:52:45 +0000 (21:52 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 4 Apr 2022 00:01:48 +0000 (17:01 -0700)
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>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220403135245.1713283-1-ytcoode@gmail.com
tools/testing/selftests/bpf/test_progs.c

index 2ecb73a65206d92e45493d997a9c0369dff03b47..0a4b45d7b51500fd960c4002de60ef1c4b80987e 100644 (file)
@@ -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;