public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 1/2] splice02: Generate input in C
Date: Thu, 15 Apr 2021 15:46:34 +0200	[thread overview]
Message-ID: <YHhDurTlljhXAKL9@yuki> (raw)
In-Reply-To: <20210413043844.5612-1-pvorel@suse.cz>

Hi!
> ---
> changes v2->v3:
> * fix bugs found by Cyril (use !num_writes, !SAFE_FORK(), break if !TST_RET)
> 
> BTW I'm still not sure if break on !TST_RET is needed, but it does not
> harm. If you really like it, I can use while (!TST_RET).

I meant that we could simplify the test with:

diff --git a/testcases/kernel/syscalls/splice/splice02.c b/testcases/kernel/syscalls/splice/splice02.c
index fd71f2995..1b566a2f4 100644
--- a/testcases/kernel/syscalls/splice/splice02.c
+++ b/testcases/kernel/syscalls/splice/splice02.c
@@ -54,18 +54,13 @@ static void do_child(void)
 
 	fd = SAFE_OPEN(TEST_FILENAME, O_WRONLY | O_CREAT | O_TRUNC, 0644);
 
-	while (to_write > 0) {
+	do {
 		TEST(splice(STDIN_FILENO, NULL, fd, NULL, WRITE_SIZE, 0));
-		tst_res(TINFO, "splice() wrote %ld, remaining %d", TST_RET, to_write);
 		if (TST_RET < 0) {
 			tst_res(TFAIL | TTERRNO, "splice failed");
 			goto cleanup;
-		} else if (!TST_RET) {
-			break;
-		} else {
-			to_write -= TST_RET;
 		}
-	}
+	} while (TST_RET > 0);
 
 	stat(TEST_FILENAME, &st);
 	if (st.st_size != num_writes) {
@@ -100,10 +95,10 @@ static void run(void)
 	for (i = 0; i < num_writes; i++)
 		SAFE_WRITE(1, pipe_fd[1], "x", 1);
 
-	tst_reap_children();
-
 	SAFE_CLOSE(pipe_fd[0]);
 	SAFE_CLOSE(pipe_fd[1]);
+
+	tst_reap_children();
 }
 
 static struct tst_test test = {


If you close the pipe in the parent before reaping children the last
splice() will return 0 and exit the loop. No need to count anything.

-- 
Cyril Hrubis
chrubis@suse.cz

  parent reply	other threads:[~2021-04-15 13:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-13  4:38 [LTP] [PATCH v3 1/2] splice02: Generate input in C Petr Vorel
2021-04-13  4:38 ` [LTP] [PATCH v3 2/2] commands: Add shell pipe test Petr Vorel
2021-04-15 13:46 ` Cyril Hrubis [this message]
2021-04-15 14:11   ` [LTP] [PATCH v3 1/2] splice02: Generate input in C Petr Vorel
2021-04-15 14:27     ` Petr Vorel
2021-04-16 12:32       ` Cyril Hrubis
2021-04-16 13:10         ` Petr Vorel

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=YHhDurTlljhXAKL9@yuki \
    --to=chrubis@suse.cz \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox