Refactor fork11 test using new LTP API
PATCH 1/1 Refactor fork11 test using new LTP API
From: Andrea Cervesato <[email protected]>
Signed-off-by Andrea Cervesato <[email protected]>
--- testcases/kernel/syscalls/fork/fork11.c | 106 +++++------------------- 1 file changed, 23 insertions(+), 83 deletions(-)
testcases/kernel/syscalls/fork/fork11.c +23 -83
@@ -1,97 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* 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 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 -* -* -* NAME -* fork11.c -* -* DESCRIPTION -* Test that parent gets a pid from each child when doing wait -* -* ALGORITHM -* Fork NUMFORKS children that do nothing. -* -* USAGE -* fork11 -* -* HISTORY -* 07/2001 Ported by Wayne Boyer +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]> +*/ +/*\ +*[Description] * -* RESTRICTIONS -* None +* This test spawns multiple processes using fork() and it checks if wait() +* returns the right PID once they end up. */ -#include <sys/types.h> -#include <sys/wait.h> -#include <stdio.h> -#include <errno.h> -#include "test.h" - -char *TCID ="fork11" ; -int TST_TOTAL =1 ; - -static void setup (void ); -static void cleanup (void ); +#include "tst_test.h" #define NUMFORKS 100 -int main (int ac,char **av) +static void run (void ) { -int i, pid, cpid, status; -int fail =0 ; -int lc; - -tst_parse_opts (ac, av,NULL ,NULL ); +pid_t pid; +int status; -setup (); +for (int i =0 ; i <NUMFORKS ; i++) { +tst_res (TINFO ,"Forking the %d process" , i); -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; + pid =SAFE_FORK (); +if (!pid) +return ; -for (i =0 ; i <NUMFORKS ; i++) { - pid =fork (); -if (pid ==0 ) -exit (0 ); - -if (pid >0 ) {/* parent */ - cpid =wait (&status); -if (cpid != pid) - fail++; - }else { - fail++; -break ; - } - } -if (fail) -tst_resm (TFAIL ,"fork failed %d times" , fail); -else -tst_resm (TPASS ,"fork test passed, %d processes" , i); +TST_EXP_EQ_LI (SAFE_WAIT (&status), pid); } - -cleanup (); -tst_exit (); } -static void setup (void ) -{ -tst_sig (FORK ,DEF_HANDLER , cleanup); -TEST_PAUSE ; -} - -static void cleanup (void ) -{ -} +static struct tst_test test = { + .test_all = run, + .forks_child =1 , +};
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi,
please ignore this patch and check "[PATCH v1] Merge fork06 and fork11 into new test" instead.
Thanks,
Andrea Cervesato
Quoted 132 lines · Andrea Cervesato
From: Andrea Cervesato <[email protected]>
Signed-off-by Andrea Cervesato <[email protected]>--- testcases/kernel/syscalls/fork/fork11.c | 106 +++++------------------- 1 file changed, 23 insertions(+), 83 deletions(-)testcases/kernel/syscalls/fork/fork11.c +23
-83@@ -1,97 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* 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 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 -* -* -* NAME -* fork11.c -* -* DESCRIPTION -* Test that parent gets a pid from each child when doing wait -* -* ALGORITHM -* Fork NUMFORKS children that do nothing. -* -* USAGE -* fork11 -* -* HISTORY -* 07/2001 Ported by Wayne Boyer +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]> +*/ +/*\ +*[Description] * -* RESTRICTIONS -* None +* This test spawns multiple processes using fork() and it checks if wait() +* returns the right PID once they end up. */ -#include <sys/types.h> -#include <sys/wait.h> -#include <stdio.h> -#include <errno.h> -#include "test.h" - -char *TCID ="fork11" ; -int TST_TOTAL =1 ; - -static void setup (void ); -static void cleanup (void ); +#include "tst_test.h" #define NUMFORKS 100 -int main (int ac,char **av) +static void run (void ) { -int i, pid, cpid, status; -int fail =0 ; -int lc; - -tst_parse_opts (ac, av,NULL ,NULL ); +pid_t pid; +int status; -setup (); +for (int i =0 ; i <NUMFORKS ; i++) { +tst_res (TINFO ,"Forking the %d process" , i); -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; + pid =SAFE_FORK (); +if (!pid) +return ; -for (i =0 ; i <NUMFORKS ; i++) { - pid =fork (); -if (pid ==0 ) -exit (0 ); - -if (pid >0 ) {/* parent */ - cpid =wait (&status); -if (cpid != pid) - fail++; - }else { - fail++; -break ; - } - } -if (fail) -tst_resm (TFAIL ,"fork failed %d times" , fail); -else -tst_resm (TPASS ,"fork test passed, %d processes" , i); +TST_EXP_EQ_LI (SAFE_WAIT (&status), pid); } - -cleanup (); -tst_exit (); } -static void setup (void ) -{ -tst_sig (FORK ,DEF_HANDLER , cleanup); -TEST_PAUSE ; -} - -static void cleanup (void ) -{ -} +static struct tst_test test = { + .test_all = run, + .forks_child =1 , +};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp