Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp3545054rwo; Fri, 4 Aug 2023 06:35:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEE2KxEsoZb1c9eHFw5npZDOKUJSQpdGL0Rl8r+3tHp7qqmKVhfiUXWRDOoShtz1iDZSucV X-Received: by 2002:a05:6a20:938a:b0:13e:8ce5:cacd with SMTP id x10-20020a056a20938a00b0013e8ce5cacdmr1742823pzh.26.1691156150474; Fri, 04 Aug 2023 06:35:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691156150; cv=none; d=google.com; s=arc-20160816; b=iMXT61vtRxmZhSxL2XOPUS+omk1HzuqMn5rQOkhcCh00Cr9IzPjzyBr5vhnZRRfXiR oI6OEAROoA7BEjYB/19H+mKh7wcyp3IzVkJXaWNfYfCvK19Gpa/8wAtoWvd7PO2pC2Sk rVZ6aaqXVvvP27OeHSiGlrG7LvgfNXAbTyo15XPXnI4jO9UBNGrSJwa3+i1Hnuykgxhd km9q1OYFWl6zrnYWgIvlRoEiDRHAFw4sEqY379rvO1cg1iKgxoisVFm3ts9ZJe0Px3It h+E07uPgdILiRBgFqSmlxRmqfxU+9OoAkmXlUumZlDEFOQys4YRPmDCXs3Tg9PBph6Yr aQMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=xjH/ryp1J57ZKJnJ2tl0LljaSJPaayNedWWuu7ipUsU=; fh=g3qvwCI0QU9yXXfSMScr82BPv2IWydszJ4quiXtvDFg=; b=o5qa7UEmpXUsPNf/AwpH+v+62bV6d0ZvYrWObkNoMMjX+e1ac9x4slG0HZHlxIaehj 9T/ud2u3zDSB6VhKYeFUHbs48i9brgKGiyaJKqZHet8+q9MSqG59aRsvNrjS0Gi2K69m Ij29dbdGFZlHE+px9fvdsbUOJhhJz3GNPcwNaDUc2zIV3CxN/2t+OGnKtQAZzoA42Ixv oIjofB4YeciHiHw1f6mJz2bw7VmLt281iP+q82K89r5+cg8/DERk/FmMBJSiDHN+Zg58 GiTXH6Eoi7t8WSS32+lSLn7A5LiCEXLUILKhZBi7dU1VCZ8FZFtGIhhN+5EtKXNX6YnY eLtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=WduViqHT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ea10-20020a056a004c0a00b0068757aae1a2si1708680pfb.87.2023.08.04.06.35.38; Fri, 04 Aug 2023 06:35:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=WduViqHT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230213AbjHDMtU (ORCPT + 99 others); Fri, 4 Aug 2023 08:49:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229880AbjHDMtT (ORCPT ); Fri, 4 Aug 2023 08:49:19 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 560F949F9; Fri, 4 Aug 2023 05:48:53 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-307d58b3efbso1747914f8f.0; Fri, 04 Aug 2023 05:48:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691153322; x=1691758122; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=xjH/ryp1J57ZKJnJ2tl0LljaSJPaayNedWWuu7ipUsU=; b=WduViqHTvAq6wggt3wylP2g1m7R03G0zmozRk7zfAa+372lYPbg9KfpKRHTIrOi6jg r+KZnGx7sNwUUy+StCRHqqcRyeGuMbkP5GaOZrMirZrZpdFaAPYFRdRW1VNuwH4HzguH KHbzw35KkOETcaJBsPuqlNGcvTE1vulIj/qUm098rCLyyxXmisOhef7l5Wwrt4lSinte SdVQLtA/715Pez0npBlm6dFiFuyYhBQUoevO7yO5SSR8wewOzSHEoiTHq3sDaNPQF70n xabYb+zwwO55ZnPfwIYG9qZeW2aehhOuCFTPbUePbXxJB6tlcxOc2JGUjDELfXrhKLRS gIDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691153322; x=1691758122; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xjH/ryp1J57ZKJnJ2tl0LljaSJPaayNedWWuu7ipUsU=; b=Za2IadEwSX5qexjLkz6GLQmPGKvftG1u7dILVyFfWl9qDkhll9JYzbL8dfn+vkEpVz 4EafxgY0E8PhFK4z58+dgEyfaFv26ibYj+2KT5IapIGWro+ZctUy/yughl1xP6CsIIZv Mu0POEB+pqfCVd4JOZylqMC0h4ruaJp6UUgARaq6MiAkV5Sjb0MjG6BiQ+tkfvBcVKK2 pQIxH9AuqIJygvqMmgCVYAh6LwphCmMO818RZwgunxwNBXf7XLo1LxgXnP3MR7YVpbNB urYMgMK95oFZdFfwpPMvXJMJd8PombF77qTlzlfcc7PI2zViuXyfBKjPWVbMRtJoq/DH PoLA== X-Gm-Message-State: AOJu0YylSDPynjPKhmCR5PNWX8Vm8FKjmsIUVTIxNGSsSn8jLw/t4ns8 mEDcip+9iZPEZiCuGZx5xfE= X-Received: by 2002:adf:ce90:0:b0:314:3b02:a8a8 with SMTP id r16-20020adfce90000000b003143b02a8a8mr1286060wrn.55.1691153321907; Fri, 04 Aug 2023 05:48:41 -0700 (PDT) Received: from [10.9.105.115] ([41.86.56.122]) by smtp.gmail.com with ESMTPSA id f9-20020a7bc8c9000000b003fba92fad35sm6606038wml.26.2023.08.04.05.48.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Aug 2023 05:48:41 -0700 (PDT) Message-ID: <3e7b020e-329b-6800-2b60-08207bda8b03@gmail.com> Date: Fri, 4 Aug 2023 15:48:34 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [RFC PATCH v1 2/2] test/vsock: shutdowned socket test Content-Language: en-US To: Stefano Garzarella , Arseniy Krasnov Cc: Stefan Hajnoczi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@sberdevices.ru References: <20230801141727.481156-1-AVKrasnov@sberdevices.ru> <20230801141727.481156-3-AVKrasnov@sberdevices.ru> <76yecufn7766obfi5zae5hpg6yrlestrqocnk56jgnukakkdds@rqbgbhh7xgck> From: Arseniy Krasnov In-Reply-To: <76yecufn7766obfi5zae5hpg6yrlestrqocnk56jgnukakkdds@rqbgbhh7xgck> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HK_RANDOM_ENVFROM, HK_RANDOM_FROM,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >> --- >> 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 >> #include >> #include >> +#include >> >> #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 >> >