splice02: Generate input in C
PATCH v3 1/2 splice02: Generate input in C
instead relying on shell piping data into it.
Found on SLES JeOS (https://progress.opensuse.org/issues/77260).
Also add metadata docs.
---
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).
Kind regards,
Petr
runtest/smoketest | 2 +- runtest/syscalls | 2 +- testcases/kernel/syscalls/splice/splice02.c | 104 +++++++++++++++++--- 3 files changed, 94 insertions(+), 14 deletions(-)
runtest/smoketest +1 -1
@@ -11,5 +11,5 @@ symlink01 symlink01 stat04 symlink01 -T stat04 utime01A symlink01 -T utime01 rename01A symlink01 -T rename01 -splice02 seq 1 20 | splice02 +splice02 splice02 -n 20 route4-change-dst route-change-dst.sh
runtest/syscalls +1 -1
@@ -1451,7 +1451,7 @@ socketpair02 socketpair02 sockioctl01 sockioctl01 splice01 splice01 -splice02 seq 1 20000 | splice02 +splice02 splice02 splice03 splice03 splice04 splice04 splice05 splice05
testcases/kernel/syscalls/splice/splice02.c +92 -12
132 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 2/2 commands: Add shell pipe test
This adds basic shell pipe testing, which was removed from splice02 in 85cebe238 ("splice02: Generate input in C").
---
The same as v2.
runtest/commands | 1 + runtest/smoketest | 1 + testcases/commands/shell/shell_pipe01.sh | 17 +++++++++++++++++ 3 files changed, 19 insertions(+) create mode 100755 testcases/commands/shell/shell_pipe01.sh
runtest/commands +1 -0
@@ -41,3 +41,4 @@ gdb01_sh gdb01.sh unshare01_sh unshare01.sh sysctl01_sh sysctl01.sh sysctl02_sh sysctl02.sh +shell_test01 echo "SUCCESS" | shell_pipe01.sh
runtest/smoketest +1 -0
@@ -13,3 +13,4 @@ utime01A symlink01 -T utime01 rename01A symlink01 -T rename01 splice02 splice02 -n 20 route4-change-dst route-change-dst.sh +shell_test01 echo "SUCCESS" | shell_pipe01.sh
testcases/commands/shell/shell_pipe01.sh new file +17 -0
@@ -0,0 +1,17 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2021 Petr Vorel <[email protected]> + +TST_TESTFUNC=do_test + +. tst_test.sh + +do_test() +{ + tst_res TINFO "expecting SUCCESS string passed from stdin" + + read line + EXPECT_PASS [ "$line" = "SUCCESS" ] +} + +tst_run
Signature · 1 line
2.31.1
PATCH v3 1/2 splice02: Generate input in C
In reply to Petr VorelHi!
Quoted 6 lines
---
changesv2->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:
testcases/kernel/syscalls/splice/splice02.c +4 -9
@@ -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.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/2 splice02: Generate input in C
Hi Cyril,
Quoted 42 lines
I meant that we could simplify the test with:
testcases/kernel/syscalls/splice/splice02.c +4
-9@@ -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 = {
Quoted 2 lines
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.
LGTM, going to merge it with these changes (+ cleanup to_write) and your Reviewed-by: tags.
Thanks a lot!
Kind regards,
Petr
PATCH v3 1/2 splice02: Generate input in C
Hi Cyril,
Quoted 3 lines
LGTM, going to merge it with these changes (+ cleanup
to_write) and your Reviewed-by: tags.
Thanks a lot!
Maybe one more change: INT_MAX is a bit too much, it timeouts. I'll use 262144 as max allowed -n (the default on intel - 2x max pipe size).
Kind regards,
Petr
PATCH v3 1/2 splice02: Generate input in C
Hi!
Quoted 6 lines
Quoted 3 lines
LGTM, going to merge it with these changes (+ cleanup
to_write) and your Reviewed-by: tags.
Thanks a lot!Maybe one more change:
INT_MAXis a bit too much, it timeouts. I'll use 262144 as max allowed -n (the default on intel - 2x max pipe size).
I guess that the main problem here is that we write one character at a time, which means that we spend most of the time in syscall handler code rather than copying the data. It may work much better if we change the code to write 512 bytes at a time. I.e. something as:
#define BUFSIZE 512
char buf[BUFSIZE];
memset(buf, 'a', BUFSIZE);
while (to_write > 0) {
size_t size = to_write > BUFSIZE ? BUFSIZE : to_write;
...
to_write -= written;
}Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/2 splice02: Generate input in C
Hi Cyril,
...
Quoted 7 lines
Quoted 2 lines
Maybe one more change:
INT_MAXis a bit too much, it timeouts. I'll use 262144 as max allowed -n (the default on intel - 2x max pipe size).I guess that the main problem here is that we write one character at a time, which means that we spend most of the time in syscall handler code rather than copying the data. It may work much better if we change the code to write 512 bytes at a time. I.e. something as:
Sounds very reasonable, thx! I'll send v4.
Kind regards,
Petr
Quoted 13 lines
#define BUFSIZE 512
char buf[BUFSIZE];
memset(buf, 'a', BUFSIZE);
while (to_write > 0) {
size_t size = to_write > BUFSIZE ? BUFSIZE : to_write;
...
to_write -= written;
}