From nobody Mon Feb 9 19:25:43 2026 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 D19B0C00528 for ; Tue, 25 Jul 2023 17:35:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232227AbjGYRfM (ORCPT ); Tue, 25 Jul 2023 13:35:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231131AbjGYRe7 (ORCPT ); Tue, 25 Jul 2023 13:34:59 -0400 Received: from mx1.sberdevices.ru (mx1.sberdevices.ru [37.18.73.165]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADE0E1BCF; Tue, 25 Jul 2023 10:34:57 -0700 (PDT) Received: from p-infra-ksmg-sc-msk01 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 2AF9910002D; Tue, 25 Jul 2023 20:34:56 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 2AF9910002D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1690306496; bh=2qfdf7pbnKoFJf+XEwGy5M3qiLXT3yX1jazMXsysx6c=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=C59Odu0on58mai2LfRMpwDZMZ4jBPj2V4sPWAReSFpUfxyrox2bgdx6rTNRZRFLK+ DWRAFq0jdzehsJKBGhNETwymXqR22lHc28u/ABEOhNJr3sMF+1nTYxZL3TqripZkx/ T+kAUEXcVELynVsUX55CqDxXU4KjtfzcF9WkVK1tIx2CUl+ruxQDomOnR5O0v6kIYq xfH23QOcmQstgzzOClw4tzJ3uXTnjZBkj2hI9Pkwl8ZLzIVEM61LwSpLr+f8/focec 2jdJq6m1ryydYhm3P3BNf7d/Vd6r4tBfhC+bgTgFbTmhbPHDfTg++72Uj9giXCsE+r GRnq1xbOklviQ== Received: from p-i-exch-sc-m01.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Tue, 25 Jul 2023 20:34:55 +0300 (MSK) Received: from localhost.localdomain (100.64.160.123) by p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Tue, 25 Jul 2023 20:34:53 +0300 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: [PATCH net-next v3 3/4] vsock/test: rework MSG_PEEK test for SOCK_STREAM Date: Tue, 25 Jul 2023 20:29:11 +0300 Message-ID: <20230725172912.1659970-4-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230725172912.1659970-1-AVKrasnov@sberdevices.ru> References: <20230725172912.1659970-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 178796 [Jul 22 2023] X-KSMG-AntiSpam-Version: 5.9.59.0 X-KSMG-AntiSpam-Envelope-From: AVKrasnov@sberdevices.ru X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 525 525 723604743bfbdb7e16728748c3fa45e9eba05f7d, {Tracking_from_domain_doesnt_match_to}, d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;100.64.160.123:7.1.2;127.0.0.199:7.1.2;sberdevices.ru:5.0.1,7.1.1;p-i-exch-sc-m01.sberdevices.ru:5.0.1,7.1.1, FromAlignment: s, {Tracking_white_helo}, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2023/07/23 08:49:00 #21663637 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Stefano Garzarella --- tools/testing/vsock/vsock_test.c | 78 ++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 3 deletions(-) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_t= est.c index ac1bd3ac1533..444a3ff0681f 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -255,9 +255,14 @@ static void test_stream_multiconn_server(const struct = test_opts *opts) close(fds[i]); } =20 +#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]; + ssize_t send_size; int fd; + int i; =20 fd =3D vsock_stream_connect(opts->peer_cid, 1234); if (fd < 0) { @@ -265,12 +270,32 @@ static void test_stream_msg_peek_client(const struct = test_opts *opts) exit(EXIT_FAILURE); } =20 - send_byte(fd, 1, 0); + for (i =3D 0; i < sizeof(buf); i++) + buf[i] =3D rand() & 0xFF; + + control_expectln("SRVREADY"); + + send_size =3D send(fd, buf, sizeof(buf), 0); + + if (send_size < 0) { + perror("send"); + exit(EXIT_FAILURE); + } + + if (send_size !=3D sizeof(buf)) { + fprintf(stderr, "Invalid send size %zi\n", send_size); + exit(EXIT_FAILURE); + } + close(fd); } =20 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; =20 fd =3D vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); @@ -279,8 +304,55 @@ static void test_stream_msg_peek_server(const struct t= est_opts *opts) exit(EXIT_FAILURE); } =20 - recv_byte(fd, 1, MSG_PEEK); - recv_byte(fd, 1, 0); + /* Peek from empty socket. */ + res =3D recv(fd, buf_peek, sizeof(buf_peek), MSG_PEEK | MSG_DONTWAIT); + if (res !=3D -1) { + fprintf(stderr, "expected recv(2) failure, got %zi\n", res); + exit(EXIT_FAILURE); + } + + if (errno !=3D EAGAIN) { + perror("EAGAIN expected"); + exit(EXIT_FAILURE); + } + + control_writeln("SRVREADY"); + + /* Peek part of data. */ + res =3D recv(fd, buf_half, sizeof(buf_half), MSG_PEEK); + if (res !=3D 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 =3D recv(fd, buf_peek, sizeof(buf_peek), MSG_PEEK); + if (res !=3D 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 =3D recv(fd, buf_normal, sizeof(buf_normal), 0); + if (res !=3D 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); } =20 --=20 2.25.1