提交 3886bd7c 编写于 作者: S Stanislav Fomichev 提交者: Alexei Starovoitov

selftests/bpf: test_progs: convert test_sockopt_multi

Move the files, adjust includes, remove entry from Makefile & .gitignore
Signed-off-by: NStanislav Fomichev <sdf@google.com>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
上级 9a365e67
...@@ -39,6 +39,5 @@ libbpf.so.* ...@@ -39,6 +39,5 @@ libbpf.so.*
test_hashmap test_hashmap
test_btf_dump test_btf_dump
xdping xdping
test_sockopt_multi
test_sockopt_inherit test_sockopt_inherit
test_tcp_rtt test_tcp_rtt
...@@ -29,7 +29,7 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test ...@@ -29,7 +29,7 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test
test_cgroup_storage test_select_reuseport test_section_names \ test_cgroup_storage test_select_reuseport test_section_names \
test_netcnt test_tcpnotify_user test_sock_fields test_sysctl test_hashmap \ test_netcnt test_tcpnotify_user test_sock_fields test_sysctl test_hashmap \
test_btf_dump test_cgroup_attach xdping \ test_btf_dump test_cgroup_attach xdping \
test_sockopt_multi test_sockopt_inherit test_tcp_rtt test_sockopt_inherit test_tcp_rtt
BPF_OBJ_FILES = $(patsubst %.c,%.o, $(notdir $(wildcard progs/*.c))) BPF_OBJ_FILES = $(patsubst %.c,%.o, $(notdir $(wildcard progs/*.c)))
TEST_GEN_FILES = $(BPF_OBJ_FILES) TEST_GEN_FILES = $(BPF_OBJ_FILES)
...@@ -113,7 +113,6 @@ $(OUTPUT)/test_netcnt: cgroup_helpers.c ...@@ -113,7 +113,6 @@ $(OUTPUT)/test_netcnt: cgroup_helpers.c
$(OUTPUT)/test_sock_fields: cgroup_helpers.c $(OUTPUT)/test_sock_fields: cgroup_helpers.c
$(OUTPUT)/test_sysctl: cgroup_helpers.c $(OUTPUT)/test_sysctl: cgroup_helpers.c
$(OUTPUT)/test_cgroup_attach: cgroup_helpers.c $(OUTPUT)/test_cgroup_attach: cgroup_helpers.c
$(OUTPUT)/test_sockopt_multi: cgroup_helpers.c
$(OUTPUT)/test_sockopt_inherit: cgroup_helpers.c $(OUTPUT)/test_sockopt_inherit: cgroup_helpers.c
$(OUTPUT)/test_tcp_rtt: cgroup_helpers.c $(OUTPUT)/test_tcp_rtt: cgroup_helpers.c
......
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>
#include <error.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/filter.h>
#include <bpf/bpf.h>
#include <bpf/libbpf.h>
#include "bpf_rlimit.h"
#include "bpf_util.h"
#include "cgroup_helpers.h" #include "cgroup_helpers.h"
static int prog_attach(struct bpf_object *obj, int cgroup_fd, const char *title) static int prog_attach(struct bpf_object *obj, int cgroup_fd, const char *title)
...@@ -308,7 +294,7 @@ static int run_setsockopt_test(struct bpf_object *obj, int cg_parent, ...@@ -308,7 +294,7 @@ static int run_setsockopt_test(struct bpf_object *obj, int cg_parent,
return err; return err;
} }
int main(int argc, char **argv) void test_sockopt_multi(void)
{ {
struct bpf_prog_load_attr attr = { struct bpf_prog_load_attr attr = {
.file = "./sockopt_multi.o", .file = "./sockopt_multi.o",
...@@ -319,56 +305,28 @@ int main(int argc, char **argv) ...@@ -319,56 +305,28 @@ int main(int argc, char **argv)
int err = -1; int err = -1;
int ignored; int ignored;
if (setup_cgroup_environment()) { cg_parent = test__join_cgroup("/parent");
log_err("Failed to setup cgroup environment\n"); if (CHECK_FAIL(cg_parent < 0))
goto out;
}
cg_parent = create_and_get_cgroup("/parent");
if (cg_parent < 0) {
log_err("Failed to create cgroup /parent\n");
goto out;
}
cg_child = create_and_get_cgroup("/parent/child");
if (cg_child < 0) {
log_err("Failed to create cgroup /parent/child\n");
goto out; goto out;
}
if (join_cgroup("/parent/child")) { cg_child = test__join_cgroup("/parent/child");
log_err("Failed to join cgroup /parent/child\n"); if (CHECK_FAIL(cg_child < 0))
goto out; goto out;
}
err = bpf_prog_load_xattr(&attr, &obj, &ignored); err = bpf_prog_load_xattr(&attr, &obj, &ignored);
if (err) { if (CHECK_FAIL(err))
log_err("Failed to load BPF object");
goto out; goto out;
}
sock_fd = socket(AF_INET, SOCK_STREAM, 0); sock_fd = socket(AF_INET, SOCK_STREAM, 0);
if (sock_fd < 0) { if (CHECK_FAIL(sock_fd < 0))
log_err("Failed to create socket");
goto out; goto out;
}
if (run_getsockopt_test(obj, cg_parent, cg_child, sock_fd)) CHECK_FAIL(run_getsockopt_test(obj, cg_parent, cg_child, sock_fd));
err = -1; CHECK_FAIL(run_setsockopt_test(obj, cg_parent, cg_child, sock_fd));
printf("test_sockopt_multi: getsockopt %s\n",
err ? "FAILED" : "PASSED");
if (run_setsockopt_test(obj, cg_parent, cg_child, sock_fd))
err = -1;
printf("test_sockopt_multi: setsockopt %s\n",
err ? "FAILED" : "PASSED");
out: out:
close(sock_fd); close(sock_fd);
bpf_object__close(obj); bpf_object__close(obj);
close(cg_child); close(cg_child);
close(cg_parent); close(cg_parent);
printf("test_sockopt_multi: %s\n", err ? "FAILED" : "PASSED");
return err ? EXIT_FAILURE : EXIT_SUCCESS;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册