public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Soichiro Ueda <the.latticeheart@gmail.com>,
	 Kuniyuki Iwashima <kuniyu@google.com>,
	 "David S. Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@google.com>,
	 Jakub Kicinski <kuba@kernel.org>,
	 netdev@vger.kernel.org
Cc: Simon Horman <horms@kernel.org>,
	 Soichiro Ueda <the.latticeheart@gmail.com>,
	 Miao Wang <shankerwangmiao@gmail.com>
Subject: Re: [PATCH v1 net] selftests: af_unix: drain after peek and verify SO_PEEK_OFF reset
Date: Thu, 22 Jan 2026 16:33:31 -0500	[thread overview]
Message-ID: <willemdebruijn.kernel.f1685fbda48c@gmail.com> (raw)
In-Reply-To: <20260122033605.148626-1-the.latticeheart@gmail.com>

Soichiro Ueda wrote:
> Extend the so_peek_off selftest to validate behavior after MSG_PEEK.
> 
> After exercising SO_PEEK_OFF via MSG_PEEK, drain the receive queue with a
> non-peek recv() and verify that it can receive all the content in the
> buffer and SO_PEEK_OFF returns back to 0.
> 
> This improvement is suggested by Miao Wang when the so_peek_off selftest
> was added.
> 
> Link: https://lore.kernel.org/all/7B657CC7-B5CA-46D2-8A4B-8AB5FB83C6DA@gmail.com/
> Suggested-by: Miao Wang <shankerwangmiao@gmail.com>
> Signed-off-by: Soichiro Ueda <the.latticeheart@gmail.com>
> ---
>  .../selftests/net/af_unix/so_peek_off.c       | 49 +++++++++++++++++++
>  1 file changed, 49 insertions(+)
> 
> diff --git a/tools/testing/selftests/net/af_unix/so_peek_off.c b/tools/testing/selftests/net/af_unix/so_peek_off.c
> index 86e7b0fb522d..813e3b3655d3 100644
> --- a/tools/testing/selftests/net/af_unix/so_peek_off.c
> +++ b/tools/testing/selftests/net/af_unix/so_peek_off.c
> @@ -76,6 +76,19 @@ FIXTURE_TEARDOWN(so_peek_off)
>  		ASSERT_STREQ(str, buf);				\
>  	} while (0)
>  
> +#define peekoffeq(fd, expected)					\
> +	do {							\
> +		int off = -1;					\
> +		socklen_t optlen = sizeof(off);		\
> +		int ret;					\
> +								\
> +		ret = getsockopt(fd, SOL_SOCKET, SO_PEEK_OFF,	\
> +				 &off, &optlen);		\
> +		ASSERT_EQ(0, ret);				\
> +		ASSERT_EQ((socklen_t)sizeof(off), optlen);	\
> +		ASSERT_EQ(expected, off);			\
> +	} while (0)
> +
>  #define async							\
>  	for (pid_t pid = (pid = fork(),				\
>  			  pid < 0 ?				\
> @@ -92,6 +105,14 @@ TEST_F(so_peek_off, single_chunk)
>  
>  	recveq(self->fd[1], "aaaa", 4, MSG_PEEK);
>  	recveq(self->fd[1], "bbbb", 100, MSG_PEEK);
> +
> +	if (variant->type == SOCK_STREAM) {
> +		recveq(self->fd[1], "aaaa", 4, 0);
> +		recveq(self->fd[1], "bbbb", 100, 0);
> +	} else {
> +		recveq(self->fd[1], "aaaabbbb", 100, 0);
> +	}
> +	peekoffeq(self->fd[1], 0);

Do you want to test peekoffeq before the non-peek read too?

>  }
>  
>  TEST_F(so_peek_off, two_chunks)
> @@ -101,6 +122,13 @@ TEST_F(so_peek_off, two_chunks)
>  
>  	recveq(self->fd[1], "aaaa", 4, MSG_PEEK);
>  	recveq(self->fd[1], "bbbb", 100, MSG_PEEK);
> +
> +	if (variant->type == SOCK_STREAM)
> +		recveq(self->fd[1], "aaaa", 4, 0);
> +	else
> +		recveq(self->fd[1], "aaaa", 100, 0);

Why this difference in length?

Because stream read will block if > 4, while datagram does not?

If so, can perhaps use 4 for both or explicitly use non-blocking read.

> +	recveq(self->fd[1], "bbbb", 100, 0);
> +	peekoffeq(self->fd[1], 0);
>  }

  reply	other threads:[~2026-01-22 21:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-22  3:36 [PATCH v1 net] selftests: af_unix: drain after peek and verify SO_PEEK_OFF reset Soichiro Ueda
2026-01-22 21:33 ` Willem de Bruijn [this message]
2026-02-12 22:49   ` Soichiro Ueda

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=willemdebruijn.kernel.f1685fbda48c@gmail.com \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=shankerwangmiao@gmail.com \
    --cc=the.latticeheart@gmail.com \
    /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