Skip to content

Commit

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

Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang authored and intel-lab-lkp committed Mar 20, 2024
1 parent b777938 commit ed39da6
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions tools/testing/selftests/bpf/prog_tests/mptcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,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 @@ -476,11 +476,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 Down Expand Up @@ -513,10 +514,6 @@ static void send_data(int lfd, int fd, char *msg)
printf("FAIL:pthread_join thread_ret:%ld\n", PTR_ERR(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 @@ -525,25 +522,23 @@ 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:");
snprintf(cmd, sizeof(cmd),
"ip netns exec %s ss -it src %s sport %d dst %s | %s",
NS_TEST, ADDR_1, PORT_1, dst, "grep -q bytes_sent:");
return system(cmd);
}

Expand Down

0 comments on commit ed39da6

Please sign in to comment.