Message ID | 158871183500.7537.4803419328947579658.stgit@john-Precision-5820-Tower |
---|---|
State | Changes Requested |
Delegated to: | BPF Maintainers |
Headers | show |
Series | bpf: selftests, test_sockmap improvements | expand |
On Tue, 05 May 2020 13:50:35 -0700 John Fastabend <john.fastabend@gmail.com> wrote: > 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> > --- > tools/testing/selftests/bpf/test_sockmap.c | 28 ++++++++++++++++++++++------ > 1 file changed, 22 insertions(+), 6 deletions(-) > > diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c > index 6bdacc4..a0884f8 100644 > --- a/tools/testing/selftests/bpf/test_sockmap.c > +++ b/tools/testing/selftests/bpf/test_sockmap.c > @@ -1725,6 +1725,7 @@ int main(int argc, char **argv) > int opt, longindex, err, cg_fd = 0; > char *bpf_file = BPF_SOCKMAP_FILENAME; > int test = PING_PONG; > + bool cg_created = 0; > > if (argc < 2) > 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) { > - fprintf(stderr, "%s requires cgroup option: --cgroup <path>\n", > - argv[0]); > - return -1; > + if (setup_cgroup_environment()) { > + fprintf(stderr, "ERROR: cgroup env failed\n"); > + 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, optarg); Looks like you wanted to log strerror(errno) instead of optarg here. > + 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); > @@ -1830,6 +1843,9 @@ int main(int argc, char **argv) > options.rate = rate; > > err = run_options(&options, cg_fd, test); > + > + if (cg_created) > + cleanup_cgroup_environment(); > close(cg_fd); > return err; > } >
Jakub Sitnicki wrote: > On Tue, 05 May 2020 13:50:35 -0700 > John Fastabend <john.fastabend@gmail.com> wrote: > > > 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> > > --- [...] > > if (!cg_fd) { > > - fprintf(stderr, "%s requires cgroup option: --cgroup <path>\n", > > - argv[0]); > > - return -1; > > + if (setup_cgroup_environment()) { > > + fprintf(stderr, "ERROR: cgroup env failed\n"); > > + 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, optarg); > > Looks like you wanted to log strerror(errno) instead of optarg here. > > > + return cg_fd; > > + } cut'n'paste error thanks.
diff --git a/tools/testing/selftests/bpf/test_sockmap.c b/tools/testing/selftests/bpf/test_sockmap.c index 6bdacc4..a0884f8 100644 --- a/tools/testing/selftests/bpf/test_sockmap.c +++ b/tools/testing/selftests/bpf/test_sockmap.c @@ -1725,6 +1725,7 @@ int main(int argc, char **argv) int opt, longindex, err, cg_fd = 0; char *bpf_file = BPF_SOCKMAP_FILENAME; int test = PING_PONG; + bool cg_created = 0; if (argc < 2) 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) { - fprintf(stderr, "%s requires cgroup option: --cgroup <path>\n", - argv[0]); - return -1; + if (setup_cgroup_environment()) { + fprintf(stderr, "ERROR: cgroup env failed\n"); + 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, optarg); + 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); @@ -1830,6 +1843,9 @@ int main(int argc, char **argv) options.rate = rate; err = run_options(&options, cg_fd, test); + + if (cg_created) + cleanup_cgroup_environment(); close(cg_fd); return err; }
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> --- tools/testing/selftests/bpf/test_sockmap.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)