syscalls/clone301: Fix the test race this time for real
PATCH 1/1 syscalls/clone301: Fix the test race this time for real
I have messed up the first fix, sorry, the signal handler has to be estabilished before the clone3() call, not just before the if ().
This also makes the test more verbose in case of failure, we print what exactly went wrong which saves time on debugging.
--- testcases/kernel/syscalls/clone3/clone301.c | 65 +++++++++++++++------ 1 file changed, 48 insertions(+), 17 deletions(-)
testcases/kernel/syscalls/clone3/clone301.c +48 -17
@@ -17,7 +17,7 @@#define DATA 777static int pidfd, child_tid, parent_tid, parent_received_signal; -static volatile int child_received_signal; +static volatile int child_received_signal, child_data;static struct clone_args *args; static struct tcase {
@@ -40,8 +40,8 @@ static void child_rx_signal(int sig, siginfo_t *info, void *ucontext) { (void ) ucontext; -if (sig ==CHILD_SIGNAL && info && info->si_value.sival_int ==DATA ) - child_received_signal =1 ; + child_received_signal = sig; + child_data = info->si_value.sival_int; }static struct sigaction psig_action = {
@@ -60,23 +60,43 @@ static siginfo_t uinfo = { }; -static void do_child (int clone_pidfd,int n) +static void do_child (int clone_pidfd) {int count =1000 ;if (clone_pidfd) { child_received_signal =0 ; + child_data =0 ; +SAFE_SIGACTION (CHILD_SIGNAL , &csig_action,NULL );TST_CHECKPOINT_WAKE (0 ); -while (!child_received_signal && --count) +while (child_received_signal !=CHILD_SIGNAL && --count)usleep (100 ); -if (child_received_signal) -tst_res (TPASS ,"clone3() passed: Child received correct signal (index %d)" , n); -else -tst_res (TFAIL ,"clone3() failed: Child received incorrect signal (index %d)" , n); +if (!child_received_signal) { +tst_res (TFAIL ,"Child haven't got signal" ); +exit (0 ); + } + +if (child_received_signal !=CHILD_SIGNAL ) { +tst_res (TFAIL ,"Child got %s (%i) signal expected %s" , +tst_strsig (child_received_signal), + child_received_signal, +tst_strsig (CHILD_SIGNAL )); +exit (0 ); + } + +tst_res (TPASS ,"Child got correct signal %s" , +tst_strsig (CHILD_SIGNAL )); + +if (child_data !=DATA ) { +tst_res (TFAIL ,"Child got wrong si_value=%i expected %i" , + child_data,DATA ); + }else { +tst_res (TPASS ,"Child got correct si_value" ); + } }exit (0 );
@@ -97,17 +117,17 @@ static void run(unsigned int n) args->stack_size =0 ; args->tls =0 ; + parent_received_signal =0 ; +SAFE_SIGACTION (tc->exit_signal, &psig_action,NULL ); +TEST (pid =clone3 (args,sizeof (*args)));if (pid <0 ) {tst_res (TFAIL |TTERRNO ,"clone3() failed (%d)" , n);return ; } - parent_received_signal =0 ; -SAFE_SIGACTION (tc->exit_signal, &psig_action,NULL ); -if (!pid) -do_child (clone_pidfd, n); +do_child (clone_pidfd);/* Need to send signal to child process */ if (clone_pidfd) {
@@ -122,10 +142,21 @@ static void run(unsigned int n)SAFE_WAITPID (pid, &status, __WALL); -if (parent_received_signal == tc->exit_signal) -tst_res (TPASS ,"clone3() passed: Parent received correct signal (index %d)" , n); -else -tst_res (TFAIL ,"clone3() failed: Parent received incorrect signal (index %d)" , n); +if (!parent_received_signal) { +tst_res (TFAIL ,"Parent haven't got signal" ); +return ; + } + +if (parent_received_signal != tc->exit_signal) { +tst_res (TFAIL ,"Parent got %s (%i) signal expected %s" , +tst_strsig (parent_received_signal), + parent_received_signal, +tst_strsig (tc->exit_signal)); +return ; + } + +tst_res (TPASS ,"Parent got correct signal %s" , +tst_strsig (parent_received_signal)); }static void setup (void )
Signature · 1 line
2.24.1
PATCH 1/1 syscalls/clone301: Fix the test race this time for real
Hello,
Quoted 49 lines · Cyril Hrubis
I have messed up the first fix, sorry, the signal handler has to be estabilished before the
clone3()call, not just before the if ().This also makes the test more verbose in case of failure, we print what exactly went wrong which saves time on debugging.
Fixes f17b3862dceb (syscalls/clone301: Fix race between parent and child)Signed-off-by Cyril Hrubis <[email protected]>CC Richard Palethorpe <[email protected]>CC Viresh Kumar <[email protected]>--- testcases/kernel/syscalls/clone3/clone301.c | 65 +++++++++++++++------ 1 file changed, 48 insertions(+), 17 deletions(-)testcases/kernel/syscalls/clone3/clone301.c +4
-4@@ -17,7 +17,7 @@#define DATA 777static int pidfd, child_tid, parent_tid, parent_received_signal; -static volatile int child_received_signal; +static volatile int child_received_signal, child_data;static struct clone_args *args; static struct tcase {@@ -40,8 +40,8 @@ static void child_rx_signal(int sig, siginfo_t *info, void *ucontext) { (void ) ucontext; -if (sig ==CHILD_SIGNAL && info && info->si_value.sival_int ==DATA ) - child_received_signal =1 ; + child_received_signal = sig; + child_data = info->si_value.sival_int; }static struct sigaction psig_action = {@@ -60,23 +60,43 @@ static siginfo_t uinfo = { }; -static void do_child (int clone_pidfd,int n) +static void do_child (int clone_pidfd) {int count =1000 ;if (clone_pidfd) {
testcases/kernel/syscalls/clone3/clone301.c static siginfo_t uinfo = { · line 76
Quoted 10 lines
testcases/kernel/syscalls/clone3/clone301.c +3
-1child_received_signal =0 ; + child_data =0 ; +SAFE_SIGACTION (CHILD_SIGNAL , &csig_action,NULL );TST_CHECKPOINT_WAKE (0 ); -while (!child_received_signal && --count) +while (child_received_signal !=CHILD_SIGNAL && --count)usleep (100 );
Maybe to be nice, we should use the exponential backoff function?
Although not too important in this case.
Otherwise LGTM!
Signature · 2 lines
Thank you, Richard.
PATCH 1/1 syscalls/clone301: Fix the test race this time for real
Hi!
Quoted 1 line
Maybe to be nice, we should use the exponential backoff function?
Let's add that in a separate patch to keep the git history clean.
I should have even split the original patch into two one that fixes a problem and second one that adds the debug info, I guess that I will do that before applying...
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 syscalls/clone301: Fix the test race this time for real
In reply to Cyril HrubisQuoted 6 lines · Cyril Hrubis
I have messed up the first fix, sorry, the signal handler has to be estabilished before the
clone3()call, not just before the if ().This also makes the test more verbose in case of failure, we print what exactly went wrong which saves time on debugging.
Quoted 8 lines
Fixes f17b3862dceb (syscalls/clone301: Fix race between parent and child)Signed-off-by Cyril Hrubis <[email protected]>CC Richard Palethorpe <[email protected]>CC Viresh Kumar <[email protected]>--- testcases/kernel/syscalls/clone3/clone301.c | 65 +++++++++++++++------ 1 file changed, 48 insertions(+), 17 deletions(-)
Signature · 1 line
viresh