Refactor mqns testing suite
v2 cover Refactor mqns testing suite
mqns testing suite has been refactored using new LTP API
Andrea Cervesato (7):
Add more safe macros for mqueue API
Refactor mqns_01 using new LTP API
Refactor mqns_02 using new LTP API
Refactor mqns_03 using new LTP API
Refactor mqns_04 using new LTP API
Delete deprecated mqns header files
Rename common.h into mqns.h for mqns suite
include/tst_safe_posix_ipc.h | 34 +++ runtest/containers | 19 +- testcases/kernel/containers/mqns/Makefile | 27 +- testcases/kernel/containers/mqns/mqns.h | 108 ++++++- testcases/kernel/containers/mqns/mqns_01.c | 187 ++++-------- testcases/kernel/containers/mqns/mqns_02.c | 217 ++++---------- testcases/kernel/containers/mqns/mqns_03.c | 271 +++++++----------- testcases/kernel/containers/mqns/mqns_04.c | 263 +++++++---------- .../kernel/containers/mqns/mqns_helper.h | 56 ---- 9 files changed, 481 insertions(+), 701 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 v2 1/7 Add more safe macros for mqueue API
Added SAFE_MQ_UNLINK and SAFE_MQ_CLOSE in tst_safe_posix_ipc.h
--- include/tst_safe_posix_ipc.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
include/tst_safe_posix_ipc.h +34 -0
@@ -11,6 +11,10 @@#define SAFE_MQ_OPEN (pathname, oflags, ...) \ safe_mq_open(__FILE__, __LINE__, (pathname), (oflags), ##__VA_ARGS__) +#define SAFE_MQ_CLOSE (__mqdes) \ + safe_mq_close(__FILE__, __LINE__, (__mqdes)) +#define SAFE_MQ_UNLINK (name) \ + safe_mq_unlink(__FILE__, __LINE__, (name))static inline int safe_mq_open (const char *file,const int lineno,const char *pathname,int oflags, ...)
@@ -46,4 +50,34 @@ static inline int safe_mq_open(const char *file, const int lineno, return rval; } +static inline int safe_mq_close (const char *file,const int lineno, +mqd_t __mqdes) +{ +int rval; + + rval =mq_close (__mqdes); + +if (rval ==-1 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"mq_close(%d) failed" , __mqdes); + } + +return rval; +} + +static inline int safe_mq_unlink (const char *file,const int lineno, +const char * name) +{ +int rval; + + rval =mq_unlink (name); + +if (rval ==-1 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"mq_unlink(%s) failed" , name); + } + +return rval; +} +#endif /* TST_SAFE_POSIX_IPC_H__ */
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/7] Add more safe macros for mqueue API
Hi Andrea,
Quoted 1 line
Added
SAFE_MQ_UNLINKandSAFE_MQ_CLOSEintst_safe_posix_ipc.h
LGTM, few minor notes below.
include/tst_safe_posix_ipc.h line 13
Quoted 5 lines
+++
b/include/tst_safe_posix_ipc.hinclude/tst_safe_posix_ipc.h +0
-0@@ -11,6 +11,10 @@#define SAFE_MQ_OPEN (pathname, oflags, ...) \ safe_mq_open(__FILE__, __LINE__, (pathname), (oflags), ##__VA_ARGS__)
I'd add blank line here (readability)
include/tst_safe_posix_ipc.h line 15
Quoted 2 lines
include/tst_safe_posix_ipc.h +2
-0+#define SAFE_MQ_CLOSE (__mqdes) \ + safe_mq_close(__FILE__, __LINE__, (__mqdes))
and here.
Quoted 10 lines
include/tst_safe_posix_ipc.h +3
-0+#define SAFE_MQ_UNLINK (name) \ + safe_mq_unlink(__FILE__, __LINE__, (name))static inline int safe_mq_open (const char *file,const int lineno,const char *pathname,int oflags, ...)@@ -46,4 +50,34 @@ static inline int safe_mq_open(const char *file, const int lineno,return rval; } +static inline int safe_mq_close(const char *file, const int lineno,
include/tst_safe_posix_ipc.h static inline int safe_mq_open(const char *file, const int lineno, · line 63
Quoted 10 lines
include/tst_safe_posix_ipc.h +10
-0+ mqd_t __mqdes) +{ +int rval; + + rval =mq_close (__mqdes); + +if (rval ==-1 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"mq_close(%d) failed" , __mqdes); + }
How about check for invalid return value?
} else if (rval < 0) {
tst_brk_(file, lineno, TBROK | TERRNO,
"Invalid mq_close(%d) return value %d", __mqdes, rval);
}Quoted 5 lines
include/tst_safe_posix_ipc.h +5
-0+ +return rval; +} + +static inline int safe_mq_unlink(const char *file, const int lineno,
include/tst_safe_posix_ipc.h static inline int safe_mq_open(const char *file, const int lineno, · line 78
Quoted 10 lines
include/tst_safe_posix_ipc.h +10
-0+ const char* name) +{ +int rval; + + rval =mq_unlink (name); + +if (rval ==-1 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"mq_unlink(%s) failed" , name); + }
And here.
Kind regards,
Petr
Quoted 5 lines
include/tst_safe_posix_ipc.h +4
-0+ + return rval; +} +#endif /* TST_SAFE_POSIX_IPC_H__ */
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/7] Add more safe macros for mqueue API
Hi Andrea,
...
Quoted 14 lines
include/tst_safe_posix_ipc.h static inline int safe_mq_open(const char *file, const int lineno, · line 63
Quoted 11 lines
include/tst_safe_posix_ipc.h +11
-0+static inline int safe_mq_close (const char *file,const int lineno, +mqd_t __mqdes) +{ +int rval; + + rval =mq_close (__mqdes); + +if (rval ==-1 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"mq_close(%d) failed" , __mqdes); + }How about check for invalid return value?
Quoted 4 lines
} else if (rval < 0) {
tst_brk_(file, lineno, TBROK | TERRNO,
"Invalid mq_close(%d) return value %d", __mqdes, rval);
}Also safe_mq_open() could have check for invalid return value.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/7] Add more safe macros for mqueue API
Hi!
Quoted 19 lines · Petr Vorel
Hi Andrea,
...
Quoted 12 lines
include/tst_safe_posix_ipc.h static inline int safe_mq_open(const char *file, const int lineno, · line 63
Quoted 11 lines
include/tst_safe_posix_ipc.h +11
-0+static inline int safe_mq_close (const char *file,const int lineno, +mqd_t __mqdes) +{ +int rval; + + rval =mq_close (__mqdes); + +if (rval ==-1 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"mq_close(%d) failed" , __mqdes); + }How about check for invalid return value?
Quoted 4 lines
} else if (rval < 0) { tst_brk_(file, lineno, TBROK | TERRNO, "Invalid mq_close(%d) return value %d", __mqdes, rval); }
Quoted 2 lines
Also
safe_mq_open()could have check for invalid return value.
It's already like that, Isn't it?
Quoted 2 lines
Kind regards,
Petr
Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/7] Add more safe macros for mqueue API
Hi Andrea,
Quoted 22 lines
Hi!
Quoted 19 lines · Petr Vorel
Hi Andrea,
...
Quoted 16 lines
include/tst_safe_posix_ipc.h static inline int safe_mq_open(const char *file, const int lineno, · line 63
Quoted 11 lines
include/tst_safe_posix_ipc.h +11
-0+static inline int safe_mq_close (const char *file,const int lineno, +mqd_t __mqdes) +{ +int rval; + + rval =mq_close (__mqdes); + +if (rval ==-1 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"mq_close(%d) failed" , __mqdes); + }How about check for invalid return value?
} else if (rval < 0) { tst_brk_(file, lineno, TBROK | TERRNO, "Invalid mq_close(%d) return value %d", __mqdes, rval); }
Quoted 3 lines
Quoted 1 line
Also
safe_mq_open()could have check for invalid return value.It's already like that, Isn't it?
No it's not. But looking for v3 of this patchset (v3) you have added it. Thanks!
Kind regards,
Petr
Quoted 4 lines
Quoted 2 lines
Kind regards,
PetrAndrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/7 Refactor mqns_01 using new LTP API
In reply to Andrea Cervesato via ltp--- runtest/containers | 5 +- testcases/kernel/containers/mqns/common.h | 101 +++++++++++ testcases/kernel/containers/mqns/mqns_01.c | 195 +++++++-------------- 3 files changed, 169 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 +101 -0
101 lines not on this page · raw message
testcases/kernel/containers/mqns/mqns_01.c +65 -130
213 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 v2 2/7] Refactor mqns_01 using new LTP API
Hi Andrea,
testcases/kernel/containers/mqns/common.h line 39
Quoted 3 lines
testcases/kernel/containers/mqns/common.h new file +3
-0+static inline int get_clone_unshare_enum (const char * str_op) +{ +if (!str_op || !strcmp (str_op,"none" ))
nit: If "none" is a default, how about drop '-m none' entirely? (use without -m)?
Quoted 8 lines
testcases/kernel/containers/mqns/common.h new file +8
-0+return T_NONE ; + else if (!strcmp(str_op, "clone")) +return T_CLONE ; + else if (!strcmp(str_op, "unshare")) +return T_UNSHARE ; + +return T_NONE ; +}
...
testcases/kernel/containers/mqns/mqns_01.c line 62
Quoted 3 lines
testcases/kernel/containers/mqns/mqns_01.c +3
-0+ mqd =SAFE_MQ_OPEN (MQNAME ,O_RDWR |O_CREAT |O_EXCL ,0777 ,NULL ); +if (mqd ==-1 ) +tst_brk (TBROK |TERRNO ,"mq_open failed" );
This if check is not needed (done by SAFE_MQ_OPEN()
Quoted 1 line
+}
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 3/7 Refactor mqns_02 using new LTP API
In reply to Andrea Cervesato via ltp--- runtest/containers | 5 +- testcases/kernel/containers/mqns/mqns_02.c | 225 ++++++--------------- 2 files changed, 68 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 +65 -160
245 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 4/7 Refactor mqns_03 using new LTP API
In reply to Andrea Cervesato via ltp--- runtest/containers | 5 +- testcases/kernel/containers/mqns/mqns_03.c | 273 ++++++++------------- 2 files changed, 103 insertions(+), 175 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 +100 -173
307 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 5/7 Refactor mqns_04 using new LTP API
In reply to Andrea Cervesato via ltp--- runtest/containers | 4 +- testcases/kernel/containers/mqns/mqns_04.c | 265 +++++++++------------ 2 files changed, 114 insertions(+), 155 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 +112 -153
299 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 6/7 Delete deprecated mqns header files
In reply to Andrea Cervesato via ltp--- 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 v2 7/7 Rename common.h into mqns.h for mqns suite
In reply to Andrea Cervesato via ltp---
testcases/kernel/containers/mqns/{common.h => mqns.h} | 8 ++++----
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, 8 insertions(+), 8 deletions(-)
rename testcases/kernel/containers/mqns/{common.h => mqns.h} (94%)testcases/kernel/containers/mqns/mqns.h renamed from testcases/kernel/containers/mqns/common.h +4 -4
@@ -3,8 +3,8 @@* Copyright (C) 2022 SUSE LLC Andrea Cervesato <[email protected]> */ -#ifndef MQNS_COMMON_H -#define MQNS_COMMON_H +#ifndef MQNS_H +#define MQNS_H #include <stdlib.h> #include "lapi/namespaces_constants.h"
@@ -23,7 +23,7 @@ static int dummy_child1(void *v)return 0 ; } -static void check_newipc (void ) +static inline void check_newipc (void ) {int pid, status;
@@ -98,4 +98,4 @@ static void clone_unshare_test(int use_clone, unsigned long clone_flags, } } -#endif /* MQNS_COMMON_H */ +#endif /* MQNS_H */
testcases/kernel/containers/mqns/mqns_01.c +1 -1
@@ -12,7 +12,7 @@* the isolated/forked child namespace. */ -#include "common.h" +#include "mqns.h" #define MQNAME "/MQ1"
testcases/kernel/containers/mqns/mqns_02.c +1 -1
@@ -12,7 +12,7 @@* then check namespace isolation. */ -#include "common.h" +#include "mqns.h" #define MQNAME "/MQ1"
testcases/kernel/containers/mqns/mqns_03.c +1 -1
@@ -25,7 +25,7 @@#define _GNU_SOURCE#include <stdio.h> -#include "common.h" +#include "mqns.h" #include "tst_safe_stdio.h" #define MQNAME1 "/MQ1"
testcases/kernel/containers/mqns/mqns_04.c +1 -1
@@ -24,7 +24,7 @@#define _GNU_SOURCE#include <stdio.h> -#include "common.h" +#include "mqns.h" #include "tst_safe_stdio.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