Commit 0b6e71c3 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov

selftests/bpf: Teach test_progs to cd into subdir

We are building a bunch of "flavors" of test_progs, e.g., w/ alu32 flag
for Clang when building BPF object. test_progs setup is relying on
having all the BPF object files and extra resources to be available in
current working directory, though. But we actually build all these files
into a separate sub-directory. Next set of patches establishes
convention of naming "flavored" test_progs (and test runner binaries in
general) as test_progs-flavor (e.g., test_progs-alu32), for each such
extra flavor. This patch teaches test_progs binary to automatically
detect its own extra flavor based on its argv[0], and if present, to
change current directory to a flavor-specific subdirectory.
Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20191016060051.2024182-2-andriin@fb.com
parent 8d285a3b
......@@ -306,7 +306,7 @@ void *spin_lock_thread(void *arg)
}
/* extern declarations for test funcs */
#define DEFINE_TEST(name) extern void test_##name();
#define DEFINE_TEST(name) extern void test_##name(void);
#include <prog_tests/tests.h>
#undef DEFINE_TEST
......@@ -518,6 +518,33 @@ static void stdio_restore(void)
#endif
}
/*
* Determine if test_progs is running as a "flavored" test runner and switch
* into corresponding sub-directory to load correct BPF objects.
*
* This is done by looking at executable name. If it contains "-flavor"
* suffix, then we are running as a flavored test runner.
*/
int cd_flavor_subdir(const char *exec_name)
{
/* General form of argv[0] passed here is:
* some/path/to/test_progs[-flavor], where -flavor part is optional.
* First cut out "test_progs[-flavor]" part, then extract "flavor"
* part, if it's there.
*/
const char *flavor = strrchr(exec_name, '/');
if (!flavor)
return 0;
flavor++;
flavor = strrchr(flavor, '-');
if (!flavor)
return 0;
flavor++;
printf("Switching to flavor '%s' subdirectory...\n", flavor);
return chdir(flavor);
}
int main(int argc, char **argv)
{
static const struct argp argp = {
......@@ -531,6 +558,10 @@ int main(int argc, char **argv)
if (err)
return err;
err = cd_flavor_subdir(argv[0]);
if (err)
return err;
libbpf_set_print(libbpf_print_fn);
srand(time(NULL));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment