bpf: Selftests, sockmap test prog run without setting cgroup
Running test_sockmap with arguments to specify a test pattern requires including a cgroup argument. Instead of requiring this if the option is not provided create one This is not used by selftest runs but I use it when I want to test a specific test. Most useful when developing new code and/or tests. Signed-off-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com> Link: https://lore.kernel.org/bpf/158939722675.15176.6294210959489131688.stgit@john-Precision-5820-Tower
This commit is contained in:
parent
d79a32129b
commit
13a5f3ffd2
1 changed files with 22 additions and 6 deletions
|
@ -1725,6 +1725,7 @@ int main(int argc, char **argv)
|
||||||
int opt, longindex, err, cg_fd = 0;
|
int opt, longindex, err, cg_fd = 0;
|
||||||
char *bpf_file = BPF_SOCKMAP_FILENAME;
|
char *bpf_file = BPF_SOCKMAP_FILENAME;
|
||||||
int test = PING_PONG;
|
int test = PING_PONG;
|
||||||
|
bool cg_created = 0;
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
return test_suite(-1);
|
return test_suite(-1);
|
||||||
|
@ -1805,13 +1806,25 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc <= 3 && cg_fd)
|
|
||||||
return test_suite(cg_fd);
|
|
||||||
|
|
||||||
if (!cg_fd) {
|
if (!cg_fd) {
|
||||||
fprintf(stderr, "%s requires cgroup option: --cgroup <path>\n",
|
if (setup_cgroup_environment()) {
|
||||||
argv[0]);
|
fprintf(stderr, "ERROR: cgroup env failed\n");
|
||||||
return -1;
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
cg_fd = create_and_get_cgroup(CG_PATH);
|
||||||
|
if (cg_fd < 0) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"ERROR: (%i) open cg path failed: %s\n",
|
||||||
|
cg_fd, strerror(errno));
|
||||||
|
return cg_fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (join_cgroup(CG_PATH)) {
|
||||||
|
fprintf(stderr, "ERROR: failed to join cgroup\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
cg_created = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = populate_progs(bpf_file);
|
err = populate_progs(bpf_file);
|
||||||
|
@ -1830,6 +1843,9 @@ int main(int argc, char **argv)
|
||||||
options.rate = rate;
|
options.rate = rate;
|
||||||
|
|
||||||
err = run_options(&options, cg_fd, test);
|
err = run_options(&options, cg_fd, test);
|
||||||
|
|
||||||
|
if (cg_created)
|
||||||
|
cleanup_cgroup_environment();
|
||||||
close(cg_fd);
|
close(cg_fd);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue