Get rid of few more useless sleep() calls
This patchset gets rid of a few useless sleeps speeding up the syscalls run by another ~17s. It may not seem a lot, but if we combine all the possible speedups we may save up to five minutes which is ~30% of the syscall testsuite runtime for me.
RFC PATCH 1/6 exit02: Rewrite to new library
We get rid of the ridiculous sleep(2) in the test as a side effect.
--- testcases/kernel/syscalls/exit/exit02.c | 249 ++++++++------------------------ 1 file changed, 60 insertions(+), 189 deletions(-)
testcases/kernel/syscalls/exit/exit02.c +60 -189
@@ -1,212 +1,83 @@/* +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2018 Cyril Hrubis <[email protected]> * -* Copyright (c) International Business Machines Corp., 2001 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. * -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* -* NAME -* exit02.c -* -* DESCRIPTION -* Check that exit flushes output file buffers and closes files upon -* exitting -* -* ALGORITHM -* Fork a process that creates a file and writes a few bytes, and -* calls exit WITHOUT calling close(). The parent then reads the -* file. If everything that was written is present in the file, then -* the test passes. -* -* USAGE -* exit02 -* -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* None +* Fork a process that creates a file and writes a few bytes, and +* calls exit WITHOUT calling close(). The parent then reads the +* file. If everything that was written is present in the file, then +* the test passes. */ -#include <sys/types.h> -#include <sys/wait.h> -#include <sys/stat.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <signal.h> -#include <fcntl.h> -#include <string.h> -#include "test.h" - -void cleanup (void ); -void setup (void ); - -char *TCID ="exit02" ; -int TST_TOTAL =1 ; - -#define READ 0 -#define WRITE 1 -#define MODE 0666 - -char filen[40 ]; - -int main (int ac,char **av) + +#include <stdlib.h> +#include "tst_test.h" + +#define FNAME "test_file" + +static void child_write (void ) { -int pid, npid, sig, nsig, exno, nexno, status; -int filed; -char wbuf[BUFSIZ ], rbuf[BUFSIZ ]; -int len, rlen; -int rval =0 ; -int lc; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); - -setup ();/* global setup for test */ - -/* -* The following loop checks looping state if -i option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { -/* -* reset tst_count in case we are looping. -*/ - tst_count =0 ; - -strcpy (wbuf,"abcd" ); - len =strlen (wbuf); - - exno = sig =0 ; - -if ((pid =FORK_OR_VFORK ()) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"fork() failed" ); - -if (pid ==0 ) {/* child */ -sleep (1 ); -if ((filed =creat (filen,MODE )) ==-1 ) { -tst_resm (TINFO ,"creat error: unable to" -"open output file" ); -exit (2 ); - } -if (write (filed, wbuf, len) != len) { -tst_resm (TINFO ,"write error" ); -exit (2 ); - } -exit (exno); - }else {/* parent */ - npid =wait (&status); - -if (npid != pid) { -tst_resm (TFAIL ,"wait error: " -"unexpected pid returned" ); - rval =1 ; - } - - nsig = status %256 ; - -/* -* to check if the core dump bit has been -* set, bit # 7 -*/ -if (nsig >=128 ) - nsig = nsig -128 ; - -/* -* nsig is the signal number returned by -* wait -*/ -if (nsig != sig) { -tst_resm (TFAIL ,"wait error: unexpected " -"signal returned %d" , nsig); - rval =1 ; - } - -/* -* nexno is the exit number returned by wait -*/ - nexno = status /256 ; -if (nexno != exno) { -tst_resm (TFAIL ,"wait error: unexpected exit " -"number %d" , nexno); - rval =1 ; - } - -sleep (2 );/* let child's exit close opened file */ - - filed =open (filen,O_RDONLY ,READ ); -if (filed ==-1 ) { -tst_resm (TFAIL ,"open error: " -"unable to open input file" ); - rval =1 ; - }else { - rlen =read (filed, rbuf, len); -if (len != rlen) { -tst_resm (TFAIL ,"exit error: file " -"buffer was not flushed" ); - rval =1 ; - }else if (strncmp (rbuf, wbuf, len) !=0 ) { -tst_resm (TFAIL ,"exit error: file " -"buffer was not flushed" ); - rval =1 ; - } - } -close (filed); -unlink (filen); - } -if (!rval) { -tst_resm (TPASS ,"exit() test PASSED" ); - } - } -cleanup (); -tst_exit (); +int fd; + + fd =SAFE_CREAT (FNAME ,0666 ); +SAFE_WRITE (1 , fd,FNAME ,sizeof (FNAME )); +exit (0 ); } -/* -* setup() - perform all ONE TIME setup for this test -*/ -void setup (void ) +static void check_file (void ) { +int fd, len; +char buf[256 ]; -tst_sig (FORK ,DEF_HANDLER , cleanup); + fd =SAFE_OPEN (FNAME ,O_RDONLY ); + len =SAFE_READ (0 , fd, buf,sizeof (buf)); -umask (0 ); +if (len !=sizeof (FNAME )) { +tst_res (TFAIL ,"Wrong length %i expected %zu" , len,sizeof (buf)); +return ; + } -TEST_PAUSE ; +if (memcmp (buf,FNAME ,sizeof (FNAME ))) { +tst_res (TFAIL ,"Wrong data read back" ); +return ; + } -tst_tmpdir (); +SAFE_CLOSE (fd); -sprintf (filen,"tfile_%d" ,getpid ()); +tst_res (TPASS ,"File written by child read back correctly" ); } -/* -* cleanup() - performs all ONE TIME cleanup for this test at completion or -* premature exit. -*/ -void cleanup (void ) +static void run (void ) { +int pid; -/* -* Remove tmp dir and all files in it -*/ -tst_rmdir (); + pid =SAFE_FORK (); +if (!pid) +child_write (); -/* -* exit with return code appropriate for results -*/ +tst_reap_children (); +check_file (); + +SAFE_UNLINK (FNAME ); } + +static struct tst_test test = { + .needs_tmpdir =1 , + .forks_child =1 , + .test_all = run, +};
Signature · 1 line
2.13.6
RFC PATCH 1/6 exit02: Rewrite to new library
----- Original Message -----
Quoted 3 lines
We get rid of the ridiculous sleep(2) in the test as a side effect.
Signed-off-by Cyril Hrubis <[email protected]>
ACK to 3/6 4/6 5/6 patches.
Just a small observation here, subject doesn't have "syscalls/" as the rest of series.
One more note below.
Quoted 233 lines
--- testcases/kernel/syscalls/exit/exit02.c | 249 ++++++++------------------------ 1 file changed, 60 insertions(+), 189 deletions(-)testcases/kernel/syscalls/exit/exit02.c +11
-13@@ -1,212 +1,83 @@/* +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2018 Cyril Hrubis <[email protected]> * -* Copyright (c) International Business Machines Corp., 2001 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. * -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/testcases/kernel/syscalls/exit/exit02.c +21
-160-/* -* NAME -* exit02.c -* -* DESCRIPTION -* Check that exit flushes output file buffers and closes files upon -* exitting -* -* ALGORITHM -* Fork a process that creates a file and writes a few bytes, and -* calls exit WITHOUT calling close(). The parent then reads the -* file. If everything that was written is present in the file, then -* the test passes. -* -* USAGE -* exit02 -* -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* None +* Fork a process that creates a file and writes a few bytes, and +* calls exit WITHOUT calling close(). The parent then reads the +* file. If everything that was written is present in the file, then +* the test passes. */ -#include <sys/types.h> -#include <sys/wait.h> -#include <sys/stat.h> -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <signal.h> -#include <fcntl.h> -#include <string.h> -#include "test.h" - -void cleanup (void ); -void setup (void ); - -char *TCID ="exit02" ; -int TST_TOTAL =1 ; - -#define READ 0 -#define WRITE 1 -#define MODE 0666 - -char filen[40 ]; - -int main (int ac,char **av) + +#include <stdlib.h> +#include "tst_test.h" + +#define FNAME "test_file" + +static void child_write (void ) { -int pid, npid, sig, nsig, exno, nexno, status; -int filed; -char wbuf[BUFSIZ ], rbuf[BUFSIZ ]; -int len, rlen; -int rval =0 ; -int lc; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); - -setup ();/* global setup for test */ - -/* -* The following loop checks looping state if -i option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { -/* -* reset tst_count in case we are looping. -*/ - tst_count =0 ; - -strcpy (wbuf,"abcd" ); - len =strlen (wbuf); - - exno = sig =0 ; - -if ((pid =FORK_OR_VFORK ()) ==-1 ) -tst_brkm (TBROK |TERRNO , cleanup,"fork() failed" ); - -if (pid ==0 ) {/* child */ -sleep (1 ); -if ((filed =creat (filen,MODE )) ==-1 ) { -tst_resm (TINFO ,"creat error: unable to" -"open output file" ); -exit (2 ); - } -if (write (filed, wbuf, len) != len) { -tst_resm (TINFO ,"write error" ); -exit (2 ); - } -exit (exno); - }else {/* parent */ - npid =wait (&status); - -if (npid != pid) { -tst_resm (TFAIL ,"wait error: " -"unexpected pid returned" ); - rval =1 ; - } - - nsig = status %256 ; - -/* -* to check if the core dump bit has been -* set, bit # 7 -*/ -if (nsig >=128 ) - nsig = nsig -128 ; - -/* -* nsig is the signal number returned by -* wait -*/ -if (nsig != sig) { -tst_resm (TFAIL ,"wait error: unexpected " -"signal returned %d" , nsig); - rval =1 ; - } - -/* -* nexno is the exit number returned by wait -*/ - nexno = status /256 ; -if (nexno != exno) { -tst_resm (TFAIL ,"wait error: unexpected exit " -"number %d" , nexno); - rval =1 ; - } - -sleep (2 );/* let child's exit close opened file */ - - filed =open (filen,O_RDONLY ,READ ); -if (filed ==-1 ) { -tst_resm (TFAIL ,"open error: " -"unable to open input file" ); - rval =1 ; - }else { - rlen =read (filed, rbuf, len); -if (len != rlen) { -tst_resm (TFAIL ,"exit error: file " -"buffer was not flushed" ); - rval =1 ; - }else if (strncmp (rbuf, wbuf, len) !=0 ) { -tst_resm (TFAIL ,"exit error: file " -"buffer was not flushed" ); - rval =1 ; - } - } -close (filed); -unlink (filen); - } -if (!rval) { -tst_resm (TPASS ,"exit() test PASSED" ); - } - } -cleanup (); -tst_exit (); +int fd; + + fd =SAFE_CREAT (FNAME ,0666 ); +SAFE_WRITE (1 , fd,FNAME ,sizeof (FNAME )); +exit (0 ); } -/* -* setup() - perform all ONE TIME setup for this test -*/ -void setup (void ) +static void check_file (void ) { +int fd, len; +char buf[256 ]; -tst_sig (FORK ,DEF_HANDLER , cleanup); + fd =SAFE_OPEN (FNAME ,O_RDONLY ); + len =SAFE_READ (0 , fd, buf,sizeof (buf));
testcases/kernel/syscalls/exit/exit02.c line 55
Quoted 10 lines
testcases/kernel/syscalls/exit/exit02.c +6
-2-umask (0 ); +if (len !=sizeof (FNAME )) { +tst_res (TFAIL ,"Wrong length %i expected %zu" , len,sizeof (buf)); +return ; + } -TEST_PAUSE ; +if (memcmp (buf,FNAME ,sizeof (FNAME ))) { +tst_res (TFAIL ,"Wrong data read back" );
We don't close fd here, but things are already going south, so it's not that big deal.
ACK
Regards,
Jan
Quoted 49 lines
testcases/kernel/syscalls/exit/exit02.c +19
-15+return ; + } -tst_tmpdir (); +SAFE_CLOSE (fd); -sprintf (filen,"tfile_%d" ,getpid ()); +tst_res (TPASS ,"File written by child read back correctly" ); } -/* -* cleanup() - performs all ONE TIME cleanup for this test at completion or -* premature exit. -*/ -void cleanup (void ) +static void run (void ) { +int pid; -/* -* Remove tmp dir and all files in it -*/ -tst_rmdir (); + pid =SAFE_FORK (); +if (!pid) +child_write (); -/* -* exit with return code appropriate for results -*/ +tst_reap_children (); +check_file (); + +SAFE_UNLINK (FNAME ); } + +static struct tst_test test = { + .needs_tmpdir =1 , + .forks_child =1 , + .test_all = run, +}; --2.13.6
--
Mailing list info: https://lists.linux.it/listinfo/ltp
RFC PATCH 2/6 syscalls/pipe11: Rewrite to new library.
In reply to Cyril Hrubis+ Check that the buffer read in the child is correct as well
+ We got rid of sleep(5) as a side effect
--- testcases/kernel/syscalls/pipe/pipe11.c | 289 +++++++++----------------------- 1 file changed, 77 insertions(+), 212 deletions(-)
testcases/kernel/syscalls/pipe/pipe11.c +77 -212
@@ -1,246 +1,111 @@/* +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2018 Cyril Hrubis <[email protected]> * -* Copyright (c) International Business Machines Corp., 2001 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. * -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* -* NAME -* pipe11.c -* -* DESCRIPTION -* Check if many children can read what is written to a pipe by the -* parent. +* Check if many children can read what is written to a pipe by the parent. * * ALGORITHM -* 1. Open a pipe and write to it -* 2. Fork a large number of children -* 3. Have the children read the pipe and check how many characters -* each got -* -* USAGE: <for command-line> -* pipe11 [-c n] [-f] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -f : Turn off functionality Testing. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* None +* For a different nchilds number: +* 1. Open a pipe and write nchilds * (PIPE_BUF/nchilds) bytes into it +* 2. Fork nchilds children +* 3. Each child reads PIPE_BUF/nchilds characters and checks that the +* bytes read are correct */ -#include <sys/types.h> -#include <sys/wait.h> -#include <errno.h> -#include <stdio.h> -#include <limits.h> -#include "test.h" - -char *TCID ="pipe11" ; -int TST_TOTAL =1 ; - -void do_child (void ); -void do_child_uclinux (void ); -void setup (void ); -void cleanup (void ); - -#define NUMCHILD 50 -#define NCPERCHILD 50 -char rawchars[] = -"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890" ; -int kidid; -int numchild;/* no of children to fork */ -int ncperchild;/* no of chars child should read */ -int szcharbuf;/* size of char buf */ -int pipewrcnt;/* chars written to pipe */ -char *wrbuf, *rdbuf; -int fd[2 ];/* fds for pipe read/write */ - -ssize_t do_read (int fd,void *buf,size_t count) -{ -ssize_t n; - -do { - n =read (fd, buf, count); - }while (n <0 && errno ==EINTR ); +#include <stdlib.h> +#include "tst_test.h" -return n; -} +static int fd[2 ]; +static unsigned char buf[PIPE_BUF ]; +static size_t read_per_child; -int main (int ac,char **av) +void do_child (void ) { -int lc; - -int i; -int fork_ret, status; -int written;/* no of chars read and written */ - -tst_parse_opts (ac, av,NULL ,NULL ); -#ifdef UCLINUX -maybe_run_child (&do_child_uclinux,"ddddd" , &fd[0 ], &fd[1 ], &kidid, - &ncperchild, &szcharbuf); -#endif - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - -/* reset tst_count in case we are looping */ - tst_count =0 ; +size_t nread; +unsigned char rbuf[read_per_child]; +unsigned int i; -TEST (pipe (fd)); +SAFE_CLOSE (fd[1 ]); -if (TEST_RETURN !=0 ) { -tst_resm (TFAIL ,"pipe creation failed" ); -continue ; - } - - written =write (fd[1 ], wrbuf, szcharbuf); -if (written != szcharbuf) { -tst_brkm (TBROK , cleanup,"write to pipe failed" ); - } - -refork: - ++kidid; - fork_ret =FORK_OR_VFORK (); - -if (fork_ret <0 ) { -tst_brkm (TBROK , cleanup,"fork() failed" ); - } - -if ((fork_ret !=0 ) && (fork_ret !=-1 ) && (kidid < numchild)) { - goto refork; - } + nread =SAFE_READ (0 , fd[0 ], rbuf,sizeof (rbuf)); -if (fork_ret ==0 ) {/* child */ -#ifdef UCLINUX -if (self_exec (av[0 ],"ddddd" , fd[0 ], fd[1 ], kidid, - ncperchild, szcharbuf) <0 ) { -tst_brkm (TBROK , cleanup,"self_exec failed" ); - } -#else -do_child (); -#endif - } +if (nread != read_per_child) { +tst_res (TFAIL ,"Invalid read size child %i size %zu" , +getpid (), nread); +return ; + } -/* parent */ -sleep (5 ); -tst_resm (TINFO ,"There are %d children to wait for" , kidid); -for (i =1 ; i <= kidid; ++i) { -wait (&status); -if (status ==0 ) { -tst_resm (TPASS ,"child %d exited successfully" , - i); - }else { -tst_resm (TFAIL ,"child %d exited with bad " -"status" , i); - } +for (i =0 ; i < read_per_child; i++) { +if (rbuf[i] != (i %256 )) { +tst_res (TFAIL , +"Invalid byte read child %i byte %i have %i expected %i" , +getpid (), i, rbuf[i], i %256 ); +return ; } } -cleanup (); - -tst_exit (); -} - -/* -* do_child() -*/ -void do_child (void ) -{ -int nread; -if (close (fd[1 ])) { -tst_resm (TINFO ,"child %d " "could not close pipe" , kidid); -exit (0 ); - } - nread =do_read (fd[0 ], rdbuf, ncperchild); -if (nread == ncperchild) { -tst_resm (TINFO ,"child %d " "got %d chars" , kidid, nread); -exit (0 ); - }else { -tst_resm (TFAIL ,"child %d did not receive expected no of " -"characters, got %d characters" , kidid, nread); -exit (1 ); - } +tst_res (TPASS ,"Child %i read pipe buffer correctly" ,getpid ()); } -/* -* do_child_uclinux() - as above, but mallocs rdbuf first -*/ -void do_child_uclinux (void ) -{ -if ((rdbuf =malloc (szcharbuf)) ==NULL ) { -tst_brkm (TBROK , cleanup,"malloc of rdbuf failed" ); - } - -do_child (); -} +static unsigned int childs[] = { +1 , +2 , +3 , +4 , +10 , +50 +}; -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) +static void run (unsigned int tcase) { -int i; -unsigned int j; +pid_t pid; +unsigned int nchilds = childs[tcase]; + read_per_child =PIPE_BUF /nchilds; +unsigned int i, j; -tst_sig (FORK ,DEF_HANDLER , cleanup); +tst_res (TINFO ,"Reading %zu per each of %u children" , + read_per_child, nchilds); -TEST_PAUSE ; - - numchild =NUMCHILD ; - ncperchild =NCPERCHILD ; +for (i =0 ; i < nchilds; i++) { +for (j =0 ; j < read_per_child; j++) { + buf[i * read_per_child + j] = j %256 ; + } + } - kidid =0 ; +SAFE_PIPE (fd); -/* allocate read and write buffers */ - szcharbuf = numchild * ncperchild; +SAFE_WRITE (1 , fd[1 ], buf, read_per_child * nchilds); -/* make sure pipe write doesn't block */ -if (szcharbuf ==PIPE_BUF ) { -/* adjust number of characters per child */ - ncperchild = szcharbuf / numchild; - } +for (i =0 ; i < nchilds; i++) { + pid =SAFE_FORK (); -if ((wrbuf =malloc (szcharbuf)) ==NULL ) { -tst_brkm (TBROK , cleanup,"malloc failed" ); - } - -if ((rdbuf =malloc (szcharbuf)) ==NULL ) { -tst_brkm (TBROK , cleanup,"malloc of rdbuf failed" ); +if (!pid) { +do_child (); +exit (0 ); + } } -/* initialize wrbuf */ - j =0 ; -for (i =0 ; i < szcharbuf;) { - wrbuf[i++] = rawchars[j++]; -if (j >=sizeof (rawchars)) - j =0 ; - } +tst_reap_children (); } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -} +static struct tst_test test = { + .forks_child =1 , + .test = run, + .tcnt =ARRAY_SIZE (childs), +};
Signature · 1 line
2.13.6
RFC PATCH 2/6 syscalls/pipe11: Rewrite to new library.
----- Original Message -----
Quoted 317 lines
+ Check that the buffer read in the child is correct as well
+ We got rid of sleep(5) as a side effect
Signed-off-by Cyril Hrubis <[email protected]>--- testcases/kernel/syscalls/pipe/pipe11.c | 289 +++++++++----------------------- 1 file changed, 77 insertions(+), 212 deletions(-)testcases/kernel/syscalls/pipe/pipe11.c +11
-13@@ -1,246 +1,111 @@/* +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2018 Cyril Hrubis <[email protected]> * -* Copyright (c) International Business Machines Corp., 2001 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. * -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*//*
- * NAME
- *pipe11.c
- *
- * DESCRIPTION
- * Check if many children can read what is written to a pipe by the
- * parent.
+ * Check if many children can read what is written to a pipe by the parent. *
* ALGORITHM
- * 1. Open a pipe and write to it
- * 2. Fork a large number of children
- * 3. Have the children read the pipe and check how many characters
- * each got
- *
- * USAGE: <for command-line>
- * pipe11 [-c n] [-f] [-i n] [-I x] [-P x] [-t]- * where, -c n : Run n copies concurrently. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing.- *
- * HISTORY
- * 07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- * None
+ * For a different nchilds number:
+ * 1. Open a pipe and write nchilds * (PIPE_BUF/nchilds) bytes into it
+ * 2. Fork nchilds children
+ * 3. Each child reads PIPE_BUF/nchilds characters and checks that the
+ * bytes read are correct
*/testcases/kernel/syscalls/pipe/pipe11.c +0
-19-#include <sys/types.h> -#include <sys/wait.h> -#include <errno.h> -#include <stdio.h> -#include <limits.h> -#include "test.h" - -char *TCID ="pipe11" ; -int TST_TOTAL =1 ; - -void do_child (void ); -void do_child_uclinux (void ); -void setup (void ); -void cleanup (void ); - -#define NUMCHILD 50 -#define NCPERCHILD 50 -char rawchars[] = -"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
testcases/kernel/syscalls/pipe/pipe11.c +51
-140-int kidid; -int numchild;/* no of children to fork */ -int ncperchild;/* no of chars child should read */ -int szcharbuf;/* size of char buf */ -int pipewrcnt;/* chars written to pipe */ -char *wrbuf, *rdbuf; -int fd[2 ];/* fds for pipe read/write */ - -ssize_t do_read (int fd,void *buf,size_t count) -{ -ssize_t n; - -do { - n =read (fd, buf, count); - }while (n <0 && errno ==EINTR ); +#include <stdlib.h> +#include "tst_test.h" -return n; -} +static int fd[2 ]; +static unsigned char buf[PIPE_BUF ]; +static size_t read_per_child; -int main (int ac,char **av) +void do_child (void ) { -int lc; - -int i; -int fork_ret, status; -int written;/* no of chars read and written */ - -tst_parse_opts (ac, av,NULL ,NULL ); -#ifdef UCLINUX -maybe_run_child (&do_child_uclinux,"ddddd" , &fd[0 ], &fd[1 ], &kidid, - &ncperchild, &szcharbuf); -#endif - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - -/* reset tst_count in case we are looping */ - tst_count =0 ; +size_t nread; +unsigned char rbuf[read_per_child]; +unsigned int i; -TEST (pipe (fd)); +SAFE_CLOSE (fd[1 ]); -if (TEST_RETURN !=0 ) { -tst_resm (TFAIL ,"pipe creation failed" ); -continue ; - } - - written =write (fd[1 ], wrbuf, szcharbuf); -if (written != szcharbuf) { -tst_brkm (TBROK , cleanup,"write to pipe failed" ); - } - -refork: - ++kidid; - fork_ret =FORK_OR_VFORK (); - -if (fork_ret <0 ) { -tst_brkm (TBROK , cleanup,"fork() failed" ); - } - -if ((fork_ret !=0 ) && (fork_ret !=-1 ) && (kidid < numchild)) { - goto refork; - } + nread =SAFE_READ (0 , fd[0 ], rbuf,sizeof (rbuf)); -if (fork_ret ==0 ) {/* child */ -#ifdef UCLINUX -if (self_exec (av[0 ],"ddddd" , fd[0 ], fd[1 ], kidid, - ncperchild, szcharbuf) <0 ) { -tst_brkm (TBROK , cleanup,"self_exec failed" ); - } -#else -do_child (); -#endif - } +if (nread != read_per_child) { +tst_res (TFAIL ,"Invalid read size child %i size %zu" , +getpid (), nread); +return ; + } -/* parent */ -sleep (5 ); -tst_resm (TINFO ,"There are %d children to wait for" , kidid); -for (i =1 ; i <= kidid; ++i) { -wait (&status); -if (status ==0 ) { -tst_resm (TPASS ,"child %d exited successfully" , - i); - }else { -tst_resm (TFAIL ,"child %d exited with bad " -"status" , i); - } +for (i =0 ; i < read_per_child; i++) { +if (rbuf[i] != (i %256 )) { +tst_res (TFAIL , +"Invalid byte read child %i byte %i have %i expected %i" , +getpid (), i, rbuf[i], i %256 ); +return ; } } -cleanup (); - -tst_exit (); -} - -/* -* do_child() -*/ -void do_child (void ) -{ -int nread; -if (close (fd[1 ])) { -tst_resm (TINFO ,"child %d " "could not close pipe" , kidid); -exit (0 ); - } - nread =do_read (fd[0 ], rdbuf, ncperchild); -if (nread == ncperchild) { -tst_resm (TINFO ,"child %d " "got %d chars" , kidid, nread); -exit (0 ); - }else { -tst_resm (TFAIL ,"child %d did not receive expected no of " -"characters, got %d characters" , kidid, nread); -exit (1 ); - } +tst_res (TPASS ,"Child %i read pipe buffer correctly" ,getpid ()); } -/* -* do_child_uclinux() - as above, but mallocs rdbuf first -*/ -void do_child_uclinux (void ) -{ -if ((rdbuf =malloc (szcharbuf)) ==NULL ) { -tst_brkm (TBROK , cleanup,"malloc of rdbuf failed" ); - } - -do_child (); -} +static unsigned int childs[] = { +1 , +2 , +3 , +4 , +10 , +50 +}; -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) +static void run (unsigned int tcase) { -int i; -unsigned int j; +pid_t pid; +unsigned int nchilds = childs[tcase]; + read_per_child =PIPE_BUF /nchilds; +unsigned int i, j; -tst_sig (FORK ,DEF_HANDLER , cleanup); +tst_res (TINFO ,"Reading %zu per each of %u children" , + read_per_child, nchilds); -TEST_PAUSE ; - - numchild =NUMCHILD ; - ncperchild =NCPERCHILD ; +for (i =0 ; i < nchilds; i++) { +for (j =0 ; j < read_per_child; j++) { + buf[i * read_per_child + j] = j %256 ; + } + } - kidid =0 ; +SAFE_PIPE (fd); -/* allocate read and write buffers */ - szcharbuf = numchild * ncperchild; +SAFE_WRITE (1 , fd[1 ], buf, read_per_child * nchilds); -/* make sure pipe write doesn't block */ -if (szcharbuf ==PIPE_BUF ) { -/* adjust number of characters per child */ - ncperchild = szcharbuf / numchild; - } +for (i =0 ; i < nchilds; i++) { + pid =SAFE_FORK (); -if ((wrbuf =malloc (szcharbuf)) ==NULL ) { -tst_brkm (TBROK , cleanup,"malloc failed" ); - } - -if ((rdbuf =malloc (szcharbuf)) ==NULL ) { -tst_brkm (TBROK , cleanup,"malloc of rdbuf failed" ); +if (!pid) { +do_child (); +exit (0 ); + }
testcases/kernel/syscalls/pipe/pipe11.c line 104
Quoted 10 lines
testcases/kernel/syscalls/pipe/pipe11.c +1
-7} -/* initialize wrbuf */ - j =0 ; -for (i =0 ; i < szcharbuf;) { - wrbuf[i++] = rawchars[j++]; -if (j >=sizeof (rawchars)) - j =0 ; - } +tst_reap_children ();
pipe fds are not closed, and this could in theory repeat many times. Other than that ACK.
Regards,
Jan
Quoted 22 lines
}
testcases/kernel/syscalls/pipe/pipe11.c +5
-9-/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -} +static struct tst_test test = { + .forks_child =1 , + .test = run, + .tcnt =ARRAY_SIZE (childs), +}; --2.13.6
--
Mailing list info: https://lists.linux.it/listinfo/ltp
RFC PATCH 3/6 syscalls/alarm05: Rewrite to the new library.
In reply to Cyril Hrubis+ Speed up the test a bit, we save 6 seconds yay!
--- testcases/kernel/syscalls/alarm/alarm05.c | 216 +++++++----------------------- 1 file changed, 45 insertions(+), 171 deletions(-)
testcases/kernel/syscalls/alarm/alarm05.c +45 -171
@@ -1,203 +1,77 @@/* +* Copyright (c) International Business Machines Corp., 2001,2005 +* 07/2001 Ported by Wayne Boyer +* 06/2005 Test for alarm cleanup by Amos Waterland * -* Copyright (c) International Business Machines Corp., 2001,2005 +* Copyright (c) 2018 Cyril Hrubis <[email protected]> * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. * -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* -* Test Name: alarm05 -* * Test Description: -* Check the functionality of the Alarm system call when the time input -* parameter is non zero. -* -* Expected Result: * The return value of the alarm system call should be equal to the * amount previously remaining in the alarm clock. * A SIGALRM signal should be received after the specified amount of * time has elapsed. -* -* Algorithm: -* Setup: -* Setup signal handling. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* Execute system call -* Check return code, if system call failed (return=-1) -* Log the errno and Issue a FAIL message. -* Otherwise, -* Verify the Functionality of system call -* if successful, -* Issue Functionality-Pass message. -* Otherwise, -* Issue Functionality-Fail message. -* Cleanup: -* Print errno log and/or timing stats if options given -* -* Usage: <for command-line> -* alarm05 [-c n] [-f] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -f : Turn off functionality Testing. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 06/2005 Test for alarm cleanup by Amos Waterland -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS: -* None. */ -#include <stdio.h> -#include <unistd.h> -#include <sys/types.h> -#include <errno.h> -#include <string.h> -#include <signal.h> - -#include "test.h" +#include "tst_test.h" -char *TCID ="alarm05" ; -int TST_TOTAL =1 ; -int alarms_received =0 ;/* flag to indicate SIGALRM received or not */ +static volatile int alarms_fired =0 ; -void setup ();/* Main setup function of test */ -void cleanup ();/* cleanup function for the test */ -void sigproc (int sig);/* signal catching function */ - -int main (int ac,char **av) +static void run (void ) { -int lc; -int time_sec1 =10 ;/* time for which 1st alarm is set */ -int time_sec2 =5 ;/* time for which 2st alarm is set */ -int ret_val1, ret_val2;/* return values for alarm() calls */ -int ret_val3; -int sleep_time1 =3 ;/* waiting time for the signal */ -int sleep_time2 =6 ;/* waiting time for the signal */ - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { +unsigned int ret; - tst_count =0 ; + alarms_fired =0 ; -/* -* Reset alarms_received for every iteration, since it has -* old values from previous iterations (if any) and not -* a value of zero -*/ - alarms_received =0 ; + ret =alarm (10 ); +if (ret) +tst_res (TFAIL ,"alarm() returned non-zero" ); +else +tst_res (TPASS ,"alarm() returned zero" ); -/* -* Call First alarm() with non-zero time parameter -* 'time_sec1' to send SIGALRM to the calling process. -*/ -TEST (alarm (time_sec1)); - ret_val1 =TEST_RETURN ; +sleep (1 ); -/* Wait for signal SIGALARM */ -sleep (sleep_time1); + ret =alarm (1 ); +if (ret ==9 ) +tst_res (TPASS ,"alarm() returned remainder correctly" ); +else +tst_res (TFAIL ,"alarm() returned wrong remained %u" , ret); -/* -* Call Second alarm() with non-zero time parameter -* 'time_sec2' to send SIGALRM to the calling process. -*/ -TEST (alarm (time_sec2)); - ret_val2 =TEST_RETURN ; +sleep (2 ); -/* Wait for signal SIGALRM */ -sleep (sleep_time2); - -/* -* Check whether the second alarm() call returned -* the amount of time previously remaining in the -* alarm clock of the calling process, and -* sigproc() executed when SIGALRM received by the -* process, the variable alarms_received is set. -*/ -if ((alarms_received ==1 ) && - (ret_val2 == (time_sec1 - sleep_time1))) { - -/* -* Make sure the system cleaned up the alarm -* after it delivered it. -*/ -TEST (alarm (0 )); - ret_val3 =TEST_RETURN ; - -if (ret_val3 !=0 ) -tst_resm (TFAIL ,"System did not " -"clean up delivered " "alarm" ); -else { -tst_resm (TPASS ,"Functionality of " -"alarm(%u) successful" , - time_sec2); - } - }else { -tst_resm (TFAIL ,"alarm(%u) fails, returned %d, " -"alarms_received:%d" , - time_sec2, ret_val2, alarms_received); - } - } - -cleanup (); -tst_exit (); +if (alarms_fired ==1 ) +tst_res (TPASS ,"alarm handler fired once" ); +else +tst_res (TFAIL ,"alarm handler filred %u times" , alarms_fired); } -/* -* setup() - performs all ONE TIME setup for this test. -* Setup the signal handler to catch SIGALRM. -*/ -void setup (void ) +static void sighandler (int sig) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* Set the signal catching function */ -if (signal (SIGALRM , sigproc) ==SIG_ERR ) { -tst_brkm (TFAIL , cleanup, -"signal() fails to catch SIGALARM, errno=%d" , errno); - } +if (sig ==SIGALRM ) + alarms_fired++; } -/* -* sigproc(int) - This function defines the action that has to be taken -* when the SIGALRM signal is caught. -* It also sets the variable which is used to check whether the -* alarm system call was successful. -*/ -void sigproc (int sig) +static void setup (void ) { - alarms_received++; +SAFE_SIGNAL (SIGALRM , sighandler); } -/* -* void -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ -} +static struct tst_test test = { + .test_all = run, + .setup = setup, +};
Signature · 1 line
2.13.6
RFC PATCH 4/6 syscalls/alarm01: Remove
In reply to Cyril HrubisThe test was simply wrong alarm() does not return a failure at all.
--- runtest/ltplite | 1 - runtest/quickhit | 2 - runtest/stress.part3 | 1 - runtest/syscalls | 1 - testcases/kernel/syscalls/.gitignore | 1 - testcases/kernel/syscalls/alarm/alarm01.c | 176 ------------------------------ 6 files changed, 182 deletions(-) delete mode 100644 testcases/kernel/syscalls/alarm/alarm01.c
runtest/ltplite +0 -1
@@ -71,7 +71,6 @@ acct01 acct01 adjtimex01 adjtimex01 adjtimex02 adjtimex02 -alarm01 alarm01 alarm02 alarm02 alarm03 alarm03 alarm05 alarm05
runtest/quickhit +0 -2
@@ -3,8 +3,6 @@ access01 access01 # Basic test for access(2) using F_OK, R_OK, W_OK and X_OK arguments. access03 access03 # EFAULT error testing for access(2) -alarm01 alarm01 -# Basic test for alarm(2) alarm02 alarm02 # Boundary Value Test for alarm(2) # TEST CASES
runtest/stress.part3 +0 -1
@@ -13,7 +13,6 @@ acct01 acct01 adjtimex01 adjtimex01 adjtimex02 adjtimex02 -alarm01 alarm01 alarm02 alarm02 alarm03 alarm03 alarm05 alarm05
runtest/syscalls +0 -1
@@ -19,7 +19,6 @@ add_key04 add_key04 adjtimex01 adjtimex01 adjtimex02 adjtimex02 -alarm01 alarm01 alarm02 alarm02 alarm03 alarm03 alarm05 alarm05
testcases/kernel/syscalls/.gitignore +0 -1
@@ -12,7 +12,6 @@ /add_key/add_key04 /adjtimex/adjtimex01 /adjtimex/adjtimex02 -/alarm/alarm01 /alarm/alarm02 /alarm/alarm03 /alarm/alarm05
testcases/kernel/syscalls/alarm/alarm01.c deleted +0 -176
176 lines not on this page · raw message
Signature · 1 line
2.13.6
RFC PATCH 5/6 syscalls/waitpid01: Rewrite to the new library.
In reply to Cyril Hrubis+ use raise(SIGALRM) instead of wasting time with alarm(2)
--- testcases/kernel/syscalls/waitpid/waitpid01.c | 172 ++++++++------------------ 1 file changed, 52 insertions(+), 120 deletions(-)
testcases/kernel/syscalls/waitpid/waitpid01.c +52 -120
@@ -1,142 +1,74 @@/* +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 John George +* Copyright (c) 2018 Cyril Hrubis <[email protected]> * -* Copyright (c) International Business Machines Corp., 2001 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. * -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* -* NAME -* waitpid01.c -* -* DESCRIPTION -* Check that when a child kills itself by generating an alarm -* exception, the waiting parent is correctly notified. -* -* ALGORITHM -* Fork a child that sets an alarm. When the alarm goes off, causing -* the death of the child, the parent checks that SIG_ALRM was returned -* -* USAGE: <for command-line> -* waitpid01 [-c n] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* History -* 07/2001 John George -* -Ported +* Check that when a child kills itself by SIGALRM the waiting parent is +* correctly notified. * -* Restrictions -* None +* Fork a child that raises(SIGALRM), the parent checks that SIGALRM was +* returned. */ - -#include <sys/signal.h> -#include <sys/types.h> +#include <stdlib.h> #include <sys/wait.h> -#include <errno.h> -#include "test.h" - -static void setup (void ); -static void cleanup (void ); - -char *TCID ="waitpid01" ; -int TST_TOTAL =1 ; +#include "tst_test.h" -int main (int argc,char **argv) +static void run (void ) { -int lc; - -int pid, npid, sig, nsig; -int exno, nexno, status; - -tst_parse_opts (argc, argv,NULL ,NULL ); +pid_t pid, rpid; +int status; -setup (); - -/* check for looping state if -i option is given */ -for (lc =0 ;TEST_LOOPING (lc); lc++) { -/* reset tst_count in case we are looping */ - tst_count =0 ; - - exno =1 ; - sig =14 ; + pid =SAFE_FORK (); +if (!pid) { +raise (SIGALRM ); +exit (0 ); + } - pid =FORK_OR_VFORK (); -if (pid <0 ) { -tst_brkm (TFAIL , cleanup,"Fork Failed" ); - }else if (pid ==0 ) { -alarm (2 ); -pause (); -exit (exno); - }else { - errno =0 ; -while (((npid =waitpid (pid, &status,0 )) !=-1 ) || - (errno ==EINTR )) { -if (errno ==EINTR ) -continue ; + rpid =waitpid (pid, &status,0 ); +if (rpid <0 ) +tst_brk (TBROK |TERRNO ,"waitpid() failed" ); -if (npid != pid) { -tst_resm (TFAIL ,"waitpid error: " -"unexpected pid returned" ); - }else { -tst_resm (TPASS , -"recieved expected pid" ); - } +if (rpid != pid) { +tst_res (TFAIL ,"waitpid() returned wrong pid %i, expected %i" , + rpid, pid); + }else { +tst_res (TPASS ,"waitpid() returned correct pid %i" , pid); + } - nsig =WTERMSIG (status); +if (!WIFSIGNALED (status)) { +tst_res (TFAIL ,"WIFSIGNALED() not set in status (%s)" , +tst_strstatus (status)); +return ; + } -/* -* nsig is the signal number returned by -* waitpid -*/ -if (nsig != sig) { -tst_resm (TFAIL ,"waitpid error: " -"unexpected signal " -"returned" ); - }else { -tst_resm (TPASS ,"recieved expected " -"signal" ); - } +tst_res (TPASS ,"WIFSIGNALED() set in status" ); -/* -* nexno is the exit number returned by -* waitpid -*/ - nexno =WEXITSTATUS (status); -if (nexno !=0 ) { -tst_resm (TFAIL ,"signal error: " -"unexpected exit number " -"returned" ); - } - } - } +if (WTERMSIG (status) !=SIGALRM ) { +tst_res (TFAIL ,"WTERMSIG() != SIGALRM but %s" , +tst_strsig (WTERMSIG (status))); +return ; } -cleanup (); -tst_exit (); +tst_res (TPASS ,"WTERMSIG() == SIGALRM" ); } -static void setup (void ) -{ -TEST_PAUSE ; -} - -static void cleanup (void ) -{ -tst_sig (FORK ,DEF_HANDLER , cleanup); -} +static struct tst_test test = { + .forks_child =1 , + .test_all = run, +};
Signature · 1 line
2.13.6
RFC PATCH 6/6 syscalls/wait401: Rewrite to the new library
In reply to Cyril Hrubis+ Get rid of the sleep(1) in the process
--- testcases/kernel/syscalls/wait4/wait401.c | 122 +++++++++++------------------- 1 file changed, 45 insertions(+), 77 deletions(-)
testcases/kernel/syscalls/wait4/wait401.c +45 -77
@@ -1,106 +1,74 @@/* +* Copyright (c) International Business Machines Corp., 2001 +* Copyright (c) 2012-2018 Cyril Hrubis <[email protected]> * -* Copyright (c) International Business Machines Corp., 2001 -* Copyright (c) 2012 Cyril Hrubis <[email protected]> +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. * -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* -* wait401 - check that a call to wait4() correctly waits for a child -* process to exit +* wait401 - check that a call to wait4() correctly waits for a child +* process to exit */ -#include "test.h" - +#include <stdlib.h> #include <errno.h> #define _USE_BSD#include <sys/types.h> #include <sys/resource.h> #include <sys/wait.h> +#include "tst_test.h" -char *TCID ="wait401" ; -int TST_TOTAL =1 ; - -static void cleanup (void ); -static void setup (void ); - -int main (int ac,char **av) +static void run (void ) { -int lc;pid_t pid;int status =1 ;struct rusage rusage; -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; - - pid =FORK_OR_VFORK (); - -switch (pid) { -case -1 : -tst_brkm (TBROK , cleanup,"fork() failed" ); -break ; -case 0 : -sleep (1 ); -exit (0 ); -break ; -default : -TEST (wait4 (pid, &status,0 , &rusage)); -break ; - } + pid =SAFE_FORK (); +if (!pid) +exit (0 ); -if (TEST_RETURN ==-1 ) { -tst_brkm (TFAIL , cleanup,"%s call failed - errno = %d " -": %s" ,TCID ,TEST_ERRNO , -strerror (TEST_ERRNO )); - } - -if (WIFEXITED (status) ==0 ) { -tst_brkm (TFAIL , cleanup, -"%s call succeeded but " -"WIFEXITED() did not return expected value " -"- %d" ,TCID ,WIFEXITED (status)); - }else if (TEST_RETURN != pid) { -tst_resm (TFAIL ,"%s did not return the " -"expected value (%d), actual: %ld" , -TCID , pid,TEST_RETURN ); - }else { +TEST (wait4 (pid, &status,0 , &rusage)); +if (TEST_RETURN ==-1 ) { +tst_res (TFAIL |TERRNO ,"wait4() failed" ); +return ; + } -tst_resm (TPASS , -"Received child pid as expected." ); - } +if (TEST_RETURN != pid) { +tst_res (TFAIL ,"waitpid() returned wrong pid %li, expected %i" , +TEST_RETURN , pid); + }else { +tst_res (TPASS ,"waitpid() returned correct pid %i" , pid); + } -tst_resm (TPASS ,"%s call succeeded" ,TCID ); +if (!WIFEXITED (status)) { +tst_res (TFAIL ,"WIFEXITED() not set in status (%s)" , +tst_strstatus (status)); +return ; } -cleanup (); -tst_exit (); -} +tst_res (TPASS ,"WIFEXITED() is set in status" ); -static void setup (void ) -{ -tst_sig (FORK ,DEF_HANDLER , cleanup); +if (WEXITSTATUS (status)) +tst_res (TFAIL ,"WEXITSTATUS() != 0 but %i" ,WEXITSTATUS (status)); +else +tst_res (TPASS ,"WEXITSTATUS() == 0" ); -TEST_PAUSE ; } -static void cleanup (void ) -{ -} +static struct tst_test test = { + .forks_child =1 , + .test_all = run, +};
Signature · 1 line
2.13.6
RFC PATCH 6/6 syscalls/wait401: Rewrite to the new library
----- Original Message -----
testcases/kernel/syscalls/wait4/wait401.c line 41
Quoted 7 lines
+ Get rid of the sleep(1) in the process
Signed-off-by Cyril Hrubis <[email protected]>testcases/kernel/syscalls/wait4/wait401.c +3
-0+ pid =SAFE_FORK (); +if (!pid) +exit (0 );
This doesn't seem to test that wait4() waits. The child can end before call to wait4().
What if added call to tst_process_state_wait() to child, so it waits on parent to sleep? If parent sleeps, then it's likely waiting on child.
Regards,
Jan
RFC PATCH 6/6 syscalls/wait401: Rewrite to the new library
Hi!
Quoted 6 lines
This doesn't seem to test that
wait4()waits. The child can end before call towait4().What if added call to
tst_process_state_wait()to child, so it waits on parent to sleep? If parent sleeps, then it's likely waiting on child.
That's a good idea, I've changed the test to do exactly that.
OK to commit with the changes you requested or should I resend the fixed patchset?
Signature · 2 lines
Cyril Hrubis [email protected]
RFC PATCH 6/6 syscalls/wait401: Rewrite to the new library
----- Original Message -----
Quoted 10 lines
From: "Cyril Hrubis" <[email protected]>
To: "Jan Stancek" <[email protected]>
Cc: [email protected]
Sent: Monday, 9 April, 2018 11:44:40 AM
Subject: Re: [LTP] [RFC PATCH 6/6] syscalls/wait401: Rewrite to the new libraryHi!
Quoted 3 lines
This doesn't seem to test that
wait4()waits. The child can end before call towait4().
Quoted 8 lines
Quoted 3 lines
What if added call to
tst_process_state_wait()to child, so it waits on parent to sleep? If parent sleeps, then it's likely waiting on child.That's a good idea, I've changed the test to do exactly that.
OK to commit with the changes you requested or should I resend the fixed patchset?
Sorry for delay, I overlooked this email. No need to resend, ACK.
Regards,
Jan
Quoted 5 lines
--
Cyril Hrubis
[email protected]