add new syscall test for setns(2)
v2 cover add new syscall test for setns(2)
Changes in v2:
- fixed setns01 to work with commit 142e1d1d5f088e7a38659daca6e84a730967774a
- revamped setns01 to use namespace any fd/types available,
at the moment any from: ipc, mnt, net, pid, uts
- setns01 now runs each test for each namespace type
- fixed typo errors in setns02
- tested with 3.7 and 3.8.0-rc6
Sample output from 3.8.0-rc6+:
setns01 0 TINFO : ns_fds[0]=3, ns_types[0]=0x8000000 setns01 0 TINFO : ns_fds[1]=4, ns_types[1]=0x20000 setns01 0 TINFO : ns_fds[2]=5, ns_types[2]=0x40000000 setns01 0 TINFO : ns_fds[3]=6, ns_types[3]=0x20000000 setns01 0 TINFO : ns_fds[4]=7, ns_types[4]=0x4000000 setns01 0 TINFO : setns(-1, 0x8000000) setns01 1 TPASS : invalid fd exp_errno=9 setns01 0 TINFO : setns(-1, 0x20000) setns01 2 TPASS : invalid fd exp_errno=9 setns01 0 TINFO : setns(-1, 0x40000000) setns01 3 TPASS : invalid fd exp_errno=9 setns01 0 TINFO : setns(-1, 0x20000000) setns01 4 TPASS : invalid fd exp_errno=9 setns01 0 TINFO : setns(-1, 0x4000000) setns01 5 TPASS : invalid fd exp_errno=9 setns01 0 TINFO : setns(8, 0x8000000) setns01 6 TPASS : regular file fd exp_errno=22 setns01 0 TINFO : setns(8, 0x20000) setns01 7 TPASS : regular file fd exp_errno=22 setns01 0 TINFO : setns(8, 0x40000000) setns01 8 TPASS : regular file fd exp_errno=22 setns01 0 TINFO : setns(8, 0x20000000) setns01 9 TPASS : regular file fd exp_errno=22 setns01 0 TINFO : setns(8, 0x4000000) setns01 10 TPASS : regular file fd exp_errno=22 setns01 0 TINFO : setns(3, 0xffffffff) setns01 11 TPASS : invalid ns_type exp_errno=22 setns01 0 TINFO : setns(4, 0xffffffff) setns01 12 TPASS : invalid ns_type exp_errno=22 setns01 0 TINFO : setns(5, 0xffffffff) setns01 13 TPASS : invalid ns_type exp_errno=22 setns01 0 TINFO : setns(6, 0xffffffff) setns01 14 TPASS : invalid ns_type exp_errno=22 setns01 0 TINFO : setns(7, 0xffffffff) setns01 15 TPASS : invalid ns_type exp_errno=22 setns01 0 TINFO : setns(3, 0x20000) setns01 16 TPASS : mismatch ns_type/fd exp_errno=22 setns01 0 TINFO : setns(4, 0x40000000) setns01 17 TPASS : mismatch ns_type/fd exp_errno=22 setns01 0 TINFO : setns(5, 0x20000000) setns01 18 TPASS : mismatch ns_type/fd exp_errno=22 setns01 0 TINFO : setns(6, 0x4000000) setns01 19 TPASS : mismatch ns_type/fd exp_errno=22 setns01 0 TINFO : setns(7, 0x8000000) setns01 20 TPASS : mismatch ns_type/fd exp_errno=22 setns01 0 TINFO : setns(3, 0x8000000) setns01 21 TPASS : without CAP_SYS_ADMIN exp_errno=1 setns01 0 TINFO : setns(4, 0x20000) setns01 22 TPASS : without CAP_SYS_ADMIN exp_errno=1 setns01 0 TINFO : setns(5, 0x40000000) setns01 23 TPASS : without CAP_SYS_ADMIN exp_errno=1 setns01 0 TINFO : setns(6, 0x20000000) setns01 24 TPASS : without CAP_SYS_ADMIN exp_errno=1 setns01 0 TINFO : setns(7, 0x4000000) setns01 25 TPASS : without CAP_SYS_ADMIN exp_errno=1
setns02 0 TINFO : test_newuts setns02 0 TINFO : creating child with clone_flag=0x4000000, ns_flag=0x4000000 setns02 0 TINFO : (child) hostname (inherited from parent): dell-pe1950-05.lab.bos.redhat.com setns02 0 TINFO : (child) hostname changed to: setns_dummy_uts setns02 1 TPASS : (child) hostname is different in parent/child setns02 0 TINFO : (child) attempting to switch ns back to parent ns setns02 0 TINFO : (child) hostname: dell-pe1950-05.lab.bos.redhat.com setns02 2 TPASS : (child) hostname now as expected setns02 1 TPASS : child finished succesfully setns02 0 TINFO : creating child with clone_flag=0x4000000, ns_flag=0x0 setns02 0 TINFO : (child) hostname (inherited from parent): dell-pe1950-05.lab.bos.redhat.com setns02 0 TINFO : (child) hostname changed to: setns_dummy_uts setns02 2 TPASS : (child) hostname is different in parent/child setns02 0 TINFO : (child) attempting to switch ns back to parent ns setns02 0 TINFO : (child) hostname: dell-pe1950-05.lab.bos.redhat.com setns02 3 TPASS : (child) hostname now as expected setns02 2 TPASS : child finished succesfully setns02 0 TINFO : test_newipc setns02 0 TINFO : creating child with clone_flag=0x8000000, ns_flag=0x8000000 setns02 3 TPASS : (child) shmat failed as expected: errno=EINVAL(22): Invalid argument setns02 0 TINFO : (child) attempting to switch ns back to parent ns setns02 4 TPASS : (child) shmat suceeded setns02 3 TPASS : child finished succesfully setns02 0 TINFO : creating child with clone_flag=0x8000000, ns_flag=0x0 setns02 4 TPASS : (child) shmat failed as expected: errno=EINVAL(22): Invalid argument setns02 0 TINFO : (child) attempting to switch ns back to parent ns setns02 5 TPASS : (child) shmat suceeded setns02 4 TPASS : child finished succesfully
Jan Stancek (3):
setns: setup directory at kernel/syscalls/setns
setns: add new syscall test setns01
setns: add new syscall test setns02
runtest/syscalls | 3 + testcases/kernel/syscalls/.gitignore | 2 + testcases/kernel/syscalls/setns/Makefile | 23 +++ testcases/kernel/syscalls/setns/setns.h | 89 +++++++++++ testcases/kernel/syscalls/setns/setns01.c | 240 +++++++++++++++++++++++++++++ testcases/kernel/syscalls/setns/setns02.c | 231 +++++++++++++++++++++++++++ 6 files changed, 588 insertions(+), 0 deletions(-) create mode 100644 testcases/kernel/syscalls/setns/Makefile create mode 100644 testcases/kernel/syscalls/setns/setns.h create mode 100644 testcases/kernel/syscalls/setns/setns01.c create mode 100644 testcases/kernel/syscalls/setns/setns02.c
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Ltp-list mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
PATCH v2 1/3 setns: setup directory at kernel/syscalls/setns
--- testcases/kernel/syscalls/setns/Makefile | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-) create mode 100644 testcases/kernel/syscalls/setns/Makefile
testcases/kernel/syscalls/setns/Makefile new file +23 -0
@@ -0,0 +1,23 @@ +# +# Copyright (C) 2013 Linux Test Project, Inc. +# +# 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 St, Fifth Floor, Boston, MA 02110-1301 USA +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +CPPFLAGS += -Wno-unused-function +include $(top_srcdir)/include/mk/generic_leaf_target.mk
Signature · 12 lines
1.7.1 ------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
PATCH v2 2/3 setns: add new syscall test setns01
In reply to Jan Stancekerrno tests for setns(2) - reassociate thread with a namespace
--- runtest/syscalls | 2 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/setns/setns.h | 89 +++++++++++ testcases/kernel/syscalls/setns/setns01.c | 240 +++++++++++++++++++++++++++++ 4 files changed, 332 insertions(+), 0 deletions(-) create mode 100644 testcases/kernel/syscalls/setns/setns.h create mode 100644 testcases/kernel/syscalls/setns/setns01.c
runtest/syscalls +2 -0
@@ -962,6 +962,8 @@ setitimer01 setitimer01 setitimer02 setitimer02 setitimer03 setitimer03 +setns01 setns01 + setpgid01 setpgid01 setpgid02 setpgid02 setpgid03 setpgid03
testcases/kernel/syscalls/.gitignore +1 -0
@@ -763,6 +763,7 @@ /setitimer/setitimer01 /setitimer/setitimer02 /setitimer/setitimer03 +/setns/setns01 /setpgid/setpgid01 /setpgid/setpgid02 /setpgid/setpgid03
testcases/kernel/syscalls/setns/setns.h new file +89 -0
89 lines not on this page · raw message
testcases/kernel/syscalls/setns/setns01.c new file +240 -0
240 lines not on this page · raw message
Signature · 12 lines
1.7.1 ------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Re: [LTP] [PATCH v2 2/3] setns: add new syscall test setns01
Hi!
Quoted 14 lines
testcases/kernel/syscalls/setns/setns.h new file +14
-0+#define NS_MAX 5 +static int ns_types[NS_MAX ]; +static int ns_fds[NS_MAX ]; +static int ns_total; + +static int get_ns_fd (int pid,const char *ns) +{ +char tmp[PATH_MAX ]; +struct stat st; +int fd =-1 ; + +sprintf (tmp,"/proc/%d/%s" , pid, ns); +if (stat (tmp, &st) ==0 ) { + fd =open (tmp,O_RDONLY );
testcases/kernel/syscalls/setns/setns.h line 48
Quoted 10 lines
testcases/kernel/syscalls/setns/setns.h new file +10
-0+if (fd ==-1 ) +tst_brkm (TBROK |TERRNO ,NULL ,"failed to open %s" , tmp); + }else { +if (errno !=ENOENT ) +tst_brkm (TBROK |TERRNO ,NULL ,"failed to stat %s" , tmp); + } +return fd; +} + +static void init_available_ns ()
Missing void in the function parameters.
testcases/kernel/syscalls/setns/setns.h line 61
Quoted 13 lines
testcases/kernel/syscalls/setns/setns.h new file +13
-0+{ +#define INIT_NS_TYPE (clone_type, proc_name) \ +{ \ + int fd; \ + fd = get_ns_fd(getpid(), "ns/"proc_name); \ + if (fd != -1) { \ + ns_types[ns_total] = clone_type; \ + ns_fds[ns_total] = fd; \ + tst_resm(TINFO, "ns_fds[%d]=%d, ns_types[%d]=0x%x", ns_total, \ + fd, ns_total, clone_type); \ + ns_total++; \ + } \ +}
I'm wondering why this is a macro and not regular function. The only thing that I see and that wouldn't work is the string concatenation, which should have been done before the function is called. Or the get_ns_fd() could have additional parameter, since it uses sprintf() anyway.
Quoted 10 lines
testcases/kernel/syscalls/setns/setns.h new file +10
-0+#if defined(CLONE_NEWIPC ) +INIT_NS_TYPE (CLONE_NEWIPC ,"ipc" ); +#endif +#if defined(CLONE_NEWNS ) +INIT_NS_TYPE (CLONE_NEWNS ,"mnt" ); +#endif +#if defined(CLONE_NEWNET ) +INIT_NS_TYPE (CLONE_NEWNET ,"net" ); +#endif +#if defined(CLONE_NEWPID )
testcases/kernel/syscalls/setns/setns.h line 82
Quoted 10 lines
testcases/kernel/syscalls/setns/setns.h new file +10
-0+INIT_NS_TYPE (CLONE_NEWPID ,"pid" ); +#endif +#if defined(CLONE_NEWUTS ) +INIT_NS_TYPE (CLONE_NEWUTS ,"uts" ); +#endif + +#undef INIT_NS_TYPE +} + +static void close_ns_fds ()
Here missing void as well.
Quoted 7 lines
testcases/kernel/syscalls/setns/setns.h new file +7
-0+{ +int i; + +for (i =0 ; i < ns_total; i++) +if (ns_fds[i] !=-1 ) +close (ns_fds[i]); +}
Signature · 12 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
PATCH v2 3/3 setns: add new syscall test setns02
In reply to Jan Stancekfunctional test for setns(2) - reassociate thread with a namespace involving CLONE_NEWIPC and CLONE_NEWUTS.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/setns/setns02.c | 231 +++++++++++++++++++++++++++++ 3 files changed, 233 insertions(+), 0 deletions(-) create mode 100644 testcases/kernel/syscalls/setns/setns02.c
runtest/syscalls +1 -0
@@ -963,6 +963,7 @@ setitimer02 setitimer02 setitimer03 setitimer03 setns01 setns01 +setns02 setns02 setpgid01 setpgid01 setpgid02 setpgid02
testcases/kernel/syscalls/.gitignore +1 -0
@@ -764,6 +764,7 @@ /setitimer/setitimer02 /setitimer/setitimer03 /setns/setns01 +/setns/setns02 /setpgid/setpgid01 /setpgid/setpgid02 /setpgid/setpgid03
testcases/kernel/syscalls/setns/setns02.c new file +231 -0
231 lines not on this page · raw message
Signature · 12 lines
1.7.1 ------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Re: [LTP] [PATCH v2 3/3] setns: add new syscall test setns02
Hi!
testcases/kernel/syscalls/setns/setns02.c line 197
Quoted 9 lines
testcases/kernel/syscalls/setns/setns02.c new file +9
-0+static void setup (void ) +{ +char tmp[PATH_MAX ]; + +tst_require_root (NULL ); + +/* runtime check if syscall is supported */ +syscall (__NR_setns,-1 ,0 ); +
What happens when the syscall is not supported? The call should return -1 and errno should be set to ENOSYS but the return value is not checked, I'm puzzled.
Quoted 16 lines
testcases/kernel/syscalls/setns/setns02.c new file +16
-0+/* check if kernel has CONFIG_*_NS set and exports /proc entries */ + ns_ipc_fd =get_ns_fd (getpid (),"ns/ipc" ); + ns_uts_fd =get_ns_fd (getpid (),"ns/uts" ); +if (ns_ipc_fd ==-1 && ns_uts_fd ==-1 ) +tst_brkm (TCONF ,NULL ,"your kernel has CONFIG_IPC_NS, " +"CONFIG_UTS_NS or CONFIG_PROC disabled" ); + +if (getcwd (tmp,PATH_MAX ) ==NULL ) +tst_brkm (TBROK |TERRNO ,NULL ,"getcwd" ); + ipc_key =ftok (tmp,65 ); + shmid =shmget (ipc_key,getpagesize (),IPC_CREAT |0666 ); +if (shmid ==-1 ) +tst_brkm (TBROK |TERRNO ,NULL ,"shmget" ); + +TEST_PAUSE ; +}
Signature · 12 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [LTP] [PATCH v2 3/3] setns: add new syscall test setns02
Hi!
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
testcases/kernel/syscalls/setns/setns02.c new file +6
-0+static void setup (void ) +{ +char tmp[PATH_MAX ]; + +tst_require_root (NULL ); +Quoted 8 lines
testcases/kernel/syscalls/setns/setns02.c line 197
Quoted 3 lines
testcases/kernel/syscalls/setns/setns02.c new file +3
-0+/* runtime check if syscall is supported */ +syscall (__NR_setns,-1 ,0 ); +What happens when the syscall is not supported? The call should return
-1 and errno should be set to ENOSYS but the return value is not checked, I'm puzzled.
Quoted 2 lines
It's a bit unfortunate name collision with syscall macro defined in
linux_syscall_numbers.h. That macro contains check for ENOSYS.
Ah, now I remeber.
We really should change that one. Any volunteers?
Signature · 12 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [LTP] [PATCH v2 3/3] setns: add new syscall test setns02
Hi!
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
What happens when the syscall is not supported? The call should return
-1 and errno should be set to ENOSYS but the return value is not checked, I'm puzzled.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
It's a bit unfortunate name collision with syscall macro defined in
linux_syscall_numbers.h. That macro contains check for ENOSYS.Ah, now I remeber.
We really should change that one. Any volunteers?
Sure :-), would "
ltp_syscall" as name of that macro work for everyone?
Works for me.
Signature · 12 lines
Cyril Hrubis [email protected] ------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list