syscall/kcmp*: Convert to new API
PATCH 1/3 syscall/kcmp*: Convert to new API
--- testcases/kernel/syscalls/kcmp/kcmp.h | 2 +- testcases/kernel/syscalls/kcmp/kcmp01.c | 119 ++++++++++++++------------------ testcases/kernel/syscalls/kcmp/kcmp02.c | 85 ++++++++--------------- 3 files changed, 82 insertions(+), 124 deletions(-)
testcases/kernel/syscalls/kcmp/kcmp.h +1 -1
@@ -46,7 +46,7 @@ enum kcmp_type {int kcmp (int pid1,int pid2,int type,int fd1,int fd2) { -return ltp_syscall (__NR_kcmp, pid1, pid2, type, fd1, fd2); +return tst_syscall (__NR_kcmp, pid1, pid2, type, fd1, fd2); }#endif
testcases/kernel/syscalls/kcmp/kcmp01.c +51 -68
166 lines not on this page · raw message
testcases/kernel/syscalls/kcmp/kcmp02.c +30 -55
123 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 2/3 lib/cloner.c: Add tst_clone.h for new API
Make sure the functions from lib/cloner.c can be used by new API.
--- include/tst_clone.h | 39 +++++++++++++++++++++++++++++++++++++++ include/tst_test.h | 1 + lib/cloner.c | 1 + 3 files changed, 41 insertions(+) create mode 100644 include/tst_clone.h
include/tst_clone.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Copyright (c) 2016 Xiao Yang <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of version 2 of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU General Public License along +* with this program. +* +*/ + +#ifndef TST_CLONE_H__ +#define TST_CLONE_H__ + +/* Functions from lib/cloner.c */ +int ltp_clone (unsigned long flags,int (*fn)(void *arg),void *arg, +size_t stack_size,void *stack); +int ltp_clone7 (unsigned long flags,int (*fn)(void *arg),void *arg, +size_t stack_size,void *stack, ...); +int ltp_clone_malloc (unsigned long clone_flags,int (*fn)(void *arg), +void *arg,size_t stacksize); +int ltp_clone_quick (unsigned long clone_flags,int (*fn)(void *arg), +void *arg); + +#define clone (...) (use_the_ltp_clone_functions, do_not_use_clone) + +#endif /* TST_CLONE_H__ */
include/tst_test.h +1 -0
@@ -32,6 +32,7 @@#include "tst_process_state.h" #include "tst_atomic.h" #include "tst_kvercmp.h" +#include "tst_clone.h" /* * Reports testcase result.
lib/cloner.c +1 -0
@@ -30,6 +30,7 @@#include <stdarg.h> #include "test.h" #include "config.h" +#include "tst_clone.h" #undef clone/* we want to use clone() */
Signature · 1 line
1.8.3.1
PATCH 2/3 lib/cloner.c: Add tst_clone.h for new API
Hi!
Quoted 25 lines
include/tst_clone.h new file +25
-0+/* +* Copyright (c) 2016 Xiao Yang <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of version 2 of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU General Public License along +* with this program. +* +*/ + +#ifndef TST_CLONE_H__ +#define TST_CLONE_H__
include/tst_clone.h line 35
Quoted 10 lines
include/tst_clone.h new file +10
-0+ +/* Functions from lib/cloner.c */ +int ltp_clone (unsigned long flags,int (*fn)(void *arg),void *arg, +size_t stack_size,void *stack); +int ltp_clone7 (unsigned long flags,int (*fn)(void *arg),void *arg, +size_t stack_size,void *stack, ...); +int ltp_clone_malloc (unsigned long clone_flags,int (*fn)(void *arg), +void *arg,size_t stacksize); +int ltp_clone_quick (unsigned long clone_flags,int (*fn)(void *arg), +void *arg);
I'm undecided if we should rename these to start with tst_ in the new library. Apart from that it's fine.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/3 syscalls/kcmp03.c: Add new testcase
In reply to Xiao Yang1) kcmp() returns 0 if the processes share the same file system information.
2) kcmp() returns 0 if the processes share I/O context.
3) kcmp() returns 0 if the processes share the same list of System V semaphore undo operations.
4) kcmp() returns 0 if the processes share the same address space.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/kcmp/kcmp03.c | 107 ++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 testcases/kernel/syscalls/kcmp/kcmp03.c
runtest/syscalls +1 -0
@@ -484,6 +484,7 @@ keyctl01 keyctl01 kcmp01 kcmp01 kcmp02 kcmp02 +kcmp03 kcmp03 kill01 kill01 kill02 kill02
testcases/kernel/syscalls/.gitignore +1 -0
@@ -452,6 +452,7 @@ /keyctl/keyctl01 /kcmp/kcmp01 /kcmp/kcmp02 +/kcmp/kcmp03 /kill/kill01 /kill/kill02 /kill/kill03
testcases/kernel/syscalls/kcmp/kcmp03.c new file +107 -0
107 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 3/3 syscalls/kcmp03.c: Add new testcase
Hi!
testcases/kernel/syscalls/kcmp/kcmp03.c line 44
Quoted 7 lines
testcases/kernel/syscalls/kcmp/kcmp03.c new file +7
-0+#ifndef CLONE_SYSVSEM +#define CLONE_SYSVSEM 0x00040000 +#endif + +#ifndef CLONE_IO +#define CLONE_IO 0x80000000 +#endif
These should rather go to the lapi/namespaces_constants.h
Quoted 21 lines
testcases/kernel/syscalls/kcmp/kcmp03.c new file +21
-0+#define STACK_SIZE (1024*1024) + +static int pid1; +static int pid2; + +static struct tcase { +int clone_type; +int kcmp_type; +} tcases[] = { + {CLONE_VM ,KCMP_VM }, + {CLONE_FS ,KCMP_FS }, + {CLONE_IO ,KCMP_IO }, + {CLONE_SYSVSEM ,KCMP_SYSVSEM } +}; + +static int do_child (void *arg) +{ + pid2 =getpid (); + +TEST (kcmp (pid1, pid2, *(int *)arg,0 ,0 )); +
testcases/kernel/syscalls/kcmp/kcmp03.c
Quoted 10 lines
testcases/kernel/syscalls/kcmp/kcmp03.c new file +10
-0+if (TEST_RETURN ==-1 ) { +tst_res (TFAIL |TTERRNO ,"kcmp() failed unexpectedly" ); +return 1 ; + } + +if (TEST_RETURN ==0 ) { +tst_res (TPASS ,"kcmp() returned the expected value" ); + }else { +tst_res (TFAIL ,"kcmp() returned the unexpected value" ); +return 1 ;
Why do we do the return 1 here if the value is not used at all? Why don't we just fall down to the return 0; below?
Quoted 5 lines
testcases/kernel/syscalls/kcmp/kcmp03.c new file +5
-0+ } + +return 0 ; +} +
testcases/kernel/syscalls/kcmp/kcmp03.c line 90
Quoted 10 lines
testcases/kernel/syscalls/kcmp/kcmp03.c new file +10
-0+static void verify_kcmp (unsigned int n) +{ +int res; +void *stack; + +struct tcase *tc = &tcases[n]; + + pid1 =getpid (); + + stack =SAFE_MALLOC (STACK_SIZE );
Well, the stack could be allocated once in the test setup and freed in the test cleanup.
Quoted 6 lines
testcases/kernel/syscalls/kcmp/kcmp03.c new file +6
-0+ res =ltp_clone (tc->clone_type |SIGCHLD , do_child, &tc->kcmp_type, +STACK_SIZE , stack); +if (res ==-1 ) +tst_res (TFAIL |TERRNO ,"clone() Failed" ); + +SAFE_WAIT (NULL );
testcases/kernel/syscalls/kcmp/kcmp03.c line 107
Quoted 10 lines
testcases/kernel/syscalls/kcmp/kcmp03.c new file +10
-0+ +free (stack); +} + +static struct tst_test test = { + .tid ="kcmp03" , + .tcnt =ARRAY_SIZE (tcases), + .test = verify_kcmp, + .min_kver ="3.5.0" +};
The rest is fine.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/3 syscall/kcmp*: Convert to new API
In reply to Xiao YangHi!
Quoted 11 lines
testcases/kernel/syscalls/kcmp/kcmp01.c +2
-7+static void verify_kcmp (unsigned int n) { -if (fd2 >0 &&close (fd2) <0 ) -tst_resm (TWARN |TERRNO ,"close fd2 failed" ); - fd2 =0 ; -if (fd3 >0 &&close (fd3) <0 ) -tst_resm (TWARN |TERRNO ,"close fd3 failed" ); - fd3 =0 ; -} +struct test_case *tc = &test_cases[n];
testcases/kernel/syscalls/kcmp/kcmp01.c static struct test_case { · line 115
Quoted 10 lines
testcases/kernel/syscalls/kcmp/kcmp01.c +2
-7-static void setup (void ) -{ -if ((tst_kvercmp (3 ,5 ,0 )) <0 ) { -tst_brkm (TCONF ,NULL , -"This test can only run on kernels that are 3.5. and higher" ); - } + pid1 =getpid (); -tst_tmpdir (); + fd1 =SAFE_OPEN (TEST_FILE ,O_CREAT |O_RDWR |O_TRUNC );
This SAFE_OPEN() has to be done in the test setup, otherwise it will start to fail with large enough iteration (-i) parameter once the maximal number of open files is reached.
The rest looks good.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/3 syscalls/kcmp*: Convert to new API
--- testcases/kernel/syscalls/kcmp/kcmp.h | 2 +- testcases/kernel/syscalls/kcmp/kcmp01.c | 121 ++++++++++++++------------------ testcases/kernel/syscalls/kcmp/kcmp02.c | 85 ++++++++-------------- 3 files changed, 84 insertions(+), 124 deletions(-)
testcases/kernel/syscalls/kcmp/kcmp.h +1 -1
@@ -46,7 +46,7 @@ enum kcmp_type {int kcmp (int pid1,int pid2,int type,int fd1,int fd2) { -return ltp_syscall (__NR_kcmp, pid1, pid2, type, fd1, fd2); +return tst_syscall (__NR_kcmp, pid1, pid2, type, fd1, fd2); }#endif
testcases/kernel/syscalls/kcmp/kcmp01.c +53 -68
168 lines not on this page · raw message
testcases/kernel/syscalls/kcmp/kcmp02.c +30 -55
123 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 2/3 lib/cloner.c: Add tst_clone.h for new API
Make sure the functions from lib/cloner.c can be used by new API.
--- include/tst_clone.h | 39 +++++++++++++++++++++++++++++++++++++++ include/tst_test.h | 1 + lib/cloner.c | 1 + 3 files changed, 41 insertions(+) create mode 100644 include/tst_clone.h
include/tst_clone.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Copyright (c) 2016 Xiao Yang <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of version 2 of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* +* Further, this software is distributed without any warranty that it is +* free of the rightful claim of any third person regarding infringement +* or the like. Any license provided herein, whether implied or +* otherwise, applies only to this software file. Patent licenses, if +* any, provided herein do not apply to combinations of this program with +* other software, or any other product whatsoever. +* +* You should have received a copy of the GNU General Public License along +* with this program. +* +*/ + +#ifndef TST_CLONE_H__ +#define TST_CLONE_H__ + +/* Functions from lib/cloner.c */ +int ltp_clone (unsigned long flags,int (*fn)(void *arg),void *arg, +size_t stack_size,void *stack); +int ltp_clone7 (unsigned long flags,int (*fn)(void *arg),void *arg, +size_t stack_size,void *stack, ...); +int ltp_clone_malloc (unsigned long clone_flags,int (*fn)(void *arg), +void *arg,size_t stacksize); +int ltp_clone_quick (unsigned long clone_flags,int (*fn)(void *arg), +void *arg); + +#define clone (...) (use_the_ltp_clone_functions, do_not_use_clone) + +#endif /* TST_CLONE_H__ */
include/tst_test.h +1 -0
@@ -32,6 +32,7 @@#include "tst_process_state.h" #include "tst_atomic.h" #include "tst_kvercmp.h" +#include "tst_clone.h" /* * Reports testcase result.
lib/cloner.c +1 -0
@@ -30,6 +30,7 @@#include <stdarg.h> #include "test.h" #include "config.h" +#include "tst_clone.h" #undef clone/* we want to use clone() */
Signature · 1 line
1.8.3.1
PATCH v2 2/3 lib/cloner.c: Add tst_clone.h for new API
Hi!
Quoted 1 line
Make sure the functions from
lib/cloner.ccan be used by new API.
I've made use of the tst_clone.h in the test.h as well, since it does not makes sense to keep two copies of the function prototypes and pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 3/3 syscalls/kcmp03.c: Add new testcase
In reply to Xiao Yang1) kcmp() returns 0 if the processes share the same file system information.
2) kcmp() returns 0 if the processes share I/O context.
3) kcmp() returns 0 if the processes share the same list of System V semaphore undo operations.
4) kcmp() returns 0 if the processes share the same address space.
--- include/lapi/sched.h | 16 +++++ runtest/syscalls | 1 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/kcmp/kcmp03.c | 105 ++++++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 testcases/kernel/syscalls/kcmp/kcmp03.c
include/lapi/sched.h +16 -0
@@ -56,4 +56,20 @@ int sched_getattr(pid_t pid, return syscall(__NR_sched_getattr, pid, attr, size, flags); } +#ifndef CLONE_VM +#define CLONE_VM 0x00000100 +#endif + +#ifndef CLONE_FS +#define CLONE_FS 0x00000200 +#endif + +#ifndef CLONE_SYSVSEM +#define CLONE_SYSVSEM 0x00040000 +#endif + +#ifndef CLONE_IO +#define CLONE_IO 0x80000000 +#endif +#endif /* __SCHED_H__ */
runtest/syscalls +1 -0
@@ -484,6 +484,7 @@ keyctl01 keyctl01 kcmp01 kcmp01 kcmp02 kcmp02 +kcmp03 kcmp03 kill01 kill01 kill02 kill02
testcases/kernel/syscalls/.gitignore +1 -0
@@ -452,6 +452,7 @@ /keyctl/keyctl01 /kcmp/kcmp01 /kcmp/kcmp02 +/kcmp/kcmp03 /kill/kill01 /kill/kill02 /kill/kill03
testcases/kernel/syscalls/kcmp/kcmp03.c new file +105 -0
105 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 3/3 syscalls/kcmp03.c: Add new testcase
Hi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/3 syscalls/kcmp*: Convert to new API
In reply to Xiao YangHi!
I've simplified the kcmp01.c a bit and pushed, thanks.
(We can safely use SAFE_CLOSE() in child since it's cleanup is not executed from test cleanup())
Signature · 2 lines
Cyril Hrubis [email protected]