From patchwork Sun Jun 18 06:24:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 109573 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2320866vqr; Sat, 17 Jun 2023 23:40:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6kokZyAOGAwEY833VpYZLgHMkgN7PCPUT72KjQdDwfWPF7PEUGTmmKA/3xC5kIbhLH+SV/ X-Received: by 2002:a05:6870:44c1:b0:1a6:979f:2a2e with SMTP id t1-20020a05687044c100b001a6979f2a2emr4645913oai.13.1687070425651; Sat, 17 Jun 2023 23:40:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687070425; cv=none; d=google.com; s=arc-20160816; b=TUeiX2TYRFFVke2nLPTZVdv0vhM4LM4WCdihO5613qo9bmZ1MV/Lp0GEbJOKsjhKqw vNo6dkaX8cZ+G8pMxXtkboJN3e3WrDwGkMh6M15mzmk5kfq3fsUk5ot1SLOWTJnHNuR4 2kX8Qkk5ed6JJJmlhGcWWQzs6hykNlqCvEZYYVpKnG7ynaXJEyAZgtxP9h6LFiESvBUm WUTaGO28iykBvzQT7glbcs7VRbeDNKTrbCJmTLakchIl668XsPngwKLU0xIHeNDGB5i8 RdFOBQxN68Lf7trXmL6OMloSgrlaKAv6AgVBulPswdB1rWWZKEOCPyyyVQ8S7j2kz8IR jgaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=C0ocaakdqj4G3FMGCAU0A4MaUUuY31aUi2qpmz1hgcU=; b=PaLV3NLuE0NcK9vyE5kGGreG04GC2faYMr3Z6+6+ofOFwlXG2LYHGtJRJ+fq2brztI B81p5qEALt9K84ckuynG51tr0/iDUCjMca0j63jfdmiGYVp/gw3iNu5nZZLEZ/h/C+tQ RL4ntPdUQhpuYiwqaxwif+hRIXr4f5tNUMqR1KpYpXus34iSz1/a9cKvZJU16MRr1qNp 1PKDdBcDjYQ4Hwnwdte0PMnIkU7CIVmjrSBbP3eZIqQRanwT1Abpc7ZEYAwuVt2MM4Ev bBT53P3rx2SFYzNOzCeEjs6ahLR4ZnasF6QRPrRC9wfpg2ClJAdRg8H7uLIIh855T4jF +rVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b="j2iKr/dS"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z11-20020a6552cb000000b00543fd615d2fsi14971545pgp.879.2023.06.17.23.40.09; Sat, 17 Jun 2023 23:40:25 -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=@sberdevices.ru header.s=mail header.b="j2iKr/dS"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229480AbjFRGa1 (ORCPT + 99 others); Sun, 18 Jun 2023 02:30:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229562AbjFRGaM (ORCPT ); Sun, 18 Jun 2023 02:30:12 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60538170F; Sat, 17 Jun 2023 23:30:06 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id ABF615FD26; Sun, 18 Jun 2023 09:30:02 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1687069802; bh=C0ocaakdqj4G3FMGCAU0A4MaUUuY31aUi2qpmz1hgcU=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=j2iKr/dSCjoUXGFex1Yk7pFgJmAUXTCmgO4d+ft9wjT/H2AYTr8TO174awZUKn+bB s6WR3ZK9xJAC5NTJxEjr7WUK26PkGMBf6YDJIKqyOVyhTb00qoNQLAI+Q/TWU2+NwA 2awTKu25ZBr5YpYM0SQyMYVbDy0OWRSeuckE+Ew9rljlU2fxgU+s1BjARX+NheEkK2 SBgQMU0/H/j7RRgdZiqLABMNGO8O+3UNaHHB8vf4KVTOUd8SfQ1Y+az+oLJbGnEhtw dP3vdPUXSld7BkukGxhR11sSdqCQ0yodgCd2dl7UdMgZ/cUltuHDutOT34LTQMXqLp 4pTW2oOcKIzkQ== Received: from p-i-exch-sc-m01.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) by mx.sberdevices.ru (Postfix) with ESMTP; Sun, 18 Jun 2023 09:30:02 +0300 (MSK) From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [RFC PATCH v1 3/4] vsock/test: rework MSG_PEEK test for SOCK_STREAM Date: Sun, 18 Jun 2023 09:24:50 +0300 Message-ID: <20230618062451.79980-4-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230618062451.79980-1-AVKrasnov@sberdevices.ru> References: <20230618062451.79980-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) 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: 2023/06/18 01:53:00 #21507494 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769021558665504837?= X-GMAIL-MSGID: =?utf-8?q?1769021558665504837?= This new version makes test more complicated by adding empty read, partial read and data comparisons between MSG_PEEK and normal reads. Signed-off-by: Arseniy Krasnov --- tools/testing/vsock/vsock_test.c | 66 ++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index ac1bd3ac1533..104ac102e411 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -255,9 +255,13 @@ static void test_stream_multiconn_server(const struct test_opts *opts) close(fds[i]); } +#define MSG_PEEK_BUF_LEN 64 + static void test_stream_msg_peek_client(const struct test_opts *opts) { + unsigned char buf[MSG_PEEK_BUF_LEN]; int fd; + int i; fd = vsock_stream_connect(opts->peer_cid, 1234); if (fd < 0) { @@ -265,12 +269,21 @@ static void test_stream_msg_peek_client(const struct test_opts *opts) exit(EXIT_FAILURE); } - send_byte(fd, 1, 0); + for (i = 0; i < sizeof(buf); i++) + buf[i] = rand() & 0xFF; + + control_expectln("SRVREADY"); + + send(fd, buf, sizeof(buf), 0); close(fd); } static void test_stream_msg_peek_server(const struct test_opts *opts) { + unsigned char buf_half[MSG_PEEK_BUF_LEN / 2]; + unsigned char buf_normal[MSG_PEEK_BUF_LEN]; + unsigned char buf_peek[MSG_PEEK_BUF_LEN]; + ssize_t res; int fd; fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); @@ -279,8 +292,55 @@ static void test_stream_msg_peek_server(const struct test_opts *opts) exit(EXIT_FAILURE); } - recv_byte(fd, 1, MSG_PEEK); - recv_byte(fd, 1, 0); + /* Peek from empty socket. */ + res = recv(fd, buf_peek, sizeof(buf_peek), MSG_PEEK | MSG_DONTWAIT); + if (res != -1) { + fprintf(stderr, "expected recv(2) failure, got %zi\n", res); + exit(EXIT_FAILURE); + } + + if (errno != EAGAIN) { + perror("EAGAIN expected"); + exit(EXIT_FAILURE); + } + + control_writeln("SRVREADY"); + + /* Peek part of data. */ + res = recv(fd, buf_half, sizeof(buf_half), MSG_PEEK); + if (res != sizeof(buf_half)) { + fprintf(stderr, "recv(2) + MSG_PEEK, expected %zu, got %zi\n", + sizeof(buf_half), res); + exit(EXIT_FAILURE); + } + + /* Peek whole data. */ + res = recv(fd, buf_peek, sizeof(buf_peek), MSG_PEEK); + if (res != sizeof(buf_peek)) { + fprintf(stderr, "recv(2) + MSG_PEEK, expected %zu, got %zi\n", + sizeof(buf_peek), res); + exit(EXIT_FAILURE); + } + + /* Compare partial and full peek. */ + if (memcmp(buf_half, buf_peek, sizeof(buf_half))) { + fprintf(stderr, "Partial peek data mismatch\n"); + exit(EXIT_FAILURE); + } + + res = recv(fd, buf_normal, sizeof(buf_normal), 0); + if (res != sizeof(buf_normal)) { + fprintf(stderr, "recv(2), expected %zu, got %zi\n", + sizeof(buf_normal), res); + exit(EXIT_FAILURE); + } + + /* Compare full peek and normal read. */ + if (memcmp(buf_peek, buf_normal, sizeof(buf_peek))) { + fprintf(stderr, "Full peek data mismatch\n"); + exit(EXIT_FAILURE); + } + close(fd); }