From ccf90159ef1ab852c175bb9aab7efcd5c2fde319 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Mon, 23 Sep 2024 10:15:02 +0800 Subject: [PATCH] selftests/bpf: Add mptcp bpf userspace pm subtest Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 7900376ead66..d8ae0d8ec61e 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -14,6 +14,7 @@ #include "mptcp_bpf_iters_subflow.skel.h" #include "mptcp_bpf_iters_entry.skel.h" #include "mptcp_bpf_sockopt.skel.h" +#include "mptcp_bpf_userspace_pm.skel.h" #include "mptcp_bpf_bytes.skel.h" #include "mptcp_bpf_first.skel.h" #include "mptcp_bpf_bkup.skel.h" @@ -58,6 +59,7 @@ enum mptcp_pm_type { MPTCP_PM_TYPE_KERNEL = 0, MPTCP_PM_TYPE_USERSPACE, + MPTCP_PM_TYPE_BPF, __MPTCP_PM_TYPE_NR, __MPTCP_PM_TYPE_MAX = __MPTCP_PM_TYPE_NR - 1, @@ -1048,6 +1050,72 @@ static void test_userspace_pm(void) cleanup_netns(nstoken); } +static void test_bpf_pm(struct bpf_object *obj, char *pm) +{ + struct nstoken *nstoken; + struct bpf_link *link; + struct bpf_map *map; + int err; + + map = bpf_object__find_map_by_name(obj, pm); + link = bpf_map__attach_struct_ops(map); + if (CHECK(!link, pm, "attach_struct_ops: %d\n", errno)) + return; + + nstoken = create_netns(NS_TEST); + if (!ASSERT_OK_PTR(nstoken, "create_netns")) + goto link_destroy; + + err = userspace_pm_init(MPTCP_PM_TYPE_BPF); + if (!ASSERT_OK(err, "userspace_pm_init: bpf pm")) + goto close_netns; + + run_userspace_pm(); + + userspace_pm_cleanup(); +close_netns: + cleanup_netns(nstoken); +link_destroy: + bpf_link__destroy(link); +} + +static void test_userspace_bpf(void) +{ + struct mptcp_bpf_userspace_pm *skel; + + skel = mptcp_bpf_userspace_pm__open(); + if (!ASSERT_OK_PTR(skel, "open: userspace_pm")) + return; + + if (!ASSERT_OK(bpf_program__set_flags(skel->progs.mptcp_pm_address_announce, + BPF_F_SLEEPABLE), "set pm_address_announce sleepable")) + goto fail; + + if (!ASSERT_OK(bpf_program__set_flags(skel->progs.mptcp_pm_address_remove, + BPF_F_SLEEPABLE), "set pm_address_remove sleepable")) + goto fail; + + if (!ASSERT_OK(bpf_program__set_flags(skel->progs.mptcp_pm_subflow_create, + BPF_F_SLEEPABLE), "set pm_subflow_create sleepable")) + goto fail; + + if (!ASSERT_OK(bpf_program__set_flags(skel->progs.mptcp_pm_subflow_destroy, + BPF_F_SLEEPABLE), "set pm_subflow_destroy sleepable")) + goto fail; + + if (!ASSERT_OK(bpf_program__set_flags(skel->progs.mptcp_pm_set_flags, + BPF_F_SLEEPABLE), "set pm_set_flags sleepable")) + goto fail; + + if (!ASSERT_OK(mptcp_bpf_userspace_pm__load(skel), "load: userspace_pm")) + goto fail; + + test_bpf_pm(skel->obj, "userspace_pm"); + +fail: + mptcp_bpf_userspace_pm__destroy(skel); +} + static struct nstoken *sched_init(char *flags, char *sched) { struct nstoken *nstoken; @@ -1252,6 +1320,8 @@ void test_mptcp(void) test_sockopt(); if (test__start_subtest("userspace_pm")) test_userspace_pm(); + if (test__start_subtest("userspace_bpf")) + test_userspace_bpf(); if (test__start_subtest("default")) test_default(); if (test__start_subtest("first"))