Remove ltp_clone_quick usage from pidns suite
PATCH 1/1 Remove ltp_clone_quick usage from pidns suite
Replaced ltp_clone_quick with SAFE_CLONE inside the pidns testing suite.
--- testcases/kernel/containers/pidns/pidns01.c | 14 ++++++------ testcases/kernel/containers/pidns/pidns02.c | 14 ++++++------ testcases/kernel/containers/pidns/pidns03.c | 14 ++++++------ testcases/kernel/containers/pidns/pidns12.c | 18 +++++++++------- testcases/kernel/containers/pidns/pidns20.c | 24 +++++++++++---------- 5 files changed, 44 insertions(+), 40 deletions(-)
testcases/kernel/containers/pidns/pidns01.c +7 -7
@@ -17,7 +17,7 @@#include "tst_test.h" #include "lapi/sched.h" -static int child_func(LTP_ATTRIBUTE_UNUSED void *arg) +static void child_func (void ) {pid_t cpid, ppid;
@@ -26,20 +26,20 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)TST_EXP_PASS (cpid ==1 );TST_EXP_PASS (ppid ==0 ); - -return 0 ; }static void run (void ) { -int ret; +const struct tst_clone_args args = {CLONE_NEWNS ,SIGCHLD }; - ret =ltp_clone_quick (CLONE_NEWNS |SIGCHLD , child_func,NULL ); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"clone failed" ); +if (!SAFE_CLONE (&args)) { +child_func (); +return ; + } }static struct tst_test test = { .test_all = run, .needs_root =1 , + .forks_child =1 , };
testcases/kernel/containers/pidns/pidns02.c +7 -7
@@ -16,7 +16,7 @@#include "tst_test.h" #include "lapi/sched.h" -static int child_func(LTP_ATTRIBUTE_UNUSED void *arg) +static void child_func (void ) {pid_t sid, pgid;
@@ -25,20 +25,20 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)TST_EXP_PASS (sid ==1 );TST_EXP_PASS (pgid ==1 ); - -return 0 ; }static void run (void ) { -int ret; +const struct tst_clone_args args = {CLONE_NEWNS ,SIGCHLD }; - ret =ltp_clone_quick (CLONE_NEWNS |SIGCHLD , child_func,NULL ); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"clone failed" ); +if (!SAFE_CLONE (&args)) { +child_func (); +return ; + } }static struct tst_test test = { .test_all = run, .needs_root =1 , + .forks_child =1 , };
testcases/kernel/containers/pidns/pidns03.c +7 -7
@@ -17,7 +17,7 @@#define PROCDIR "proc" -static int child_func(LTP_ATTRIBUTE_UNUSED void *arg) +static void child_func (void ) {char proc_self[10 ];
@@ -28,8 +28,6 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)SAFE_UMOUNT (PROCDIR );TST_EXP_PASS (strcmp (proc_self,"1" ),PROCDIR "/self contains 1:" ); - -return 0 ; }static void setup (void )
@@ -45,11 +43,12 @@ static void cleanup(void)static void run (void ) { -int ret; +const struct tst_clone_args args = {CLONE_NEWPID ,SIGCHLD }; - ret =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_func,NULL ); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"clone failed" ); +if (!SAFE_CLONE (&args)) { +child_func (); +return ; + } }static struct tst_test test = {
@@ -57,5 +56,6 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .needs_root = 1, + .forks_child = 1, .needs_tmpdir = 1, };
testcases/kernel/containers/pidns/pidns12.c +10 -8
@@ -25,7 +25,7 @@ static void child_signal_handler(LTP_ATTRIBUTE_UNUSED int sig, siginfo_t *si, LT sig_pid = si->si_pid; } -static int child_func(LTP_ATTRIBUTE_UNUSED void *arg) +static void child_func (void ) {struct sigaction sa;
@@ -41,21 +41,22 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)TST_CHECKPOINT_WAKE_AND_WAIT (0 );TST_EXP_EQ_LI (sig_pid,0 ); - -return 0 ; }static void run (void ) { -int ret; +const struct tst_clone_args args = {CLONE_NEWPID ,SIGCHLD }; +int pid; - ret =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_func,NULL ); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"clone failed" ); + pid =SAFE_CLONE (&args); +if (!pid) { +child_func (); +return ; + }TST_CHECKPOINT_WAIT (0 ); -SAFE_KILL (ret,SIGUSR1 ); +SAFE_KILL (pid,SIGUSR1 );TST_CHECKPOINT_WAKE (0 ); }
@@ -63,5 +64,6 @@ static void run(void)static struct tst_test test = { .test_all = run, .needs_root =1 , + .forks_child =1 , .needs_checkpoints =1 , };
testcases/kernel/containers/pidns/pidns20.c +13 -11
@@ -26,7 +26,7 @@ static void child_signal_handler(LTP_ATTRIBUTE_UNUSED int sig, siginfo_t *si, LT signals++; } -static int child_func(LTP_ATTRIBUTE_UNUSED void *arg) +static void child_func (void ) {struct sigaction sa;sigset_t newset;
@@ -37,7 +37,7 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)if (cpid !=1 || ppid !=0 ) {tst_res (TFAIL ,"Got unexpected result of cpid=%d ppid=%d" , cpid, ppid); -return 0 ; +return ; }SAFE_SIGEMPTYSET (&newset);
@@ -56,30 +56,31 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)if (signals !=1 ) {tst_res (TFAIL ,"Received %d signals" , signals); -return 0 ; +return ; }if (last_signo !=SIGUSR1 ) {tst_res (TFAIL ,"Received %s signal" ,tst_strsig (last_signo)); -return 0 ; +return ; }tst_res (TPASS ,"Received SIGUSR1 signal after unblock" ); - -return 0 ; }static void run (void ) { -int ret; +const struct tst_clone_args args = {CLONE_NEWPID ,SIGCHLD }; +int pid; - ret =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_func,NULL ); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"clone failed" ); + pid =SAFE_CLONE (&args); +if (!pid) { +child_func (); +return ; + }TST_CHECKPOINT_WAIT (0 ); -SAFE_KILL (ret,SIGUSR1 ); +SAFE_KILL (pid,SIGUSR1 );TST_CHECKPOINT_WAKE (0 ); }
@@ -87,5 +88,6 @@ static void run(void)static struct tst_test test = { .test_all = run, .needs_root =1 , + .forks_child =1 , .needs_checkpoints =1 , };
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hello,
Quoted 27 lines · Andrea Cervesato via ltp
Replaced
ltp_clone_quickwithSAFE_CLONEinside the pidns testing suite.Signed-off-by Andrea Cervesato <[email protected]>--- testcases/kernel/containers/pidns/pidns01.c | 14 ++++++------ testcases/kernel/containers/pidns/pidns02.c | 14 ++++++------ testcases/kernel/containers/pidns/pidns03.c | 14 ++++++------ testcases/kernel/containers/pidns/pidns12.c | 18 +++++++++------- testcases/kernel/containers/pidns/pidns20.c | 24 +++++++++++---------- 5 files changed, 44 insertions(+), 40 deletions(-)testcases/kernel/containers/pidns/pidns01.c +1
-1@@ -17,7 +17,7 @@#include "tst_test.h" #include "lapi/sched.h" -static int child_func(LTP_ATTRIBUTE_UNUSED void *arg) +static void child_func (void ) {pid_t cpid, ppid;@@ -26,20 +26,20 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
testcases/kernel/containers/pidns/pidns01.c static int child_func(LTP_ATTRIBUTE_UNUSED void *arg) · line 33
Quoted 10 lines
testcases/kernel/containers/pidns/pidns01.c +1
-3TST_EXP_PASS (cpid ==1 );TST_EXP_PASS (ppid ==0 ); - -return 0 ; }static void run (void ) { -int ret; +const struct tst_clone_args args = {CLONE_NEWNS ,SIGCHLD };
At some point CLONE_NEWNS was substituted for CLONE_NEWPID. It still passes because TST_EXP_PASS expects a zero return val. It should be TST_EXP_EXPR or similar.
Quoted 4 lines
testcases/kernel/containers/pidns/pidns01.c +0
-3- ret =ltp_clone_quick (CLONE_NEWNS |SIGCHLD , child_func,NULL ); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"clone failed" );
testcases/kernel/containers/pidns/pidns01.c static int child_func(LTP_ATTRIBUTE_UNUSED void *arg) · line 44
Quoted 10 lines
testcases/kernel/containers/pidns/pidns01.c +5
-0+if (!SAFE_CLONE (&args)) { +child_func (); +return ; + } }static struct tst_test test = { .test_all = run, .needs_root =1 , + .forks_child =1 ,
We need to check PID namespaces are supported in the kernel config.
Quoted 16 lines
testcases/kernel/containers/pidns/pidns01.c +0
-0};testcases/kernel/containers/pidns/pidns02.c +1
-1@@ -16,7 +16,7 @@#include "tst_test.h" #include "lapi/sched.h" -static int child_func(LTP_ATTRIBUTE_UNUSED void *arg) +static void child_func (void ) {pid_t sid, pgid;@@ -25,20 +25,20 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
testcases/kernel/containers/pidns/pidns02.c static int child_func(LTP_ATTRIBUTE_UNUSED void *arg) · line 32
Quoted 10 lines
testcases/kernel/containers/pidns/pidns02.c +1
-3TST_EXP_PASS (sid ==1 );TST_EXP_PASS (pgid ==1 ); - -return 0 ; }static void run (void ) { -int ret; +const struct tst_clone_args args = {CLONE_NEWNS ,SIGCHLD };
Same issue here.
Quoted 4 lines
testcases/kernel/containers/pidns/pidns02.c +0
-3- ret =ltp_clone_quick (CLONE_NEWNS |SIGCHLD , child_func,NULL ); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"clone failed" );
testcases/kernel/containers/pidns/pidns02.c static int child_func(LTP_ATTRIBUTE_UNUSED void *arg) · line 42
Quoted 10 lines
testcases/kernel/containers/pidns/pidns02.c +5
-0+if (!SAFE_CLONE (&args)) { +child_func (); +return ; + } }static struct tst_test test = { .test_all = run, .needs_root =1 , + .forks_child =1 ,
Also needs config check
Quoted 41 lines
testcases/kernel/containers/pidns/pidns02.c +0
-0};testcases/kernel/containers/pidns/pidns03.c +6
-7@@ -17,7 +17,7 @@#define PROCDIR "proc" -static int child_func(LTP_ATTRIBUTE_UNUSED void *arg) +static void child_func (void ) {char proc_self[10 ];@@ -28,8 +28,6 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)SAFE_UMOUNT (PROCDIR );TST_EXP_PASS (strcmp (proc_self,"1" ),PROCDIR "/self contains 1:" ); - -return 0 ; }static void setup (void )@@ -45,11 +43,12 @@ static void cleanup(void)static void run (void ) { -int ret; +const struct tst_clone_args args = {CLONE_NEWPID ,SIGCHLD }; - ret =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_func,NULL ); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"clone failed" ); +if (!SAFE_CLONE (&args)) { +child_func (); +return ; + } }static struct tst_test test = {
testcases/kernel/containers/pidns/pidns03.c static struct tst_test test = { · line 60
Quoted 5 lines
testcases/kernel/containers/pidns/pidns03.c +1
-0@@ -57,5 +56,6 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .needs_root = 1, + .forks_child = 1, .needs_tmpdir = 1,
Need config check.
Quoted 45 lines
testcases/kernel/containers/pidns/pidns03.c +0
-0};testcases/kernel/containers/pidns/pidns12.c +9
-8@@ -25,7 +25,7 @@ static void child_signal_handler(LTP_ATTRIBUTE_UNUSED int sig, siginfo_t *si, LT sig_pid = si->si_pid; } -static int child_func(LTP_ATTRIBUTE_UNUSED void *arg) +static void child_func (void ) {struct sigaction sa;@@ -41,21 +41,22 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)TST_CHECKPOINT_WAKE_AND_WAIT (0 );TST_EXP_EQ_LI (sig_pid,0 ); - -return 0 ; }static void run (void ) { -int ret; +const struct tst_clone_args args = {CLONE_NEWPID ,SIGCHLD }; +int pid; - ret =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_func,NULL ); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"clone failed" ); + pid =SAFE_CLONE (&args); +if (!pid) { +child_func (); +return ; + }TST_CHECKPOINT_WAIT (0 ); -SAFE_KILL (ret,SIGUSR1 ); +SAFE_KILL (pid,SIGUSR1 );TST_CHECKPOINT_WAKE (0 ); }
testcases/kernel/containers/pidns/pidns12.c static void run(void) · line 68
Quoted 5 lines
testcases/kernel/containers/pidns/pidns12.c +1
-0@@ -63,5 +64,6 @@ static void run(void)static struct tst_test test = { .test_all = run, .needs_root =1 , + .forks_child =1 , .needs_checkpoints =1 ,
Needs config check
Quoted 65 lines
testcases/kernel/containers/pidns/pidns12.c +0
-0};testcases/kernel/containers/pidns/pidns20.c +12
-11@@ -26,7 +26,7 @@ static void child_signal_handler(LTP_ATTRIBUTE_UNUSED int sig, siginfo_t *si, LT signals++; } -static int child_func(LTP_ATTRIBUTE_UNUSED void *arg) +static void child_func (void ) {struct sigaction sa;sigset_t newset;@@ -37,7 +37,7 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)if (cpid !=1 || ppid !=0 ) {tst_res (TFAIL ,"Got unexpected result of cpid=%d ppid=%d" , cpid, ppid); -return 0 ; +return ; }SAFE_SIGEMPTYSET (&newset);@@ -56,30 +56,31 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)if (signals !=1 ) {tst_res (TFAIL ,"Received %d signals" , signals); -return 0 ; +return ; }if (last_signo !=SIGUSR1 ) {tst_res (TFAIL ,"Received %s signal" ,tst_strsig (last_signo)); -return 0 ; +return ; }tst_res (TPASS ,"Received SIGUSR1 signal after unblock" ); - -return 0 ; }static void run (void ) { -int ret; +const struct tst_clone_args args = {CLONE_NEWPID ,SIGCHLD }; +int pid; - ret =ltp_clone_quick (CLONE_NEWPID |SIGCHLD , child_func,NULL ); -if (ret <0 ) -tst_brk (TBROK |TERRNO ,"clone failed" ); + pid =SAFE_CLONE (&args); +if (!pid) { +child_func (); +return ; + }TST_CHECKPOINT_WAIT (0 ); -SAFE_KILL (ret,SIGUSR1 ); +SAFE_KILL (pid,SIGUSR1 );TST_CHECKPOINT_WAKE (0 ); }
testcases/kernel/containers/pidns/pidns20.c static void run(void) · line 92
Quoted 5 lines
testcases/kernel/containers/pidns/pidns20.c +1
-0@@ -87,5 +88,6 @@ static void run(void)static struct tst_test test = { .test_all = run, .needs_root =1 , + .forks_child =1 , .needs_checkpoints =1 ,
Needs config check
Quoted 3 lines
testcases/kernel/containers/pidns/pidns20.c +0
-0};Signature · 1 line
2.35.3
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi all,
Quoted 8 lines
Review
Quoted 4 lines
static void run(void)
{(quoted diff) +1
-1- int ret; + const struct tst_clone_args args = { CLONE_NEWNS, SIGCHLD };At some point
CLONE_NEWNSwas substituted forCLONE_NEWPID. It still passes becauseTST_EXP_PASSexpects a zero return val. It should beTST_EXP_EXPRor similar.
Good catch. I suppose copy paste error. These were introduced during testsuite rewrite, later Andrea fixed the docparse description in 3fc912172, but not the actual value in tst_clone_args.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp