[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <j6dgi7ptup6op37lgwpwdvrkfxpnelholoyc3rk6hb26xamgxk@h3nfy4ypnf36>
Date: Wed, 9 Jul 2025 17:05:38 +0200
From: Luigi Leonardi <leonardi@...hat.com>
To: Xuewei Niu <niuxuewei.nxw@...group.com>
Cc: "K. Y. Srinivasan" <kys@...rosoft.com>,
Haiyang Zhang <haiyangz@...rosoft.com>, Wei Liu <wei.liu@...nel.org>, Dexuan Cui <decui@...rosoft.com>,
Stefano Garzarella <sgarzare@...hat.com>, "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>, Simon Horman <horms@...nel.org>, linux-hyperv@...r.kernel.org,
virtualization@...ts.linux.dev, netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
niuxuewei97@...il.com
Subject: Re: [PATCH net-next v6 4/4] test/vsock: Add ioctl SIOCINQ tests
On Tue, Jul 08, 2025 at 02:36:14PM +0800, Xuewei Niu wrote:
>Add SIOCINQ ioctl tests for both SOCK_STREAM and SOCK_SEQPACKET.
>
>The client waits for the server to send data, and checks if the SIOCINQ
>ioctl value matches the data size. After consuming the data, the client
>checks if the SIOCINQ value is 0.
>
>Signed-off-by: Xuewei Niu <niuxuewei.nxw@...group.com>
>---
> tools/testing/vsock/vsock_test.c | 79 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 79 insertions(+)
>
>diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c
>index be6ce764f69480c0f9c3e2288fc19cd2e74be148..a66d2360133dd0e36940a5907679aeacc8af7714 100644
>--- a/tools/testing/vsock/vsock_test.c
>+++ b/tools/testing/vsock/vsock_test.c
>@@ -24,6 +24,7 @@
> #include <linux/time64.h>
> #include <pthread.h>
> #include <fcntl.h>
>+#include <linux/sockios.h>
>
> #include "vsock_test_zerocopy.h"
> #include "timeout.h"
>@@ -1307,6 +1308,54 @@ static void test_unsent_bytes_client(const struct test_opts *opts, int type)
> close(fd);
> }
>
>+static void test_unread_bytes_server(const struct test_opts *opts, int type)
>+{
>+ unsigned char buf[MSG_BUF_IOCTL_LEN];
>+ int client_fd;
>+
>+ client_fd = vsock_accept(VMADDR_CID_ANY, opts->peer_port, NULL, type);
>+ if (client_fd < 0) {
>+ perror("accept");
>+ exit(EXIT_FAILURE);
>+ }
>+
>+ for (int i = 0; i < sizeof(buf); i++)
>+ buf[i] = rand() & 0xFF;
>+
>+ send_buf(client_fd, buf, sizeof(buf), 0, sizeof(buf));
>+ control_writeln("SENT");
>+
>+ close(client_fd);
>+}
>+
>+static void test_unread_bytes_client(const struct test_opts *opts, int type)
>+{
>+ unsigned char buf[MSG_BUF_IOCTL_LEN];
>+ int fd;
>+
>+ fd = vsock_connect(opts->peer_cid, opts->peer_port, type);
>+ if (fd < 0) {
>+ perror("connect");
>+ exit(EXIT_FAILURE);
>+ }
>+
>+ control_expectln("SENT");
>+ /* The data has arrived but has not been read. The expected is
>+ * MSG_BUF_IOCTL_LEN.
>+ */
>+ if (!vsock_ioctl_int(fd, SIOCINQ, MSG_BUF_IOCTL_LEN)) {
>+ fprintf(stderr, "Test skipped, SIOCINQ not supported.\n");
>+ goto out;
>+ }
>+
>+ recv_buf(fd, buf, sizeof(buf), 0, sizeof(buf));
>+ /* All data has been consumed, so the expected is 0. */
>+ vsock_ioctl_int(fd, SIOCINQ, 0);
>+
>+out:
>+ close(fd);
>+}
>+
> static void test_stream_unsent_bytes_client(const struct test_opts *opts)
> {
> test_unsent_bytes_client(opts, SOCK_STREAM);
>@@ -1327,6 +1376,26 @@ static void test_seqpacket_unsent_bytes_server(const struct test_opts *opts)
> test_unsent_bytes_server(opts, SOCK_SEQPACKET);
> }
>
>+static void test_stream_unread_bytes_client(const struct test_opts *opts)
>+{
>+ test_unread_bytes_client(opts, SOCK_STREAM);
>+}
>+
>+static void test_stream_unread_bytes_server(const struct test_opts *opts)
>+{
>+ test_unread_bytes_server(opts, SOCK_STREAM);
>+}
>+
>+static void test_seqpacket_unread_bytes_client(const struct test_opts *opts)
>+{
>+ test_unread_bytes_client(opts, SOCK_SEQPACKET);
>+}
>+
>+static void test_seqpacket_unread_bytes_server(const struct test_opts *opts)
>+{
>+ test_unread_bytes_server(opts, SOCK_SEQPACKET);
>+}
>+
> #define RCVLOWAT_CREDIT_UPD_BUF_SIZE (1024 * 128)
> /* This define is the same as in 'include/linux/virtio_vsock.h':
> * it is used to decide when to send credit update message during
>@@ -2276,6 +2345,16 @@ static struct test_case test_cases[] = {
> .run_client = test_stream_transport_change_client,
> .run_server = test_stream_transport_change_server,
> },
>+ {
>+ .name = "SOCK_STREAM ioctl(SIOCINQ) functionality",
>+ .run_client = test_stream_unread_bytes_client,
>+ .run_server = test_stream_unread_bytes_server,
>+ },
>+ {
>+ .name = "SOCK_SEQPACKET ioctl(SIOCINQ) functionality",
>+ .run_client = test_seqpacket_unread_bytes_client,
>+ .run_server = test_seqpacket_unread_bytes_server,
>+ },
> {},
> };
>
>
>--
>2.34.1
>
I ran the tests, everything went smoothly!
I had to apply this patch[1] first otherwise the transport_change test
would cause problems.
Tested-by: Luigi Leonardi <leonardi@...hat.com>
Reviewed-by: Luigi Leonardi <leonardi@...hat.com>
Thanks for the series!
[1]https://lore.kernel.org/netdev/20250708111701.129585-1-sgarzare@redhat.com/
Powered by blists - more mailing lists