Rewrite waitid01.c test using new LTP API
PATCH 1/1 Rewrite waitid01.c test using new LTP API
Signed-off-by Andrea Cervesato <[email protected]>
--- testcases/kernel/syscalls/waitid/waitid01.c | 151 +++++--------------- 1 file changed, 34 insertions(+), 117 deletions(-)
testcases/kernel/syscalls/waitid/waitid01.c +34 -117
@@ -1,126 +1,43 @@ -/******************************************************************************/ -/* Copyright (c) Crackerjack Project., 2007 */ -/* */ -/* 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 */ -/* */ -/******************************************************************************/ -/******************************************************************************/ -/* */ -/* Description: This tests the waitid() syscall */ -/* */ -/* Test Name: waitid01 */ -/* History: Porting from Crackerjack to LTP is done by */ -/* Manas Kumar Nayak [email protected]> */ -/******************************************************************************/ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) Crackerjack Project., 2007 +* Copyright (C) 2022 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* This test is checking if waitid() syscall does wait for WEXITED and check for +* the return value. +*/ -#include <stdio.h> -#include <errno.h> #include <stdlib.h> #include <sys/wait.h> -#include <sys/types.h> -#include <unistd.h> -#include <sys/stat.h> +#include "tst_test.h" -#include "test.h" +static siginfo_t *infop; -char *TCID ="waitid01" ; -int testno; -int TST_TOTAL =3 ; - -void setup (void ) -{ -TEST_PAUSE ; -} - -void display_status (siginfo_t * infop) +static void run (void ) { -tst_resm (TINFO ,"Process %d terminated:" , infop->si_pid); -tst_resm (TINFO ,"code = %d" , infop->si_code); -if (infop->si_code ==CLD_EXITED ) -tst_resm (TINFO ,"exit value = %d" , infop->si_status); -else -tst_resm (TINFO ,"signal = %d" , infop->si_status); -} - -int main (int ac,char **av) -{ -id_t pid; -siginfo_t infop; -int lc; - -tst_parse_opts (ac, av,NULL ,NULL ); +pid_t pidchild; -setup (); + pidchild =SAFE_FORK (); +if (!pidchild) +exit (123 ); -for (lc =0 ;TEST_LOOPING (lc); ++lc) { - tst_count =0 ; -for (testno =0 ; testno <TST_TOTAL ; ++testno) { - -TEST (fork ()); -if (TEST_RETURN <0 ) -tst_brkm (TBROK |TTERRNO ,NULL , -"fork() failed" ); - -if (TEST_RETURN ==0 ) { -exit (123 ); - }else { -TEST (waitid (P_ALL ,getpid (), &infop,WEXITED )); -if (TEST_RETURN ==-1 ) { -tst_brkm (TFAIL |TTERRNO , -NULL , -"waitid(getpid()) failed" ); - }else -display_status (&infop);//CLD_EXITED = 1 - } - -TEST (fork ()); -if (TEST_RETURN <0 ) -tst_brkm (TBROK |TTERRNO ,NULL , -"fork() failed" ); - -if (TEST_RETURN ==0 ) { -int a, b =0 ; - a =1 / b; -tst_exit (); - }else { -TEST (waitid (P_ALL ,0 , &infop,WEXITED )); -if (TEST_RETURN ==-1 ) { -tst_brkm (TFAIL |TTERRNO , -NULL ,"waitid(0) failed" ); - }else -display_status (&infop);//CLD_DUMPED = 3 ; SIGFPE = 8 - } - -TEST (pid =fork ()); -if (TEST_RETURN <0 ) -tst_brkm (TBROK |TTERRNO ,NULL , -"fork() failed" ); - -if (TEST_RETURN ==0 ) { -TEST (sleep (10 )); -tst_exit (); - } -TEST (kill (pid,SIGHUP )); -TEST (waitid (P_ALL ,0 , &infop,WEXITED )); -if (TEST_RETURN ==-1 ) { -tst_brkm (TFAIL |TTERRNO ,NULL , -"waitid(0) failed" ); - }else -display_status (&infop);//CLD_KILLED = 2 ; SIGHUP = 1 - } - } -tst_resm (TPASS ,"waitid(): system call passed" ); -tst_exit (); +TST_EXP_PASS (waitid (P_ALL ,getpid (), infop,WEXITED )); +TST_EXP_EQ_LI (infop->si_pid, pidchild); +TST_EXP_EQ_LI (infop->si_status,123 ); +TST_EXP_EQ_LI (infop->si_signo,SIGCHLD ); +TST_EXP_EQ_LI (infop->si_code,CLD_EXITED ); } + +static struct tst_test test = { + .test_all = run, + .forks_child =1 , + .bufs = + (struct tst_buffers []){ + { &infop, .size =sizeof (*infop) }, + {}, + }, +};
Signature · 5 lines
2.35.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
testcases/kernel/syscalls/waitid/waitid01.c line 33
Quoted 6 lines
testcases/kernel/syscalls/waitid/waitid01.c +5
-0+TST_EXP_PASS (waitid (P_ALL ,getpid (), infop,WEXITED )); +TST_EXP_EQ_LI (infop->si_pid, pidchild); +TST_EXP_EQ_LI (infop->si_status,123 ); +TST_EXP_EQ_LI (infop->si_signo,SIGCHLD ); +TST_EXP_EQ_LI (infop->si_code,CLD_EXITED ); }
Looks good, but we should add the two different cases as well.
The one that kills the child with SIGHUP should have si_code set to CLD_KILLED and and the si_status should be SIGHUP. And the 'division by zero' case is supposed to have it set to CLD_DUMPED. I think that we should add these two tests as well.
Also looking at man pages the idtype can be set to P_PIDFD since 5.4 as well, so we should add a waitid test with a pidfd too.
Quoted 15 lines
testcases/kernel/syscalls/waitid/waitid01.c +9
-0+static struct tst_test test = { + .test_all = run, + .forks_child =1 , + .bufs = + (struct tst_buffers []){ + { &infop, .size =sizeof (*infop) }, + {}, + }, +};Signature · 5 lines
2.35.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp