From patchwork Wed Dec 18 18:06:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1212665 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="VmpakIWa"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47dNJb5MYGz9sPL for ; Thu, 19 Dec 2019 05:07:27 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727412AbfLRSH0 (ORCPT ); Wed, 18 Dec 2019 13:07:26 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:46289 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727367AbfLRSHY (ORCPT ); Wed, 18 Dec 2019 13:07:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576692443; 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=Ak7zDmp1/cfdOQnn19i2bAKVAQPiklhpPuuaiXWuaLc=; b=VmpakIWa/jcrYN620jT3HHVjYB/8IVFpU9v95zWIy4/XsMolDr4DSEHSyFN8t5DcUPHXjy 0bIvgcTl4ysMykcCtIR0y59SrhPVj4fMbRxarX2hf0cWRxpqn7IUMzCpc8mZlaV4ZsEdVk lEnf6NZQAFHLzFbsa9Du5EZSy+kqBUU= 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-411-WFFPBcoKMuGlKOSiuW5jFg-1; Wed, 18 Dec 2019 13:07:20 -0500 X-MC-Unique: WFFPBcoKMuGlKOSiuW5jFg-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 896C6100726C; Wed, 18 Dec 2019 18:07:18 +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 6E5F45D9E2; Wed, 18 Dec 2019 18:07:16 +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 01/11] VSOCK: fix header include in vsock_diag_test Date: Wed, 18 Dec 2019 19:06:58 +0100 Message-Id: <20191218180708.120337-2-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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Stefan Hajnoczi The vsock_diag_test program directly included ../../../include/uapi/ headers from the source tree. Tests are supposed to use the usr/include/linux/ headers that have been prepared with make headers_install instead. Suggested-by: David S. Miller Signed-off-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- tools/testing/vsock/Makefile | 2 +- tools/testing/vsock/README | 2 +- tools/testing/vsock/vsock_diag_test.c | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/testing/vsock/Makefile b/tools/testing/vsock/Makefile index 5be687b1e16c..d41a4e13960a 100644 --- a/tools/testing/vsock/Makefile +++ b/tools/testing/vsock/Makefile @@ -3,7 +3,7 @@ all: test test: vsock_diag_test vsock_diag_test: vsock_diag_test.o timeout.o control.o -CFLAGS += -g -O2 -Werror -Wall -I. -I../../include/uapi -I../../include -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE -D_GNU_SOURCE +CFLAGS += -g -O2 -Werror -Wall -I. -I../../include -I../../../usr/include -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE -D_GNU_SOURCE .PHONY: all test clean clean: ${RM} *.o *.d vsock_diag_test diff --git a/tools/testing/vsock/README b/tools/testing/vsock/README index 2cc6d7302db6..cf7dc64273bf 100644 --- a/tools/testing/vsock/README +++ b/tools/testing/vsock/README @@ -10,7 +10,7 @@ The following tests are available: The following prerequisite steps are not automated and must be performed prior to running tests: -1. Build the kernel and these tests. +1. Build the kernel, make headers_install, and build these tests. 2. Install the kernel and tests on the host. 3. Install the kernel and tests inside the guest. 4. Boot the guest and ensure that the AF_VSOCK transport is enabled. diff --git a/tools/testing/vsock/vsock_diag_test.c b/tools/testing/vsock/vsock_diag_test.c index c481101364a4..fc391e041954 100644 --- a/tools/testing/vsock/vsock_diag_test.c +++ b/tools/testing/vsock/vsock_diag_test.c @@ -21,12 +21,11 @@ #include #include #include +#include #include +#include #include -#include "../../../include/uapi/linux/vm_sockets.h" -#include "../../../include/uapi/linux/vm_sockets_diag.h" - #include "timeout.h" #include "control.h" From patchwork Wed Dec 18 18:06:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1212666 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="YvoIhn7O"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47dNJm4Ch3z9sRK for ; Thu, 19 Dec 2019 05:07:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727500AbfLRSHb (ORCPT ); Wed, 18 Dec 2019 13:07:31 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:28632 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727474AbfLRSH3 (ORCPT ); Wed, 18 Dec 2019 13:07:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576692448; 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=N8qrytZMVdHBi4BdEHQin5N9/kMWlYC5/mlW+wdXOXw=; b=YvoIhn7OMa9FYXAxQtGbL7ooJOIxrvLsSBs0xrBLs+9fT7ozdy7voU3YBSqw2PV5JsoAun f/znVuIvFgcAVCJsg8XLJGTRBOIW6FaZTuAi5gWDxTmabtSNY/VtO0NmvJ6VQFXNZa9fFc ez7WCUDpIAAPbvx59TdZMQ9xE27CraY= 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-291-rwlitvt8O5W6vyhltMDwnw-1; Wed, 18 Dec 2019 13:07:24 -0500 X-MC-Unique: rwlitvt8O5W6vyhltMDwnw-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 113F38024F7; Wed, 18 Dec 2019 18:07:23 +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 DFB7B5D9E2; Wed, 18 Dec 2019 18:07:18 +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 02/11] VSOCK: add SPDX identifiers to vsock tests Date: Wed, 18 Dec 2019 19:06:59 +0100 Message-Id: <20191218180708.120337-3-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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Stefan Hajnoczi Signed-off-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- v2: * Aligned with the current SPDX [Stefano] --- tools/testing/vsock/control.h | 1 + tools/testing/vsock/timeout.h | 1 + 2 files changed, 2 insertions(+) diff --git a/tools/testing/vsock/control.h b/tools/testing/vsock/control.h index 54a07efd267c..dac3964a891d 100644 --- a/tools/testing/vsock/control.h +++ b/tools/testing/vsock/control.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ #ifndef CONTROL_H #define CONTROL_H diff --git a/tools/testing/vsock/timeout.h b/tools/testing/vsock/timeout.h index 77db9ce9860a..ecb7c840e65a 100644 --- a/tools/testing/vsock/timeout.h +++ b/tools/testing/vsock/timeout.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ #ifndef TIMEOUT_H #define TIMEOUT_H From patchwork Wed Dec 18 18:07:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1212667 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="cGXORTIz"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47dNJs4SJHz9sRQ for ; Thu, 19 Dec 2019 05:07:41 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727524AbfLRSHi (ORCPT ); Wed, 18 Dec 2019 13:07:38 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:51253 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727519AbfLRSHg (ORCPT ); Wed, 18 Dec 2019 13:07:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576692455; 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=R0baLjp0RSWLGyQbUMoUgnF3ovbGuvh5LnfEYrDFhNM=; b=cGXORTIz4X61GYBm1nlcmgdLh6SDrlGpxTKqE0RgZA6frwkJbCqRFUPIkJ3tVoem3halCO T2uyIWATb1nNEIxmlrTJ3QVnUJ2/giVfhsLfsNQNHKuQbLVTKSkpNMOBVHQGigykrU5e3e Fn75SBrFdXkyufpI0KTp4+gY2qbH9f0= 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-54-C1YMcPs6PlGhC4zeAksxFA-1; Wed, 18 Dec 2019 13:07:30 -0500 X-MC-Unique: C1YMcPs6PlGhC4zeAksxFA-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 C8A7A1856A64; Wed, 18 Dec 2019 18:07:27 +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 70EB85D9E2; Wed, 18 Dec 2019 18:07:23 +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 03/11] VSOCK: extract utility functions from vsock_diag_test.c Date: Wed, 18 Dec 2019 19:07:00 +0100 Message-Id: <20191218180708.120337-4-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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Stefan Hajnoczi Move useful functions into a separate file in preparation for more vsock test programs. Signed-off-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- v2: * aligned with the current SPDX [Stefano] --- tools/testing/vsock/Makefile | 2 +- tools/testing/vsock/util.c | 66 +++++++++++++++++++ tools/testing/vsock/util.h | 36 +++++++++++ tools/testing/vsock/vsock_diag_test.c | 92 +++++++-------------------- 4 files changed, 125 insertions(+), 71 deletions(-) create mode 100644 tools/testing/vsock/util.c create mode 100644 tools/testing/vsock/util.h diff --git a/tools/testing/vsock/Makefile b/tools/testing/vsock/Makefile index d41a4e13960a..a916878a2d8c 100644 --- a/tools/testing/vsock/Makefile +++ b/tools/testing/vsock/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only all: test test: vsock_diag_test -vsock_diag_test: vsock_diag_test.o timeout.o control.o +vsock_diag_test: vsock_diag_test.o timeout.o control.o util.o CFLAGS += -g -O2 -Werror -Wall -I. -I../../include -I../../../usr/include -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE -D_GNU_SOURCE .PHONY: all test clean diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c new file mode 100644 index 000000000000..f40f45b36d2f --- /dev/null +++ b/tools/testing/vsock/util.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * vsock test utilities + * + * Copyright (C) 2017 Red Hat, Inc. + * + * Author: Stefan Hajnoczi + */ + +#include +#include +#include +#include + +#include "timeout.h" +#include "util.h" + +/* Install signal handlers */ +void init_signals(void) +{ + struct sigaction act = { + .sa_handler = sigalrm, + }; + + sigaction(SIGALRM, &act, NULL); + signal(SIGPIPE, SIG_IGN); +} + +/* Parse a CID in string representation */ +unsigned int parse_cid(const char *str) +{ + char *endptr = NULL; + unsigned long n; + + errno = 0; + n = strtoul(str, &endptr, 10); + if (errno || *endptr != '\0') { + fprintf(stderr, "malformed CID \"%s\"\n", str); + exit(EXIT_FAILURE); + } + return n; +} + +/* Run test cases. The program terminates if a failure occurs. */ +void run_tests(const struct test_case *test_cases, + const struct test_opts *opts) +{ + int i; + + for (i = 0; test_cases[i].name; i++) { + void (*run)(const struct test_opts *opts); + + printf("%s...", test_cases[i].name); + fflush(stdout); + + if (opts->mode == TEST_MODE_CLIENT) + run = test_cases[i].run_client; + else + run = test_cases[i].run_server; + + if (run) + run(opts); + + printf("ok\n"); + } +} diff --git a/tools/testing/vsock/util.h b/tools/testing/vsock/util.h new file mode 100644 index 000000000000..033e7d59a42a --- /dev/null +++ b/tools/testing/vsock/util.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef UTIL_H +#define UTIL_H + +/* Tests can either run as the client or the server */ +enum test_mode { + TEST_MODE_UNSET, + TEST_MODE_CLIENT, + TEST_MODE_SERVER +}; + +/* Test runner options */ +struct test_opts { + enum test_mode mode; + unsigned int peer_cid; +}; + +/* A test case definition. Test functions must print failures to stderr and + * terminate with exit(EXIT_FAILURE). + */ +struct test_case { + const char *name; /* human-readable name */ + + /* Called when test mode is TEST_MODE_CLIENT */ + void (*run_client)(const struct test_opts *opts); + + /* Called when test mode is TEST_MODE_SERVER */ + void (*run_server)(const struct test_opts *opts); +}; + +void init_signals(void); +unsigned int parse_cid(const char *str); +void run_tests(const struct test_case *test_cases, + const struct test_opts *opts); + +#endif /* UTIL_H */ diff --git a/tools/testing/vsock/vsock_diag_test.c b/tools/testing/vsock/vsock_diag_test.c index fc391e041954..944c8a72eed7 100644 --- a/tools/testing/vsock/vsock_diag_test.c +++ b/tools/testing/vsock/vsock_diag_test.c @@ -9,12 +9,10 @@ #include #include -#include #include #include #include #include -#include #include #include #include @@ -28,12 +26,7 @@ #include "timeout.h" #include "control.h" - -enum test_mode { - TEST_MODE_UNSET, - TEST_MODE_CLIENT, - TEST_MODE_SERVER -}; +#include "util.h" /* Per-socket status */ struct vsock_stat { @@ -334,7 +327,7 @@ static void free_sock_stat(struct list_head *sockets) free(st); } -static void test_no_sockets(unsigned int peer_cid) +static void test_no_sockets(const struct test_opts *opts) { LIST_HEAD(sockets); @@ -345,7 +338,7 @@ static void test_no_sockets(unsigned int peer_cid) free_sock_stat(&sockets); } -static void test_listen_socket_server(unsigned int peer_cid) +static void test_listen_socket_server(const struct test_opts *opts) { union { struct sockaddr sa; @@ -383,7 +376,7 @@ static void test_listen_socket_server(unsigned int peer_cid) free_sock_stat(&sockets); } -static void test_connect_client(unsigned int peer_cid) +static void test_connect_client(const struct test_opts *opts) { union { struct sockaddr sa; @@ -392,7 +385,7 @@ static void test_connect_client(unsigned int peer_cid) .svm = { .svm_family = AF_VSOCK, .svm_port = 1234, - .svm_cid = peer_cid, + .svm_cid = opts->peer_cid, }, }; int fd; @@ -429,7 +422,7 @@ static void test_connect_client(unsigned int peer_cid) free_sock_stat(&sockets); } -static void test_connect_server(unsigned int peer_cid) +static void test_connect_server(const struct test_opts *opts) { union { struct sockaddr sa; @@ -481,9 +474,9 @@ static void test_connect_server(unsigned int peer_cid) clientaddr.sa.sa_family); exit(EXIT_FAILURE); } - if (clientaddr.svm.svm_cid != peer_cid) { + if (clientaddr.svm.svm_cid != opts->peer_cid) { fprintf(stderr, "expected peer CID %u from accept(2), got %u\n", - peer_cid, clientaddr.svm.svm_cid); + opts->peer_cid, clientaddr.svm.svm_cid); exit(EXIT_FAILURE); } @@ -502,11 +495,7 @@ static void test_connect_server(unsigned int peer_cid) free_sock_stat(&sockets); } -static struct { - const char *name; - void (*run_client)(unsigned int peer_cid); - void (*run_server)(unsigned int peer_cid); -} test_cases[] = { +static struct test_case test_cases[] = { { .name = "No sockets", .run_server = test_no_sockets, @@ -523,30 +512,6 @@ static struct { {}, }; -static void init_signals(void) -{ - struct sigaction act = { - .sa_handler = sigalrm, - }; - - sigaction(SIGALRM, &act, NULL); - signal(SIGPIPE, SIG_IGN); -} - -static unsigned int parse_cid(const char *str) -{ - char *endptr = NULL; - unsigned long int n; - - errno = 0; - n = strtoul(str, &endptr, 10); - if (errno || *endptr != '\0') { - fprintf(stderr, "malformed CID \"%s\"\n", str); - exit(EXIT_FAILURE); - } - return n; -} - static const char optstring[] = ""; static const struct option longopts[] = { { @@ -601,9 +566,10 @@ int main(int argc, char **argv) { const char *control_host = NULL; const char *control_port = NULL; - int mode = TEST_MODE_UNSET; - unsigned int peer_cid = VMADDR_CID_ANY; - int i; + struct test_opts opts = { + .mode = TEST_MODE_UNSET, + .peer_cid = VMADDR_CID_ANY, + }; init_signals(); @@ -619,16 +585,16 @@ int main(int argc, char **argv) break; case 'm': if (strcmp(optarg, "client") == 0) - mode = TEST_MODE_CLIENT; + opts.mode = TEST_MODE_CLIENT; else if (strcmp(optarg, "server") == 0) - mode = TEST_MODE_SERVER; + opts.mode = TEST_MODE_SERVER; else { fprintf(stderr, "--mode must be \"client\" or \"server\"\n"); return EXIT_FAILURE; } break; case 'p': - peer_cid = parse_cid(optarg); + opts.peer_cid = parse_cid(optarg); break; case 'P': control_port = optarg; @@ -641,35 +607,21 @@ int main(int argc, char **argv) if (!control_port) usage(); - if (mode == TEST_MODE_UNSET) + if (opts.mode == TEST_MODE_UNSET) usage(); - if (peer_cid == VMADDR_CID_ANY) + if (opts.peer_cid == VMADDR_CID_ANY) usage(); if (!control_host) { - if (mode != TEST_MODE_SERVER) + if (opts.mode != TEST_MODE_SERVER) usage(); control_host = "0.0.0.0"; } - control_init(control_host, control_port, mode == TEST_MODE_SERVER); - - for (i = 0; test_cases[i].name; i++) { - void (*run)(unsigned int peer_cid); + control_init(control_host, control_port, + opts.mode == TEST_MODE_SERVER); - printf("%s...", test_cases[i].name); - fflush(stdout); - - if (mode == TEST_MODE_CLIENT) - run = test_cases[i].run_client; - else - run = test_cases[i].run_server; - - if (run) - run(peer_cid); - - printf("ok\n"); - } + run_tests(test_cases, &opts); control_cleanup(); return EXIT_SUCCESS; From patchwork Wed Dec 18 18:07:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1212668 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="YmVLytEd"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47dNK254Vzz9sRm for ; Thu, 19 Dec 2019 05:07:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727572AbfLRSHn (ORCPT ); Wed, 18 Dec 2019 13:07:43 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:57940 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727527AbfLRSHk (ORCPT ); Wed, 18 Dec 2019 13:07:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576692458; 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=0Bswzipg/wW4k9QMFQpExONm3qDrCwLdO1TlY5CPDow=; b=YmVLytEdy5SkEzJFrlkPxg/1+PYYmN+hDl0dQmsx+I4nauycYbbuUv2DaBTde1l12lpSe2 csxPLz6oi+S9CsAHC/JRSnvZRs13uJtuRarK850wZzxTFBnjKI8vz0kaSI/476W4OTxxb4 TpwHFi5t+XosTKtOdbqhjkezg6Xs50w= 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-386-K8zRqRR-NaOSCOvgPOkZGQ-1; Wed, 18 Dec 2019 13:07:34 -0500 X-MC-Unique: K8zRqRR-NaOSCOvgPOkZGQ-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 C08F21007271; Wed, 18 Dec 2019 18:07:32 +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 2C2905D9E2; Wed, 18 Dec 2019 18:07:27 +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 04/11] VSOCK: extract connect/accept functions from vsock_diag_test.c Date: Wed, 18 Dec 2019 19:07:01 +0100 Message-Id: <20191218180708.120337-5-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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Stefan Hajnoczi Many test cases will need to connect to the server or accept incoming connections. This patch extracts these operations into utility functions that can be reused. Signed-off-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- tools/testing/vsock/util.c | 108 ++++++++++++++++++++++++++ tools/testing/vsock/util.h | 6 ++ tools/testing/vsock/vsock_diag_test.c | 81 ++----------------- 3 files changed, 119 insertions(+), 76 deletions(-) diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c index f40f45b36d2f..f838bcee3589 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c @@ -11,8 +11,10 @@ #include #include #include +#include #include "timeout.h" +#include "control.h" #include "util.h" /* Install signal handlers */ @@ -41,6 +43,112 @@ unsigned int parse_cid(const char *str) return n; } +/* Connect to and return the file descriptor. */ +int vsock_stream_connect(unsigned int cid, unsigned int port) +{ + union { + struct sockaddr sa; + struct sockaddr_vm svm; + } addr = { + .svm = { + .svm_family = AF_VSOCK, + .svm_port = port, + .svm_cid = cid, + }, + }; + int ret; + int fd; + + control_expectln("LISTENING"); + + fd = socket(AF_VSOCK, SOCK_STREAM, 0); + + timeout_begin(TIMEOUT); + do { + ret = connect(fd, &addr.sa, sizeof(addr.svm)); + timeout_check("connect"); + } while (ret < 0 && errno == EINTR); + timeout_end(); + + if (ret < 0) { + int old_errno = errno; + + close(fd); + fd = -1; + errno = old_errno; + } + return fd; +} + +/* Listen on and return the first incoming connection. The remote + * address is stored to clientaddrp. clientaddrp may be NULL. + */ +int vsock_stream_accept(unsigned int cid, unsigned int port, + struct sockaddr_vm *clientaddrp) +{ + union { + struct sockaddr sa; + struct sockaddr_vm svm; + } addr = { + .svm = { + .svm_family = AF_VSOCK, + .svm_port = port, + .svm_cid = cid, + }, + }; + union { + struct sockaddr sa; + struct sockaddr_vm svm; + } clientaddr; + socklen_t clientaddr_len = sizeof(clientaddr.svm); + int fd; + int client_fd; + int old_errno; + + fd = socket(AF_VSOCK, SOCK_STREAM, 0); + + if (bind(fd, &addr.sa, sizeof(addr.svm)) < 0) { + perror("bind"); + exit(EXIT_FAILURE); + } + + if (listen(fd, 1) < 0) { + perror("listen"); + exit(EXIT_FAILURE); + } + + control_writeln("LISTENING"); + + timeout_begin(TIMEOUT); + do { + client_fd = accept(fd, &clientaddr.sa, &clientaddr_len); + timeout_check("accept"); + } while (client_fd < 0 && errno == EINTR); + timeout_end(); + + old_errno = errno; + close(fd); + errno = old_errno; + + if (client_fd < 0) + return client_fd; + + if (clientaddr_len != sizeof(clientaddr.svm)) { + fprintf(stderr, "unexpected addrlen from accept(2), %zu\n", + (size_t)clientaddr_len); + exit(EXIT_FAILURE); + } + if (clientaddr.sa.sa_family != AF_VSOCK) { + fprintf(stderr, "expected AF_VSOCK from accept(2), got %d\n", + clientaddr.sa.sa_family); + exit(EXIT_FAILURE); + } + + if (clientaddrp) + *clientaddrp = clientaddr.svm; + return client_fd; +} + /* Run test cases. The program terminates if a failure occurs. */ void run_tests(const struct test_case *test_cases, const struct test_opts *opts) diff --git a/tools/testing/vsock/util.h b/tools/testing/vsock/util.h index 033e7d59a42a..1786305cfddd 100644 --- a/tools/testing/vsock/util.h +++ b/tools/testing/vsock/util.h @@ -2,6 +2,9 @@ #ifndef UTIL_H #define UTIL_H +#include +#include + /* Tests can either run as the client or the server */ enum test_mode { TEST_MODE_UNSET, @@ -30,6 +33,9 @@ struct test_case { void init_signals(void); unsigned int parse_cid(const char *str); +int vsock_stream_connect(unsigned int cid, unsigned int port); +int vsock_stream_accept(unsigned int cid, unsigned int port, + struct sockaddr_vm *clientaddrp); void run_tests(const struct test_case *test_cases, const struct test_opts *opts); diff --git a/tools/testing/vsock/vsock_diag_test.c b/tools/testing/vsock/vsock_diag_test.c index 944c8a72eed7..abd7dc2a9631 100644 --- a/tools/testing/vsock/vsock_diag_test.c +++ b/tools/testing/vsock/vsock_diag_test.c @@ -13,13 +13,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include @@ -378,33 +376,12 @@ static void test_listen_socket_server(const struct test_opts *opts) static void test_connect_client(const struct test_opts *opts) { - union { - struct sockaddr sa; - struct sockaddr_vm svm; - } addr = { - .svm = { - .svm_family = AF_VSOCK, - .svm_port = 1234, - .svm_cid = opts->peer_cid, - }, - }; int fd; - int ret; LIST_HEAD(sockets); struct vsock_stat *st; - control_expectln("LISTENING"); - - fd = socket(AF_VSOCK, SOCK_STREAM, 0); - - timeout_begin(TIMEOUT); - do { - ret = connect(fd, &addr.sa, sizeof(addr.svm)); - timeout_check("connect"); - } while (ret < 0 && errno == EINTR); - timeout_end(); - - if (ret < 0) { + fd = vsock_stream_connect(opts->peer_cid, 1234); + if (fd < 0) { perror("connect"); exit(EXIT_FAILURE); } @@ -424,66 +401,19 @@ static void test_connect_client(const struct test_opts *opts) static void test_connect_server(const struct test_opts *opts) { - union { - struct sockaddr sa; - struct sockaddr_vm svm; - } addr = { - .svm = { - .svm_family = AF_VSOCK, - .svm_port = 1234, - .svm_cid = VMADDR_CID_ANY, - }, - }; - union { - struct sockaddr sa; - struct sockaddr_vm svm; - } clientaddr; - socklen_t clientaddr_len = sizeof(clientaddr.svm); - LIST_HEAD(sockets); struct vsock_stat *st; - int fd; + LIST_HEAD(sockets); int client_fd; - fd = socket(AF_VSOCK, SOCK_STREAM, 0); - - if (bind(fd, &addr.sa, sizeof(addr.svm)) < 0) { - perror("bind"); - exit(EXIT_FAILURE); - } - - if (listen(fd, 1) < 0) { - perror("listen"); - exit(EXIT_FAILURE); - } - - control_writeln("LISTENING"); - - timeout_begin(TIMEOUT); - do { - client_fd = accept(fd, &clientaddr.sa, &clientaddr_len); - timeout_check("accept"); - } while (client_fd < 0 && errno == EINTR); - timeout_end(); - + client_fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); if (client_fd < 0) { perror("accept"); exit(EXIT_FAILURE); } - if (clientaddr.sa.sa_family != AF_VSOCK) { - fprintf(stderr, "expected AF_VSOCK from accept(2), got %d\n", - clientaddr.sa.sa_family); - exit(EXIT_FAILURE); - } - if (clientaddr.svm.svm_cid != opts->peer_cid) { - fprintf(stderr, "expected peer CID %u from accept(2), got %u\n", - opts->peer_cid, clientaddr.svm.svm_cid); - exit(EXIT_FAILURE); - } read_vsock_stat(&sockets); - check_num_sockets(&sockets, 2); - find_vsock_stat(&sockets, fd); + check_num_sockets(&sockets, 1); st = find_vsock_stat(&sockets, client_fd); check_socket_state(st, TCP_ESTABLISHED); @@ -491,7 +421,6 @@ static void test_connect_server(const struct test_opts *opts) control_expectln("DONE"); close(client_fd); - close(fd); free_sock_stat(&sockets); } From patchwork Wed Dec 18 18:07:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1212669 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="K0t4+sBT"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47dNK64tJCz9sRm for ; Thu, 19 Dec 2019 05:07:54 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727605AbfLRSHo (ORCPT ); Wed, 18 Dec 2019 13:07:44 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:58091 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727565AbfLRSHn (ORCPT ); Wed, 18 Dec 2019 13:07:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576692462; 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=FlkaeYSFXvcGkCKY6XBlUXahFqgenbvaIYvHtAYj1TY=; b=K0t4+sBTNHxQr/9+uh3aub/x05NXVthrBFLcByoJUQGfVJWlzcvCDI9J1py1Ip8UiH7+Rw TjTy8SgagjmSeOZmxhy/51h1ykTTO3o5N3CjgS9Flx0QpgF7e+3SlNlODcMOCtEe25Q0Zw AbsDeH5BS4XetgqEmaHcEWqfZ1OWk0E= 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-396-_Cr8_2JDMlK5tZ86RYOKog-1; Wed, 18 Dec 2019 13:07:38 -0500 X-MC-Unique: _Cr8_2JDMlK5tZ86RYOKog-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 4FD50802B60; Wed, 18 Dec 2019 18:07:35 +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 2765F5D9E5; Wed, 18 Dec 2019 18:07:32 +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 05/11] VSOCK: add full barrier between test cases Date: Wed, 18 Dec 2019 19:07:02 +0100 Message-Id: <20191218180708.120337-6-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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Stefan Hajnoczi See code comment for details. Signed-off-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- tools/testing/vsock/util.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c index f838bcee3589..4280a56ba677 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c @@ -161,10 +161,24 @@ void run_tests(const struct test_case *test_cases, printf("%s...", test_cases[i].name); fflush(stdout); - if (opts->mode == TEST_MODE_CLIENT) + if (opts->mode == TEST_MODE_CLIENT) { + /* Full barrier before executing the next test. This + * ensures that client and server are executing the + * same test case. In particular, it means whoever is + * faster will not see the peer still executing the + * last test. This is important because port numbers + * can be used by multiple test cases. + */ + control_expectln("NEXT"); + control_writeln("NEXT"); + run = test_cases[i].run_client; - else + } else { + control_writeln("NEXT"); + control_expectln("NEXT"); + run = test_cases[i].run_server; + } if (run) run(opts); From patchwork Wed Dec 18 18:07:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1212675 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="XgPWDXGy"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47dNKw3QtVz9sRK for ; Thu, 19 Dec 2019 05:08:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727650AbfLRSIf (ORCPT ); Wed, 18 Dec 2019 13:08:35 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:36832 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727527AbfLRSHn (ORCPT ); Wed, 18 Dec 2019 13:07:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576692463; 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=mub2wd3Ra/02EpcL0dbiRF0hcLXprsOY9Pb/jiP+caQ=; b=XgPWDXGyuxiG6+ynoVFwTG5w9eO01IEA2BE7AKNGXCqbkyHr3EPRgs4L4dxCUMbs0rIZGX HCjsHKoVikJc+Jhtk8/41gt1PPSzpJVE44neTz6n8pyf/NfZS+DpJbev6stxniquwRuQfc 3AE/SPbrUWyOykTpjehj7fxk60hC/eY= 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-85-OGXhYp4LOFqXDxkkZZZRtQ-1; Wed, 18 Dec 2019 13:07:39 -0500 X-MC-Unique: OGXhYp4LOFqXDxkkZZZRtQ-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 C650F1088392; Wed, 18 Dec 2019 18:07:37 +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 A5DFF5D9E2; Wed, 18 Dec 2019 18:07:35 +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 06/11] VSOCK: add send_byte()/recv_byte() test utilities Date: Wed, 18 Dec 2019 19:07:03 +0100 Message-Id: <20191218180708.120337-7-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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Stefan Hajnoczi Test cases will want to transfer data. This patch adds utility functions to do this. Signed-off-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- v3: * check the byte received in the recv_byte() * use send(2)/recv(2) instead of write(2)/read(2) to test also flags (e.g. MSG_PEEK) --- tools/testing/vsock/util.c | 103 +++++++++++++++++++++++++++++++++++++ tools/testing/vsock/util.h | 2 + 2 files changed, 105 insertions(+) diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c index 4280a56ba677..6026ef3ce512 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -149,6 +150,108 @@ int vsock_stream_accept(unsigned int cid, unsigned int port, return client_fd; } +/* Transmit one byte and check the return value. + * + * expected_ret: + * <0 Negative errno (for testing errors) + * 0 End-of-file + * 1 Success + */ +void send_byte(int fd, int expected_ret, int flags) +{ + const uint8_t byte = 'A'; + ssize_t nwritten; + + timeout_begin(TIMEOUT); + do { + nwritten = send(fd, &byte, sizeof(byte), flags); + timeout_check("write"); + } while (nwritten < 0 && errno == EINTR); + timeout_end(); + + if (expected_ret < 0) { + if (nwritten != -1) { + fprintf(stderr, "bogus send(2) return value %zd\n", + nwritten); + exit(EXIT_FAILURE); + } + if (errno != -expected_ret) { + perror("write"); + exit(EXIT_FAILURE); + } + return; + } + + if (nwritten < 0) { + perror("write"); + exit(EXIT_FAILURE); + } + if (nwritten == 0) { + if (expected_ret == 0) + return; + + fprintf(stderr, "unexpected EOF while sending byte\n"); + exit(EXIT_FAILURE); + } + if (nwritten != sizeof(byte)) { + fprintf(stderr, "bogus send(2) return value %zd\n", nwritten); + exit(EXIT_FAILURE); + } +} + +/* Receive one byte and check the return value. + * + * expected_ret: + * <0 Negative errno (for testing errors) + * 0 End-of-file + * 1 Success + */ +void recv_byte(int fd, int expected_ret, int flags) +{ + uint8_t byte; + ssize_t nread; + + timeout_begin(TIMEOUT); + do { + nread = recv(fd, &byte, sizeof(byte), flags); + timeout_check("read"); + } while (nread < 0 && errno == EINTR); + timeout_end(); + + if (expected_ret < 0) { + if (nread != -1) { + fprintf(stderr, "bogus recv(2) return value %zd\n", + nread); + exit(EXIT_FAILURE); + } + if (errno != -expected_ret) { + perror("read"); + exit(EXIT_FAILURE); + } + return; + } + + if (nread < 0) { + perror("read"); + exit(EXIT_FAILURE); + } + if (nread == 0) { + if (expected_ret == 0) + return; + + fprintf(stderr, "unexpected EOF while receiving byte\n"); + exit(EXIT_FAILURE); + } + if (nread != sizeof(byte)) { + fprintf(stderr, "bogus recv(2) return value %zd\n", nread); + exit(EXIT_FAILURE); + } + if (byte != 'A') { + fprintf(stderr, "unexpected byte read %c\n", byte); + exit(EXIT_FAILURE); + } +} + /* Run test cases. The program terminates if a failure occurs. */ void run_tests(const struct test_case *test_cases, const struct test_opts *opts) diff --git a/tools/testing/vsock/util.h b/tools/testing/vsock/util.h index 1786305cfddd..4df12e4b5ebe 100644 --- a/tools/testing/vsock/util.h +++ b/tools/testing/vsock/util.h @@ -36,6 +36,8 @@ unsigned int parse_cid(const char *str); int vsock_stream_connect(unsigned int cid, unsigned int port); int vsock_stream_accept(unsigned int cid, unsigned int port, struct sockaddr_vm *clientaddrp); +void send_byte(int fd, int expected_ret, int flags); +void recv_byte(int fd, int expected_ret, int flags); void run_tests(const struct test_case *test_cases, const struct test_opts *opts); From patchwork Wed Dec 18 18:07:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1212670 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="GraQRKj9"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47dNKG1B9tz9sRm for ; Thu, 19 Dec 2019 05:08:02 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727655AbfLRSH4 (ORCPT ); Wed, 18 Dec 2019 13:07:56 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:49866 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727630AbfLRSHv (ORCPT ); Wed, 18 Dec 2019 13:07:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576692470; 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=Ba+jdilHJOq5z4M9yN1rn/HCKx5aiHP0bqMQXqZ4gWs=; b=GraQRKj9TDDWyxSB/3Ax3/noKW9KtdCWNjZvuCtEaGDWPiDNfgl/3tc+NjZpVqx9sNwrF5 GQdXVrQwXheqzjyEMkfLRx4D6fIZlDJqhZc6Knph9fzQf1sGNcoqG6Hj2WD4SbG3EOzEXb dL87ICLd2jNPydnxTTK+FFZTqfRF0sU= 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-386-674jwpI1NKi7qts0unCKJg-1; Wed, 18 Dec 2019 13:07:45 -0500 X-MC-Unique: 674jwpI1NKi7qts0unCKJg-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 D383810883A1; Wed, 18 Dec 2019 18:07:43 +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 2622A5D9E5; Wed, 18 Dec 2019 18:07:37 +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 07/11] VSOCK: add AF_VSOCK test cases Date: Wed, 18 Dec 2019 19:07:04 +0100 Message-Id: <20191218180708.120337-8-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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Stefan Hajnoczi The vsock_test.c program runs a test suite of AF_VSOCK test cases. Signed-off-by: Stefan Hajnoczi Signed-off-by: Stefano Garzarella --- v2: * Drop unnecessary includes [Stefan] * Aligned with the current SPDX [Stefano] * Set MULTICONN_NFDS to 100 [Stefano] * Change (i % 1) in (i % 2) in the 'multiconn' test [Stefano] --- tools/testing/vsock/.gitignore | 1 + tools/testing/vsock/Makefile | 5 +- tools/testing/vsock/README | 1 + tools/testing/vsock/vsock_test.c | 312 +++++++++++++++++++++++++++++++ 4 files changed, 317 insertions(+), 2 deletions(-) create mode 100644 tools/testing/vsock/vsock_test.c diff --git a/tools/testing/vsock/.gitignore b/tools/testing/vsock/.gitignore index dc5f11faf530..7f7a2ccc30c4 100644 --- a/tools/testing/vsock/.gitignore +++ b/tools/testing/vsock/.gitignore @@ -1,2 +1,3 @@ *.d +vsock_test vsock_diag_test diff --git a/tools/testing/vsock/Makefile b/tools/testing/vsock/Makefile index a916878a2d8c..f8293c6910c9 100644 --- a/tools/testing/vsock/Makefile +++ b/tools/testing/vsock/Makefile @@ -1,10 +1,11 @@ # SPDX-License-Identifier: GPL-2.0-only all: test -test: vsock_diag_test +test: vsock_test vsock_diag_test +vsock_test: vsock_test.o timeout.o control.o util.o vsock_diag_test: vsock_diag_test.o timeout.o control.o util.o CFLAGS += -g -O2 -Werror -Wall -I. -I../../include -I../../../usr/include -Wno-pointer-sign -fno-strict-overflow -fno-strict-aliasing -fno-common -MMD -U_FORTIFY_SOURCE -D_GNU_SOURCE .PHONY: all test clean clean: - ${RM} *.o *.d vsock_diag_test + ${RM} *.o *.d vsock_test vsock_diag_test -include *.d diff --git a/tools/testing/vsock/README b/tools/testing/vsock/README index cf7dc64273bf..4d5045e7d2c3 100644 --- a/tools/testing/vsock/README +++ b/tools/testing/vsock/README @@ -5,6 +5,7 @@ Hyper-V. The following tests are available: + * vsock_test - core AF_VSOCK socket functionality * vsock_diag_test - vsock_diag.ko module for listing open sockets The following prerequisite steps are not automated and must be performed prior diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c new file mode 100644 index 000000000000..fae8ddc3ef72 --- /dev/null +++ b/tools/testing/vsock/vsock_test.c @@ -0,0 +1,312 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * vsock_test - vsock.ko test suite + * + * Copyright (C) 2017 Red Hat, Inc. + * + * Author: Stefan Hajnoczi + */ + +#include +#include +#include +#include +#include +#include + +#include "timeout.h" +#include "control.h" +#include "util.h" + +static void test_stream_connection_reset(const struct test_opts *opts) +{ + union { + struct sockaddr sa; + struct sockaddr_vm svm; + } addr = { + .svm = { + .svm_family = AF_VSOCK, + .svm_port = 1234, + .svm_cid = opts->peer_cid, + }, + }; + int ret; + int fd; + + fd = socket(AF_VSOCK, SOCK_STREAM, 0); + + timeout_begin(TIMEOUT); + do { + ret = connect(fd, &addr.sa, sizeof(addr.svm)); + timeout_check("connect"); + } while (ret < 0 && errno == EINTR); + timeout_end(); + + if (ret != -1) { + fprintf(stderr, "expected connect(2) failure, got %d\n", ret); + exit(EXIT_FAILURE); + } + if (errno != ECONNRESET) { + fprintf(stderr, "unexpected connect(2) errno %d\n", errno); + exit(EXIT_FAILURE); + } + + close(fd); +} + +static void test_stream_client_close_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); + control_writeln("CLOSED"); +} + +static void test_stream_client_close_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); + } + + control_expectln("CLOSED"); + + send_byte(fd, -EPIPE, 0); + recv_byte(fd, 1, 0); + recv_byte(fd, 0, 0); + close(fd); +} + +static void test_stream_server_close_client(const struct test_opts *opts) +{ + int fd; + + fd = vsock_stream_connect(opts->peer_cid, 1234); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + control_expectln("CLOSED"); + + send_byte(fd, -EPIPE, 0); + recv_byte(fd, 1, 0); + recv_byte(fd, 0, 0); + close(fd); +} + +static void test_stream_server_close_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); + } + + send_byte(fd, 1, 0); + close(fd); + control_writeln("CLOSED"); +} + +/* With the standard socket sizes, VMCI is able to support about 100 + * concurrent stream connections. + */ +#define MULTICONN_NFDS 100 + +static void test_stream_multiconn_client(const struct test_opts *opts) +{ + int fds[MULTICONN_NFDS]; + int i; + + for (i = 0; i < MULTICONN_NFDS; i++) { + fds[i] = vsock_stream_connect(opts->peer_cid, 1234); + if (fds[i] < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + } + + for (i = 0; i < MULTICONN_NFDS; i++) { + if (i % 2) + recv_byte(fds[i], 1, 0); + else + send_byte(fds[i], 1, 0); + } + + for (i = 0; i < MULTICONN_NFDS; i++) + close(fds[i]); +} + +static void test_stream_multiconn_server(const struct test_opts *opts) +{ + int fds[MULTICONN_NFDS]; + int i; + + for (i = 0; i < MULTICONN_NFDS; i++) { + fds[i] = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); + if (fds[i] < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + } + + for (i = 0; i < MULTICONN_NFDS; i++) { + if (i % 2) + send_byte(fds[i], 1, 0); + else + recv_byte(fds[i], 1, 0); + } + + for (i = 0; i < MULTICONN_NFDS; i++) + close(fds[i]); +} + +static struct test_case test_cases[] = { + { + .name = "SOCK_STREAM connection reset", + .run_client = test_stream_connection_reset, + }, + { + .name = "SOCK_STREAM client close", + .run_client = test_stream_client_close_client, + .run_server = test_stream_client_close_server, + }, + { + .name = "SOCK_STREAM server close", + .run_client = test_stream_server_close_client, + .run_server = test_stream_server_close_server, + }, + { + .name = "SOCK_STREAM multiple connections", + .run_client = test_stream_multiconn_client, + .run_server = test_stream_multiconn_server, + }, + {}, +}; + +static const char optstring[] = ""; +static const struct option longopts[] = { + { + .name = "control-host", + .has_arg = required_argument, + .val = 'H', + }, + { + .name = "control-port", + .has_arg = required_argument, + .val = 'P', + }, + { + .name = "mode", + .has_arg = required_argument, + .val = 'm', + }, + { + .name = "peer-cid", + .has_arg = required_argument, + .val = 'p', + }, + { + .name = "help", + .has_arg = no_argument, + .val = '?', + }, + {}, +}; + +static void usage(void) +{ + fprintf(stderr, "Usage: vsock_test [--help] [--control-host=] --control-port= --mode=client|server --peer-cid=\n" + "\n" + " Server: vsock_test --control-port=1234 --mode=server --peer-cid=3\n" + " Client: vsock_test --control-host=192.168.0.1 --control-port=1234 --mode=client --peer-cid=2\n" + "\n" + "Run vsock.ko tests. Must be launched in both guest\n" + "and host. One side must use --mode=client and\n" + "the other side must use --mode=server.\n" + "\n" + "A TCP control socket connection is used to coordinate tests\n" + "between the client and the server. The server requires a\n" + "listen address and the client requires an address to\n" + "connect to.\n" + "\n" + "The CID of the other side must be given with --peer-cid=.\n"); + exit(EXIT_FAILURE); +} + +int main(int argc, char **argv) +{ + const char *control_host = NULL; + const char *control_port = NULL; + struct test_opts opts = { + .mode = TEST_MODE_UNSET, + .peer_cid = VMADDR_CID_ANY, + }; + + init_signals(); + + for (;;) { + int opt = getopt_long(argc, argv, optstring, longopts, NULL); + + if (opt == -1) + break; + + switch (opt) { + case 'H': + control_host = optarg; + break; + case 'm': + if (strcmp(optarg, "client") == 0) + opts.mode = TEST_MODE_CLIENT; + else if (strcmp(optarg, "server") == 0) + opts.mode = TEST_MODE_SERVER; + else { + fprintf(stderr, "--mode must be \"client\" or \"server\"\n"); + return EXIT_FAILURE; + } + break; + case 'p': + opts.peer_cid = parse_cid(optarg); + break; + case 'P': + control_port = optarg; + break; + case '?': + default: + usage(); + } + } + + if (!control_port) + usage(); + if (opts.mode == TEST_MODE_UNSET) + usage(); + if (opts.peer_cid == VMADDR_CID_ANY) + usage(); + + if (!control_host) { + if (opts.mode != TEST_MODE_SERVER) + usage(); + control_host = "0.0.0.0"; + } + + control_init(control_host, control_port, + opts.mode == TEST_MODE_SERVER); + + run_tests(test_cases, &opts); + + control_cleanup(); + return EXIT_SUCCESS; +} From patchwork Wed Dec 18 18:07:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1212674 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="Eib+zEJ5"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47dNKk52hLz9sRK for ; Thu, 19 Dec 2019 05:08:26 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727754AbfLRSIX (ORCPT ); Wed, 18 Dec 2019 13:08:23 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:57266 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727654AbfLRSH4 (ORCPT ); Wed, 18 Dec 2019 13:07:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576692475; 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=7lW+cxoZMuu0TO4yVVOLW4Vw9qRm3Vps7ty8G8tFB/M=; b=Eib+zEJ584HaGpZVUfoip756On+DDGWncFxDTeekFqily6VFbmtcwo2i8PE74KkUug/WvH PpliimjlAgVnIuneZFv/jxggm7B4l2+bZYsnl3fOMDv//3jmHjsti2iP3FBrXmDDwmg7CA atTUIkNkTFzP1sUHw34EySJxNyvr2bY= 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-51-MStQOSH1NAmxIEs9wBUUZw-1; Wed, 18 Dec 2019 13:07:50 -0500 X-MC-Unique: MStQOSH1NAmxIEs9wBUUZw-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 1BFFC8C3ECB; Wed, 18 Dec 2019 18:07:49 +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 3A83B5D9E5; Wed, 18 Dec 2019 18:07:44 +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 08/11] vsock_test: wait for the remote to close the connection Date: Wed, 18 Dec 2019 19:07:05 +0100 Message-Id: <20191218180708.120337-9-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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Before check if a send returns -EPIPE, we need to make sure the connection is closed. To do that, we use epoll API to wait EPOLLRDHUP or EPOLLHUP events on the socket. Reported-by: Jorgen Hansen Signed-off-by: Stefano Garzarella --- v3: - removed unnecessary control_expectln("CLOSED") [Stefan] --- tools/testing/vsock/util.c | 39 ++++++++++++++++++++++++++++++++ tools/testing/vsock/util.h | 1 + tools/testing/vsock/vsock_test.c | 12 ++++++---- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c index 6026ef3ce512..b132c96c87fc 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include "timeout.h" #include "control.h" @@ -44,6 +46,43 @@ unsigned int parse_cid(const char *str) return n; } +/* Wait for the remote to close the connection */ +void vsock_wait_remote_close(int fd) +{ + struct epoll_event ev; + int epollfd, nfds; + + epollfd = epoll_create1(0); + if (epollfd == -1) { + perror("epoll_create1"); + exit(EXIT_FAILURE); + } + + ev.events = EPOLLRDHUP | EPOLLHUP; + ev.data.fd = fd; + if (epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev) == -1) { + perror("epoll_ctl"); + exit(EXIT_FAILURE); + } + + nfds = epoll_wait(epollfd, &ev, 1, TIMEOUT * 1000); + if (nfds == -1) { + perror("epoll_wait"); + exit(EXIT_FAILURE); + } + + if (nfds == 0) { + fprintf(stderr, "epoll_wait timed out\n"); + exit(EXIT_FAILURE); + } + + assert(nfds == 1); + assert(ev.events & (EPOLLRDHUP | EPOLLHUP)); + assert(ev.data.fd == fd); + + close(epollfd); +} + /* Connect to and return the file descriptor. */ int vsock_stream_connect(unsigned int cid, unsigned int port) { diff --git a/tools/testing/vsock/util.h b/tools/testing/vsock/util.h index 4df12e4b5ebe..331e945f3ae6 100644 --- a/tools/testing/vsock/util.h +++ b/tools/testing/vsock/util.h @@ -36,6 +36,7 @@ unsigned int parse_cid(const char *str); int vsock_stream_connect(unsigned int cid, unsigned int port); int vsock_stream_accept(unsigned int cid, unsigned int port, struct sockaddr_vm *clientaddrp); +void vsock_wait_remote_close(int fd); void send_byte(int fd, int expected_ret, int flags); void recv_byte(int fd, int expected_ret, int flags); void run_tests(const struct test_case *test_cases, diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index fae8ddc3ef72..629d7ce58202 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -66,7 +66,6 @@ static void test_stream_client_close_client(const struct test_opts *opts) send_byte(fd, 1, 0); close(fd); - control_writeln("CLOSED"); } static void test_stream_client_close_server(const struct test_opts *opts) @@ -79,7 +78,10 @@ static void test_stream_client_close_server(const struct test_opts *opts) exit(EXIT_FAILURE); } - control_expectln("CLOSED"); + /* Wait for the remote to close the connection, before check + * -EPIPE error on send. + */ + vsock_wait_remote_close(fd); send_byte(fd, -EPIPE, 0); recv_byte(fd, 1, 0); @@ -97,7 +99,10 @@ static void test_stream_server_close_client(const struct test_opts *opts) exit(EXIT_FAILURE); } - control_expectln("CLOSED"); + /* Wait for the remote to close the connection, before check + * -EPIPE error on send. + */ + vsock_wait_remote_close(fd); send_byte(fd, -EPIPE, 0); recv_byte(fd, 1, 0); @@ -117,7 +122,6 @@ static void test_stream_server_close_server(const struct test_opts *opts) send_byte(fd, 1, 0); close(fd); - control_writeln("CLOSED"); } /* With the standard socket sizes, VMCI is able to support about 100 From patchwork Wed Dec 18 18:07:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1212673 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="E9oTB5wK"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47dNKh24Ntz9sRl for ; Thu, 19 Dec 2019 05:08:24 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727747AbfLRSIU (ORCPT ); Wed, 18 Dec 2019 13:08:20 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:27531 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727650AbfLRSIB (ORCPT ); Wed, 18 Dec 2019 13:08:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576692479; 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=SLZdv4nILYavPlNd4vydpr9CWIiu4xi175TY2KQEKPY=; b=E9oTB5wKl/5Z1BZzGhIockuP9KyQ5L/Rbng23a/LlJszmVXF626Z3SweTm0d0OIQt7whCE A2OzkOVwTKJc8PDBFffAP0ADulcEdss2VqORyEf86JHkGLQ5fqWS3N+gQKyBOT0ulRR6mO Z5+6w2Ihojx+pt5lvuf3VOCTie4Tak8= 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-22-34aWA1McOgOly0raw9LTwA-1; Wed, 18 Dec 2019 13:07:55 -0500 X-MC-Unique: 34aWA1McOgOly0raw9LTwA-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 1C0E28C3ECB; Wed, 18 Dec 2019 18:07:54 +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 801B05D9E2; Wed, 18 Dec 2019 18:07:49 +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 09/11] testing/vsock: add parameters to list and skip tests Date: Wed, 18 Dec 2019 19:07:06 +0100 Message-Id: <20191218180708.120337-10-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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Some tests can fail with transports that have a slightly different behavior, so let's add the possibility to specify which tests to skip. Signed-off-by: Stefano Garzarella --- tools/testing/vsock/control.c | 15 +++++- tools/testing/vsock/control.h | 1 + tools/testing/vsock/util.c | 76 +++++++++++++++++++++------ tools/testing/vsock/util.h | 6 ++- tools/testing/vsock/vsock_diag_test.c | 19 ++++++- tools/testing/vsock/vsock_test.c | 20 ++++++- 6 files changed, 117 insertions(+), 20 deletions(-) diff --git a/tools/testing/vsock/control.c b/tools/testing/vsock/control.c index 45f328c6ff23..4874872fc5a3 100644 --- a/tools/testing/vsock/control.c +++ b/tools/testing/vsock/control.c @@ -205,11 +205,22 @@ void control_expectln(const char *str) char *line; line = control_readln(); - if (strcmp(str, line) != 0) { + + control_cmpln(line, str, true); + + free(line); +} + +bool control_cmpln(char *line, const char *str, bool fail) +{ + if (strcmp(str, line) == 0) + return true; + + if (fail) { fprintf(stderr, "expected \"%s\" on control socket, got \"%s\"\n", str, line); exit(EXIT_FAILURE); } - free(line); + return false; } diff --git a/tools/testing/vsock/control.h b/tools/testing/vsock/control.h index dac3964a891d..51814b4f9ac1 100644 --- a/tools/testing/vsock/control.h +++ b/tools/testing/vsock/control.h @@ -10,5 +10,6 @@ void control_cleanup(void); void control_writeln(const char *str); char *control_readln(void); void control_expectln(const char *str); +bool control_cmpln(char *line, const char *str, bool fail); #endif /* CONTROL_H */ diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c index b132c96c87fc..b290fa78405f 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c @@ -299,32 +299,78 @@ void run_tests(const struct test_case *test_cases, for (i = 0; test_cases[i].name; i++) { void (*run)(const struct test_opts *opts); + char *line; - printf("%s...", test_cases[i].name); + printf("%d - %s...", i, test_cases[i].name); fflush(stdout); - if (opts->mode == TEST_MODE_CLIENT) { - /* Full barrier before executing the next test. This - * ensures that client and server are executing the - * same test case. In particular, it means whoever is - * faster will not see the peer still executing the - * last test. This is important because port numbers - * can be used by multiple test cases. - */ - control_expectln("NEXT"); + /* Full barrier before executing the next test. This + * ensures that client and server are executing the + * same test case. In particular, it means whoever is + * faster will not see the peer still executing the + * last test. This is important because port numbers + * can be used by multiple test cases. + */ + if (test_cases[i].skip) + control_writeln("SKIP"); + else control_writeln("NEXT"); - run = test_cases[i].run_client; - } else { - control_writeln("NEXT"); - control_expectln("NEXT"); + line = control_readln(); + if (control_cmpln(line, "SKIP", false) || test_cases[i].skip) { - run = test_cases[i].run_server; + printf("skipped\n"); + + free(line); + continue; } + control_cmpln(line, "NEXT", true); + free(line); + + if (opts->mode == TEST_MODE_CLIENT) + run = test_cases[i].run_client; + else + run = test_cases[i].run_server; + if (run) run(opts); printf("ok\n"); } } + +void list_tests(const struct test_case *test_cases) +{ + int i; + + printf("ID\tTest name\n"); + + for (i = 0; test_cases[i].name; i++) + printf("%d\t%s\n", i, test_cases[i].name); + + exit(EXIT_FAILURE); +} + +void skip_test(struct test_case *test_cases, size_t test_cases_len, + const char *test_id_str) +{ + unsigned long test_id; + char *endptr = NULL; + + errno = 0; + test_id = strtoul(test_id_str, &endptr, 10); + if (errno || *endptr != '\0') { + fprintf(stderr, "malformed test ID \"%s\"\n", test_id_str); + exit(EXIT_FAILURE); + } + + if (test_id >= test_cases_len) { + fprintf(stderr, "test ID (%lu) larger than the max allowed (%lu)\n", + test_id, test_cases_len - 1); + exit(EXIT_FAILURE); + } + + test_cases[test_id].skip = true; +} + diff --git a/tools/testing/vsock/util.h b/tools/testing/vsock/util.h index 331e945f3ae6..e53dd09d26d9 100644 --- a/tools/testing/vsock/util.h +++ b/tools/testing/vsock/util.h @@ -29,6 +29,8 @@ struct test_case { /* Called when test mode is TEST_MODE_SERVER */ void (*run_server)(const struct test_opts *opts); + + bool skip; }; void init_signals(void); @@ -41,5 +43,7 @@ void send_byte(int fd, int expected_ret, int flags); void recv_byte(int fd, int expected_ret, int flags); void run_tests(const struct test_case *test_cases, const struct test_opts *opts); - +void list_tests(const struct test_case *test_cases); +void skip_test(struct test_case *test_cases, size_t test_cases_len, + const char *test_id_str); #endif /* UTIL_H */ diff --git a/tools/testing/vsock/vsock_diag_test.c b/tools/testing/vsock/vsock_diag_test.c index abd7dc2a9631..b82483627259 100644 --- a/tools/testing/vsock/vsock_diag_test.c +++ b/tools/testing/vsock/vsock_diag_test.c @@ -463,6 +463,16 @@ static const struct option longopts[] = { .has_arg = required_argument, .val = 'p', }, + { + .name = "list", + .has_arg = no_argument, + .val = 'l', + }, + { + .name = "skip", + .has_arg = required_argument, + .val = 's', + }, { .name = "help", .has_arg = no_argument, @@ -473,7 +483,7 @@ static const struct option longopts[] = { static void usage(void) { - fprintf(stderr, "Usage: vsock_diag_test [--help] [--control-host=] --control-port= --mode=client|server --peer-cid=\n" + fprintf(stderr, "Usage: vsock_diag_test [--help] [--control-host=] --control-port= --mode=client|server --peer-cid= [--list] [--skip=]\n" "\n" " Server: vsock_diag_test --control-port=1234 --mode=server --peer-cid=3\n" " Client: vsock_diag_test --control-host=192.168.0.1 --control-port=1234 --mode=client --peer-cid=2\n" @@ -528,6 +538,13 @@ int main(int argc, char **argv) case 'P': control_port = optarg; break; + case 'l': + list_tests(test_cases); + break; + case 's': + skip_test(test_cases, ARRAY_SIZE(test_cases) - 1, + optarg); + break; case '?': default: usage(); diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index 629d7ce58202..3ac56651f3f9 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "timeout.h" #include "control.h" @@ -222,6 +223,16 @@ static const struct option longopts[] = { .has_arg = required_argument, .val = 'p', }, + { + .name = "list", + .has_arg = no_argument, + .val = 'l', + }, + { + .name = "skip", + .has_arg = required_argument, + .val = 's', + }, { .name = "help", .has_arg = no_argument, @@ -232,7 +243,7 @@ static const struct option longopts[] = { static void usage(void) { - fprintf(stderr, "Usage: vsock_test [--help] [--control-host=] --control-port= --mode=client|server --peer-cid=\n" + fprintf(stderr, "Usage: vsock_test [--help] [--control-host=] --control-port= --mode=client|server --peer-cid= [--list] [--skip=]\n" "\n" " Server: vsock_test --control-port=1234 --mode=server --peer-cid=3\n" " Client: vsock_test --control-host=192.168.0.1 --control-port=1234 --mode=client --peer-cid=2\n" @@ -287,6 +298,13 @@ int main(int argc, char **argv) case 'P': control_port = optarg; break; + case 'l': + list_tests(test_cases); + break; + case 's': + skip_test(test_cases, ARRAY_SIZE(test_cases) - 1, + optarg); + break; case '?': default: usage(); From patchwork Wed Dec 18 18:07:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 1212672 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="Fc5Cso+M"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47dNKf2JGQz9sRK for ; Thu, 19 Dec 2019 05:08:22 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727678AbfLRSIR (ORCPT ); Wed, 18 Dec 2019 13:08:17 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:48982 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727649AbfLRSIC (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=1576692481; 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=PKgRJKmCUaU0qajJf3X0inD9I5OriDwjAbgS1hT2Rhk=; b=Fc5Cso+MWIiiwIHwTc0AERrX6Hu7Q1PJRql5yIc55+FcWUqNt8CJIdALEi/+lJE5jKcgCs KGePDoRo0fLiSrQOoBHOkPSSSSOsUtdCchp8CFcYCZKCgANS4O5x78r15NrN5nrTYz+4z8 ne9Ed2ZnFwePR3wd/pZO7Y+ivY1aAt0= 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-336-jV9ud2qrPS-QuMVkwgfOvQ-1; Wed, 18 Dec 2019 13:07:58 -0500 X-MC-Unique: jV9ud2qrPS-QuMVkwgfOvQ-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 8E06A64A96; Wed, 18 Dec 2019 18:07:56 +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 7216A5D9E2; Wed, 18 Dec 2019 18:07:54 +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 10/11] testing/vsock: print list of options and description Date: Wed, 18 Dec 2019 19:07:07 +0100 Message-Id: <20191218180708.120337-11-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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Since we now have several options, in the help we print the list of all supported options and a brief description of them. Signed-off-by: Stefano Garzarella --- tools/testing/vsock/vsock_diag_test.c | 13 ++++++++++++- tools/testing/vsock/vsock_test.c | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tools/testing/vsock/vsock_diag_test.c b/tools/testing/vsock/vsock_diag_test.c index b82483627259..cec6f5a738e1 100644 --- a/tools/testing/vsock/vsock_diag_test.c +++ b/tools/testing/vsock/vsock_diag_test.c @@ -497,7 +497,18 @@ static void usage(void) "listen address and the client requires an address to\n" "connect to.\n" "\n" - "The CID of the other side must be given with --peer-cid=.\n"); + "The CID of the other side must be given with --peer-cid=.\n" + "\n" + "Options:\n" + " --help This help message\n" + " --control-host Server IP address to connect to\n" + " --control-port Server port to listen on/connect to\n" + " --mode client|server Server or client mode\n" + " --peer-cid CID of the other side\n" + " --list List of tests that will be executed\n" + " --skip Test ID to skip;\n" + " use multiple --skip options to skip more tests\n" + ); exit(EXIT_FAILURE); } diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index 3ac56651f3f9..a63e05d6a0f9 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -257,7 +257,18 @@ static void usage(void) "listen address and the client requires an address to\n" "connect to.\n" "\n" - "The CID of the other side must be given with --peer-cid=.\n"); + "The CID of the other side must be given with --peer-cid=.\n" + "\n" + "Options:\n" + " --help This help message\n" + " --control-host Server IP address to connect to\n" + " --control-port Server port to listen on/connect to\n" + " --mode client|server Server or client mode\n" + " --peer-cid CID of the other side\n" + " --list List of tests that will be executed\n" + " --skip Test ID to skip;\n" + " use multiple --skip options to skip more tests\n" + ); exit(EXIT_FAILURE); } 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: 1212671 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="OMHtU+Fg"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47dNKP6mBGz9sRW for ; Thu, 19 Dec 2019 05:08:09 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727717AbfLRSIG (ORCPT ); Wed, 18 Dec 2019 13:08:06 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:53190 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727677AbfLRSIE (ORCPT ); Wed, 18 Dec 2019 13:08:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576692484; 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=OMHtU+FgW0REp8xJ/ry8/u491+lD5SdHl3ZKnDWwAWGziAkI9KqZPczs+koiXBQ6jtyjkn I73lk9hFf/j8d/dHWyQ3UYP8XJDXwbVRStgF8bsPpI/u4oUnxNlNm92Fn3gBj40FjdVi4P R1U1Dg2KRz2CR6ePYtMN+d51VH3rG8w= 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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@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, + }, {}, };