All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xie Ziyao <xieziyao@huawei.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] syscalls/sendfile: Delete unnecessary loop logic in do_child()
Date: Tue, 20 Apr 2021 21:38:39 +0800	[thread overview]
Message-ID: <20210420133839.145408-1-xieziyao@huawei.com> (raw)

We don't need do_child() loop 'TEST_LOOPING(lc)' times to invoke the
recvfrom() function, whitch makes no sense. If we run with "-i large number",
this will slow down the program.

Signed-off-by: Xie Ziyao <xieziyao@huawei.com>
---
 testcases/kernel/syscalls/sendfile/sendfile02.c | 14 ++++++++------
 testcases/kernel/syscalls/sendfile/sendfile04.c | 14 ++++++++------
 testcases/kernel/syscalls/sendfile/sendfile05.c | 14 ++++++++------
 3 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/testcases/kernel/syscalls/sendfile/sendfile02.c b/testcases/kernel/syscalls/sendfile/sendfile02.c
index e5f115146..acd7a5a50 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile02.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile02.c
@@ -156,15 +156,17 @@ void do_sendfile(OFF_T offset, int i)
  */
 void do_child(void)
 {
-	int lc;
-	socklen_t length;
 	char rbuf[4096];
+	ssize_t ret = 0;
+	socklen_t length = sizeof(sin1);

-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		length = sizeof(sin1);
-		recvfrom(sockfd, rbuf, 4096, 0, (struct sockaddr *)&sin1,
-			 &length);
+	ret = recvfrom(sockfd, rbuf, 4096, 0, (struct sockaddr *)&sin1, &length);
+	if (ret < 0) {
+		tst_resm(TFAIL, "child process recvfrom failed: %s\n",
+			 strerror(errno));
+		exit(1);
 	}
+
 	exit(0);
 }

diff --git a/testcases/kernel/syscalls/sendfile/sendfile04.c b/testcases/kernel/syscalls/sendfile/sendfile04.c
index 0f315abb0..322e2b58e 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile04.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile04.c
@@ -153,15 +153,17 @@ void do_sendfile(int prot, int pass_unmapped_buffer)
  */
 void do_child(void)
 {
-	int lc;
-	socklen_t length;
 	char rbuf[4096];
+	ssize_t ret = 0;
+	socklen_t length = sizeof(sin1);

-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		length = sizeof(sin1);
-		recvfrom(sockfd, rbuf, 4096, 0, (struct sockaddr *)&sin1,
-			 &length);
+	ret = recvfrom(sockfd, rbuf, 4096, 0, (struct sockaddr *)&sin1, &length);
+	if (ret < 0) {
+		tst_resm(TFAIL, "child process recvfrom failed: %s\n",
+			 strerror(errno));
+		exit(1);
 	}
+
 	exit(0);
 }

diff --git a/testcases/kernel/syscalls/sendfile/sendfile05.c b/testcases/kernel/syscalls/sendfile/sendfile05.c
index 0f268ceb3..a8e76d91d 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile05.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile05.c
@@ -118,15 +118,17 @@ void do_sendfile(void)
  */
 void do_child(void)
 {
-	int lc;
-	socklen_t length;
 	char rbuf[4096];
+	ssize_t ret = 0;
+	socklen_t length = sizeof(sin1);

-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		length = sizeof(sin1);
-		recvfrom(sockfd, rbuf, 4096, 0, (struct sockaddr *)&sin1,
-			 &length);
+	ret = recvfrom(sockfd, rbuf, 4096, 0, (struct sockaddr *)&sin1, &length);
+	if (ret < 0) {
+		tst_resm(TFAIL, "child process recvfrom failed: %s\n",
+			 strerror(errno));
+		exit(1);
 	}
+
 	exit(0);
 }

--
2.17.1


             reply	other threads:[~2021-04-20 13:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-20 13:38 Xie Ziyao [this message]
2021-04-21 12:35 ` [LTP] [PATCH] syscalls/sendfile: Delete unnecessary loop logic in do_child() Cyril Hrubis
2021-04-22  7:13   ` xieziyao
2021-04-23 10:14   ` xieziyao
2021-04-23 13:32     ` Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210420133839.145408-1-xieziyao@huawei.com \
    --to=xieziyao@huawei.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.