mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-04-01 20:14:08 +00:00
bpf: use --cgroup in test_suite if supplied
If the user supplies a --cgroup value in the arguments when running the test_suite go ahaead and run the self tests there. I use this to test with multiple cgroup users. Signed-off-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:
parent
b5d83fec73
commit
7d2c6cfc54
1 changed files with 31 additions and 22 deletions
|
@ -1345,9 +1345,9 @@ static int populate_progs(char *bpf_file)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __test_suite(char *bpf_file)
|
static int __test_suite(int cg_fd, char *bpf_file)
|
||||||
{
|
{
|
||||||
int cg_fd, err;
|
int err, cleanup = cg_fd;
|
||||||
|
|
||||||
err = populate_progs(bpf_file);
|
err = populate_progs(bpf_file);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
|
@ -1355,22 +1355,24 @@ static int __test_suite(char *bpf_file)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
if (cg_fd < 0) {
|
||||||
fprintf(stderr,
|
if (setup_cgroup_environment()) {
|
||||||
"ERROR: (%i) open cg path failed: %s\n",
|
fprintf(stderr, "ERROR: cgroup env failed\n");
|
||||||
cg_fd, optarg);
|
return -EINVAL;
|
||||||
return cg_fd;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (join_cgroup(CG_PATH)) {
|
cg_fd = create_and_get_cgroup(CG_PATH);
|
||||||
fprintf(stderr, "ERROR: failed to join cgroup\n");
|
if (cg_fd < 0) {
|
||||||
return -EINVAL;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tests basic commands and APIs with range of iov values */
|
/* Tests basic commands and APIs with range of iov values */
|
||||||
|
@ -1391,20 +1393,24 @@ static int __test_suite(char *bpf_file)
|
||||||
|
|
||||||
out:
|
out:
|
||||||
printf("Summary: %i PASSED %i FAILED\n", passed, failed);
|
printf("Summary: %i PASSED %i FAILED\n", passed, failed);
|
||||||
cleanup_cgroup_environment();
|
if (cleanup < 0) {
|
||||||
close(cg_fd);
|
cleanup_cgroup_environment();
|
||||||
|
close(cg_fd);
|
||||||
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int test_suite(void)
|
static int test_suite(int cg_fd)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = __test_suite(BPF_SOCKMAP_FILENAME);
|
err = __test_suite(cg_fd, BPF_SOCKMAP_FILENAME);
|
||||||
if (err)
|
if (err)
|
||||||
goto out;
|
goto out;
|
||||||
err = __test_suite(BPF_SOCKHASH_FILENAME);
|
err = __test_suite(cg_fd, BPF_SOCKHASH_FILENAME);
|
||||||
out:
|
out:
|
||||||
|
if (cg_fd > -1)
|
||||||
|
close(cg_fd);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1417,7 +1423,7 @@ int main(int argc, char **argv)
|
||||||
int test = PING_PONG;
|
int test = PING_PONG;
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
return test_suite();
|
return test_suite(-1);
|
||||||
|
|
||||||
while ((opt = getopt_long(argc, argv, ":dhvc:r:i:l:t:",
|
while ((opt = getopt_long(argc, argv, ":dhvc:r:i:l:t:",
|
||||||
long_options, &longindex)) != -1) {
|
long_options, &longindex)) != -1) {
|
||||||
|
@ -1483,6 +1489,9 @@ 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",
|
fprintf(stderr, "%s requires cgroup option: --cgroup <path>\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue