Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4844070rwd; Sat, 17 Jun 2023 23:58:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4nPbx4hMyzoyx/Kfp/C8P5MAyAQmrEZlBAl+okdAdohPsP73njMdeQGk6HELbMBGYnsV3l X-Received: by 2002:aca:1c16:0:b0:39a:bf5a:dcbf with SMTP id c22-20020aca1c16000000b0039abf5adcbfmr6747282oic.49.1687071483229; Sat, 17 Jun 2023 23:58:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687071483; cv=none; d=google.com; s=arc-20160816; b=e3/o7QpcvjvNkN3KIR3rxC9Tcnr4SIwgaPCxI3G/37PtVawNeqVZVk2swNWlzEHBZq ACNqAXoN7CBl5xL0bXW8olnB3IObPhbTT4+YeXo0GyYglS7Nxi2n/d11Z8dOWB/KBlcR eZcvO7+wnd2xWHDoLkuiFpygZJrKcIgvHI2U53ZRyU52Xc+RWSfRBaZl3r/LFrOJOvBB 1MJu7b9hBo/ixG7EIbdwCJwV6I6oSfnQtlLVFTE+YBZdGs0cz0vlpl2eDKwA5qMSXN33 117U/ZC2WDzji0qnXuiaVbgriBN7bN+SSYKZUg94uciZMXlyOAKK/8109dI0YwYQxxQ1 zEwg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z7-20020a626507000000b006664122cc6csi8776202pfb.404.2023.06.17.23.57.49; Sat, 17 Jun 2023 23:58:03 -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 S229623AbjFRGaZ (ORCPT + 99 others); Sun, 18 Jun 2023 02:30:25 -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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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 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); } -- 2.25.1