request_key/request_key01.c: add new testcase
PATCH 1/2 request_key/request_key01.c: add new testcase
The testcase checks the basic functionality of the request_key(2). request_key(2) asks the kernel to find a key which matches the specified description. If successful, it attaches it to the nominated keyring and returns its serial number.
--- runtest/ltplite | 2 + runtest/syscalls | 2 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/request_key/Makefile | 22 +++++ .../kernel/syscalls/request_key/request_key01.c | 107 +++++++++++++++++++++ 5 files changed, 134 insertions(+) create mode 100644 testcases/kernel/syscalls/request_key/Makefile create mode 100644 testcases/kernel/syscalls/request_key/request_key01.c
runtest/ltplite +2 -0
@@ -663,6 +663,8 @@ rename12 rename12 rename13 rename13 rename14 rename14 +request_key01 request_key01 + rmdir01 rmdir01 rmdir02 rmdir02 rmdir03 rmdir03
runtest/syscalls +2 -0
@@ -891,6 +891,8 @@ renameat01 renameat01 renameat201 renameat201 renameat202 renameat202 -i 10 +request_key01 request_key01 + rmdir01 rmdir01 rmdir02 rmdir02 rmdir03 rmdir03
testcases/kernel/syscalls/.gitignore +1 -0
@@ -736,6 +736,7 @@ /renameat/renameat01 /renameat2/renameat201 /renameat2/renameat202 +/request_key/request_key01 /rmdir/rmdir01 /rmdir/rmdir02 /rmdir/rmdir03
testcases/kernel/syscalls/request_key/Makefile new file +22 -0
@@ -0,0 +1,22 @@ +# Copyright (c) 2016 Fujitsu Ltd. +# Author: Xiao Yang <[email protected]> +# +# 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. +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/request_key/request_key01.c new file +107 -0
107 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 2/2 request_key/request_key02.c: add new testcase
1) request_key(2) fails if no matching key was found and set errno to ENOKEY.
2) request_key(2) fails if a revoked key was found and set errno to EKEYREVOKED.
3) request_key(2) fails if an expired key was found and set errno to EKEYEXPIRED.
--- runtest/ltplite | 1 + runtest/syscalls | 1 + testcases/kernel/syscalls/.gitignore | 1 + .../kernel/syscalls/request_key/request_key02.c | 143 +++++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 testcases/kernel/syscalls/request_key/request_key02.c
runtest/ltplite +1 -0
@@ -664,6 +664,7 @@ rename13 rename13 rename14 rename14 request_key01 request_key01 +request_key02 request_key02 rmdir01 rmdir01 rmdir02 rmdir02
runtest/syscalls +1 -0
@@ -892,6 +892,7 @@ renameat201 renameat201 renameat202 renameat202 -i 10 request_key01 request_key01 +request_key02 request_key02 rmdir01 rmdir01 rmdir02 rmdir02
testcases/kernel/syscalls/.gitignore +1 -0
@@ -737,6 +737,7 @@ /renameat2/renameat201 /renameat2/renameat202 /request_key/request_key01 +/request_key/request_key02 /rmdir/rmdir01 /rmdir/rmdir02 /rmdir/rmdir03
testcases/kernel/syscalls/request_key/request_key02.c new file +143 -0
143 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 2/2 request_key/request_key02.c: add new testcase
Hi!
Quoted 39 lines
testcases/kernel/syscalls/request_key/request_key02.c new file +39
-0+#ifdef HAVE_LINUX_KEYCTL_H + +static struct test_case { +const char *des; +int exp_err; +} tc[] = { +/* test1 */ + {"ltp1" ,ENOKEY }, +/* test2 */ + {"ltp" ,EKEYREVOKED }, +/* test3 */ + {"ltp" ,EKEYEXPIRED } +}; + +static void verify_request_key (struct test_case *); +static void setup (void ); +static void cleanup (void ); + +int TST_TOTAL =ARRAY_SIZE (tc); + +int main (int ac,char **av) +{ +int lc; +int i; + +tst_parse_opts (ac, av,NULL ,NULL ); + +setup (); + +for (lc =0 ;TEST_LOOPING (lc); lc++) { + tst_count =0 ; + +for (i =0 ; i <TST_TOTAL ; i++) +verify_request_key (&tc[i]); + } + +cleanup (); +tst_exit (); +}
testcases/kernel/syscalls/request_key/request_key02.c line 92
Quoted 10 lines
testcases/kernel/syscalls/request_key/request_key02.c new file +10
-0+ +static void verify_request_key (struct test_case *tc) +{ +int sec =1 ; +int res; +int n; + + res =ltp_syscall (__NR_add_key,"keyring" ,"ltp" ,NULL ,0 ,KEY_SPEC_THREAD_KEYRING ); +if (res ==-1 ) +tst_brkm (TBROK |TERRNO , cleanup,"add_key() failed" );
Here as well, do not call the raw syscalls here.
Quoted 6 lines
testcases/kernel/syscalls/request_key/request_key02.c new file +6
-0+if (tc->exp_err ==EKEYREVOKED ) { + n =ltp_syscall (__NR_keyctl,KEYCTL_REVOKE , res); +if (n ==-1 ) { +tst_brkm (TBROK |TERRNO , cleanup, +"fail to revoke a key" ); + }
testcases/kernel/syscalls/request_key/request_key02.c line 109
Quoted 10 lines
testcases/kernel/syscalls/request_key/request_key02.c new file +10
-0+ } + +if (tc->exp_err ==EKEYEXPIRED ) { + n =ltp_syscall (__NR_keyctl,KEYCTL_SET_TIMEOUT , res, sec); +if (n ==-1 ) { +tst_brkm (TBROK |TERRNO , cleanup, +"fail to set timeout for a key" ); + } +sleep (sec +1 ); + }
This part should be done in setup as well, especially since the the expiration takes at least second to expire. As it is ten iteration of this test would take 20 seconds compared with 2 seconds if this was done in setup.
Quoted 41 lines
testcases/kernel/syscalls/request_key/request_key02.c new file +33
-0+TEST (ltp_syscall (__NR_request_key,"keyring" , tc->des,NULL , res)); +if (TEST_RETURN !=-1 ) { +tst_resm (TFAIL ,"request_key() succeed unexpectly" ); +return ; + } +if (TEST_ERRNO == tc->exp_err) +tst_resm (TPASS |TTERRNO ,"request_key() failed expectly" ); +else + tst_resm(TFAIL | TTERRNO, "request_key() failed unexpectly"); +} + +static void setup (void ) +{ +tst_require_root (); + +tst_sig (NOFORK ,DEF_HANDLER , cleanup); + +TEST_PAUSE ; + +tst_tmpdir (); +} + +static void cleanup (void ) +{ +tst_rmdir (); +} + +#else +int main (int ac,char **av) +{ +tst_brkm (TCONF ,NULL ,"linux/keyctl.h was missing upon compilation." ); +} +#endif Signature · 7 lines
1.8.3.1 -- Mailing list info: http://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/2 request_key/request_key01.c: add new testcase
The testcase checks basic functionality of the request_key(2). request_key(2) asks the kernel to find a key which matches the specified description. If successful, it attaches it to the nominated keyring and returns its serial number.
--- configure.ac | 1 + runtest/ltplite | 2 + runtest/syscalls | 2 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/request_key/Makefile | 27 ++++++ .../kernel/syscalls/request_key/request_key01.c | 103 +++++++++++++++++++++ 6 files changed, 136 insertions(+) create mode 100644 testcases/kernel/syscalls/request_key/Makefile create mode 100644 testcases/kernel/syscalls/request_key/request_key01.c
configure.ac +1 -0
@@ -45,6 +45,7 @@ AC_CHECK_HEADERS([ \ sys/fanotify.h \ sys/jfsdmapi.h \ sys/prctl.h \ + keyutils.h \ ]) # Tools knobs
runtest/ltplite +2 -0
@@ -668,6 +668,8 @@ rename12 rename12 rename13 rename13 rename14 rename14 +request_key01 request_key01 + rmdir01 rmdir01 rmdir02 rmdir02 rmdir03 rmdir03
runtest/syscalls +2 -0
@@ -896,6 +896,8 @@ renameat01 renameat01 renameat201 renameat201 renameat202 renameat202 -i 10 +request_key01 request_key01 + rmdir01 rmdir01 rmdir02 rmdir02 rmdir03 rmdir03
testcases/kernel/syscalls/.gitignore +1 -0
@@ -740,6 +740,7 @@ /renameat/renameat01 /renameat2/renameat201 /renameat2/renameat202 +/request_key/request_key01 /rmdir/rmdir01 /rmdir/rmdir02 /rmdir/rmdir03
testcases/kernel/syscalls/request_key/Makefile new file +27 -0
@@ -0,0 +1,27 @@ +# Copyright (c) 2016 Fujitsu Ltd. +# Author: Xiao Yang <[email protected]> +# +# 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. +# + +top_srcdir ?= ../../../.. +have_keyutil ?= /usr/include/keyutils.h + +include $(top_srcdir)/include/mk/testcases.mk + +ifeq ($(have_keyutil), $(wildcard $(have_keyutil))) +LDLIBS += -lkeyutils +endif + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/request_key/request_key01.c new file +103 -0
103 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 1/2 request_key/request_key01.c: add new testcase
Hi!
ping :-)
Thanks
Xiao Yang
Quoted 209 lines
The testcase checks basic functionality of the
request_key(2).request_key(2)asks the kernel to find a key which matches the specified description. If successful, it attaches it to the nominated keyring and returns its serial number.Signed-off-by Xiao Yang <[email protected]>--- configure.ac | 1 + runtest/ltplite | 2 + runtest/syscalls | 2 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/request_key/Makefile | 27 ++++++ .../kernel/syscalls/request_key/request_key01.c | 103 +++++++++++++++++++++ 6 files changed, 136 insertions(+) create mode 100644 testcases/kernel/syscalls/request_key/Makefile create mode 100644 testcases/kernel/syscalls/request_key/request_key01.cconfigure.ac +1
-0@@ -45,6 +45,7 @@ AC_CHECK_HEADERS([ \ sys/fanotify.h \ sys/jfsdmapi.h \ sys/prctl.h \ + keyutils.h \ ]) # Tools knobsruntest/ltplite +2
-0@@ -668,6 +668,8 @@ rename12 rename12 rename13 rename13 rename14 rename14 +request_key01 request_key01 + rmdir01 rmdir01 rmdir02 rmdir02 rmdir03 rmdir03runtest/syscalls +2
-0@@ -896,6 +896,8 @@ renameat01 renameat01 renameat201 renameat201 renameat202 renameat202 -i 10 +request_key01 request_key01 + rmdir01 rmdir01 rmdir02 rmdir02 rmdir03 rmdir03testcases/kernel/syscalls/.gitignore +1
-0@@ -740,6 +740,7 @@ /renameat/renameat01 /renameat2/renameat201 /renameat2/renameat202 +/request_key/request_key01 /rmdir/rmdir01 /rmdir/rmdir02 /rmdir/rmdir03testcases/kernel/syscalls/request_key/Makefile new file +27
-0@@ -0,0 +1,27 @@ +# Copyright (c) 2016 Fujitsu Ltd. +# Author: Xiao Yang <[email protected]> +# +# 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. +# + +top_srcdir ?= ../../../.. +have_keyutil ?= /usr/include/keyutils.h + +include $(top_srcdir)/include/mk/testcases.mk + +ifeq ($(have_keyutil), $(wildcard $(have_keyutil))) +LDLIBS += -lkeyutils +endif + +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/syscalls/request_key/request_key01.c new file +103
-0@@ -0,0 +1,103 @@ +/* +* Copyright (c) 2016 Fujitsu Ltd. +* Author: 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. +* +* You should have received a copy of the GNU General Public License +* alone with this program. +*/ + +/* +* Test Name: request_key01 +* +* Description: +* The testcase checks basic functionality of the request_key(2). +* request_key(2) asks the kernel to find a key which matches the +* specified description. If successful, it attaches it to the +* nominated keyring and returns its serial number. +* +*/ + +#include "config.h" +#include <errno.h> +#include <sys/types.h> +#ifdef HAVE_KEYUTILS_H +#include <keyutils.h> +#endif + +#include "test.h" + +char *TCID ="request_key01" ; + +static int res; + +static void verify_request_key (void ); +static void setup (void ); +static void cleanup (void ); + +int TST_TOTAL =1 ; + +#ifdef HAVE_KEYUTILS_H +int main (int ac,char **av) +{ +int lc; + +tst_parse_opts (ac, av,NULL ,NULL ); + +setup (); + +for (lc =0 ;TEST_LOOPING (lc); lc++) { + tst_count =0 ; + +verify_request_key (); + } + +cleanup (); +tst_exit (); +} + +static void verify_request_key (void ) +{ +TEST (request_key ("keyring" ,"ltp" ,NULL ,KEY_REQKEY_DEFL_DEFAULT )); +if (TEST_RETURN ==-1 ) { +tst_resm (TFAIL |TERRNO ,"request_key() failed" ); +return ; + } + +if (TEST_RETURN != res) +tst_resm (TFAIL ,"serial number mismatched" ); +else +tst_resm (TPASS ,"request_key() succeed" ); +} + +static void setup (void ) +{ +tst_sig (NOFORK ,DEF_HANDLER , cleanup); + +TEST_PAUSE ; + +tst_tmpdir (); + + res =add_key ("keyring" ,"ltp" ,NULL ,0 ,KEY_SPEC_THREAD_KEYRING ); +if (res ==-1 ) +tst_brkm (TBROK |TERRNO , cleanup,"add_key() failed" ); +} + +static void cleanup (void ) +{ +tst_rmdir (); +} + +#else +int main (void ) +{ +tst_brkm (TCONF ,NULL ,"compilation failed without keyutils.h" ); +} +#endif /* HAVE_LINUX_KEYCTL_H */
PATCH v2 2/2 request_key/request_key02.c: add new testcase
In reply to Xiao Yang1) request_key(2) fails if no matching key was found and set errno to ENOKEY.
2) request_key(2) fails if a revoked key was found and set errno to EKEYREVOKED.
3) request_key(2) fails if an expired key was found and set errno to EKEYEXPIRED.
--- runtest/ltplite | 1 + runtest/syscalls | 1 + testcases/kernel/syscalls/.gitignore | 1 + .../kernel/syscalls/request_key/request_key02.c | 150 +++++++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 testcases/kernel/syscalls/request_key/request_key02.c
runtest/ltplite +1 -0
@@ -669,6 +669,7 @@ rename13 rename13 rename14 rename14 request_key01 request_key01 +request_key02 request_key02 rmdir01 rmdir01 rmdir02 rmdir02
runtest/syscalls +1 -0
@@ -897,6 +897,7 @@ renameat201 renameat201 renameat202 renameat202 -i 10 request_key01 request_key01 +request_key02 request_key02 rmdir01 rmdir01 rmdir02 rmdir02
testcases/kernel/syscalls/.gitignore +1 -0
@@ -741,6 +741,7 @@ /renameat2/renameat201 /renameat2/renameat202 /request_key/request_key01 +/request_key/request_key02 /rmdir/rmdir01 /rmdir/rmdir02 /rmdir/rmdir03
testcases/kernel/syscalls/request_key/request_key02.c new file +150 -0
150 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 2/2 request_key/request_key02.c: add new testcase
Hi!
Quoted 68 lines
testcases/kernel/syscalls/request_key/request_key02.c new file +68
-0+/* +* Test Name: request_key02 +* +* Description: +* 1) request_key(2) fails if no matching key was found. +* 2) request_key(2) fails if A revoked key was found. +* 3) request_key(2) fails if An expired key was found. +* +* Expected Result: +* 1) request_key(2) should return -1 and set errno to ENOKEY. +* 2) request_key(2) should return -1 and set errno to EKEYREVOKED. +* 3) request_key(2) should return -1 and set errno to EKEYEXPIRED. +* +*/ + +#include "config.h" +#include <errno.h> +#include <sys/types.h> +#ifdef HAVE_KEYUTILS_H +#include <keyutils.h> +#endif +#include "test.h" + +char *TCID ="request_key02" ; + +static struct test_case { +const char *des; +int exp_err; +int id; +} tc[] = { +/* test1 */ + {"ltp1" ,ENOKEY ,0 }, +/* test2 */ + {"ltp2" ,EKEYREVOKED ,0 }, +/* test3 */ + {"ltp3" ,EKEYEXPIRED ,0 } +}; + +static void verify_request_key (struct test_case *); +static void setup (void ); +static int init_key (char *,int ); +static void cleanup (void ); + +int TST_TOTAL =ARRAY_SIZE (tc); + +#ifdef HAVE_KEYUTILS_H +int main (int ac,char **av) +{ +int lc; +int i; + +tst_parse_opts (ac, av,NULL ,NULL ); + +setup (); + +for (lc =0 ;TEST_LOOPING (lc); lc++) { + tst_count =0 ; + +for (i =0 ; i <TST_TOTAL ; i++) +verify_request_key (&tc[i]); + } + +cleanup (); +tst_exit (); +} + +static void verify_request_key (struct test_case *tc) +{
testcases/kernel/syscalls/request_key/request_key02.c line 94
Quoted 10 lines
testcases/kernel/syscalls/request_key/request_key02.c new file +10
-0+TEST (request_key ("keyring" , tc->des,NULL , tc->id)); +if (TEST_RETURN !=-1 ) { +tst_resm (TFAIL ,"request_key() succeed unexpectly" ); +return ; + } + +if (TEST_ERRNO == tc->exp_err) +tst_resm (TPASS |TTERRNO ,"request_key() failed expectly" ); +else +tst_resm (TFAIL |TTERRNO ,"request_key() failed unexpectly" );
Ideally the error message should contain the expected errno as well.
testcases/kernel/syscalls/request_key/request_key02.c line 103
Quoted 9 lines
testcases/kernel/syscalls/request_key/request_key02.c new file +9
-0+} + +static void setup (void ) +{ +tst_sig (NOFORK ,DEF_HANDLER , cleanup); + +TEST_PAUSE ; + +tst_tmpdir ();
Here as well.
testcases/kernel/syscalls/request_key/request_key02.c line 109
Quoted 5 lines
testcases/kernel/syscalls/request_key/request_key02.c new file +5
-0+ tc[0 ].id =KEY_REQKEY_DEFL_DEFAULT ; + + tc[1 ].id =init_key ("ltp2" ,KEYCTL_REVOKE ); + + tc[2 ].id =init_key ("ltp3" ,KEYCTL_SET_TIMEOUT );
This is ugly. What you should do instead is to declare the id in the test structure as a pointer and initialize it to a pointer to a variable that is initialized in the setup.
Quoted 29 lines
testcases/kernel/syscalls/request_key/request_key02.c new file +29
-0+} + +static int init_key (char *name,int cmd) +{ +int n; +int sec =1 ; + + n =add_key ("keyring" , name,NULL ,0 ,KEY_SPEC_THREAD_KEYRING ); +if (n ==-1 ) +tst_brkm (TBROK |TERRNO , cleanup,"add_key() failed" ); + +if (cmd ==KEYCTL_REVOKE ) { +if (keyctl (cmd, n) ==-1 ) { +tst_brkm (TBROK |TERRNO , cleanup, +"failed to revoke a key" ); + } + } + +if (cmd ==KEYCTL_SET_TIMEOUT ) { +if (keyctl (cmd, n, sec) ==-1 ) { +tst_brkm (TBROK |TERRNO , cleanup, +"failed to set timeout for a key" ); + } + +sleep (sec +1 ); + } + +return n; +}
testcases/kernel/syscalls/request_key/request_key02.c line 148
Quoted 10 lines
testcases/kernel/syscalls/request_key/request_key02.c new file +10
-0+ +static void cleanup (void ) +{ +tst_rmdir (); +} + +#else +int main (void ) +{ +tst_brkm (TCONF ,NULL ,"compilation failed without keyutils.h" );
Here as well.
Quoted 2 lines
(quoted diff) +2
-0+} +#endif /* HAVE_LINUX_KEYCTL_H */
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/2 request_key/request_key01.c: add new testcase
The testcase checks basic functionality of the request_key(2). request_key(2) asks the kernel to find a key which matches the specified description. If successful, it attaches it to the nominated keyring and returns its serial number.
--- configure.ac | 1 + include/mk/config.mk.in | 1 + m4/ltp-keyutils.m4 | 24 ++++++ runtest/ltplite | 2 + runtest/syscalls | 2 + testcases/kernel/syscalls/.gitignore | 1 + testcases/kernel/syscalls/request_key/Makefile | 24 ++++++ .../kernel/syscalls/request_key/request_key01.c | 95 ++++++++++++++++++++++ 8 files changed, 150 insertions(+) create mode 100644 m4/ltp-keyutils.m4 create mode 100644 testcases/kernel/syscalls/request_key/Makefile create mode 100644 testcases/kernel/syscalls/request_key/request_key01.c
configure.ac +1 -0
@@ -185,5 +185,6 @@ LTP_CHECK_KCMP_TYPE LTP_CHECK_PREADV LTP_CHECK_PWRITEV LTP_CHECK_EPOLL_PWAIT +LTP_CHECK_KEYUTILS_SUPPORT AC_OUTPUT
include/mk/config.mk.in +1 -0
@@ -46,6 +46,7 @@ NUMA_LIBS := @NUMA_LIBS@ SELINUX_LIBS := @SELINUX_LIBS@ TIRPC_CPPFLAGS := @TIRPC_CPPFLAGS@ TIRPC_LIBS := @TIRPC_LIBS@ +KEYUTILS_LIBS := @KEYUTILS_LIBS@ prefix := @prefix@
m4/ltp-keyutils.m4 new file +24 -0
@@ -0,0 +1,24 @@ +dnl +dnl Copyright (c) 2016 Fujitsu Ltd. +dnl Author: Xiao Yang <[email protected]> +dnl +dnl This program is free software; you can redistribute it and/or modify it +dnl under the terms of version 2 of the GNU General Public License as +dnl published by the Free Software Foundation. +dnl +dnl This program is distributed in the hope that it would be useful, but +dnl WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +dnl +dnl You should have received a copy of the GNU General Public License +dnl alone with this program. +dnl + +dnl +dnl LTP_CHECK_KEYUTILS_SUPPORT +dnl ---------------------------- +dnl +AC_DEFUN([LTP_CHECK_KEYUTILS_SUPPORT],[ +AC_CHECK_HEADERS([keyutils.h], [keyutils_libs="-lkeyutils"]) +AC_SUBST([KEYUTILS_LIBS], [$keyutils_libs]) +])
runtest/ltplite +2 -0
@@ -664,6 +664,8 @@ rename12 rename12 rename13 rename13 rename14 rename14 +request_key01 request_key01 + rmdir01 rmdir01 rmdir02 rmdir02 rmdir03 rmdir03
runtest/syscalls +2 -0
@@ -895,6 +895,8 @@ renameat01 renameat01 renameat201 renameat201 renameat202 renameat202 -i 10 +request_key01 request_key01 + rmdir01 rmdir01 rmdir02 rmdir02 rmdir03 rmdir03
testcases/kernel/syscalls/.gitignore +1 -0
@@ -742,6 +742,7 @@ /renameat/renameat01 /renameat2/renameat201 /renameat2/renameat202 +/request_key/request_key01 /rmdir/rmdir01 /rmdir/rmdir02 /rmdir/rmdir03
testcases/kernel/syscalls/request_key/Makefile new file +24 -0
@@ -0,0 +1,24 @@ +# Copyright (c) 2016 Fujitsu Ltd. +# Author: Xiao Yang <[email protected]> +# +# 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. +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +LDLIBS += $(KEYUTILS_LIBS) + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/request_key/request_key01.c new file +95 -0
95 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 2/2 request_key/request_key02.c: add new testcase
1) request_key(2) fails if no matching key was found and set errno to ENOKEY.
2) request_key(2) fails if a revoked key was found and set errno to EKEYREVOKED.
3) request_key(2) fails if an expired key was found and set errno to EKEYEXPIRED.
--- runtest/ltplite | 1 + runtest/syscalls | 1 + testcases/kernel/syscalls/.gitignore | 1 + .../kernel/syscalls/request_key/request_key02.c | 146 +++++++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 testcases/kernel/syscalls/request_key/request_key02.c
runtest/ltplite +1 -0
@@ -665,6 +665,7 @@ rename13 rename13 rename14 rename14 request_key01 request_key01 +request_key02 request_key02 rmdir01 rmdir01 rmdir02 rmdir02
runtest/syscalls +1 -0
@@ -896,6 +896,7 @@ renameat201 renameat201 renameat202 renameat202 -i 10 request_key01 request_key01 +request_key02 request_key02 rmdir01 rmdir01 rmdir02 rmdir02
testcases/kernel/syscalls/.gitignore +1 -0
@@ -743,6 +743,7 @@ /renameat2/renameat201 /renameat2/renameat202 /request_key/request_key01 +/request_key/request_key02 /rmdir/rmdir01 /rmdir/rmdir02 /rmdir/rmdir03
testcases/kernel/syscalls/request_key/request_key02.c new file +146 -0
146 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v3 2/2 request_key/request_key02.c: add new testcase
Hi!
I've rewrote the tests for the new test library and pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/2 request_key/request_key01.c: add new testcase
In reply to Xiao YangHi!
Quoted 14 lines
testcases/kernel/syscalls/request_key/Makefile new file +13
-0@@ -0,0 +1,27 @@ +# Copyright (c) 2016 Fujitsu Ltd. +# Author: Xiao Yang <[email protected]> +# +# 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. +#
testcases/kernel/syscalls/request_key/Makefile line 23
Quoted 10 lines
testcases/kernel/syscalls/request_key/Makefile new file +10
-0+# You should have received a copy of the GNU General Public License +# along with this program. +# + +top_srcdir ?= ../../../.. +have_keyutil ?= /usr/include/keyutils.h + +include $(top_srcdir)/include/mk/testcases.mk + +ifeq ($(have_keyutil), $(wildcard $(have_keyutil)))
This is ugly hack. The header does not need to be in the standard path at all. What you should do instead is to call AC_SUBST([KEYUTIL_LIBS, ...) in the configure part and do LDLIBS+=$(KEYUTILS_LIBS) here. Have a look at the m4/ltp-acl.m4 or m4/ltp-cap.m4 for instance.
Quoted 86 lines
testcases/kernel/syscalls/request_key/Makefile new file +4
-0+LDLIBS += -lkeyutils +endif + +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/syscalls/request_key/request_key01.c new file +76
-0@@ -0,0 +1,103 @@ +/* +* Copyright (c) 2016 Fujitsu Ltd. +* Author: 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. +* +* You should have received a copy of the GNU General Public License +* alone with this program. +*/ + +/* +* Test Name: request_key01 +* +* Description: +* The testcase checks basic functionality of the request_key(2). +* request_key(2) asks the kernel to find a key which matches the +* specified description. If successful, it attaches it to the +* nominated keyring and returns its serial number. +* +*/ + +#include "config.h" +#include <errno.h> +#include <sys/types.h> +#ifdef HAVE_KEYUTILS_H +#include <keyutils.h> +#endif + +#include "test.h" + +char *TCID ="request_key01" ; + +static int res; + +static void verify_request_key (void ); +static void setup (void ); +static void cleanup (void ); + +int TST_TOTAL =1 ; + +#ifdef HAVE_KEYUTILS_H +int main (int ac,char **av) +{ +int lc; + +tst_parse_opts (ac, av,NULL ,NULL ); + +setup (); + +for (lc =0 ;TEST_LOOPING (lc); lc++) { + tst_count =0 ; + +verify_request_key (); + } + +cleanup (); +tst_exit (); +} + +static void verify_request_key (void ) +{ +TEST (request_key ("keyring" ,"ltp" ,NULL ,KEY_REQKEY_DEFL_DEFAULT )); +if (TEST_RETURN ==-1 ) { +tst_resm (TFAIL |TERRNO ,"request_key() failed" ); +return ; + } + +if (TEST_RETURN != res) +tst_resm (TFAIL ,"serial number mismatched" ); +else
testcases/kernel/syscalls/request_key/request_key01.c line 86
Quoted 10 lines
testcases/kernel/syscalls/request_key/request_key01.c new file +10
-0+tst_resm (TPASS ,"request_key() succeed" ); +} + +static void setup (void ) +{ +tst_sig (NOFORK ,DEF_HANDLER , cleanup); + +TEST_PAUSE ; + +tst_tmpdir ();
What do we create the temporary directory for? The test does not seem to work with files at all.
Quoted 4 lines
testcases/kernel/syscalls/request_key/request_key01.c new file +4
-0+ res =add_key ("keyring" ,"ltp" ,NULL ,0 ,KEY_SPEC_THREAD_KEYRING ); +if (res ==-1 ) +tst_brkm (TBROK |TERRNO , cleanup,"add_key() failed" ); +}
testcases/kernel/syscalls/request_key/request_key01.c line 101
Quoted 10 lines
testcases/kernel/syscalls/request_key/request_key01.c new file +10
-0+ +static void cleanup (void ) +{ +tst_rmdir (); +} + +#else +int main (void ) +{ +tst_brkm (TCONF ,NULL ,"compilation failed without keyutils.h" );
^
Technically it didn't fail, but only stub was compiled due to missing library.
It should say something as:
"keyutils.h was missing at compilation"
Quoted 7 lines
testcases/kernel/syscalls/request_key/request_key01.c new file +2
-0+} +#endif /* HAVE_LINUX_KEYCTL_H */ Signature · 1 line
1.8.3.1
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/2 request_key/request_key01.c: add new testcase
In reply to Xiao YangHi!
Quoted 63 lines
testcases/kernel/syscalls/request_key/request_key01.c new file +60
-0@@ -0,0 +1,107 @@ +/* +* Copyright (c) 2016 Fujitsu Ltd. +* Author: 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. +* +* You should have received a copy of the GNU General Public License +* alone with this program. +*/ + +/* +* Test Name: request_key01 +* +* Description: +* The testcase checks the basic functionality of the request_key(2). +* request_key(2) asks the kernel to find a key which matches the +* specified description. If successful, it attaches it to the nominated +* keyring and returns its serial number. +* +*/ + +#include "config.h" +#include <errno.h> + +#ifdef HAVE_LINUX_KEYCTL_H +#include <linux/keyctl.h> +#endif + +#include "test.h" +#include "linux_syscall_numbers.h" + +char *TCID ="request_key01" ; + +#ifdef HAVE_LINUX_KEYCTL_H + +static void verify_request_key (void ); +static void setup (void ); +static void cleanup (void ); + +int TST_TOTAL =1 ; + +int main (int ac,char **av) +{ +int lc; + +tst_parse_opts (ac, av,NULL ,NULL ); + +setup (); + +for (lc =0 ;TEST_LOOPING (lc); lc++) { + tst_count =0 ; + +verify_request_key (); + }
testcases/kernel/syscalls/request_key/request_key01.c line 70
Quoted 10 lines
testcases/kernel/syscalls/request_key/request_key01.c new file +10
-0+ +cleanup (); +tst_exit (); +} + +static void verify_request_key (void ) +{ +int res; + + res =ltp_syscall (__NR_add_key,"keyring" ,"ltp" ,NULL ,0 ,KEY_SPEC_THREAD_KEYRING );
You should not call the add_key directly via syscall here.
Ideally you should add a common wrapper into a shared header and possibly use keyutils library, if it's available.
And the same goes for KEY_SPEC_THREAD_KEYRING. There is no reason to ifdef the whole testcases out if this value is not defined. You just have to add a lapi/keyctl.h header with fallback definitons.
testcases/kernel/syscalls/request_key/request_key01.c line 72
Quoted 2 lines
testcases/kernel/syscalls/request_key/request_key01.c new file +2
-0+if (res ==-1 ) +tst_brkm (TBROK |TERRNO , cleanup,"add_key() failed" );
This part should be done in setup, shoudldn't it?
testcases/kernel/syscalls/request_key/request_key01.c line 78
Quoted 5 lines
testcases/kernel/syscalls/request_key/request_key01.c new file +5
-0+TEST (ltp_syscall (__NR_request_key,"keyring" ,"ltp" ,NULL ,KEY_SPEC_PROCESS_KEYRING )); +if (TEST_RETURN ==-1 ) { +tst_resm (TFAIL |TERRNO ,"request_key() failed" ); +return ; + }
Same here.
Quoted 28 lines
testcases/kernel/syscalls/request_key/request_key01.c new file +28
-0+if (TEST_RETURN != res) +tst_resm (TFAIL ,"serial number mismatched" ); +else + tst_resm(TPASS, "request_key() succeed"); +} + +static void setup (void ) +{ +tst_require_root (); + +tst_sig (NOFORK ,DEF_HANDLER , cleanup); + +TEST_PAUSE ; + +tst_tmpdir (); +} + +static void cleanup (void ) +{ +tst_rmdir (); +} + +#else +int main (int ac,char **av) +{ +tst_brkm (TCONF ,NULL ,"linux/keyctl.h was missing upon compilation." ); +} +#endif
Signature · 2 lines
Cyril Hrubis [email protected]