diff mbox series

[RFC,v1,2/2] vsock_test: mutual hungup reproducer

Message ID 26d57ed5-f2f5-5e1d-b557-67a41c1c573c@sberdevices.ru (mailing list archive)
State RFC
Headers show
Series virtio/vsock: fix mutual rx/tx hungup | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Arseniy Krasnov Dec. 17, 2022, 7:47 p.m. UTC
This is not for merge, just demo.

Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
---
 tools/testing/vsock/vsock_test.c | 78 ++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)
diff mbox series

Patch

diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c
index bb6d691cb30d..320ecf4db74b 100644
--- a/tools/testing/vsock/vsock_test.c
+++ b/tools/testing/vsock/vsock_test.c
@@ -699,7 +699,85 @@  static void test_stream_poll_rcvlowat_client(const struct test_opts *opts)
 	close(fd);
 }
 
+static void test_stall_client(const struct test_opts *opts)
+{
+	int fd;
+	unsigned long lowat_val = 128*1024;
+	size_t data_size = 64 * 1024;
+	void *data;
+
+
+	fd = vsock_stream_connect(opts->peer_cid, 1234);
+	assert(fd != -1);
+
+	assert(!setsockopt(fd, SOL_SOCKET, SO_RCVLOWAT,
+		       &lowat_val, sizeof(lowat_val)));
+
+	data = malloc(data_size);
+	assert(data);
+
+	/* Wait for tx to send data. */
+	sleep(3);
+
+	while (1) {
+		struct pollfd fds = {0};
+
+		fds.fd = fd;
+		fds.events = POLLIN | POLLRDNORM | POLLERR | POLLRDHUP | POLLHUP;
+
+		/* Try to wait for 1 sec. */
+		printf("[RX] ENTER POLL\n");
+		assert(poll(&fds, 1, -1) >= 0);
+		printf("[RX] LEAVE POLL\n");
+
+		if (fds.revents & (POLLIN | POLLRDNORM)) {
+			read(fd, data, data_size);
+		}
+
+		if (fds.revents & POLLERR) {
+			printf("[RX] POLL ERR\n");
+			break;
+		}
+
+		if (fds.revents & (POLLRDHUP | POLLHUP)) {
+			printf("[RX] POLL DONE\n");
+			break;
+		}
+	}
+
+	close(fd);
+	exit(0);
+}
+
+static void test_stall_server(const struct test_opts *opts)
+{
+	size_t data_size = (256 * 1024) + 1;
+	void *data;
+	int fd;
+
+	fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL);
+	assert(fd != -1);
+
+	data = malloc(data_size);
+	assert(data);
+
+	printf("[TX] ENTER WRITE\n");
+	assert(write(fd, data, data_size) == data_size);
+
+	/* Never get here without kernel patch. */
+	printf("[TX] LEAVE WRITE\n");
+
+	close(fd);
+	exit(0);
+}
+
+
 static struct test_case test_cases[] = {
+	{
+		.name = "Test stall",
+		.run_client = test_stall_client,
+		.run_server = test_stall_server,
+	},
 	{
 		.name = "SOCK_STREAM connection reset",
 		.run_client = test_stream_connection_reset,