diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 7f3cd8baae2566..21308b9e776faa 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -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) { @@ -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) @@ -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 */ @@ -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; @@ -526,12 +518,9 @@ 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; @@ -539,13 +528,9 @@ static struct nstoken *sched_init(char *flags, char *sched) 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)