From nobody Thu Feb 12 06:33:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3FA8EE645A for ; Fri, 15 Sep 2023 12:16:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234818AbjIOMQe (ORCPT ); Fri, 15 Sep 2023 08:16:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234723AbjIOMQ1 (ORCPT ); Fri, 15 Sep 2023 08:16:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C9CFA2120 for ; Fri, 15 Sep 2023 05:15:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694780130; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RMEGvb3Sq84IyOhcCt8lUx9+cduXmZG2jRi2oEjFcn4=; b=iA1eWIA2fj6SuWECU7ptV+aGgKp+3Vv16bl2SpKy9BjdhArOaoLlypBtBmYlEE8dX76zJn /UFLqK10oAIMYqBVwecYgg+H8oKFeMWT8IzIaR17ziHUx4nF+IpzdrON63QTMEAjWN7YQB UA37+D8fH2lLITimCOACgpWUX+S9inw= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-220-A1nB6_X0OH2CpuCJqZveEA-1; Fri, 15 Sep 2023 08:15:28 -0400 X-MC-Unique: A1nB6_X0OH2CpuCJqZveEA-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-401c19fc097so16044085e9.1 for ; Fri, 15 Sep 2023 05:15:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694780127; x=1695384927; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RMEGvb3Sq84IyOhcCt8lUx9+cduXmZG2jRi2oEjFcn4=; b=NVQbkbsW9ZLcScUEdLlawwCTByLtC0u9hCeBuWL7xAqj27AcerFEWVgo6E9kKVeE4x ExHeP+g7UEwtWiLvjCjeYhd6b0fL6Kf1U1QofrL96nQ2l9kxdFwIhPw6aXtoWrPfaPzW 6fIraBzAcFE9D+ho92tGnaBP+Dn5d/FK4txdwgGSz52CAjHPPZr5TRcPTdDJrUDpSHzJ 6bWtALOaRogoLGW/SotjkBBIby7JkjQPohdnCmVwVSblp5+F+JQufgWoHraauBNIbn2T BxNbDMiURiZgm4/2ZjwwN4MVAMBUFQlcUk8tqyB4L4tSDpgVYvcdk28Y1P5dTx3cWjlh +U8w== X-Gm-Message-State: AOJu0Ywb33QjRmrAFdtl00lWGxd/zzgocP00AaYF/JnkAMqk5imTNMIi /N3gLK8lOcooM8G3CvF2sjumxbUzLtC5gR7oluSginUb7wz70aWsUGBkU25bRpU/3HNmc+vKCZV gWvEcK8L9wPQAqml6xtE9fZBJ X-Received: by 2002:a5d:6dcb:0:b0:31f:eb8d:4823 with SMTP id d11-20020a5d6dcb000000b0031feb8d4823mr1120364wrz.26.1694780116117; Fri, 15 Sep 2023 05:15:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHmZEMz8JTAkutLT6oF8NF90vZ5bmQukR1ASa3FCQYrmpM8Mq37F3IN0p/HD9/gA/uhMXLXfw== X-Received: by 2002:a5d:6dcb:0:b0:31f:eb8d:4823 with SMTP id d11-20020a5d6dcb000000b0031feb8d4823mr1119962wrz.26.1694780101879; Fri, 15 Sep 2023 05:15:01 -0700 (PDT) Received: from step1.lan ([46.222.72.72]) by smtp.gmail.com with ESMTPSA id l12-20020a5d674c000000b0030ae53550f5sm4257548wrw.51.2023.09.15.05.14.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:15:00 -0700 (PDT) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Stefano Garzarella , Arseniy Krasnov , virtualization@lists.linux-foundation.org, oxffffaa@gmail.com, Bobby Eshleman Subject: [PATCH net-next 1/5] vsock/test: add recv_buf() utility function Date: Fri, 15 Sep 2023 14:14:48 +0200 Message-ID: <20230915121452.87192-2-sgarzare@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230915121452.87192-1-sgarzare@redhat.com> References: <20230915121452.87192-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move the code of recv_byte() out in a new utility function that can be used to receive a generic buffer. This new function can be used when we need to receive a custom buffer and not just a single 'A' byte. Signed-off-by: Stefano Garzarella Reviewed-by: Arseniy Krasnov --- tools/testing/vsock/util.h | 1 + tools/testing/vsock/util.c | 88 +++++++++++++++++++++++--------------- 2 files changed, 54 insertions(+), 35 deletions(-) diff --git a/tools/testing/vsock/util.h b/tools/testing/vsock/util.h index fb99208a95ea..fe31f267e67e 100644 --- a/tools/testing/vsock/util.h +++ b/tools/testing/vsock/util.h @@ -42,6 +42,7 @@ int vsock_stream_accept(unsigned int cid, unsigned int po= rt, int vsock_seqpacket_accept(unsigned int cid, unsigned int port, struct sockaddr_vm *clientaddrp); void vsock_wait_remote_close(int fd); +void recv_buf(int fd, void *buf, size_t len, int flags, ssize_t expected_r= et); 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/util.c b/tools/testing/vsock/util.c index 01b636d3039a..2826902706e8 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c @@ -211,6 +211,58 @@ int vsock_seqpacket_accept(unsigned int cid, unsigned = int port, return vsock_accept(cid, port, clientaddrp, SOCK_SEQPACKET); } =20 +/* Receive bytes in a buffer and check the return value. + * + * expected_ret: + * <0 Negative errno (for testing errors) + * 0 End-of-file + * >0 Success (bytes successfully read) + */ +void recv_buf(int fd, void *buf, size_t len, int flags, ssize_t expected_r= et) +{ + ssize_t nread =3D 0; + ssize_t ret; + + timeout_begin(TIMEOUT); + do { + ret =3D recv(fd, buf + nread, len - nread, flags); + timeout_check("recv"); + + if (ret =3D=3D 0 || (ret < 0 && errno !=3D EINTR)) + break; + + nread +=3D ret; + } while (nread < len); + timeout_end(); + + if (expected_ret < 0) { + if (ret !=3D -1) { + fprintf(stderr, "bogus recv(2) return value %zd (expected %zd)\n", + ret, expected_ret); + exit(EXIT_FAILURE); + } + if (errno !=3D -expected_ret) { + perror("recv"); + exit(EXIT_FAILURE); + } + return; + } + + if (ret < 0) { + perror("recv"); + exit(EXIT_FAILURE); + } + + if (nread !=3D expected_ret) { + if (ret =3D=3D 0) + fprintf(stderr, "unexpected EOF while receiving bytes\n"); + + fprintf(stderr, "bogus recv(2) bytes read %zd (expected %zd)\n", + nread, expected_ret); + exit(EXIT_FAILURE); + } +} + /* Transmit one byte and check the return value. * * expected_ret: @@ -270,43 +322,9 @@ void send_byte(int fd, int expected_ret, int flags) void recv_byte(int fd, int expected_ret, int flags) { uint8_t byte; - ssize_t nread; - - timeout_begin(TIMEOUT); - do { - nread =3D recv(fd, &byte, sizeof(byte), flags); - timeout_check("read"); - } while (nread < 0 && errno =3D=3D EINTR); - timeout_end(); - - if (expected_ret < 0) { - if (nread !=3D -1) { - fprintf(stderr, "bogus recv(2) return value %zd\n", - nread); - exit(EXIT_FAILURE); - } - if (errno !=3D -expected_ret) { - perror("read"); - exit(EXIT_FAILURE); - } - return; - } =20 - if (nread < 0) { - perror("read"); - exit(EXIT_FAILURE); - } - if (nread =3D=3D 0) { - if (expected_ret =3D=3D 0) - return; + recv_buf(fd, &byte, sizeof(byte), flags, expected_ret); =20 - fprintf(stderr, "unexpected EOF while receiving byte\n"); - exit(EXIT_FAILURE); - } - if (nread !=3D sizeof(byte)) { - fprintf(stderr, "bogus recv(2) return value %zd\n", nread); - exit(EXIT_FAILURE); - } if (byte !=3D 'A') { fprintf(stderr, "unexpected byte read %c\n", byte); exit(EXIT_FAILURE); --=20 2.41.0 From nobody Thu Feb 12 06:33:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B819BEE645A for ; Fri, 15 Sep 2023 12:16:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234700AbjIOMQE (ORCPT ); Fri, 15 Sep 2023 08:16:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234698AbjIOMQC (ORCPT ); Fri, 15 Sep 2023 08:16:02 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CEF8E268A for ; Fri, 15 Sep 2023 05:15:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694780111; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0FP0IT9D2do1i/qXeFKAhCEFBnRZ2j14dkv/qsnZwWc=; b=CSqrGf3WBmVVU+zExhHPCtrNwcPygnWsyTQZcR+p3wZy39B/zuOlLwwYntP3bFbq7AN2lw obt4a0nJTXdzerWMhjqoa4u2PgNytvIPgUXVsSijafylaZGbHLi2IyFHrd3wzycoQCzS56 7eKs8B5WaNrY4nUVQ6CvJv7MEjm9Amk= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-303-8J5piP9FMNK80LmhvJZ_Sw-1; Fri, 15 Sep 2023 08:15:09 -0400 X-MC-Unique: 8J5piP9FMNK80LmhvJZ_Sw-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-31f79595669so1295938f8f.0 for ; Fri, 15 Sep 2023 05:15:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694780108; x=1695384908; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0FP0IT9D2do1i/qXeFKAhCEFBnRZ2j14dkv/qsnZwWc=; b=BTRX7bzZznwEN9RoypsMznD61wULZ0l24pgpGSpUL17NbjbChxBJ2Z0+s+LMDthsmL xOaNyfln7m7n0aGI8bw0vG+kHCd3EPy76w4e8gv5Lp78HlG8IrSC4wqKQtK5P1A+ejWn 8/d1yy0Jb+hu9u1Vv4c4XapEuM7/GQrTqqmvJYujvvdchKJs9Tk0T0i9w08724gYywhI ZAFuoGU2LoX9OHjQ1p4opkRs/GQwOLijp0qQHqzmbD3Vm8Qx2IfCNvW32G3Ss4onjLDa s4AAoeULmfQa6IYaD4cmnPVjGHRxsyPNR/MRX5SJgqqDWFkTKFort+TY0hpmxoL/9orr w6BQ== X-Gm-Message-State: AOJu0Yx5GxHaitDdRZQHAbrjIn1MKK7U25zMgFiVMiPKzDV+3dBsoMma l2E8VoP9rktZA6A7GApjNYd5YUbj+i504dQ9+fz0J7hhRdPW3D+MQkSF+w+uog4Z8FMgf/HHQSm MM+G/flFeRPdZ+ZQr9zl17iK58ocUU4DXmkU= X-Received: by 2002:adf:d202:0:b0:31f:f8a7:a26c with SMTP id j2-20020adfd202000000b0031ff8a7a26cmr619574wrh.25.1694780108275; Fri, 15 Sep 2023 05:15:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJF6T446VPfAO2MFW1Z0pgHTw0vTmbNmzAcUKmbss0UAE9W23X6m2itdgZ2I4QNcEqteZP5Q== X-Received: by 2002:adf:d202:0:b0:31f:f8a7:a26c with SMTP id j2-20020adfd202000000b0031ff8a7a26cmr619554wrh.25.1694780107830; Fri, 15 Sep 2023 05:15:07 -0700 (PDT) Received: from step1.lan ([46.222.72.72]) by smtp.gmail.com with ESMTPSA id d6-20020adfef86000000b0031f82743e25sm4300429wro.67.2023.09.15.05.15.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:15:06 -0700 (PDT) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Stefano Garzarella , Arseniy Krasnov , virtualization@lists.linux-foundation.org, oxffffaa@gmail.com, Bobby Eshleman Subject: [PATCH net-next 2/5] vsock/test: use recv_buf() in vsock_test.c Date: Fri, 15 Sep 2023 14:14:49 +0200 Message-ID: <20230915121452.87192-3-sgarzare@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230915121452.87192-1-sgarzare@redhat.com> References: <20230915121452.87192-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We have a very common pattern used in vsock_test that we can now replace with the new recv_buf(). This allows us to reuse the code we already had to check the actual return value and wait for all bytes to be received with an appropriate timeout. Signed-off-by: Stefano Garzarella Reviewed-by: Arseniy Krasnov --- tools/testing/vsock/vsock_test.c | 104 +++++-------------------------- 1 file changed, 17 insertions(+), 87 deletions(-) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_t= est.c index 90718c2fd4ea..d1dcbaeb477a 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -301,7 +301,6 @@ static void test_msg_peek_server(const struct test_opts= *opts, unsigned char buf_half[MSG_PEEK_BUF_LEN / 2]; unsigned char buf_normal[MSG_PEEK_BUF_LEN]; unsigned char buf_peek[MSG_PEEK_BUF_LEN]; - ssize_t res; int fd; =20 if (seqpacket) @@ -315,34 +314,16 @@ static void test_msg_peek_server(const struct test_op= ts *opts, } =20 /* Peek from empty socket. */ - res =3D recv(fd, buf_peek, sizeof(buf_peek), MSG_PEEK | MSG_DONTWAIT); - if (res !=3D -1) { - fprintf(stderr, "expected recv(2) failure, got %zi\n", res); - exit(EXIT_FAILURE); - } - - if (errno !=3D EAGAIN) { - perror("EAGAIN expected"); - exit(EXIT_FAILURE); - } + recv_buf(fd, buf_peek, sizeof(buf_peek), MSG_PEEK | MSG_DONTWAIT, + -EAGAIN); =20 control_writeln("SRVREADY"); =20 /* Peek part of data. */ - res =3D recv(fd, buf_half, sizeof(buf_half), MSG_PEEK); - if (res !=3D sizeof(buf_half)) { - fprintf(stderr, "recv(2) + MSG_PEEK, expected %zu, got %zi\n", - sizeof(buf_half), res); - exit(EXIT_FAILURE); - } + recv_buf(fd, buf_half, sizeof(buf_half), MSG_PEEK, sizeof(buf_half)); =20 /* Peek whole data. */ - res =3D recv(fd, buf_peek, sizeof(buf_peek), MSG_PEEK); - if (res !=3D sizeof(buf_peek)) { - fprintf(stderr, "recv(2) + MSG_PEEK, expected %zu, got %zi\n", - sizeof(buf_peek), res); - exit(EXIT_FAILURE); - } + recv_buf(fd, buf_peek, sizeof(buf_peek), MSG_PEEK, sizeof(buf_peek)); =20 /* Compare partial and full peek. */ if (memcmp(buf_half, buf_peek, sizeof(buf_half))) { @@ -355,22 +336,11 @@ static void test_msg_peek_server(const struct test_op= ts *opts, * so check it with MSG_PEEK. We must get length * of the message. */ - res =3D recv(fd, buf_half, sizeof(buf_half), MSG_PEEK | - MSG_TRUNC); - if (res !=3D sizeof(buf_peek)) { - fprintf(stderr, - "recv(2) + MSG_PEEK | MSG_TRUNC, exp %zu, got %zi\n", - sizeof(buf_half), res); - exit(EXIT_FAILURE); - } + recv_buf(fd, buf_half, sizeof(buf_half), MSG_PEEK | MSG_TRUNC, + sizeof(buf_peek)); } =20 - res =3D recv(fd, buf_normal, sizeof(buf_normal), 0); - if (res !=3D sizeof(buf_normal)) { - fprintf(stderr, "recv(2), expected %zu, got %zi\n", - sizeof(buf_normal), res); - exit(EXIT_FAILURE); - } + recv_buf(fd, buf_normal, sizeof(buf_normal), 0, sizeof(buf_normal)); =20 /* Compare full peek and normal read. */ if (memcmp(buf_peek, buf_normal, sizeof(buf_peek))) { @@ -900,7 +870,6 @@ static void test_stream_poll_rcvlowat_client(const stru= ct test_opts *opts) unsigned long lowat_val =3D RCVLOWAT_BUF_SIZE; char buf[RCVLOWAT_BUF_SIZE]; struct pollfd fds; - ssize_t read_res; short poll_flags; int fd; =20 @@ -955,12 +924,7 @@ static void test_stream_poll_rcvlowat_client(const str= uct test_opts *opts) /* Use MSG_DONTWAIT, if call is going to wait, EAGAIN * will be returned. */ - read_res =3D recv(fd, buf, sizeof(buf), MSG_DONTWAIT); - if (read_res !=3D RCVLOWAT_BUF_SIZE) { - fprintf(stderr, "Unexpected recv result %zi\n", - read_res); - exit(EXIT_FAILURE); - } + recv_buf(fd, buf, sizeof(buf), MSG_DONTWAIT, RCVLOWAT_BUF_SIZE); =20 control_writeln("POLLDONE"); =20 @@ -972,7 +936,7 @@ static void test_stream_poll_rcvlowat_client(const stru= ct test_opts *opts) static void test_inv_buf_client(const struct test_opts *opts, bool stream) { unsigned char data[INV_BUF_TEST_DATA_LEN] =3D {0}; - ssize_t ret; + ssize_t expected_ret; int fd; =20 if (stream) @@ -988,39 +952,18 @@ static void test_inv_buf_client(const struct test_opt= s *opts, bool stream) control_expectln("SENDDONE"); =20 /* Use invalid buffer here. */ - ret =3D recv(fd, NULL, sizeof(data), 0); - if (ret !=3D -1) { - fprintf(stderr, "expected recv(2) failure, got %zi\n", ret); - exit(EXIT_FAILURE); - } - - if (errno !=3D EFAULT) { - fprintf(stderr, "unexpected recv(2) errno %d\n", errno); - exit(EXIT_FAILURE); - } - - ret =3D recv(fd, data, sizeof(data), MSG_DONTWAIT); + recv_buf(fd, NULL, sizeof(data), 0, -EFAULT); =20 if (stream) { /* For SOCK_STREAM we must continue reading. */ - if (ret !=3D sizeof(data)) { - fprintf(stderr, "expected recv(2) success, got %zi\n", ret); - exit(EXIT_FAILURE); - } - /* Don't check errno in case of success. */ + expected_ret =3D sizeof(data); } else { /* For SOCK_SEQPACKET socket's queue must be empty. */ - if (ret !=3D -1) { - fprintf(stderr, "expected recv(2) failure, got %zi\n", ret); - exit(EXIT_FAILURE); - } - - if (errno !=3D EAGAIN) { - fprintf(stderr, "unexpected recv(2) errno %d\n", errno); - exit(EXIT_FAILURE); - } + expected_ret =3D -EAGAIN; } =20 + recv_buf(fd, data, sizeof(data), MSG_DONTWAIT, expected_ret); + control_writeln("DONE"); =20 close(fd); @@ -1117,7 +1060,6 @@ static void test_stream_virtio_skb_merge_client(const= struct test_opts *opts) static void test_stream_virtio_skb_merge_server(const struct test_opts *op= ts) { unsigned char buf[64]; - ssize_t res; int fd; =20 fd =3D vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); @@ -1129,26 +1071,14 @@ static void test_stream_virtio_skb_merge_server(con= st struct test_opts *opts) control_expectln("SEND0"); =20 /* Read skbuff partially. */ - res =3D recv(fd, buf, 2, 0); - if (res !=3D 2) { - fprintf(stderr, "expected recv(2) returns 2 bytes, got %zi\n", res); - exit(EXIT_FAILURE); - } + recv_buf(fd, buf, 2, 0, 2); =20 control_writeln("REPLY0"); control_expectln("SEND1"); =20 - res =3D recv(fd, buf + 2, sizeof(buf) - 2, 0); - if (res !=3D 8) { - fprintf(stderr, "expected recv(2) returns 8 bytes, got %zi\n", res); - exit(EXIT_FAILURE); - } + recv_buf(fd, buf + 2, 8, 0, 8); =20 - res =3D recv(fd, buf, sizeof(buf) - 8 - 2, MSG_DONTWAIT); - if (res !=3D -1) { - fprintf(stderr, "expected recv(2) failure, got %zi\n", res); - exit(EXIT_FAILURE); - } + recv_buf(fd, buf, sizeof(buf) - 8 - 2, MSG_DONTWAIT, -EAGAIN); =20 if (memcmp(buf, HELLO_STR WORLD_STR, strlen(HELLO_STR WORLD_STR))) { fprintf(stderr, "pattern mismatch\n"); --=20 2.41.0 From nobody Thu Feb 12 06:33:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F02FEEE645A for ; Fri, 15 Sep 2023 12:16:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234707AbjIOMQM (ORCPT ); Fri, 15 Sep 2023 08:16:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234702AbjIOMQK (ORCPT ); Fri, 15 Sep 2023 08:16:10 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7B7DD271C for ; Fri, 15 Sep 2023 05:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694780116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3Wsy1q2POvkf/slH3ci56G5sHfd/fayJdujAf9EVUnI=; b=WiyevuVOD9kARfYqkbi9WXhcOMBBx6xWZYKCq2umtAFN7W0iqe7/muSmn9c2kMq+dUZYHO VfsQfmq7rIFsJrOn2/Wfa+ul3Dk232/5qLur/1jxSU6AT1SGzUN3s6O9r0Ow10xs4MnCGi WUoixHS1NmgKzR/xubs3tDuWck1mIo0= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-696-eKCSCtAvMO611vH_W1oMoQ-1; Fri, 15 Sep 2023 08:15:15 -0400 X-MC-Unique: eKCSCtAvMO611vH_W1oMoQ-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-402d1892cecso9706265e9.1 for ; Fri, 15 Sep 2023 05:15:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694780114; x=1695384914; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3Wsy1q2POvkf/slH3ci56G5sHfd/fayJdujAf9EVUnI=; b=gBOT/W29Bm4cShH4/LMNw59IeTkfr+Jts57Et0ykL8NAYhj/N8ALEdG9sQiwC/UZ6u uDqTtV97pMruG+j83p9+eek56uAh5XeZP7SBJLmjCaAsbLVEwTwVLKjgKwmP70xsP8o1 NYHan2NrIk/3jA+08q5Wgf2fIcIQZHJfKK/leY5Yn1y2xN3/5q4e9E280WL2EuUPU8Ei vWgWJDUqtv6hciVki8wKc8tv5z/RUmTsGRnnUO5txUXJBoEm1hB64VNyNA1dLj6dqnmg nN2tsLgOlBL7tZwvaErsyBJip3j+ZB6ObuX8RXtmr+rrHBtSlohjBEOUQ1T1GxlCakh8 5e0A== X-Gm-Message-State: AOJu0YyO4ZF1LCVCkJajyGsV3u13uNygGFXN/MM17h97gqI4iyVIvJco FLq+EzDry1pQ4/4YQKcFbEgR7QyVPqmARZeNFOHS/au4PUmxyibYSfRF0LxPw8PjSvVhSaXd3w4 RMZfnBmFB4smLq6B+3wnxrxGxmngOJWyNV/A= X-Received: by 2002:a05:600c:1914:b0:401:bcec:be3e with SMTP id j20-20020a05600c191400b00401bcecbe3emr3493380wmq.17.1694780113966; Fri, 15 Sep 2023 05:15:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF80cLLN3KCVixXwI3Sp+oFXdhCzhUU59hAIcQenPXVtkDPh17T7T+QOc2QolC6Hazp8647uA== X-Received: by 2002:a05:600c:1914:b0:401:bcec:be3e with SMTP id j20-20020a05600c191400b00401bcecbe3emr3493366wmq.17.1694780113612; Fri, 15 Sep 2023 05:15:13 -0700 (PDT) Received: from step1.lan ([46.222.72.72]) by smtp.gmail.com with ESMTPSA id v13-20020a05600c214d00b00401dc20a070sm7346864wml.43.2023.09.15.05.15.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:15:12 -0700 (PDT) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Stefano Garzarella , Arseniy Krasnov , virtualization@lists.linux-foundation.org, oxffffaa@gmail.com, Bobby Eshleman Subject: [PATCH net-next 3/5] vsock/test: add send_buf() utility function Date: Fri, 15 Sep 2023 14:14:50 +0200 Message-ID: <20230915121452.87192-4-sgarzare@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230915121452.87192-1-sgarzare@redhat.com> References: <20230915121452.87192-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move the code of send_byte() out in a new utility function that can be used to send a generic buffer. This new function can be used when we need to send a custom buffer and not just a single 'A' byte. Signed-off-by: Stefano Garzarella Reviewed-by: Arseniy Krasnov --- tools/testing/vsock/util.h | 2 + tools/testing/vsock/util.c | 90 +++++++++++++++++++++++--------------- 2 files changed, 56 insertions(+), 36 deletions(-) diff --git a/tools/testing/vsock/util.h b/tools/testing/vsock/util.h index fe31f267e67e..e5407677ce05 100644 --- a/tools/testing/vsock/util.h +++ b/tools/testing/vsock/util.h @@ -42,6 +42,8 @@ int vsock_stream_accept(unsigned int cid, unsigned int po= rt, int vsock_seqpacket_accept(unsigned int cid, unsigned int port, struct sockaddr_vm *clientaddrp); void vsock_wait_remote_close(int fd); +void send_buf(int fd, const void *buf, size_t len, int flags, + ssize_t expected_ret); void recv_buf(int fd, void *buf, size_t len, int flags, ssize_t expected_r= et); void send_byte(int fd, int expected_ret, int flags); void recv_byte(int fd, int expected_ret, int flags); diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c index 2826902706e8..6779d5008b27 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c @@ -211,6 +211,59 @@ int vsock_seqpacket_accept(unsigned int cid, unsigned = int port, return vsock_accept(cid, port, clientaddrp, SOCK_SEQPACKET); } =20 +/* Transmit bytes from a buffer and check the return value. + * + * expected_ret: + * <0 Negative errno (for testing errors) + * 0 End-of-file + * >0 Success (bytes successfully written) + */ +void send_buf(int fd, const void *buf, size_t len, int flags, + ssize_t expected_ret) +{ + ssize_t nwritten =3D 0; + ssize_t ret; + + timeout_begin(TIMEOUT); + do { + ret =3D send(fd, buf + nwritten, len - nwritten, flags); + timeout_check("send"); + + if (ret =3D=3D 0 || (ret < 0 && errno !=3D EINTR)) + break; + + nwritten +=3D ret; + } while (nwritten < len); + timeout_end(); + + if (expected_ret < 0) { + if (ret !=3D -1) { + fprintf(stderr, "bogus send(2) return value %zd (expected %zd)\n", + ret, expected_ret); + exit(EXIT_FAILURE); + } + if (errno !=3D -expected_ret) { + perror("send"); + exit(EXIT_FAILURE); + } + return; + } + + if (ret < 0) { + perror("send"); + exit(EXIT_FAILURE); + } + + if (nwritten !=3D expected_ret) { + if (ret =3D=3D 0) + fprintf(stderr, "unexpected EOF while sending bytes\n"); + + fprintf(stderr, "bogus send(2) bytes written %zd (expected %zd)\n", + nwritten, expected_ret); + exit(EXIT_FAILURE); + } +} + /* Receive bytes in a buffer and check the return value. * * expected_ret: @@ -273,43 +326,8 @@ void recv_buf(int fd, void *buf, size_t len, int flags= , ssize_t expected_ret) void send_byte(int fd, int expected_ret, int flags) { const uint8_t byte =3D 'A'; - ssize_t nwritten; - - timeout_begin(TIMEOUT); - do { - nwritten =3D send(fd, &byte, sizeof(byte), flags); - timeout_check("write"); - } while (nwritten < 0 && errno =3D=3D EINTR); - timeout_end(); - - if (expected_ret < 0) { - if (nwritten !=3D -1) { - fprintf(stderr, "bogus send(2) return value %zd\n", - nwritten); - exit(EXIT_FAILURE); - } - if (errno !=3D -expected_ret) { - perror("write"); - exit(EXIT_FAILURE); - } - return; - } =20 - if (nwritten < 0) { - perror("write"); - exit(EXIT_FAILURE); - } - if (nwritten =3D=3D 0) { - if (expected_ret =3D=3D 0) - return; - - fprintf(stderr, "unexpected EOF while sending byte\n"); - exit(EXIT_FAILURE); - } - if (nwritten !=3D sizeof(byte)) { - fprintf(stderr, "bogus send(2) return value %zd\n", nwritten); - exit(EXIT_FAILURE); - } + send_buf(fd, &byte, sizeof(byte), flags, expected_ret); } =20 /* Receive one byte and check the return value. --=20 2.41.0 From nobody Thu Feb 12 06:33:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 764C4EE645B for ; Fri, 15 Sep 2023 12:16:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234770AbjIOMQU (ORCPT ); Fri, 15 Sep 2023 08:16:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234672AbjIOMQS (ORCPT ); Fri, 15 Sep 2023 08:16:18 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 26216211E for ; Fri, 15 Sep 2023 05:15:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694780124; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GDBE00lKHk1z88MDFMXNFeObsJMvojUkDq7liDEdWcM=; b=EnZ5rGH0gBcplfxoNzQXlPKm1VaNa/2NVS3yrrh3a2hUeat9Hvea4s27ixL/FkSHKDflc6 4m8Mf7SZCHQiE3MYLBo27jdIc7lBpjyDoS/U1rP+xBZYP0Dpua0zphUcmtrlr/4PzI0YO3 0HmDVPWwpO/JrIXfN9fbKlZyfhfpKtU= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-509-iH5mqS86PwGccXqpq59F7Q-1; Fri, 15 Sep 2023 08:15:20 -0400 X-MC-Unique: iH5mqS86PwGccXqpq59F7Q-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-31aef28315eso1405995f8f.2 for ; Fri, 15 Sep 2023 05:15:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694780119; x=1695384919; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GDBE00lKHk1z88MDFMXNFeObsJMvojUkDq7liDEdWcM=; b=DS7CgOz+J+VkmqgeAiOwwRVQbvqz01l3FHqUmk5DXj1WgPw2S1iAtt1W3bg8oLSFHG Nb3YjhXHPAyjWqY8IhAUXcr4z3/WOHh3QvZaXGN6A3GcE8BG5CUObrVWyTyV30Jyg/qX CC4XdS9ew6oXCk8b6bas59QTCUuIT0hy41DYfqobGtrW4Xbko6eaLKov7I5Emgd2tjXX wWDszZEms3HsvS4pqC6K8lajK5sP9z5fRRA0tMG+MCrR+/bR3dHhGiKXZba2RLQ3RPD/ 8ixidOHGc+1cOvEfKzrFa4uPA/boXRdrfB9sdNYnIngdWXSmQl7JfYfBDDRnsfefYZmf INgA== X-Gm-Message-State: AOJu0YwYXUD2wwJJeWpgnNKKPuNu9BKytd1SBHzWu21u/83eUjYmr3tH O7zk4zqQduHjutOtL2bVmggxGE04o/nE9O+5g03DM7Yo7AzW/ISMzgtDLr7kvKvW7/3TGzKtQzy BQvKhYmQ1IXFPc+UWUz9CHOc5 X-Received: by 2002:adf:fb50:0:b0:31f:d7bb:481e with SMTP id c16-20020adffb50000000b0031fd7bb481emr1184332wrs.63.1694780119411; Fri, 15 Sep 2023 05:15:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeyzHuoaEGMp/jTcaIbZGY1B+QuzLExkcenZEXxgsQDgcXpE6ANREgAfuYkNjFwkxggDkAvQ== X-Received: by 2002:adf:fb50:0:b0:31f:d7bb:481e with SMTP id c16-20020adffb50000000b0031fd7bb481emr1184319wrs.63.1694780119150; Fri, 15 Sep 2023 05:15:19 -0700 (PDT) Received: from step1.lan ([46.222.72.72]) by smtp.gmail.com with ESMTPSA id m2-20020a056000174200b0031fe9a47a87sm3054745wrf.112.2023.09.15.05.15.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:15:18 -0700 (PDT) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Stefano Garzarella , Arseniy Krasnov , virtualization@lists.linux-foundation.org, oxffffaa@gmail.com, Bobby Eshleman Subject: [PATCH net-next 4/5] vsock/test: use send_buf() in vsock_test.c Date: Fri, 15 Sep 2023 14:14:51 +0200 Message-ID: <20230915121452.87192-5-sgarzare@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230915121452.87192-1-sgarzare@redhat.com> References: <20230915121452.87192-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We have a very common pattern used in vsock_test that we can now replace with the new send_buf(). This allows us to reuse the code we already had to check the actual return value and wait for all the bytes to be sent with an appropriate timeout. Signed-off-by: Stefano Garzarella Reviewed-by: Arseniy Krasnov --- tools/testing/vsock/vsock_test.c | 75 ++++---------------------------- 1 file changed, 9 insertions(+), 66 deletions(-) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_t= est.c index d1dcbaeb477a..b18acbaf92e2 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -261,7 +261,6 @@ static void test_msg_peek_client(const struct test_opts= *opts, bool seqpacket) { unsigned char buf[MSG_PEEK_BUF_LEN]; - ssize_t send_size; int fd; int i; =20 @@ -280,17 +279,7 @@ static void test_msg_peek_client(const struct test_opt= s *opts, =20 control_expectln("SRVREADY"); =20 - send_size =3D send(fd, buf, sizeof(buf), 0); - - if (send_size < 0) { - perror("send"); - exit(EXIT_FAILURE); - } - - if (send_size !=3D sizeof(buf)) { - fprintf(stderr, "Invalid send size %zi\n", send_size); - exit(EXIT_FAILURE); - } + send_buf(fd, buf, sizeof(buf), 0, sizeof(buf)); =20 close(fd); } @@ -385,7 +374,6 @@ static void test_seqpacket_msg_bounds_client(const stru= ct test_opts *opts) msg_count =3D SOCK_BUF_SIZE / MAX_MSG_SIZE; =20 for (int i =3D 0; i < msg_count; i++) { - ssize_t send_size; size_t buf_size; int flags; void *buf; @@ -413,17 +401,7 @@ static void test_seqpacket_msg_bounds_client(const str= uct test_opts *opts) flags =3D 0; } =20 - send_size =3D send(fd, buf, buf_size, flags); - - if (send_size < 0) { - perror("send"); - exit(EXIT_FAILURE); - } - - if (send_size !=3D buf_size) { - fprintf(stderr, "Invalid send size\n"); - exit(EXIT_FAILURE); - } + send_buf(fd, buf, buf_size, flags, buf_size); =20 /* * Hash sum is computed at both client and server in @@ -524,10 +502,7 @@ static void test_seqpacket_msg_trunc_client(const stru= ct test_opts *opts) exit(EXIT_FAILURE); } =20 - if (send(fd, buf, sizeof(buf), 0) !=3D sizeof(buf)) { - perror("send failed"); - exit(EXIT_FAILURE); - } + send_buf(fd, buf, sizeof(buf), 0, sizeof(buf)); =20 control_writeln("SENDDONE"); close(fd); @@ -649,7 +624,6 @@ static void test_seqpacket_timeout_server(const struct = test_opts *opts) static void test_seqpacket_bigmsg_client(const struct test_opts *opts) { unsigned long sock_buf_size; - ssize_t send_size; socklen_t len; void *data; int fd; @@ -676,18 +650,7 @@ static void test_seqpacket_bigmsg_client(const struct = test_opts *opts) exit(EXIT_FAILURE); } =20 - send_size =3D send(fd, data, sock_buf_size, 0); - if (send_size !=3D -1) { - fprintf(stderr, "expected 'send(2)' failure, got %zi\n", - send_size); - exit(EXIT_FAILURE); - } - - if (errno !=3D EMSGSIZE) { - fprintf(stderr, "expected EMSGSIZE in 'errno', got %i\n", - errno); - exit(EXIT_FAILURE); - } + send_buf(fd, data, sock_buf_size, 0, -EMSGSIZE); =20 control_writeln("CLISENT"); =20 @@ -741,15 +704,9 @@ static void test_seqpacket_invalid_rec_buffer_client(c= onst struct test_opts *opt memset(buf1, BUF_PATTERN_1, buf_size); memset(buf2, BUF_PATTERN_2, buf_size); =20 - if (send(fd, buf1, buf_size, 0) !=3D buf_size) { - perror("send failed"); - exit(EXIT_FAILURE); - } + send_buf(fd, buf1, buf_size, 0, buf_size); =20 - if (send(fd, buf2, buf_size, 0) !=3D buf_size) { - perror("send failed"); - exit(EXIT_FAILURE); - } + send_buf(fd, buf2, buf_size, 0, buf_size); =20 close(fd); } @@ -972,7 +929,6 @@ static void test_inv_buf_client(const struct test_opts = *opts, bool stream) static void test_inv_buf_server(const struct test_opts *opts, bool stream) { unsigned char data[INV_BUF_TEST_DATA_LEN] =3D {0}; - ssize_t res; int fd; =20 if (stream) @@ -985,11 +941,7 @@ static void test_inv_buf_server(const struct test_opts= *opts, bool stream) exit(EXIT_FAILURE); } =20 - res =3D send(fd, data, sizeof(data), 0); - if (res !=3D sizeof(data)) { - fprintf(stderr, "unexpected send(2) result %zi\n", res); - exit(EXIT_FAILURE); - } + send_buf(fd, data, sizeof(data), 0, sizeof(data)); =20 control_writeln("SENDDONE"); =20 @@ -1023,7 +975,6 @@ static void test_seqpacket_inv_buf_server(const struct= test_opts *opts) =20 static void test_stream_virtio_skb_merge_client(const struct test_opts *op= ts) { - ssize_t res; int fd; =20 fd =3D vsock_stream_connect(opts->peer_cid, 1234); @@ -1033,22 +984,14 @@ static void test_stream_virtio_skb_merge_client(cons= t struct test_opts *opts) } =20 /* Send first skbuff. */ - res =3D send(fd, HELLO_STR, strlen(HELLO_STR), 0); - if (res !=3D strlen(HELLO_STR)) { - fprintf(stderr, "unexpected send(2) result %zi\n", res); - exit(EXIT_FAILURE); - } + send_buf(fd, HELLO_STR, strlen(HELLO_STR), 0, strlen(HELLO_STR)); =20 control_writeln("SEND0"); /* Peer reads part of first skbuff. */ control_expectln("REPLY0"); =20 /* Send second skbuff, it will be appended to the first. */ - res =3D send(fd, WORLD_STR, strlen(WORLD_STR), 0); - if (res !=3D strlen(WORLD_STR)) { - fprintf(stderr, "unexpected send(2) result %zi\n", res); - exit(EXIT_FAILURE); - } + send_buf(fd, WORLD_STR, strlen(WORLD_STR), 0, strlen(WORLD_STR)); =20 control_writeln("SEND1"); /* Peer reads merged skbuff packet. */ --=20 2.41.0 From nobody Thu Feb 12 06:33:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE0DDEE6457 for ; Fri, 15 Sep 2023 12:16:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234795AbjIOMQb (ORCPT ); Fri, 15 Sep 2023 08:16:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234777AbjIOMQ1 (ORCPT ); Fri, 15 Sep 2023 08:16:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2DD9F2715 for ; Fri, 15 Sep 2023 05:15:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694780129; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4IzPTIpBjDzBGvsyRo0gBVOG837dBZudcrNhelcBAVs=; b=dfvMqVfyvQ0j6+M3Q7eswFMUxV/FXBnVNAmiIBTTC/soC7XJegtOsAmbNCV6rTbYL7crDN WysCkwFDGwOvKVYeGn1HzZtU0mUl1+t38bJZXE/2PmXN/CECsAALpVGwLt4BwlCJK/QbnZ Ukq+92JbGeLiyuiFNOk2EXvC0xtCr2U= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-uq9ypopcOkSRoyDePEM61A-1; Fri, 15 Sep 2023 08:15:26 -0400 X-MC-Unique: uq9ypopcOkSRoyDePEM61A-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-3f5df65f9f4so15413495e9.2 for ; Fri, 15 Sep 2023 05:15:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694780125; x=1695384925; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4IzPTIpBjDzBGvsyRo0gBVOG837dBZudcrNhelcBAVs=; b=TrsViEo0cxSrsQzW1qY9GTyiYzXlI0smWdUziSPvU8V3HpwVbOu4RqDhvjo0LL9F6E 5s/MK9duewX7tn9AWdzpdevce10sP/DFuscjESSCG5tgY+fbqOocrWp2ERg4m2ZlN5YN p7Iy14uoPDe3sq3V6lFn5b0rTAYxrKO9EUXsY0fLv0bdly7gBpL5B2BMrRfEJ3gysTap pIjjAA2bKDDkJDzkk7Ks4EJ46a23O/P/NkaAppp8yYol0YuTl1H1PQeID2zG0o4Glipa SfVwM70GQv/2p0Gmpa/C9l3krqqF0pB8NXbtfmoQfm58AiV8Jzsvn6kvt7OqJKmNWFMc 9wfA== X-Gm-Message-State: AOJu0YyVBJbMAMxd7rfhKr0ARjqbA21MDfEbxPXZZC+ERFlk9JFZKbLm 2uAzolly5FPi+mHCB2dcZbynACiXd7GZyNGFD1W8M9DkbQnIyw/isA7rZPLZl9NdcGxxCahkeFX bnOvg93xQx0drzKARtfLbV31x X-Received: by 2002:adf:cd08:0:b0:31f:afeb:4e71 with SMTP id w8-20020adfcd08000000b0031fafeb4e71mr1327904wrm.48.1694780124841; Fri, 15 Sep 2023 05:15:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEAM+qT8oGEefSDmkyANZPTMrHB/rc6Va9KYPc9DtRjeZCpejNAvp5rpxARReDs63NX0XPsvQ== X-Received: by 2002:adf:cd08:0:b0:31f:afeb:4e71 with SMTP id w8-20020adfcd08000000b0031fafeb4e71mr1327892wrm.48.1694780124604; Fri, 15 Sep 2023 05:15:24 -0700 (PDT) Received: from step1.lan ([46.222.72.72]) by smtp.gmail.com with ESMTPSA id s1-20020a5d4ec1000000b0031fbbe347e1sm4287767wrv.65.2023.09.15.05.15.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 05:15:23 -0700 (PDT) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Stefano Garzarella , Arseniy Krasnov , virtualization@lists.linux-foundation.org, oxffffaa@gmail.com, Bobby Eshleman Subject: [PATCH net-next 5/5] vsock/test: track bytes in MSG_PEEK test for SOCK_SEQPACKET Date: Fri, 15 Sep 2023 14:14:52 +0200 Message-ID: <20230915121452.87192-6-sgarzare@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230915121452.87192-1-sgarzare@redhat.com> References: <20230915121452.87192-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The test was a bit complicated to read. Added variables to keep track of the bytes read and to be read in each step. Also some comments. The test is unchanged. Signed-off-by: Stefano Garzarella Reviewed-by: Arseniy Krasnov --- tools/testing/vsock/vsock_test.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_t= est.c index b18acbaf92e2..5743dcae2350 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -1002,6 +1002,7 @@ static void test_stream_virtio_skb_merge_client(const= struct test_opts *opts) =20 static void test_stream_virtio_skb_merge_server(const struct test_opts *op= ts) { + size_t read =3D 0, to_read; unsigned char buf[64]; int fd; =20 @@ -1014,14 +1015,21 @@ static void test_stream_virtio_skb_merge_server(con= st struct test_opts *opts) control_expectln("SEND0"); =20 /* Read skbuff partially. */ - recv_buf(fd, buf, 2, 0, 2); + to_read =3D 2; + recv_buf(fd, buf + read, to_read, 0, to_read); + read +=3D to_read; =20 control_writeln("REPLY0"); control_expectln("SEND1"); =20 - recv_buf(fd, buf + 2, 8, 0, 8); + /* Read the rest of both buffers */ + to_read =3D strlen(HELLO_STR WORLD_STR) - read; + recv_buf(fd, buf + read, to_read, 0, to_read); + read +=3D to_read; =20 - recv_buf(fd, buf, sizeof(buf) - 8 - 2, MSG_DONTWAIT, -EAGAIN); + /* No more bytes should be there */ + to_read =3D sizeof(buf) - read; + recv_buf(fd, buf + read, to_read, MSG_DONTWAIT, -EAGAIN); =20 if (memcmp(buf, HELLO_STR WORLD_STR, strlen(HELLO_STR WORLD_STR))) { fprintf(stderr, "pattern mismatch\n"); --=20 2.41.0