From patchwork Wed Dec 18 18:07:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 11301587 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7707817EF for ; Wed, 18 Dec 2019 18:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5440F2467B for ; Wed, 18 Dec 2019 18:08:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WuYJLdLq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727696AbfLRSID (ORCPT ); Wed, 18 Dec 2019 13:08:03 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:21055 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727686AbfLRSIC (ORCPT ); Wed, 18 Dec 2019 13:08:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576692482; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Vrd2YMHgYqCL3NryYw02VWg7A0uKKgAHx3jq/JxCp5I=; b=WuYJLdLqF3dssYPiWk9DUcXVu/i99ZJPFtHqVjuVRpSEArJeg63iAHcTS9+yr7kB/2epP9 7qAb5p37z0J/JDuZ8XWIfs87a4IIWiSX+OCDhqhnleR2jIXd5/XtqeMM8ZNgsXtkzA+f3a MsiDEYZwVyUtJDKGcNeevKICsXiJfWE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-338-8k2LkPvON3iKCuAAOxJTcQ-1; Wed, 18 Dec 2019 13:08:00 -0500 X-MC-Unique: 8k2LkPvON3iKCuAAOxJTcQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 13DD6800D4E; Wed, 18 Dec 2019 18:07:59 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-117-218.ams2.redhat.com [10.36.117.218]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2FBB5D9E2; Wed, 18 Dec 2019 18:07:56 +0000 (UTC) From: Stefano Garzarella To: davem@davemloft.net Cc: Jorgen Hansen , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Hajnoczi , Dexuan Cui , netdev@vger.kernel.org, virtualization@lists.linux-foundation.org, Stefano Garzarella Subject: [PATCH net-next v3 11/11] vsock_test: add SOCK_STREAM MSG_PEEK test Date: Wed, 18 Dec 2019 19:07:08 +0100 Message-Id: <20191218180708.120337-12-sgarzare@redhat.com> In-Reply-To: <20191218180708.120337-1-sgarzare@redhat.com> References: <20191218180708.120337-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Test if the MSG_PEEK flags of recv(2) works as expected. Signed-off-by: Stefano Garzarella --- tools/testing/vsock/vsock_test.c | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index a63e05d6a0f9..1d8b93f1af31 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -178,6 +178,35 @@ static void test_stream_multiconn_server(const struct test_opts *opts) close(fds[i]); } +static void test_stream_msg_peek_client(const struct test_opts *opts) +{ + int fd; + + fd = vsock_stream_connect(opts->peer_cid, 1234); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + send_byte(fd, 1, 0); + close(fd); +} + +static void test_stream_msg_peek_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); + } + + recv_byte(fd, 1, MSG_PEEK); + recv_byte(fd, 1, 0); + close(fd); +} + static struct test_case test_cases[] = { { .name = "SOCK_STREAM connection reset", @@ -198,6 +227,11 @@ static struct test_case test_cases[] = { .run_client = test_stream_multiconn_client, .run_server = test_stream_multiconn_server, }, + { + .name = "SOCK_STREAM MSG_PEEK", + .run_client = test_stream_msg_peek_client, + .run_server = test_stream_msg_peek_server, + }, {}, };