syscalls/waitid: Guarded buf + result assertions
PATCH 1/1 syscalls/waitid: Guarded buf + result assertions
- make use of guarded buffers for the infop
- add assertion for the values reported in the infop
- Add a few more assertions for pid and gid filter tests
+ adjustements to the docparse comments
Signed-off-by Cyril Hrubis <[email protected]>
--- testcases/kernel/syscalls/waitid/waitid02.c | 17 +++++------ testcases/kernel/syscalls/waitid/waitid03.c | 18 +++++------ testcases/kernel/syscalls/waitid/waitid04.c | 19 +++++++----- testcases/kernel/syscalls/waitid/waitid05.c | 33 ++++++++++++++------- testcases/kernel/syscalls/waitid/waitid06.c | 28 +++++++++++------ testcases/kernel/syscalls/waitid/waitid07.c | 22 ++++++++------ testcases/kernel/syscalls/waitid/waitid08.c | 30 ++++++++++++------- testcases/kernel/syscalls/waitid/waitid09.c | 33 ++++++++------------- 8 files changed, 115 insertions(+), 85 deletions(-)
testcases/kernel/syscalls/waitid/waitid02.c +8 -9
@@ -8,24 +8,23 @@/*\ * [Description] * -* This test is checking if waitid() syscall returns EINVAL when passing -* invalid set of input values. +* Tests if waitid() returns EINVAL when passed invalid options flag value. */ #include <sys/wait.h> #include "tst_test.h" +static siginfo_t *infop; +static void run (void ) { -siginfo_t infop; - -memset (&infop,0 ,sizeof (infop)); -TST_EXP_FAIL (waitid (P_ALL ,0 , &infop,WNOHANG ),EINVAL ); - -tst_res (TINFO ,"si_pid = %d ; si_code = %d ; si_status = %d" , - infop.si_pid, infop.si_code, infop.si_status); +TST_EXP_FAIL (waitid (P_ALL ,0 , infop,WNOHANG ),EINVAL ); }static struct tst_test test = { .test_all = run, + .bufs = (struct tst_buffers []) { + {&infop, .size =sizeof (*infop)}, + {} + } };
testcases/kernel/syscalls/waitid/waitid03.c +9 -9
@@ -8,24 +8,24 @@/*\ * [Description] * -* This test is checking if waitid() syscall returns ECHILD when the calling -* process has no existing unwaited-for child processes. +* Tests if waitid() syscall returns ECHILD when the calling process has no +* child processes. */ #include <sys/wait.h> #include "tst_test.h" +static siginfo_t *infop; +static void run (void ) { -siginfo_t infop; - -memset (&infop,0 ,sizeof (infop)); -TST_EXP_FAIL (waitid (P_ALL ,0 , &infop,WNOHANG |WEXITED ),ECHILD ); - -tst_res (TINFO ,"si_pid = %d ; si_code = %d ; si_status = %d" , - infop.si_pid, infop.si_code, infop.si_status); +TST_EXP_FAIL (waitid (P_ALL ,0 , infop,WNOHANG |WEXITED ),ECHILD ); }static struct tst_test test = { .test_all = run, + .bufs = (struct tst_buffers []) { + {&infop, .size =sizeof (*infop)}, + {} + } };
testcases/kernel/syscalls/waitid/waitid04.c +11 -8
@@ -8,15 +8,17 @@/*\ * [Description] * -* This test is checking if waitid() syscall filters a child in WNOHANG status. +* This test if waitid() syscall leaves the si_pid set to 0 with WNOHANG flag +* when no child was waited for. */ #include <sys/wait.h> #include "tst_test.h" +static siginfo_t *infop; +static void run (void ) { -siginfo_t infop;pid_t pid_child; pid_child =SAFE_FORK ();
@@ -25,13 +27,10 @@ static void run(void)return ; } -tst_res (TINFO ,"filter all children by WNOHANG | WEXITED" ); - -memset (&infop,0 ,sizeof (infop)); -TST_EXP_PASS (waitid (P_ALL , pid_child, &infop,WNOHANG |WEXITED )); +memset (infop,0 ,sizeof (*infop)); +TST_EXP_PASS (waitid (P_ALL , pid_child, infop,WNOHANG |WEXITED )); -tst_res (TINFO ,"si_pid = %d ; si_code = %d ; si_status = %d" , - infop.si_pid, infop.si_code, infop.si_status); +TST_EXP_EQ_LI (infop->si_pid,0 );TST_CHECKPOINT_WAKE (0 ); }
@@ -40,4 +39,8 @@ static struct tst_test test = { .test_all = run, .forks_child = 1, .needs_checkpoints = 1, + .bufs = (struct tst_buffers []) { + {&infop, .size =sizeof (*infop)}, + {} + } };
testcases/kernel/syscalls/waitid/waitid05.c +22 -11
@@ -8,34 +8,45 @@/*\ * [Description] * -* This test is checking if waitid() syscall filters children which exited from -* the same group ID. +* Tests if waitid() filters children correctly by the group ID. +* +* - waitid() with GID + 1 returns ECHILD +* - waitid() with GID returns correct data */ +#include <stdlib.h> #include <sys/wait.h> #include "tst_test.h" +static siginfo_t *infop; +static void run (void ) { -siginfo_t infop;pid_t pid_group; +pid_t pid_child; -/* dummy fork to spawn child in the same group ID */ -if (!SAFE_FORK ()) -return ; + pid_child =SAFE_FORK (); +if (!pid_child) +exit (0 ); pid_group =getpgid (0 ); -tst_res (TINFO ,"filter child by group ID and WEXITED" ); +TST_EXP_FAIL (waitid (P_PGID , pid_group+1 , infop,WEXITED ),ECHILD ); -memset (&infop,0 ,sizeof (infop)); -TST_EXP_PASS (waitid (P_PGID , pid_group, &infop,WEXITED )); +memset (infop,0 ,sizeof (*infop)); +TST_EXP_PASS (waitid (P_PGID , pid_group, infop,WEXITED )); -tst_res (TINFO ,"si_pid = %d ; si_code = %d ; si_status = %d" , - infop.si_pid, infop.si_code, infop.si_status); +TST_EXP_EQ_LI (infop->si_pid, pid_child); +TST_EXP_EQ_LI (infop->si_status,0 ); +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)}, + {} + } };
testcases/kernel/syscalls/waitid/waitid06.c +19 -9
@@ -8,32 +8,42 @@/*\ * [Description] * -* This test is checking if waitid() syscall filters children which exited. +* Tests if waitid() filters children correctly by the PID. +* +* - waitid() with PID + 1 returns ECHILD +* - waitid() with PID returns correct data */ +#include <stdlib.h> #include <sys/wait.h> #include "tst_test.h" +static siginfo_t *infop; +static void run (void ) { -siginfo_t infop;pid_t pid_child; -/* dummy fork */ pid_child =SAFE_FORK ();if (!pid_child) -return ; +exit (0 ); -tst_res (TINFO ,"filter child by WEXITED" ); +TST_EXP_FAIL (waitid (P_PID , pid_child+1 , infop,WEXITED ),ECHILD ); -memset (&infop,0 ,sizeof (infop)); -TST_EXP_PASS (waitid (P_PID , pid_child, &infop,WEXITED )); +memset (infop,0 ,sizeof (*infop)); +TST_EXP_PASS (waitid (P_PID , pid_child, infop,WEXITED )); -tst_res (TINFO ,"si_pid = %d ; si_code = %d ; si_status = %d" , - infop.si_pid, infop.si_code, infop.si_status); +TST_EXP_EQ_LI (infop->si_pid, pid_child); +TST_EXP_EQ_LI (infop->si_status,0 ); +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)}, + {} + } };
testcases/kernel/syscalls/waitid/waitid07.c +13 -9
@@ -8,16 +8,16 @@/*\ * [Description] * -* This test is checking if waitid() syscall filters children killed with -* SIGSTOP. +* Test if waitid() filters children killed with SIGSTOP. */ #include <sys/wait.h> #include "tst_test.h" +static siginfo_t *infop; +static void run (void ) { -siginfo_t infop;pid_t pid_child; pid_child =SAFE_FORK ();
@@ -27,13 +27,13 @@ static void run(void)return ; } -tst_res (TINFO ,"filter child by WSTOPPED | WNOWAIT" ); - -memset (&infop,0 ,sizeof (infop)); -TST_EXP_PASS (waitid (P_PID , pid_child, &infop,WSTOPPED |WNOWAIT )); +memset (infop,0 ,sizeof (*infop)); +TST_EXP_PASS (waitid (P_PID , pid_child, infop,WSTOPPED |WNOWAIT )); -tst_res (TINFO ,"si_pid = %d ; si_code = %d ; si_status = %d" , - infop.si_pid, infop.si_code, infop.si_status); +TST_EXP_EQ_LI (infop->si_pid, pid_child); +TST_EXP_EQ_LI (infop->si_status,SIGSTOP ); +TST_EXP_EQ_LI (infop->si_signo,SIGCHLD ); +TST_EXP_EQ_LI (infop->si_code,CLD_STOPPED );SAFE_KILL (pid_child,SIGCONT );
@@ -44,4 +44,8 @@ static struct tst_test test = { .test_all = run, .forks_child = 1, .needs_checkpoints = 1, + .bufs = (struct tst_buffers []) { + {&infop, .size =sizeof (*infop)}, + {} + } };
testcases/kernel/syscalls/waitid/waitid08.c +20 -10
@@ -8,16 +8,16 @@/*\ * [Description] * -* This test is checking if waitid() syscall filters children killed with -* SIGCONT. +* Test if waitid() filters children killed with SIGCONT. */ #include <sys/wait.h> #include "tst_test.h" +static siginfo_t *infop; +static void run (void ) { -siginfo_t infop;pid_t pid_child; pid_child =SAFE_FORK ();
@@ -29,19 +29,25 @@ static void run(void)tst_res (TINFO ,"send SIGCONT to child" ); -memset (&infop,0 ,sizeof (infop)); -TST_EXP_PASS (waitid (P_PID , pid_child, &infop,WSTOPPED )); +memset (infop,0 ,sizeof (*infop)); +TST_EXP_PASS (waitid (P_PID , pid_child, infop,WSTOPPED )); + +TST_EXP_EQ_LI (infop->si_pid, pid_child); +TST_EXP_EQ_LI (infop->si_status,SIGSTOP ); +TST_EXP_EQ_LI (infop->si_signo,SIGCHLD ); +TST_EXP_EQ_LI (infop->si_code,CLD_STOPPED );SAFE_KILL (pid_child,SIGCONT );tst_res (TINFO ,"filter child by WCONTINUED" ); -TST_EXP_PASS (waitid (P_PID , pid_child, &infop,WCONTINUED )); +memset (infop,0 ,sizeof (*infop)); +TST_EXP_PASS (waitid (P_PID , pid_child, infop,WCONTINUED )); -tst_res (TINFO ,"si_pid = %d ; si_code = %d ; si_status = %d" , - infop.si_pid, infop.si_code, infop.si_status); - -SAFE_KILL (pid_child,SIGCONT ); +TST_EXP_EQ_LI (infop->si_pid, pid_child); +TST_EXP_EQ_LI (infop->si_status,SIGCONT ); +TST_EXP_EQ_LI (infop->si_signo,SIGCHLD ); +TST_EXP_EQ_LI (infop->si_code,CLD_CONTINUED );TST_CHECKPOINT_WAKE (0 ); }
@@ -50,4 +56,8 @@ static struct tst_test test = { .test_all = run, .forks_child = 1, .needs_checkpoints = 1, + .bufs = (struct tst_buffers []) { + {&infop, .size =sizeof (*infop)}, + {} + } };
testcases/kernel/syscalls/waitid/waitid09.c +13 -20
@@ -8,37 +8,30 @@/*\ * [Description] * -* This test is checking that waitid() syscall filters not a child of the -* current process. +* Test that waitid() fails with ECHILD with process that is not child of the +* current process. We fork() one child just to be sure that there are unwaited +* for children available while the test runs. */ +#include <stdlib.h> #include <sys/wait.h> #include "tst_test.h" +static siginfo_t *infop; +static void run (void ) { -siginfo_t infop; -pid_t pid_child; - - pid_child =SAFE_FORK (); -if (!pid_child) { -TST_CHECKPOINT_WAIT (0 ); -return ; - } - -tst_res (TINFO ,"filter not a child of the current process by WEXITED" ); +if (!SAFE_FORK ()) +exit (0 ); -memset (&infop,0 ,sizeof (infop)); -TST_EXP_FAIL (waitid (P_PID ,1 , &infop,WEXITED ),ECHILD ); - -tst_res (TINFO ,"si_pid = %d ; si_code = %d ; si_status = %d" , - infop.si_pid, infop.si_code, infop.si_status); - -TST_CHECKPOINT_WAKE (0 ); +TST_EXP_FAIL (waitid (P_PID ,1 , infop,WEXITED ),ECHILD ); }static struct tst_test test = { .test_all = run, .forks_child =1 , - .needs_checkpoints =1 , + .bufs = (struct tst_buffers []) { + {&infop, .size =sizeof (*infop)}, + {} + } };
Signature · 5 lines
2.34.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp