diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index f0681633108e..b4fa9f28159d 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -43,74 +43,6 @@ #define TCP_CA_NAME_MAX 16 #endif -#define MPTCP_BASE_TEST(name) \ -static void test_##name(void) \ -{ \ - struct nstoken *nstoken; \ - int cgroup_fd, err; \ - struct name *skel; \ - \ - cgroup_fd = test__join_cgroup("/" #name); \ - if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup")) \ - return; \ - \ - skel = name##__open_and_load(); \ - if (!ASSERT_OK_PTR(skel, "skel_open_load")) \ - goto out; \ - \ - err = name##__attach(skel); \ - if (!ASSERT_OK(err, "skel_attach")) \ - goto out; \ - \ - nstoken = create_netns(); \ - if (!ASSERT_OK_PTR(nstoken, "create_netns" #name)) \ - goto fail; \ - \ - run_##name(cgroup_fd, skel); \ - \ -fail: \ - cleanup_netns(nstoken); \ - name##__destroy(skel); \ -out: \ - close(cgroup_fd); \ -} - -#define MPTCP_SCHED_TEST(name, addr1, addr2) \ -static void test_##name(void) \ -{ \ - struct mptcp_bpf_##name *skel; \ - struct nstoken *nstoken; \ - struct bpf_link *link; \ - struct bpf_map *map; \ - \ - skel = mptcp_bpf_##name##__open_and_load(); \ - if (!ASSERT_OK_PTR(skel, "open_and_load:" #name)) \ - return; \ - \ - map = bpf_object__find_map_by_name(skel->obj, #name); \ - link = bpf_map__attach_struct_ops(map); \ - if (!ASSERT_OK_PTR(link, "attach_struct_ops:" #name)) \ - goto fail; \ - \ - nstoken = sched_init("subflow", "bpf_" #name); \ - if (!ASSERT_OK_PTR(nstoken, "sched_init:" #name)) \ - goto out; \ - \ - send_data_and_verify(#name, atoi(#addr1), atoi(#addr2));\ - \ - cleanup_netns(nstoken); \ -out: \ - bpf_link__destroy(link); \ -fail: \ - mptcp_bpf_##name##__destroy(skel); \ -} - -#define RUN_MPTCP_TEST(suffix) \ -do { \ - if (test__start_subtest(#suffix)) \ - test_##suffix(); \ -} while (0) - static const unsigned int total_bytes = 10 * 1024 * 1024; struct __mptcp_info { @@ -283,8 +215,6 @@ static void run_mptcp_sock(int cgroup_fd, struct mptcp_sock *skel) close(server_fd); } -MPTCP_BASE_TEST(mptcp_sock); - static int verify_mptcpify(int server_fd, int client_fd) { struct __mptcp_info info; @@ -340,8 +270,6 @@ static void run_mptcpify(int cgroup_fd, struct mptcpify *skel) close(server_fd); } -MPTCP_BASE_TEST(mptcpify); - static int endpoint_init(char *flags) { SYS(fail, "ip -net %s link add veth1 type veth peer name veth2", NS_TEST); @@ -407,6 +335,40 @@ static void run_mptcp_subflow(int cgroup_fd, struct mptcp_subflow *skel) close(server_fd); } +#define MPTCP_BASE_TEST(name) \ +static void test_##name(void) \ +{ \ + struct nstoken *nstoken; \ + int cgroup_fd, err; \ + struct name *skel; \ + \ + cgroup_fd = test__join_cgroup("/" #name); \ + if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup " #name)) \ + return; \ + \ + skel = name##__open_and_load(); \ + if (!ASSERT_OK_PTR(skel, "skel_open_load " #name)) \ + goto close_cgroup; \ + \ + err = name##__attach(skel); \ + if (!ASSERT_OK(err, "skel_attach " #name)) \ + goto skel_destroy; \ + \ + nstoken = create_netns(); \ + if (!ASSERT_OK_PTR(nstoken, "create_netns " #name)) \ + goto skel_destroy; \ + \ + run_##name(cgroup_fd, skel); \ + \ + cleanup_netns(nstoken); \ +skel_destroy: \ + name##__destroy(skel); \ +close_cgroup: \ + close(cgroup_fd); \ +} + +MPTCP_BASE_TEST(mptcp_sock); +MPTCP_BASE_TEST(mptcpify); MPTCP_BASE_TEST(mptcp_subflow); static struct nstoken *sched_init(char *flags, char *sched) @@ -487,6 +449,36 @@ static void test_default(void) cleanup_netns(nstoken); } +#define MPTCP_SCHED_TEST(name, addr1, addr2) \ +static void test_##name(void) \ +{ \ + struct mptcp_bpf_##name *skel; \ + struct nstoken *nstoken; \ + struct bpf_link *link; \ + struct bpf_map *map; \ + \ + skel = mptcp_bpf_##name##__open_and_load(); \ + if (!ASSERT_OK_PTR(skel, "open_and_load " #name)) \ + return; \ + \ + map = bpf_object__find_map_by_name(skel->obj, #name); \ + link = bpf_map__attach_struct_ops(map); \ + if (!ASSERT_OK_PTR(link, "attach_struct_ops " #name)) \ + goto skel_destroy; \ + \ + nstoken = sched_init("subflow", "bpf_" #name); \ + if (!ASSERT_OK_PTR(nstoken, "sched_init " #name)) \ + goto link_destroy; \ + \ + send_data_and_verify(#name, atoi(#addr1), atoi(#addr2));\ + \ + cleanup_netns(nstoken); \ +link_destroy: \ + bpf_link__destroy(link); \ +skel_destroy: \ + mptcp_bpf_##name##__destroy(skel); \ +} + MPTCP_SCHED_TEST(first, 1, 0); MPTCP_SCHED_TEST(bkup, 1, 0); MPTCP_SCHED_TEST(rr, 1, 1); @@ -494,6 +486,12 @@ MPTCP_SCHED_TEST(red, 1, 1); MPTCP_SCHED_TEST(burst, 1, 1); MPTCP_SCHED_TEST(stale, 1, 0); +#define RUN_MPTCP_TEST(suffix) \ +do { \ + if (test__start_subtest(#suffix)) \ + test_##suffix(); \ +} while (0) + void test_mptcp(void) { RUN_MPTCP_TEST(mptcp_sock);