[PATCH mptcp-next v2 8/8] selftests: bpf: add bpf_first test

Geliang Tang posted 8 patches 3 years, 10 months ago
There is a newer version of this series
[PATCH mptcp-next v2 8/8] selftests: bpf: add bpf_first test
Posted by Geliang Tang 3 years, 10 months ago
This patch added the MPTCP sched testcases. Use sysctl to set
net.mptcp.scheduler in the tests.

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 .../selftests/bpf/prog_tests/bpf_tcp_ca.c     | 42 +++++++++++++++++--
 1 file changed, 38 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
index 8f7a1cef7d87..979b6e90b372 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c
@@ -9,6 +9,7 @@
 #include "bpf_cubic.skel.h"
 #include "bpf_tcp_nogpl.skel.h"
 #include "bpf_dctcp_release.skel.h"
+#include "bpf_first.skel.h"
 
 #define min(a, b) ((a) < (b) ? (a) : (b))
 
@@ -16,6 +17,10 @@
 #define ENOTSUPP 524
 #endif
 
+#ifndef IPPROTO_MPTCP
+#define IPPROTO_MPTCP 262
+#endif
+
 static const unsigned int total_bytes = 10 * 1024 * 1024;
 static int expected_stg = 0xeB9F;
 static int stop, duration;
@@ -85,21 +90,26 @@ static void do_test(const char *tcp_ca, const struct bpf_map *sk_stg_map)
 	socklen_t addrlen = sizeof(sa6);
 	void *thread_ret;
 	char batch[1500];
+	int proto = 0;
 	int err;
 
 	WRITE_ONCE(stop, 0);
 
-	lfd = socket(AF_INET6, SOCK_STREAM, 0);
+	if (!strcmp(tcp_ca, "bpf_first"))
+		proto = IPPROTO_MPTCP;
+
+	lfd = socket(AF_INET6, SOCK_STREAM, proto);
 	if (CHECK(lfd == -1, "socket", "errno:%d\n", errno))
 		return;
-	fd = socket(AF_INET6, SOCK_STREAM, 0);
+	fd = socket(AF_INET6, SOCK_STREAM, proto);
 	if (CHECK(fd == -1, "socket", "errno:%d\n", errno)) {
 		close(lfd);
 		return;
 	}
 
-	if (settcpca(lfd, tcp_ca) || settcpca(fd, tcp_ca) ||
-	    settimeo(lfd, 0) || settimeo(fd, 0))
+	if (!proto &&
+	    (settcpca(lfd, tcp_ca) || settcpca(fd, tcp_ca) ||
+	     settimeo(lfd, 0) || settimeo(fd, 0)))
 		goto done;
 
 	/* bind, listen and start server thread to accept */
@@ -324,6 +334,28 @@ static void test_rel_setsockopt(void)
 	bpf_dctcp_release__destroy(rel_skel);
 }
 
+static void test_first(void)
+{
+	struct bpf_first *first_skel;
+	struct bpf_link *link;
+
+	first_skel = bpf_first__open_and_load();
+	if (CHECK(!first_skel, "bpf_first__open_and_load", "failed\n"))
+		return;
+
+	link = bpf_map__attach_struct_ops(first_skel->maps.first);
+	if (!ASSERT_OK_PTR(link, "bpf_map__attach_struct_ops")) {
+		bpf_first__destroy(first_skel);
+		return;
+	}
+
+	system("sysctl -q net.mptcp.scheduler=bpf_first");
+	do_test("bpf_first", NULL);
+
+	bpf_link__destroy(link);
+	bpf_first__destroy(first_skel);
+}
+
 void test_bpf_tcp_ca(void)
 {
 	if (test__start_subtest("dctcp"))
@@ -336,4 +368,6 @@ void test_bpf_tcp_ca(void)
 		test_dctcp_fallback();
 	if (test__start_subtest("rel_setsockopt"))
 		test_rel_setsockopt();
+	if (test__start_subtest("first"))
+		test_first();
 }
-- 
2.34.1