[LTP] [PATCH v3 1/2] splice02: Generate input in C
Cyril Hrubis
chrubis@suse.cz
Thu Apr 15 15:46:34 CEST 2021
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
More information about the ltp
mailing list