syscalls/splice04: add test for splice() from pipe to pipe
PATCH v3 1/1 syscalls/splice04: add test for splice() from pipe to pipe
From: Boyang Xue <[email protected]>
This test case covers pipe to pipe splice operation, which was introduced in kernel commit 7c77f0b3f920 ("splice: implement pipe to pipe splicing").
--- runtest/syscalls | 1 + testcases/kernel/syscalls/splice/splice04.c | 99 +++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 testcases/kernel/syscalls/splice/splice04.c
runtest/syscalls +1 -0
@@ -1222,6 +1222,7 @@ sockioctl01 sockioctl01 splice01 splice01 splice02 seq 1 20000 | splice02 splice02-temp splice03 splice03 +splice04 splice04 tee01 tee01 tee02 tee02
testcases/kernel/syscalls/splice/splice04.c new file +99 -0
99 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 1/1 syscalls/splice04: add test for splice() from pipe to pipe
Hi!
testcases/kernel/syscalls/splice/splice04.c line 53
Quoted 7 lines
testcases/kernel/syscalls/splice/splice04.c new file +7
-0+static void setup (void ) +{ +int i; + +if (tst_parse_int (str_len_data, &num_len_data,1 ,MAX_DATA_LEN )) +tst_brk (TBROK ,"Invalid length of data: '%s'" , str_len_data); +tst_res (TINFO ,"splice size = %d\n" , num_len_data);
^
The \n should be removed as it adds a second newline after the message.
Quoted 11 lines
testcases/kernel/syscalls/splice/splice04.c new file +11
-0+ arr_in =SAFE_MALLOC (num_len_data); + arr_out =SAFE_MALLOC (num_len_data); +for (i =0 ; i < num_len_data; i++) + arr_in[i] = i &0xff ; +} + +static void cleanup (void ) +{ +free (arr_in); +free (arr_out); +}
testcases/kernel/syscalls/splice/splice04.c line 74
Quoted 10 lines
testcases/kernel/syscalls/splice/splice04.c new file +10
-0+ +static void pipe_pipe (void ) +{ +int pp1[2 ], pp2[2 ], i; + +SAFE_PIPE (pp1); +SAFE_PIPE (pp2); +SAFE_WRITE (1 , pp1[1 ], arr_in, num_len_data); +if (splice (pp1[0 ],NULL , pp2[1 ],NULL , num_len_data,SPLICE_F_MOVE ) != num_len_data) +tst_res (TFAIL ,"incomplete splice operation." );
We should print the return value from the splice and errno as well and also close the fds and return.
ret = splice(...)
if (ret != num_len_data) {
tst_res(TFAIL | TERRNO, "Splice returned %i", ret);
goto exit;
}testcases/kernel/syscalls/splice/splice04.c line 84
Quoted 10 lines
testcases/kernel/syscalls/splice/splice04.c new file +10
-0+SAFE_READ (1 , pp2[0 ], arr_out, num_len_data); + +SAFE_CLOSE (pp1[1 ]); +SAFE_CLOSE (pp1[0 ]); +SAFE_CLOSE (pp2[1 ]); +SAFE_CLOSE (pp2[0 ]); + +for (i =0 ; i < num_len_data; i++) { +if (arr_in[i] != arr_out[i]) { +tst_res (TFAIL ,"splice(2) from pipe to pipe fails." );
We may print the actual and expected value, something as:
tst_res(TFAIL, "wrong data at %i have %i expected %i",
i, arr_out[i], arr_in[i]);
Review
Quoted 1 line
(quoted diff) +1
-0+ return;
And do the goto exit; to close the fds.
testcases/kernel/syscalls/splice/splice04.c line 89
Quoted 4 lines
testcases/kernel/syscalls/splice/splice04.c new file +4
-0+ } + } +tst_res (TPASS ,"splice(2) from pipe to pipe run pass." ); +return ;
^
The return here is useless
Here we should add the exit label
exit:
SAFE_CLOSE(pp1[1]); SAFE_CLOSE(pp1[0]); SAFE_CLOSE(pp2[1]); SAFE_CLOSE(pp2[0]);
Quoted 16 lines
testcases/kernel/syscalls/splice/splice04.c new file +10
-0+} + +static struct tst_test test = { + .tid ="splice04" , + .test_all = pipe_pipe, + .setup = setup, + .cleanup = cleanup, + .options = options, + .min_kver ="2.6.31" +};Signature · 5 lines
1.8.3.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/1 syscalls/splice04: add test for splice() from pipe to pipe
In reply to [email protected]Hi!
testcases/kernel/syscalls/splice/splice04.c line 35
Quoted 3 lines
testcases/kernel/syscalls/splice/splice04.c new file +3
-0+static void setup (void ); +static void cleanup (void ); +static void pipe_pipe (void );
Also these function prototypes are useless as well.
Signature · 2 lines
Cyril Hrubis [email protected]