Skip to content

Commit

Permalink
selftests/bpf: Add mptcp_subflow bpf_iter subtest
Browse files Browse the repository at this point in the history
This patch adds a subtest named test_bpf_iter to load and verify the newly
added mptcp_subflow type bpf_iter example in test_mptcp. Use endpoint_init()
to add a new subflow endpoint. A new helper recv_send() is invoked to trigger
the ftrace hook for mptcp_sched_get_send() after wait_for_new_subflows().
Check if skel->bss->iter equals 2 to verify whether the ftrace program loops
twice as expected.

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang authored and intel-lab-lkp committed Sep 10, 2024
1 parent d9384eb commit 0aec96a
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions tools/testing/selftests/bpf/prog_tests/mptcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "mptcp_sock.skel.h"
#include "mptcpify.skel.h"
#include "mptcp_subflow.skel.h"
#include "mptcp_bpf_iter.skel.h"
#include "mptcp_bpf_first.skel.h"
#include "mptcp_bpf_bkup.skel.h"
#include "mptcp_bpf_rr.skel.h"
Expand Down Expand Up @@ -258,6 +259,34 @@ static void send_byte(int fd)
ASSERT_EQ(write(fd, &b, sizeof(b)), 1, "send single byte");
}

static int recv_send(int server_fd)
{
char buf[1];
int ret, fd;
ssize_t n;

fd = accept(server_fd, NULL, NULL);
if (!ASSERT_OK_FD(fd, "accept"))
return -1;

n = recv(fd, buf, sizeof(buf), 0);
if (!ASSERT_GT(n, 0, "recv")) {
ret = -1;
goto close;
}

n = send(fd, buf, n, 0);
if (!ASSERT_GT(n, 0, "send")) {
ret = -1;
goto close;
}

ret = 0;
close:
close(fd);
return ret;
}

static int verify_mptcpify(int server_fd, int client_fd)
{
struct __mptcp_info info;
Expand Down Expand Up @@ -470,6 +499,60 @@ static void test_subflow(void)
close(cgroup_fd);
}

static void run_bpf_iter(void)
{
int server_fd, client_fd;

server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
if (!ASSERT_OK_FD(server_fd, "start_mptcp_server"))
return;

client_fd = connect_to_fd(server_fd, 0);
if (!ASSERT_OK_FD(client_fd, "connect_to_fd"))
goto close_server;

send_byte(client_fd);
wait_for_new_subflows(client_fd);
recv_send(server_fd);

close(client_fd);
close_server:
close(server_fd);
}

static void test_bpf_iter(void)
{
struct mptcp_bpf_iter *skel;
struct nstoken *nstoken;
int err;

skel = mptcp_bpf_iter__open_and_load();
if (!ASSERT_OK_PTR(skel, "skel_open_load: mptcp_iter"))
return;

skel->bss->pid = getpid();

err = mptcp_bpf_iter__attach(skel);
if (!ASSERT_OK(err, "skel_attach: mptcp_iter"))
goto skel_destroy;

nstoken = create_netns();
if (!ASSERT_OK_PTR(nstoken, "create_netns: mptcp_iter"))
goto skel_destroy;

if (endpoint_init("subflow") < 0)
goto close_netns;

run_bpf_iter();

ASSERT_EQ(skel->bss->iter, 2, "iter");

close_netns:
cleanup_netns(nstoken);
skel_destroy:
mptcp_bpf_iter__destroy(skel);
}

static struct nstoken *sched_init(char *flags, char *sched)
{
struct nstoken *nstoken;
Expand Down Expand Up @@ -651,6 +734,8 @@ void test_mptcp(void)
test_mptcpify();
if (test__start_subtest("subflow"))
test_subflow();
if (test__start_subtest("bpf_iter"))
test_bpf_iter();
if (test__start_subtest("default"))
test_default();
if (test__start_subtest("first"))
Expand Down

0 comments on commit 0aec96a

Please sign in to comment.