mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arseniy Krasnov <oxffffaa@gmail.com>
To: Stefano Garzarella <sgarzare@redhat.com>,
	Arseniy Krasnov <AVKrasnov@sberdevices.ru>
Cc: Stefan Hajnoczi <stefanha@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	Bobby Eshleman <bobby.eshleman@bytedance.com>,
	kvm@vger.kernel.org, virtualization@lists.linux-foundation.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel@sberdevices.ru
Subject: Re: [RFC PATCH v1 2/2] test/vsock: shutdowned socket test
Date: Fri, 4 Aug 2023 15:48:34 +0300	[thread overview]
Message-ID: <3e7b020e-329b-6800-2b60-08207bda8b03@gmail.com> (raw)
In-Reply-To: <76yecufn7766obfi5zae5hpg6yrlestrqocnk56jgnukakkdds@rqbgbhh7xgck>



On 02.08.2023 11:00, Stefano Garzarella wrote:
> On Tue, Aug 01, 2023 at 05:17:27PM +0300, Arseniy Krasnov wrote:
>> This adds two tests for 'shutdown()' call. It checks that SIGPIPE is
>> sent when MSG_NOSIGNAL is not set and vice versa. Both flags SHUT_WR
>> and SHUT_RD are tested.
>>
>> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
>> ---
>> tools/testing/vsock/vsock_test.c | 138 +++++++++++++++++++++++++++++++
>> 1 file changed, 138 insertions(+)
>>
>> diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c
>> index 90718c2fd4ea..21d40a8d881c 100644
>> --- a/tools/testing/vsock/vsock_test.c
>> +++ b/tools/testing/vsock/vsock_test.c
>> @@ -19,6 +19,7 @@
>> #include <time.h>
>> #include <sys/mman.h>
>> #include <poll.h>
>> +#include <signal.h>
>>
>> #include "timeout.h"
>> #include "control.h"
>> @@ -1170,6 +1171,133 @@ static void test_seqpacket_msg_peek_server(const struct test_opts *opts)
>>     return test_msg_peek_server(opts, true);
>> }
>>
>> +static bool have_sigpipe;
>                  ^
> We should define it as `volatile sig_atomic_t`:
> 
> the behavior is undefined if the signal handler refers to any object
> [CX] [Option Start]  other than errno [Option End]  with static storage
> duration other than by assigning a value to an object declared as
> volatile sig_atomic_t

Yes, exactly, I forgot about sig_atomic_t.

I'll fix it.

Thanks, Arseniy

> 
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/signal.html
> 
> The rest LGTM!
> 
> Thanks,
> Stefano
> 
>> +
>> +static void sigpipe(int signo)
>> +{
>> +    have_sigpipe = true;
>> +}
>> +
>> +static void test_stream_check_sigpipe(int fd)
>> +{
>> +    ssize_t res;
>> +
>> +    have_sigpipe = false;
>> +
>> +    res = send(fd, "A", 1, 0);
>> +    if (res != -1) {
>> +        fprintf(stderr, "expected send(2) failure, got %zi\n", res);
>> +        exit(EXIT_FAILURE);
>> +    }
>> +
>> +    if (!have_sigpipe) {
>> +        fprintf(stderr, "SIGPIPE expected\n");
>> +        exit(EXIT_FAILURE);
>> +    }
>> +
>> +    have_sigpipe = false;
>> +
>> +    res = send(fd, "A", 1, MSG_NOSIGNAL);
>> +    if (res != -1) {
>> +        fprintf(stderr, "expected send(2) failure, got %zi\n", res);
>> +        exit(EXIT_FAILURE);
>> +    }
>> +
>> +    if (have_sigpipe) {
>> +        fprintf(stderr, "SIGPIPE not expected\n");
>> +        exit(EXIT_FAILURE);
>> +    }
>> +}
>> +
>> +static void test_stream_shutwr_client(const struct test_opts *opts)
>> +{
>> +    int fd;
>> +
>> +    struct sigaction act = {
>> +        .sa_handler = sigpipe,
>> +    };
>> +
>> +    sigaction(SIGPIPE, &act, NULL);
>> +
>> +    fd = vsock_stream_connect(opts->peer_cid, 1234);
>> +    if (fd < 0) {
>> +        perror("connect");
>> +        exit(EXIT_FAILURE);
>> +    }
>> +
>> +    if (shutdown(fd, SHUT_WR)) {
>> +        perror("shutdown");
>> +        exit(EXIT_FAILURE);
>> +    }
>> +
>> +    test_stream_check_sigpipe(fd);
>> +
>> +    control_writeln("CLIENTDONE");
>> +
>> +    close(fd);
>> +}
>> +
>> +static void test_stream_shutwr_server(const struct test_opts *opts)
>> +{
>> +    int fd;
>> +
>> +    fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL);
>> +    if (fd < 0) {
>> +        perror("accept");
>> +        exit(EXIT_FAILURE);
>> +    }
>> +
>> +    control_expectln("CLIENTDONE");
>> +
>> +    close(fd);
>> +}
>> +
>> +static void test_stream_shutrd_client(const struct test_opts *opts)
>> +{
>> +    int fd;
>> +
>> +    struct sigaction act = {
>> +        .sa_handler = sigpipe,
>> +    };
>> +
>> +    sigaction(SIGPIPE, &act, NULL);
>> +
>> +    fd = vsock_stream_connect(opts->peer_cid, 1234);
>> +    if (fd < 0) {
>> +        perror("connect");
>> +        exit(EXIT_FAILURE);
>> +    }
>> +
>> +    control_expectln("SHUTRDDONE");
>> +
>> +    test_stream_check_sigpipe(fd);
>> +
>> +    control_writeln("CLIENTDONE");
>> +
>> +    close(fd);
>> +}
>> +
>> +static void test_stream_shutrd_server(const struct test_opts *opts)
>> +{
>> +    int fd;
>> +
>> +    fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL);
>> +    if (fd < 0) {
>> +        perror("accept");
>> +        exit(EXIT_FAILURE);
>> +    }
>> +
>> +    if (shutdown(fd, SHUT_RD)) {
>> +        perror("shutdown");
>> +        exit(EXIT_FAILURE);
>> +    }
>> +
>> +    control_writeln("SHUTRDDONE");
>> +    control_expectln("CLIENTDONE");
>> +
>> +    close(fd);
>> +}
>> +
>> static struct test_case test_cases[] = {
>>     {
>>         .name = "SOCK_STREAM connection reset",
>> @@ -1250,6 +1378,16 @@ static struct test_case test_cases[] = {
>>         .run_client = test_seqpacket_msg_peek_client,
>>         .run_server = test_seqpacket_msg_peek_server,
>>     },
>> +    {
>> +        .name = "SOCK_STREAM SHUT_WR",
>> +        .run_client = test_stream_shutwr_client,
>> +        .run_server = test_stream_shutwr_server,
>> +    },
>> +    {
>> +        .name = "SOCK_STREAM SHUT_RD",
>> +        .run_client = test_stream_shutrd_client,
>> +        .run_server = test_stream_shutrd_server,
>> +    },
>>     {},
>> };
>>
>> -- 
>> 2.25.1
>>
> 

      reply	other threads:[~2023-08-04 12:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-01 14:17 [RFC PATCH v1 0/2] vsock: handle writes to shutdowned socket Arseniy Krasnov
2023-08-01 14:17 ` [RFC PATCH v1 1/2] vsock: send SIGPIPE on write " Arseniy Krasnov
2023-08-02  7:46   ` Stefano Garzarella
2023-08-04 12:46     ` Arseniy Krasnov
2023-08-04 14:28       ` Stefano Garzarella
2023-08-04 14:34         ` Arseniy Krasnov
2023-08-04 15:02           ` Stefano Garzarella
2023-08-04 16:24             ` Arseniy Krasnov
2023-08-14 19:40             ` Arseniy Krasnov
2023-08-22  9:36               ` Stefano Garzarella
2023-08-14 19:46         ` Arseniy Krasnov
2023-08-22  9:39           ` Stefano Garzarella
2023-08-22 12:51             ` Arseniy Krasnov
2023-08-01 14:17 ` [RFC PATCH v1 2/2] test/vsock: shutdowned socket test Arseniy Krasnov
2023-08-02  8:00   ` Stefano Garzarella
2023-08-04 12:48     ` Arseniy Krasnov [this message]

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=3e7b020e-329b-6800-2b60-08207bda8b03@gmail.com \
    --to=oxffffaa@gmail.com \
    --cc=AVKrasnov@sberdevices.ru \
    --cc=bobby.eshleman@bytedance.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jasowang@redhat.com \
    --cc=kernel@sberdevices.ru \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /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

all inboxes | Powered by JetHome®