Refactor mqns testing suite
cover Refactor mqns testing suite
mqns testing suite has been refactored using new LTP API
Andrea Cervesato (6):
Rewrite mqns_01 test using new LTP API
Rewrite mqns_02 test using new LTP API
Rewrite mqns_03 test using new LTP API
Rewrite mqns_04 test using new LTP API
Delete header files from mqns tests
Rename common header in mqns test suite
runtest/containers | 19 +- testcases/kernel/containers/mqns/Makefile | 27 +- testcases/kernel/containers/mqns/mqns.h | 108 ++++++- testcases/kernel/containers/mqns/mqns_01.c | 189 ++++-------- testcases/kernel/containers/mqns/mqns_02.c | 221 ++++---------- testcases/kernel/containers/mqns/mqns_03.c | 285 +++++++----------- testcases/kernel/containers/mqns/mqns_04.c | 273 +++++++---------- .../kernel/containers/mqns/mqns_helper.h | 56 ---- 8 files changed, 461 insertions(+), 717 deletions(-) delete mode 100644 testcases/kernel/containers/mqns/mqns_helper.h
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/6 Rewrite mqns_01 test using new LTP API
--- runtest/containers | 5 +- testcases/kernel/containers/mqns/common.h | 107 +++++++++++ testcases/kernel/containers/mqns/mqns_01.c | 197 +++++++-------------- 3 files changed, 177 insertions(+), 132 deletions(-) create mode 100644 testcases/kernel/containers/mqns/common.h
runtest/containers +3 -2
@@ -15,8 +15,9 @@ pidns30 pidns30 pidns31 pidns31 pidns32 pidns32 -mqns_01 mqns_01 -mqns_01_clone mqns_01 -clone +mqns_01_none mqns_01 -m none +mqns_01_clone mqns_01 -m clone +mqns_01_unshare mqns_01 -m unshare mqns_02 mqns_02 mqns_02_clone mqns_02 -clone mqns_03 mqns_03
testcases/kernel/containers/mqns/common.h new file +107 -0
107 lines not on this page · raw message
testcases/kernel/containers/mqns/mqns_01.c +67 -130
215 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v1 1/6] Rewrite mqns_01 test using new LTP API
Hi!
Quoted 14 lines
runtest/containers +3
-2-mqns_01 mqns_01 -mqns_01_clone mqns_01 -clone +mqns_01_none mqns_01 -m none +mqns_01_clone mqns_01 -m clone +mqns_01_unshare mqns_01 -m unshare mqns_02 mqns_02 mqns_02_clone mqns_02 -clone mqns_03 mqns_03testcases/kernel/containers/mqns/common.h new file +0
-0
testcases/kernel/containers/mqns/common.h line 7
Quoted 7 lines
testcases/kernel/containers/mqns/common.h new file +7
-0@@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2022 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +#ifndef __MQNS_H +#define __MQNS_H
Any identifier that starts with underscore is reserved for libc and compiler implementation, please make sure not to use such names.
Also the file is called common.h so probably this should be something as MQNS_COMMON_H instead.
Quoted 23 lines
testcases/kernel/containers/mqns/common.h new file +23
-0+#include <stdlib.h> +#include <mqueue.h> +#include "lapi/namespaces_constants.h" +#include "tst_test.h" + +enum { +T_CLONE , +T_UNSHARE , +T_NONE , +}; + +static int dummy_child1 (void *v) +{ + (void )v; +return 0 ; +} + +static void check_newipc (void ) +{ +int pid, status; + + pid =ltp_clone_quick (CLONE_NEWIPC |SIGCHLD , dummy_child1,NULL ); +if (pid <0 )
testcases/kernel/containers/mqns/common.h line 41
Quoted 10 lines
testcases/kernel/containers/mqns/common.h new file +10
-0+tst_brk (TCONF |TERRNO ,"CLONE_NEWIPC not supported" ); + +SAFE_WAITPID (pid, &status,0 ); +} + +static inline int get_clone_unshare_enum (const char * str_op) +{ +int use_clone; + + use_clone =T_NONE ;
I do not think that we have to initialize the variable, we either set it or exit. Is this code here to silence a warning?
maybe it would be better to use return instead of variable as:
if (foo) return BAR; else if (bar) return FOO; ... return 0;
This piece of code has dummy return at the end but is a bit more clear.
Quoted 118 lines
testcases/kernel/containers/mqns/common.h new file +65
-0+if (!str_op || !strcmp (str_op,"none" )) + use_clone =T_NONE ; +else if (!strcmp (str_op,"clone" )) + use_clone =T_CLONE ; +else if (!strcmp (str_op,"unshare" )) + use_clone =T_UNSHARE ; +else +tst_brk (TBROK ,"Test execution mode <clone|unshare|none>" ); + +return use_clone; +} + +static void clone_test (unsigned long clone_flags,int (*fn1)(void *arg),void *arg1) +{ +int pid; + + pid =ltp_clone_quick (clone_flags |SIGCHLD , fn1, arg1); +if (pid <0 ) +tst_brk (TBROK |TERRNO ,"ltp_clone_quick error" ); +} + +static void unshare_test (unsigned long clone_flags,int (*fn1)(void *arg),void *arg1) +{ +int pid; + + pid =SAFE_FORK (); +if (!pid) { +SAFE_UNSHARE (clone_flags); + +fn1 (arg1); +exit (0 ); + } +} + +static void plain_test (int (*fn1)(void *arg),void *arg1) +{ +int pid; + + pid =SAFE_FORK (); +if (!pid) { +fn1 (arg1); +exit (0 ); + } +} + +static void clone_unshare_test (int use_clone,unsigned long clone_flags, +int (*fn1)(void *arg),void *arg1) +{ +switch (use_clone) { +case T_NONE : +plain_test (fn1, arg1); +break ; +case T_CLONE : +clone_test (clone_flags, fn1, arg1); +break ; +case T_UNSHARE : +unshare_test (clone_flags, fn1, arg1); +break ; +default : +tst_brk (TBROK ,"%s: bad use_clone option: %d" , __FUNCTION__, use_clone); +break ; + } +} + +#endif /* __MQNS_H */ testcases/kernel/containers/mqns/mqns_01.c +1
-46@@ -1,148 +1,85 @@ +// SPDX-License-Identifier: GPL-2.0 /* -* Copyright (c) International Business Machines Corp., 2009 -* Copyright (c) Nadia Derbey, 2009 -* 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 -* -* Author: Nadia Derbey <[email protected]> -* -* Check mqns isolation: father mqns cannot be accessed from newinstance -* -* Mount mqueue fs -* Create a posix mq -->mq1 -* unshare -* In unshared process: -* Mount newinstance mqueuefs -* Check that mq1 is not readable from new ns - -***************************************************************************/ - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif -#include <sys/wait.h> -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include "mqns.h" -#include "mqns_helper.h" - -char *TCID ="posixmq_namespace_01" ; -int TST_TOTAL =1 ; - -int p1[2 ]; -int p2[2 ]; -
testcases/kernel/containers/mqns/mqns_01.c line 11
Quoted 10 lines
testcases/kernel/containers/mqns/mqns_01.c +9
-1-int check_mqueue (void *vtest) +* Copyright (c) International Business Machines Corp., 2009 +* Copyright (c) Nadia Derbey, 2009 <[email protected]> +* Copyright (C) 2022 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* [Description] +* +* Create a mqueue inside the father and check if it can be accessed from
^ parent
The most usual wording is parent/child process, they don't have a gender after all.
Quoted 120 lines
testcases/kernel/containers/mqns/mqns_01.c +36
-70+* the isolated/forked child namespace. +*/ + +#include <mqueue.h> +#include "common.h" + +#define MQNAME "/MQ1" + +static mqd_t mqd; +static char *str_op; +static int use_clone; + +static int check_mqueue(LTP_ATTRIBUTE_UNUSED void *vtest) { -char buf[30 ]; -mqd_t mqd; +mqd_t mqd1; - (void ) vtest; + mqd1 =mq_open (MQNAME ,O_RDONLY ); -close (p1[1 ]); -close (p2[0 ]); +if (use_clone ==T_NONE ) { +if (mqd1 ==-1 ) +tst_res (TFAIL ,"Queue has been accessed form plain cloned process" ); +else +tst_res (TPASS ,"Can't access to queue from plain cloned process" ); -if (read (p1[0 ], buf,strlen ("go" ) +1 ) <0 ) { -printf ("read(p1[0], ...) failed: %s\n" ,strerror (errno)); -exit (1 ); - } - mqd =tst_syscall (__NR_mq_open,NOSLASH_MQ1 ,O_RDONLY ); -if (mqd ==-1 ) { -if (write (p2[1 ],"notfnd" ,strlen ("notfnd" ) +1 ) <0 ) { -perror ("write(p2[1], ...) failed" ); -exit (1 ); - } - }else { -if (write (p2[1 ],"exists" ,strlen ("exists" ) +1 ) <0 ) { -perror ("write(p2[1], \"exists\", 7) failed" ); -exit (1 ); - }else if (mq_close (mqd) <0 ) { -perror ("mq_close(mqd) failed" ); -exit (1 ); - } +return 0 ; } -exit (0 ); +if (mqd1 ==-1 ) +tst_res (TPASS ,"Can't access to queue from isolated process" ); +else +tst_res (TFAIL ,"Queue has been accessed from isolated process" ); + +return 0 ; } -static void setup (void ) +static void run (void ) { -tst_require_root (); -check_mqns (); +tst_res (TINFO ,"Checking namespaces isolation from parent to child" ); + +clone_unshare_test (use_clone,CLONE_NEWIPC , check_mqueue,NULL ); } -int main (int argc,char *argv[]) +static void setup (void ) { -int r; -mqd_t mqd; -char buf[30 ]; -int use_clone =T_UNSHARE ; - -setup (); - -if (argc ==2 &&strcmp (argv[1 ],"-clone" ) ==0 ) { + -tst_resm (TINFO , -"Testing posix mq namespaces through clone(2)." ); - use_clone =T_CLONE ; - }else -tst_resm (TINFO , -"Testing posix mq namespaces through unshare(2)." ); - -if (pipe (p1) ==-1 ||pipe (p2) ==-1 ) { -tst_brkm (TBROK |TERRNO ,NULL ,"pipe failed" ); - } + use_clone =get_clone_unshare_enum (str_op); - mqd =tst_syscall (__NR_mq_open,NOSLASH_MQ1 ,O_RDWR |O_CREAT |O_EXCL , -0777 ,NULL ); -if (mqd ==-1 ) { -perror ("mq_open" ); -tst_brkm (TFAIL ,NULL ,"mq_open failed" ); - } +if (use_clone !=T_NONE ) +check_newipc (); -tst_resm (TINFO ,"Checking namespaces isolation from parent to child" ); -/* fire off the test */ - r =do_clone_unshare_test (use_clone,CLONE_NEWIPC , check_mqueue,NULL ); -if (r <0 ) { -tst_resm (TFAIL ,"failed clone/unshare" ); -mq_close (mqd); -tst_syscall (__NR_mq_unlink,NOSLASH_MQ1 ); -tst_exit (); - } - -close (p1[0 ]); -close (p2[1 ]); -if (write (p1[1 ],"go" ,strlen ("go" ) +1 ) <0 ) -tst_resm (TBROK |TERRNO ,"write(p1[1], \"go\", ...) failed" ); -else if (read (p2[0 ], buf,7 ) <0 ) -tst_resm (TBROK |TERRNO ,"read(p2[0], buf, ...) failed" ); -else { -if (!strcmp (buf,"exists" )) {
testcases/kernel/containers/mqns/mqns_01.c line 63
Quoted 10 lines
testcases/kernel/containers/mqns/mqns_01.c +3
-7-tst_resm (TFAIL ,"child process found mqueue" ); - }else if (!strcmp (buf,"notfnd" )) { -tst_resm (TPASS ,"child process didn't find mqueue" ); - }else { -tst_resm (TFAIL ,"UNKNOWN RESULT" ); - } - } + mqd =mq_open (MQNAME ,O_RDWR |O_CREAT |O_EXCL ,0777 ,NULL ); +if (mqd ==-1 ) +tst_brk (TBROK |TERRNO ,"mq_open failed" );
We do have SAFE_MQ_OPEN() in tst_safe_posix_ipc.h
testcases/kernel/containers/mqns/mqns_01.c line 70
Quoted 10 lines
testcases/kernel/containers/mqns/mqns_01.c +6
-3+} -/* destroy the mqueue */ -if (mq_close (mqd) ==-1 ) { -tst_brkm (TBROK |TERRNO ,NULL ,"mq_close failed" ); +static void cleanup (void ) +{ +if (mqd !=-1 ) { +mq_close (mqd); +mq_unlink (MQNAME );
And these two should be added to the tst_safe_posix_ipc.h as well and used here.
Quoted 24 lines
testcases/kernel/containers/mqns/mqns_01.c +13
-3} -tst_syscall (__NR_mq_unlink,NOSLASH_MQ1 ); - -tst_exit (); } + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .forks_child =1 , + .min_kver ="2.6.30" , + .options = (struct tst_option []) { + {"m:" , &str_op,"Test execution mode <clone|unshare|none>" }, + {}, + }, +};Signature · 5 lines
2.35.3 -- 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
PATCH 2/6 Rewrite mqns_02 test using new LTP API
In reply to Andrea Cervesato--- runtest/containers | 5 +- testcases/kernel/containers/mqns/mqns_02.c | 229 +++++++-------------- 2 files changed, 72 insertions(+), 162 deletions(-)
runtest/containers +3 -2
@@ -18,8 +18,9 @@ pidns32 pidns32 mqns_01_none mqns_01 -m none mqns_01_clone mqns_01 -m clone mqns_01_unshare mqns_01 -m unshare -mqns_02 mqns_02 -mqns_02_clone mqns_02 -clone +mqns_02_none mqns_02 -m none +mqns_02_clone mqns_02 -m clone +mqns_02_unshare mqns_02 -m unshare mqns_03 mqns_03 mqns_03_clone mqns_03 -clone mqns_04 mqns_04
testcases/kernel/containers/mqns/mqns_02.c +69 -160
249 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 3/6 Rewrite mqns_03 test using new LTP API
In reply to Andrea Cervesato--- runtest/containers | 5 +- testcases/kernel/containers/mqns/mqns_03.c | 287 ++++++++------------- 2 files changed, 106 insertions(+), 186 deletions(-)
runtest/containers +3 -2
@@ -21,8 +21,9 @@ mqns_01_unshare mqns_01 -m unshare mqns_02_none mqns_02 -m none mqns_02_clone mqns_02 -m clone mqns_02_unshare mqns_02 -m unshare -mqns_03 mqns_03 -mqns_03_clone mqns_03 -clone +mqns_03_none mqns_03 -m none +mqns_03_clone mqns_03 -m clone +mqns_03_unshare mqns_03 -m unshare mqns_04 mqns_04 mqns_04_clone mqns_04 -clone
testcases/kernel/containers/mqns/mqns_03.c +103 -184
310 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 4/6 Rewrite mqns_04 test using new LTP API
In reply to Andrea Cervesato--- runtest/containers | 4 +- testcases/kernel/containers/mqns/mqns_04.c | 275 +++++++++------------ 2 files changed, 116 insertions(+), 163 deletions(-)
runtest/containers +2 -2
@@ -24,8 +24,8 @@ mqns_02_unshare mqns_02 -m unshare mqns_03_none mqns_03 -m none mqns_03_clone mqns_03 -m clone mqns_03_unshare mqns_03 -m unshare -mqns_04 mqns_04 -mqns_04_clone mqns_04 -clone +mqns_04_clone mqns_04 -m clone +mqns_04_unshare mqns_04 -m unshare netns_netlink netns_netlink netns_breakns_ip_ipv4_netlink netns_breakns.sh
testcases/kernel/containers/mqns/mqns_04.c +114 -161
301 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 5/6 Delete header files from mqns tests
In reply to Andrea Cervesato--- testcases/kernel/containers/mqns/Makefile | 27 ++------- testcases/kernel/containers/mqns/mqns.h | 11 ---- .../kernel/containers/mqns/mqns_helper.h | 56 ------------------- 3 files changed, 5 insertions(+), 89 deletions(-) delete mode 100644 testcases/kernel/containers/mqns/mqns.h delete mode 100644 testcases/kernel/containers/mqns/mqns_helper.h
testcases/kernel/containers/mqns/Makefile +5 -22
@@ -1,29 +1,12 @@ -################################################################################ -## ## -## Copyright (c) International Business Machines Corp., 2009 ## -## Copyright (c) Nadia Derbey, 2009 ## -## ## -## 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 ## -## ## -################################################################################ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) International Business Machines Corp., 2009 +# Copyright (c) Nadia Derbey, 2009 +# Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]> top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk -include $(abs_srcdir)/../Makefile.inc -LDLIBS := -lpthread -lrt -lclone $(LDLIBS) +LDLIBS := -lpthread -lrt $(LDLIBS) include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/containers/mqns/mqns.h deleted +0 -11
@@ -1,11 +0,0 @@ -#ifndef __MQNS_H -#define __MQNS_H - -#define DEV_MQUEUE "/dev/mqueue" -#define DEV_MQUEUE2 "/dev/mqueue2" -#define SLASH_MQ1 "/MQ1" -#define NOSLASH_MQ1 "MQ1" -#define SLASH_MQ2 "/MQ2" -#define NOSLASH_MQ2 "MQ2" - -#endif /* __MQNS_H */
testcases/kernel/containers/mqns/mqns_helper.h deleted +0 -56
56 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 6/6 Rename common header in mqns test suite
In reply to Andrea Cervesato---
testcases/kernel/containers/mqns/{common.h => mqns.h} | 0
testcases/kernel/containers/mqns/mqns_01.c | 2 +-
testcases/kernel/containers/mqns/mqns_02.c | 2 +-
testcases/kernel/containers/mqns/mqns_03.c | 2 +-
testcases/kernel/containers/mqns/mqns_04.c | 2 +-
5 files changed, 4 insertions(+), 4 deletions(-)
rename testcases/kernel/containers/mqns/{common.h => mqns.h} (100%)testcases/kernel/containers/mqns/mqns.h renamed from testcases/kernel/containers/mqns/common.h +0 -0
testcases/kernel/containers/mqns/mqns_01.c +1 -1
@@ -13,7 +13,7 @@*/ #include <mqueue.h> -#include "common.h" +#include "mqns.h" #define MQNAME "/MQ1"
testcases/kernel/containers/mqns/mqns_02.c +1 -1
@@ -13,7 +13,7 @@*/ #include <mqueue.h> -#include "common.h" +#include "mqns.h" #define MQNAME "/MQ1"
testcases/kernel/containers/mqns/mqns_03.c +1 -1
@@ -27,7 +27,7 @@#include <stdio.h> #include <mqueue.h> #include "tst_safe_stdio.h" -#include "common.h" +#include "mqns.h" #define MQNAME1 "/MQ1"#define MQNAME2 "/MQ2"
testcases/kernel/containers/mqns/mqns_04.c +1 -1
@@ -26,7 +26,7 @@#include <stdio.h> #include <mqueue.h> #include "tst_safe_stdio.h" -#include "common.h" +#include "mqns.h" #define CHECK_MQ_OPEN_RET (x) ((x) >= 0 || ((x) == -1 && errno != EMFILE))
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp