Skip to content

Commit

Permalink
Squash to "selftests/bpf: Add bpf scheduler test"
Browse files Browse the repository at this point in the history
Some cleanups.

Use ASSERT_EQ and ASSERT_OK like below commit:

b0e2a03 selftests/bpf: Replaces the usage of CHECK calls for ASSERTs in bpf_tcp_ca

Use newly added endpoint_init and _ss_search helpers.

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang authored and intel-lab-lkp committed Mar 24, 2024
1 parent 6525cab commit 72e0d1a
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions tools/testing/selftests/bpf/prog_tests/mptcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ void test_subflow(void)
}

static const unsigned int total_bytes = 10 * 1024 * 1024;
static int stop, duration;
static int stop;

static void *server(void *arg)
{
Expand Down Expand Up @@ -455,8 +455,7 @@ static void *server(void *arg)
bytes += nr_sent;
}

CHECK(bytes != total_bytes, "send", "%zd != %u nr_sent:%zd errno:%d\n",
bytes, total_bytes, nr_sent, errno);
ASSERT_EQ(bytes, total_bytes, "send");

done:
if (fd >= 0)
Expand All @@ -479,11 +478,12 @@ static void send_data(int lfd, int fd, char *msg)
int err;

WRITE_ONCE(stop, 0);

if (clock_gettime(CLOCK_MONOTONIC, &start) < 0)
return;

err = pthread_create(&srv_thread, NULL, server, (void *)(long)lfd);
if (CHECK(err != 0, "pthread_create", "err:%d errno:%d\n", err, errno))
if (!ASSERT_OK(err, "pthread_create"))
return;

/* recv total_bytes */
Expand All @@ -501,23 +501,15 @@ static void send_data(int lfd, int fd, char *msg)
return;

delta_ms = (end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000;

CHECK(bytes != total_bytes, "recv", "%zd != %u nr_recv:%zd errno:%d\n",
bytes, total_bytes, nr_recv, errno);

printf("%s: %u ms\n", msg, delta_ms);

WRITE_ONCE(stop, 1);
ASSERT_EQ(bytes, total_bytes, "recv");

WRITE_ONCE(stop, 1);
pthread_join(srv_thread, &thread_ret);
CHECK(IS_ERR(thread_ret), "pthread_join", "thread_ret:%ld",
PTR_ERR(thread_ret));
ASSERT_OK(IS_ERR(thread_ret), "thread_ret");
}

#define ADDR_1 "10.0.1.1"
#define ADDR_2 "10.0.1.2"
#define PORT_1 10001

static struct nstoken *sched_init(char *flags, char *sched)
{
struct nstoken *nstoken;
Expand All @@ -526,26 +518,19 @@ static struct nstoken *sched_init(char *flags, char *sched)
if (!ASSERT_OK_PTR(nstoken, "create_netns"))
goto fail;

SYS(fail, "ip -net %s link add veth1 type veth peer name veth2", NS_TEST);
SYS(fail, "ip -net %s addr add %s/24 dev veth1", NS_TEST, ADDR_1);
SYS(fail, "ip -net %s link set dev veth1 up", NS_TEST);
SYS(fail, "ip -net %s addr add %s/24 dev veth2", NS_TEST, ADDR_2);
SYS(fail, "ip -net %s link set dev veth2 up", NS_TEST);
SYS(fail, "ip -net %s mptcp endpoint add %s %s", NS_TEST, ADDR_2, flags);
if (!ASSERT_OK(endpoint_init("subflow"), "endpoint_init"))
goto fail;

SYS(fail, "ip netns exec %s sysctl -qw net.mptcp.scheduler=%s", NS_TEST, sched);

return nstoken;
fail:
return NULL;
}

static int has_bytes_sent(char *addr)
static int has_bytes_sent(char *dst)
{
char cmd[128];

snprintf(cmd, sizeof(cmd), "ip netns exec %s ss -it src %s sport %d dst %s | %s",
NS_TEST, ADDR_1, PORT_1, addr, "grep -q bytes_sent:");
return system(cmd);
return _ss_search(ADDR_1, dst, "sport", "bytes_sent:");
}

static void test_default(void)
Expand Down

0 comments on commit 72e0d1a

Please sign in to comment.