Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp55818ybi; Thu, 1 Aug 2019 14:32:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5VGY8WYIqayR7pEHYmObvUnZuCD+iUcc1sgwVwU/fhXssOrd8PDWgn8/ANMyYucE+7pLf X-Received: by 2002:a62:2a4d:: with SMTP id q74mr55832178pfq.86.1564695122826; Thu, 01 Aug 2019 14:32:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564695122; cv=none; d=google.com; s=arc-20160816; b=MFPJzOF9Qe56OlUq5lODr77zjci7vB69IwUVdltDwWuTzZoAKFc2qPoreK0FLm+cE8 ogjIkqBD/FLDKEIKUst0inPzHnFcE8V4ZQNBF4QK2/0iE+e6WKFXCmCRUoeEQcivBaxR BmJK9UicMtLtV94nPxw7Og4veI7EAYsiXQ1tMNbzUN3T+Fp6M/d/DnHPbKv/UGIdMOF1 8AAIDJsoe896giePuvnv8Le3dL1O9C0UPHsYgr+5OAV1sRzckKQFsbzJHgIpdk2BRxA8 W5JXtYEbYhzXmqDFii8LLPivNCVIGdO+nz4+k9Fz1CtPc/V+Mt1G5tUpCV22JhZexQRG mNxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=/ss1VxT8qW2yjETzzm2w6xc/NdpyvWHivVc3wBVaRL0=; b=yXn9+uzI42i+4+zWFA+GDf0K8jipraty/JF+5BHMn/IkIlpLSlFYhNHgw4aHccxlQe bouNQ15hmU3xBjQYqGHzpJq4e5oAxGMlnaU4Aw2RYMT/qTJfevUcvrGlTBEIdlr+K+uo otIi/tkYROL+sfh/Uh5RsBhl/EVdxH02E+rsyNy1tqCq1gykNLJPSvA8mcpB7h960CUo yPfd3ozbLred7A/nx+a7MkSlPzP7I+VW8sXU8NidiLdAZ1EuWhzqWR8v6BIki9InFlcR h0/wZ5IE/zakdXDiUHatthYvdGfpzqY9Daqbp+xTEcDKuZewZukVnyBF9wMBQMdjV+vI ZXxw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n6si34685414pgp.424.2019.08.01.14.31.44; Thu, 01 Aug 2019 14:32:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732751AbfHAP0S (ORCPT + 99 others); Thu, 1 Aug 2019 11:26:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38008 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732735AbfHAP0R (ORCPT ); Thu, 1 Aug 2019 11:26:17 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EB6FE3179B5F; Thu, 1 Aug 2019 15:26:16 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-117-63.ams2.redhat.com [10.36.117.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB2F5600D1; Thu, 1 Aug 2019 15:26:14 +0000 (UTC) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: kvm@vger.kernel.org, Stefan Hajnoczi , Dexuan Cui , virtualization@lists.linux-foundation.org, "David S. Miller" , Jorgen Hansen , linux-kernel@vger.kernel.org Subject: [PATCH v2 10/11] vsock_test: skip read() in test_stream*close tests on a VMCI host Date: Thu, 1 Aug 2019 17:25:40 +0200 Message-Id: <20190801152541.245833-11-sgarzare@redhat.com> In-Reply-To: <20190801152541.245833-1-sgarzare@redhat.com> References: <20190801152541.245833-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 01 Aug 2019 15:26:17 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When VMCI transport is used, if the guest closes a connection, all data is gone and EOF is returned, so we should skip the read of data written by the peer before closing the connection. Reported-by: Jorgen Hansen Signed-off-by: Stefano Garzarella --- tools/testing/vsock/vsock_test.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index cb606091489f..64adf45501ca 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -71,6 +71,7 @@ static void test_stream_client_close_client(const struct test_opts *opts) static void test_stream_client_close_server(const struct test_opts *opts) { + unsigned int local_cid; int fd; fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); @@ -79,16 +80,27 @@ static void test_stream_client_close_server(const struct test_opts *opts) exit(EXIT_FAILURE); } + local_cid = vsock_get_local_cid(fd); + control_expectln("CLOSED"); send_byte(fd, -EPIPE); - recv_byte(fd, 1); + + /* Skip the read of data wrote by the peer if we are on VMCI and + * we are on the host side, because when the guest closes a + * connection, all data is gone and EOF is returned. + */ + if (!(opts->transport == TEST_TRANSPORT_VMCI && + local_cid == VMADDR_CID_HOST)) + recv_byte(fd, 1); + recv_byte(fd, 0); close(fd); } static void test_stream_server_close_client(const struct test_opts *opts) { + unsigned int local_cid; int fd; fd = vsock_stream_connect(opts->peer_cid, 1234); @@ -97,10 +109,20 @@ static void test_stream_server_close_client(const struct test_opts *opts) exit(EXIT_FAILURE); } + local_cid = vsock_get_local_cid(fd); + control_expectln("CLOSED"); send_byte(fd, -EPIPE); - recv_byte(fd, 1); + + /* Skip the read of data wrote by the peer if we are on VMCI and + * we are on the host side, because when the guest closes a + * connection, all data is gone and EOF is returned. + */ + if (!(opts->transport == TEST_TRANSPORT_VMCI && + local_cid == VMADDR_CID_HOST)) + recv_byte(fd, 1); + recv_byte(fd, 0); close(fd); } -- 2.20.1