public inbox for [email protected]
 help / color / mirror / Atom feed
From: Pavel Begunkov <[email protected]>
To: [email protected]
Cc: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing 2/6] tests/zc: test tcp
Date: Thu,  4 Aug 2022 15:20:21 +0100	[thread overview]
Message-ID: <29a52de00c6cc1bebc9d8fd70afd698746cc91c1.1659622771.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>

Add tests for TCP zerocopy send

Signed-off-by: Pavel Begunkov <[email protected]>
---
 test/send-zerocopy.c | 53 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 42 insertions(+), 11 deletions(-)

diff --git a/test/send-zerocopy.c b/test/send-zerocopy.c
index c04e905..7999f46 100644
--- a/test/send-zerocopy.c
+++ b/test/send-zerocopy.c
@@ -550,10 +550,12 @@ static int test_registration(int sock_tx, int sock_rx)
 }
 
 static int prepare_ip(struct sockaddr_storage *addr, int *sock_client, int *sock_server,
-		      bool ipv6, bool client_connect, bool msg_zc)
+		      bool ipv6, bool client_connect, bool msg_zc, bool tcp)
 {
 	int family, addr_size;
 	int ret, val;
+	int listen_sock = -1;
+	int sock;
 
 	memset(addr, 0, sizeof(*addr));
 	if (ipv6) {
@@ -574,18 +576,29 @@ static int prepare_ip(struct sockaddr_storage *addr, int *sock_client, int *sock
 	}
 
 	/* server sock setup */
-	*sock_server = socket(family, SOCK_DGRAM, 0);
-	if (*sock_server < 0) {
+	if (tcp) {
+		sock = listen_sock = socket(family, SOCK_STREAM, IPPROTO_TCP);
+	} else {
+		sock = *sock_server = socket(family, SOCK_DGRAM, 0);
+	}
+	if (sock < 0) {
 		perror("socket");
 		return 1;
 	}
 	val = 1;
-	setsockopt(*sock_server, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
-	ret = bind(*sock_server, (struct sockaddr *)addr, addr_size);
+	setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
+	val = 1;
+	setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(val));
+
+	ret = bind(sock, (struct sockaddr *)addr, addr_size);
 	if (ret < 0) {
 		perror("bind");
 		return 1;
 	}
+	if (tcp) {
+		ret = listen(sock, 128);
+		assert(ret != -1);
+	}
 
 	if (ipv6) {
 		struct sockaddr_in6 *saddr = (struct sockaddr_in6 *)addr;
@@ -598,7 +611,12 @@ static int prepare_ip(struct sockaddr_storage *addr, int *sock_client, int *sock
 	}
 
 	/* client sock setup */
-	*sock_client = socket(family, SOCK_DGRAM, 0);
+	if (tcp) {
+		*sock_client = socket(family, SOCK_STREAM, IPPROTO_TCP);
+		assert(client_connect);
+	} else {
+		*sock_client = socket(family, SOCK_DGRAM, 0);
+	}
 	if (*sock_client < 0) {
 		perror("socket");
 		return 1;
@@ -617,6 +635,14 @@ static int prepare_ip(struct sockaddr_storage *addr, int *sock_client, int *sock
 			return 1;
 		}
 	}
+	if (tcp) {
+		*sock_server = accept(listen_sock, NULL, NULL);
+		if (!*sock_server) {
+			fprintf(stderr, "can't accept\n");
+			return 1;
+		}
+		close(listen_sock);
+	}
 	return 0;
 }
 
@@ -721,17 +747,20 @@ static int do_test_inet_send(struct io_uring *ring, int sock_client, int sock_se
 static int test_inet_send(struct io_uring *ring)
 {
 	struct sockaddr_storage addr;
-	int sock_client, sock_server;
-	int ret, j;
-	__u64 i;
+	int sock_client = -1, sock_server = -1;
+	int ret, j, i;
 
-	for (j = 0; j < 8; j++) {
+	for (j = 0; j < 16; j++) {
 		bool ipv6 = j & 1;
 		bool client_connect = j & 2;
 		bool msg_zc_set = j & 4;
+		bool tcp = j & 8;
+
+		if (tcp && !client_connect)
+			continue;
 
 		ret = prepare_ip(&addr, &sock_client, &sock_server, ipv6,
-				 client_connect, msg_zc_set);
+				 client_connect, msg_zc_set, tcp);
 		if (ret) {
 			fprintf(stderr, "sock prep failed %d\n", ret);
 			return 1;
@@ -746,6 +775,8 @@ static int test_inet_send(struct io_uring *ring)
 			bool aligned = i & 32;
 			int buf_idx = aligned ? 0 : 1;
 
+			if (tcp && cork)
+				continue;
 			if (mix_register && (!cork || fixed_buf))
 				continue;
 			if (!client_connect && addr_arg == NULL)
-- 
2.37.0


  parent reply	other threads:[~2022-08-04 14:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-04 14:20 [PATCH liburing 0/6] improve zeoropy testing Pavel Begunkov
2022-08-04 14:20 ` [PATCH liburing 1/6] test/zc: improve error messages Pavel Begunkov
2022-08-04 14:20 ` Pavel Begunkov [this message]
2022-08-04 14:20 ` [PATCH liburing 3/6] test/zc: allocate buffers dynamically Pavel Begunkov
2022-08-04 14:20 ` [PATCH liburing 4/6] test/zc: handle short rx Pavel Begunkov
2022-08-04 14:20 ` [PATCH liburing 5/6] test/zc: recv asynchronously Pavel Begunkov
2022-08-04 14:20 ` [PATCH liburing 6/6] test/zc: test short zc send Pavel Begunkov
2022-08-04 22:22 ` [PATCH liburing 0/6] improve zeoropy testing Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=29a52de00c6cc1bebc9d8fd70afd698746cc91c1.1659622771.git.asml.silence@gmail.com \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox