[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fnznqsbg56rfk7szjcprpo4mxy7e4patmj2u5yxbtj33dlj34w@7t5xylskewa5>
Date: Tue, 17 Jun 2025 17:21:16 +0200
From: Stefano Garzarella <sgarzare@...hat.com>
To: Xuewei Niu <niuxuewei97@...il.com>
Cc: mst@...hat.com, pabeni@...hat.com, jasowang@...hat.com,
xuanzhuo@...ux.alibaba.com, davem@...emloft.net, netdev@...r.kernel.org, stefanha@...hat.com,
leonardi@...hat.com, virtualization@...ts.linux.dev, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, fupan.lfp@...group.com, Xuewei Niu <niuxuewei.nxw@...group.com>
Subject: Re: [PATCH net-next v3 3/3] test/vsock: Add ioctl SIOCINQ tests
On Tue, Jun 17, 2025 at 12:53:46PM +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 | 82 ++++++++++++++++++++++++++++++++
> 1 file changed, 82 insertions(+)
>
>diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c
>index f669baaa0dca..66bb9fde7eca 100644
>--- a/tools/testing/vsock/vsock_test.c
>+++ b/tools/testing/vsock/vsock_test.c
>@@ -1305,6 +1305,58 @@ 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");
>+ control_expectln("RECEIVED");
>+
>+ close(client_fd);
>+}
>+
>+static void test_unread_bytes_client(const struct test_opts *opts, int type)
>+{
>+ unsigned char buf[MSG_BUF_IOCTL_LEN];
>+ int ret, fd;
>+ int sock_bytes_unread;
>+
>+ 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.
>+ */
>+ ret = ioctl_int(fd, TIOCINQ, &sock_bytes_unread, MSG_BUF_IOCTL_LEN);
>+ if (ret) {
Since we are returning a value !=0 only if EOPNOTSUPP, I think we can
just return a bool when the ioctl is supported or not, like for
vsock_wait_sent().
>+ fprintf(stderr, "Test skipped, TIOCINQ not supported.\n");
>+ goto out;
>+ }
>+
>+ recv_buf(fd, buf, sizeof(buf), 0, sizeof(buf));
>+ // All date has been consumed, so the expected is 0.
s/date/data
Please follow the style of the file (/* */ for comments)
>+ ioctl_int(fd, TIOCINQ, &sock_bytes_unread, 0);
>+ control_writeln("RECEIVED");
Why we need this control barrier here?
Thanks,
Stefano
>+
>+out:
>+ close(fd);
>+}
>+
> static void test_stream_unsent_bytes_client(const struct test_opts *opts)
> {
> test_unsent_bytes_client(opts, SOCK_STREAM);
>@@ -1325,6 +1377,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
>@@ -2051,6 +2123,16 @@ static struct test_case test_cases[] = {
> .run_client = test_stream_nolinger_client,
> .run_server = test_stream_nolinger_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
>
Powered by blists - more mailing lists