From patchwork Fri Mar 11 10:55:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 12777825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5804BC433F5 for ; Fri, 11 Mar 2022 10:56:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348108AbiCKK5S (ORCPT ); Fri, 11 Mar 2022 05:57:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347547AbiCKK5R (ORCPT ); Fri, 11 Mar 2022 05:57:17 -0500 Received: from mail.sberdevices.ru (mail.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 787381BBF40; Fri, 11 Mar 2022 02:56:13 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mail.sberdevices.ru (Postfix) with ESMTP id E843F5FD03; Fri, 11 Mar 2022 13:56:10 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1646996170; bh=DD/056Xz/HdtVJttGh/0J3YuBHetrOfFSU0k/r+/LWU=; h=From:To:Subject:Date:Message-ID:Content-Type:MIME-Version; b=oygVYYnfmxInViijSb+SiWbY6FDcVbeACrqVXJ5/lj7pzqrJUhON6MRdmOrX5a2BX DeKfafmEVkco3JdxvWnNvbqxJtig5Rd1MZNcP/SjDjAYFgaX0HO2TZhQCjuA04iR0z WcVHnmNFBl8tPFPy5kue7LGFxeI1Njgm+/9ZoHGvriXc1JE55spbw6+lWpOntj5+eC nehQQqH2XgxIcm9CQfl75vAPOG0p2MzNqYQeRxvHzvPCXhSdiqq+UfiMhAjGpg1TsC J8jnPCH3ZoooJMC2N8R4O9MqNrJ6HsgP464NpkFZ/16dn6tdkXqLwvrdLQWVMPPjGt uEafdS1fWAxxA== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mail.sberdevices.ru (Postfix) with ESMTP; Fri, 11 Mar 2022 13:56:10 +0300 (MSK) From: Krasnov Arseniy Vladimirovich To: Stefano Garzarella CC: Krasnov Arseniy , Rokosov Dmitry Dmitrievich , "kvm@vger.kernel.org" , "virtualization@lists.linux-foundation.org" , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Krasnov Arseniy Vladimirovich Subject: [RFC PATCH v1 2/3] af_vsock: SOCK_SEQPACKET receive timeout test Thread-Topic: [RFC PATCH v1 2/3] af_vsock: SOCK_SEQPACKET receive timeout test Thread-Index: AQHYNTaJU61+cjcYFEaSzJHWUZnmpA== Date: Fri, 11 Mar 2022 10:55:42 +0000 Message-ID: <6981b132-4121-62d8-7172-dca28ad1e498@sberdevices.ru> In-Reply-To: <1bb5ce91-da53-7de9-49ba-f49f76f45512@sberdevices.ru> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.16.1.12] Content-ID: MIME-Version: 1.0 X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2022/03/11 07:23:00 #18938550 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-State: RFC Test for receive timeout check: connection is established, receiver sets timeout, but sender does nothing. Receiver's 'read()' call must return EAGAIN. Signed-off-by: Arseniy Krasnov --- tools/testing/vsock/vsock_test.c | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index 2a3638c0a008..aa2de27d0f77 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -391,6 +391,50 @@ static void test_seqpacket_msg_trunc_server(const struct test_opts *opts) close(fd); } +static void test_seqpacket_timeout_client(const struct test_opts *opts) +{ + int fd; + struct timeval tv; + char dummy; + + fd = vsock_seqpacket_connect(opts->peer_cid, 1234); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + tv.tv_sec = 1; + tv.tv_usec = 0; + + if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv, sizeof(tv)) == -1) { + perror("setsockopt 'SO_RCVTIMEO'"); + exit(EXIT_FAILURE); + } + + if ((read(fd, &dummy, sizeof(dummy)) != -1) || + (errno != EAGAIN)) { + perror("EAGAIN expected"); + exit(EXIT_FAILURE); + } + + control_writeln("WAITDONE"); + close(fd); +} + +static void test_seqpacket_timeout_server(const struct test_opts *opts) +{ + int fd; + + fd = vsock_seqpacket_accept(VMADDR_CID_ANY, 1234, NULL); + if (fd < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + control_expectln("WAITDONE"); + close(fd); +} + static struct test_case test_cases[] = { { .name = "SOCK_STREAM connection reset", @@ -431,6 +475,11 @@ static struct test_case test_cases[] = { .run_client = test_seqpacket_msg_trunc_client, .run_server = test_seqpacket_msg_trunc_server, }, + { + .name = "SOCK_SEQPACKET timeout", + .run_client = test_seqpacket_timeout_client, + .run_server = test_seqpacket_timeout_server, + }, {}, };