Listxattr related calls: new tests and testcase
v2 cover Listxattr related calls: new tests and testcase
v1 -> v2:
- Modified the setup for the new testcase in llistxattr02 and a testcase in listxattr02.
- Modified commit messages.
In this series, there is a new testcase added in the existing llistxattr02 test. Also, new tests are added for system calls flistxattr(), and listxattr() which are based on the existing tests for llistxattr.
Dejan Jovicevic (2):
llistxattr: added a new test case to llistxattr02 flistxattr and listxattr: added tests
runtest/syscalls | 8 ++ testcases/kernel/syscalls/.gitignore | 6 + testcases/kernel/syscalls/flistxattr/Makefile | 23 ++++ .../kernel/syscalls/flistxattr/flistxattr01.c | 124 +++++++++++++++++++++ .../kernel/syscalls/flistxattr/flistxattr02.c | 116 +++++++++++++++++++ .../kernel/syscalls/flistxattr/flistxattr03.c | 111 ++++++++++++++++++ testcases/kernel/syscalls/listxattr/Makefile | 23 ++++ testcases/kernel/syscalls/listxattr/listxattr01.c | 115 +++++++++++++++++++ testcases/kernel/syscalls/listxattr/listxattr02.c | 119 ++++++++++++++++++++ testcases/kernel/syscalls/listxattr/listxattr03.c | 101 +++++++++++++++++ .../kernel/syscalls/llistxattr/llistxattr02.c | 11 +- 11 files changed, 756 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/flistxattr/Makefile create mode 100644 testcases/kernel/syscalls/flistxattr/flistxattr01.c create mode 100644 testcases/kernel/syscalls/flistxattr/flistxattr02.c create mode 100644 testcases/kernel/syscalls/flistxattr/flistxattr03.c create mode 100644 testcases/kernel/syscalls/listxattr/Makefile create mode 100644 testcases/kernel/syscalls/listxattr/listxattr01.c create mode 100644 testcases/kernel/syscalls/listxattr/listxattr02.c create mode 100644 testcases/kernel/syscalls/listxattr/listxattr03.c
Signature · 1 line
1.9.1
PATCH v2 1/2 llistxattr: added a new test case to llistxattr02
v1 -> v2:
- Using memset() for initializing the longpathname buffer.
- Modified commit message.
Added a test case that checks if the path name, given by the first argument of the function, is too long. If that is the case, the function should return -1 and errno should be set to ENAMETOOLONG.
--- testcases/kernel/syscalls/llistxattr/llistxattr02.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/llistxattr/llistxattr02.c +10 -1
@@ -22,11 +22,13 @@* to hold the result. * 2) llistxattr(2) fails if path is an empty string. * 3) llistxattr(2) fails when attempted to read from a invalid address. +* 4) llistxattr(2) fails if path is longer than allowed. * * Expected Result: * 1) llistxattr(2) should return -1 and set errno to ERANGE. * 2) llistxattr(2) should return -1 and set errno to ENOENT. * 3) llistxattr(2) should return -1 and set errno to EFAULT. +* 4) llistxattr(2) should return -1 and set errno to ENAMETOOLONG. */ #include "config.h"
@@ -45,6 +47,8 @@#define VALUE "test"#define VALUE_SIZE 4 +char longpathname[PATH_MAX +2 ]; + static struct test_case { const char *path; size_t size;
@@ -55,7 +59,9 @@ static struct test_case {/* test2 */ {"", 20, ENOENT},/* test3 */ - {(char *)-1, 20, EFAULT} + {(char *)-1, 20, EFAULT}, +/* test4 */ + {longpathname, 20, ENAMETOOLONG} };static void verify_llistxattr (unsigned int n)
@@ -95,6 +101,9 @@ static void setup(void)tst_brk (TBROK |TERRNO ,"lsetxattr() failed" ); } } + +memset (&longpathname,'a' ,sizeof (longpathname) -1 ); + longpathname[sizeof (longpathname)] ='\0' ; }static struct tst_test test = {
Signature · 1 line
1.9.1
PATCH v2 1/2 llistxattr: added a new test case to llistxattr02
Hi!
testcases/kernel/syscalls/llistxattr/llistxattr02.c static void setup(void) · line 106
Quoted 8 lines
static void
verify_llistxattr(unsigned int n)testcases/kernel/syscalls/llistxattr/llistxattr02.c +3
-0@@ -95,6 +101,9 @@ static void setup(void)tst_brk (TBROK |TERRNO ,"lsetxattr() failed" ); } } + +memset (&longpathname,'a' ,sizeof (longpathname) -1 ); + longpathname[sizeof (longpathname)] ='\0' ;
This is off-by-one, the last array element is at sizeof(longpathname)-1. Also this is not needed since the array is global, hence initialized to 0 and we fill first n-1 elements with the memset() leaving the last one to be the '\0'.
Quoted 9 lines
testcases/kernel/syscalls/llistxattr/llistxattr02.c +0
-0}static struct tst_test test = {Signature · 5 lines
1.9.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 2/2 flistxattr and listxattr: added tests
In reply to Dejan Jovicevicv1 -> v2:
- Using memset() for initializing the longpathname buffer in listxattr02.
- Modified commit message.
Tests for these two system calls were not present.
flistxattr(), listxattr() and llistxattr() are identical, the only difference is in the first argument:
- in listxattr() it refers to the file in the path.
- in llistxattr() in the case of a symbolic link, the list of names of extended attributes associated with the link itself is retrieved, not the file that it refers to.
- in flistxattr() the open file referred to by fd is interrogated in place of path.
Because of these similarities, implemented tests for flistxattr() and listxattr() are based on the existing tests for llistxattr(), with some adjustments to fit the appropriate system call.
--- runtest/syscalls | 8 ++ testcases/kernel/syscalls/.gitignore | 6 + testcases/kernel/syscalls/flistxattr/Makefile | 23 ++++ .../kernel/syscalls/flistxattr/flistxattr01.c | 124 +++++++++++++++++++++ .../kernel/syscalls/flistxattr/flistxattr02.c | 116 +++++++++++++++++++ .../kernel/syscalls/flistxattr/flistxattr03.c | 111 ++++++++++++++++++ testcases/kernel/syscalls/listxattr/Makefile | 23 ++++ testcases/kernel/syscalls/listxattr/listxattr01.c | 115 +++++++++++++++++++ testcases/kernel/syscalls/listxattr/listxattr02.c | 119 ++++++++++++++++++++ testcases/kernel/syscalls/listxattr/listxattr03.c | 101 +++++++++++++++++ 10 files changed, 746 insertions(+) create mode 100644 testcases/kernel/syscalls/flistxattr/Makefile create mode 100644 testcases/kernel/syscalls/flistxattr/flistxattr01.c create mode 100644 testcases/kernel/syscalls/flistxattr/flistxattr02.c create mode 100644 testcases/kernel/syscalls/flistxattr/flistxattr03.c create mode 100644 testcases/kernel/syscalls/listxattr/Makefile create mode 100644 testcases/kernel/syscalls/listxattr/listxattr01.c create mode 100644 testcases/kernel/syscalls/listxattr/listxattr02.c create mode 100644 testcases/kernel/syscalls/listxattr/listxattr03.c
runtest/syscalls +8 -0
@@ -272,6 +272,10 @@ fcntl34_64 fcntl34_64 fdatasync01 fdatasync01 fdatasync02 fdatasync02 +flistxattr01 flistxattr01 +flistxattr02 flistxattr02 +flistxattr03 flistxattr03 + flock01 flock01 flock02 flock02 flock03 flock03
@@ -523,6 +527,10 @@ linkat02 linkat02 listen01 listen01 +listxattr01 listxattr01 +listxattr02 listxattr02 +listxattr03 listxattr03 + llistxattr01 llistxattr01 llistxattr02 llistxattr02 llistxattr03 llistxattr03
testcases/kernel/syscalls/.gitignore +6 -0
@@ -233,6 +233,9 @@ /fcntl/fcntl34_64 /fdatasync/fdatasync01 /fdatasync/fdatasync02 +/flistxattr/flistxattr01 +/flistxattr/flistxattr02 +/flistxattr/flistxattr03 /flock/flock01 /flock/flock02 /flock/flock03
@@ -482,6 +485,9 @@ /linkat/linkat01 /linkat/linkat02 /listen/listen01 +/listxattr/listxattr01 +/listxattr/listxattr02 +/listxattr/listxattr03 /llistxattr/llistxattr01 /llistxattr/llistxattr02 /llistxattr/llistxattr03
testcases/kernel/syscalls/flistxattr/Makefile new file +23 -0
@@ -0,0 +1,23 @@ +# +# 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/flistxattr/flistxattr01.c new file +124 -0
124 lines not on this page · raw message
testcases/kernel/syscalls/flistxattr/flistxattr02.c new file +116 -0
116 lines not on this page · raw message
testcases/kernel/syscalls/flistxattr/flistxattr03.c new file +111 -0
111 lines not on this page · raw message
testcases/kernel/syscalls/listxattr/Makefile new file +23 -0
@@ -0,0 +1,23 @@ +# +# 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/listxattr/listxattr01.c new file +115 -0
115 lines not on this page · raw message
testcases/kernel/syscalls/listxattr/listxattr02.c new file +119 -0
119 lines not on this page · raw message
testcases/kernel/syscalls/listxattr/listxattr03.c new file +101 -0
101 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 2/2 flistxattr and listxattr: added tests
Hi!
Quoted 6 lines
testcases/kernel/syscalls/flistxattr/flistxattr01.c new file +6
-0+#include "config.h" +#include <errno.h> +#include <sys/types.h> +#include <string.h> + +#ifdef HAVE_SYS_XATTR_H
testcases/kernel/syscalls/flistxattr/flistxattr01.c line 42
Quoted 10 lines
testcases/kernel/syscalls/flistxattr/flistxattr01.c new file +10
-0+# include <sys/xattr.h> +#endif + +#include "tst_test.h" + +#ifdef HAVE_SYS_XATTR_H + +#define SECURITY_KEY1 "security.ltptest1" +#define VALUE "test" +#define VALUE_SIZE 4
^ (sizeof(VALUE) - 1)
Quoted 1 line
+#define
KEY_SIZE17
^ (sizeof(SECURITY_KEY1) - 1)
Let's avoid hardcoded magic constants whenever possible.
Review
Quoted 2 lines
(quoted diff) +2
-0+ +int fd;
This should be static int fd, but that is minor.
Quoted 8 lines
testcases/kernel/syscalls/flistxattr/flistxattr01.c new file +8
-0+static void set_xattr (int fd,const char *key) +{ +int n; + + n =fsetxattr (fd, key,VALUE ,VALUE_SIZE ,XATTR_CREATE ); +if (n ==-1 ) { +if (errno ==ENOTSUP ) { + tst_brk(TCONF,
testcases/kernel/syscalls/flistxattr/flistxattr01.c line 64
Quoted 10 lines
testcases/kernel/syscalls/flistxattr/flistxattr01.c new file +10
-0+"no xattr support in fs or mounted " + "without user_xattr option"); + } + +if (errno ==EEXIST ) { +tst_brk (TBROK ,"exist attribute %s" , key); + }else { +tst_brk (TBROK |TERRNO , +"fsetxattr() failed" ); + }
Hmm, why do we treat the EEXIST separately here?
Why not just tst_brk(TBROK | TERRNO, "fsetxattr(%s, ...)") ?
Maybe we should SAFE_FSETXATTR() and SAFE_SETXATTR() and use it in all fooxattr() testcases.
Quoted 8 lines
testcases/kernel/syscalls/flistxattr/flistxattr01.c new file +8
-0+ } +} + +static int has_attribute (const char *list,int llen,const char *attr) +{ +int i; + +for (i =0 ; i < llen; i +=strlen (list + i) +1 ) {
testcases/kernel/syscalls/flistxattr/flistxattr01.c line 82
Quoted 10 lines
testcases/kernel/syscalls/flistxattr/flistxattr01.c new file +10
-0+if (!strcmp (list + i, attr)) +return 1 ; + } +return 0 ; +} + +static void verify_flistxattr (void ) +{ +int size =64 ; +char buf[size];
Just do char buf[64]; here and pass the sizeof(buf) to the flistxattr() instead.
testcases/kernel/syscalls/flistxattr/flistxattr01.c line 86
Quoted 4 lines
testcases/kernel/syscalls/flistxattr/flistxattr01.c new file +4
-0+ +TEST (flistxattr (fd, buf, size)); +if (TEST_RETURN ==-1 ) { +tst_res (TFAIL |TERRNO ,"flistxattr() failed" );
^
TTERRNO would be better here, since we use the TEST() macro.
Quoted 44 lines
testcases/kernel/syscalls/flistxattr/flistxattr01.c new file +38
-0+ return; + } + +if (!has_attribute (buf, size,SECURITY_KEY1 )) { +tst_res (TFAIL ,"missing attribute %s" , +SECURITY_KEY1 ); +return ; + } + +tst_res (TPASS ,"flistxattr() succeeded" ); +} + +static void setup (void ) +{ + fd =SAFE_OPEN ("testfile" ,O_RDWR |O_CREAT ,0644 ); + +set_xattr (fd,SECURITY_KEY1 ); +} + +static void cleanup (void ) +{ +if (fd >0 &&close (fd)) +tst_res (TWARN |TERRNO ,"failed to close file" ); +} + +static struct tst_test test = { + .tid ="flistxattr01" , + .needs_tmpdir =1 , + .needs_root =1 , + .test_all = verify_flistxattr, + .setup = setup, + .cleanup = cleanup, +}; + +#else +TST_TEST_TCONF ("<sys/xattr.h> does not exist." ); +#endif /* HAVE_SYS_XATTR_H */ +testcases/kernel/syscalls/flistxattr/flistxattr02.c new file +0
-0
testcases/kernel/syscalls/flistxattr/flistxattr02.c line 3
Quoted 3 lines
testcases/kernel/syscalls/flistxattr/flistxattr02.c new file +3
-0@@ -0,0 +1,116 @@ +/* +* Copyright (c) 2016 Fujitsu Ltd. +* Author: Xiao Yang <[email protected]>
^
You should update the copyright as well.
Quoted 30 lines
testcases/kernel/syscalls/flistxattr/flistxattr02.c new file +30
-0+* 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: flistxattr02 +* +* Description: +* 1) flistxattr(2) fails if the size of the list buffer is too small +* to hold the result. +* 2) flistxattr(2) fails if fd is an invalid file descriptor. +* +* Expected Result: +* 1) flistxattr(2) should return -1 and set errno to ERANGE. +* 2) flistxattr(2) should return -1 and set errno to EBADF. +*/ + +#include "config.h" +#include <errno.h> +#include <sys/types.h> + +#ifdef HAVE_SYS_XATTR_H
testcases/kernel/syscalls/flistxattr/flistxattr02.c line 44
Quoted 10 lines
testcases/kernel/syscalls/flistxattr/flistxattr02.c new file +10
-0+# include <sys/xattr.h> +#endif + +#include "tst_test.h" + +#ifdef HAVE_SYS_XATTR_H + +#define SECURITY_KEY "security.ltptest" +#define VALUE "test" +#define VALUE_SIZE 4
^ (sizeof(VALUE) - 1)
testcases/kernel/syscalls/flistxattr/flistxattr02.c line 54
Quoted 9 lines
testcases/kernel/syscalls/flistxattr/flistxattr02.c new file +9
-0+static int fd1; +static int fd2; + +static struct test_case { +int *fd; +size_t size; +int exp_err; +} tc[] = { +/* test1 */
^
These comments seem useless to me, I would have removed them.
testcases/kernel/syscalls/flistxattr/flistxattr02.c line 66
Quoted 12 lines
testcases/kernel/syscalls/flistxattr/flistxattr02.c new file +12
-0+ {&fd1, 1, ERANGE}, +/* test2 */ + {&fd2, 20, EBADF} +}; + +static void verify_flistxattr (unsigned int n) +{ +struct test_case *t = tc + n; +char buf[t->size]; + +TEST (flistxattr (*t->fd, buf, t->size)); +if (TEST_RETURN !=-1 ) {
^ TEST_RETURN == 0 is a bit more robust, that would catch if we got any garbage out of the call.
testcases/kernel/syscalls/flistxattr/flistxattr02.c line 67
Quoted 1 line
testcases/kernel/syscalls/flistxattr/flistxattr02.c new file +1
-0+tst_res (TFAIL ,"flistxattr() succeeded unexpectedly" );
I would add return; here so that the rest of the code does not need to be in the else branch (that saves a bit of indentation and the result is IMHO easier to read).
Quoted 8 lines
testcases/kernel/syscalls/flistxattr/flistxattr02.c new file +8
-0+ }else { +if (t->exp_err !=TEST_ERRNO ) { +tst_res (TFAIL |TTERRNO ,"flistxattr() failed " +"unexpectedlly, expected %s" , +tst_strerrno (t->exp_err)); + }else { +tst_res (TPASS |TTERRNO , +"flistxattr() failed as expected" );
testcases/kernel/syscalls/flistxattr/flistxattr02.c line 85
Quoted 10 lines
testcases/kernel/syscalls/flistxattr/flistxattr02.c new file +10
-0+ } + } +} + +static void setup (void ) +{ +int n; + + fd1 =SAFE_OPEN ("testfile" ,O_RDWR |O_CREAT ,0644 ); + fd2 =-1 ;
^
This should be initialized statically when the variable is declared.
testcases/kernel/syscalls/flistxattr/flistxattr02.c line 94
Quoted 8 lines
testcases/kernel/syscalls/flistxattr/flistxattr02.c new file +8
-0+ n =fsetxattr (fd1,SECURITY_KEY ,VALUE ,VALUE_SIZE ,XATTR_CREATE ); +if (n ==-1 ) { +if (errno ==ENOTSUP ) { +tst_brk (TCONF ,"no xattr support in fs or " +"mounted without user_xattr option" ); + }else { +tst_brk (TBROK |TERRNO ,"fsetxattr() failed" ); + }
No need for the else branch here. The tst_brk() exits the test and hence the call never returns.
Quoted 58 lines
testcases/kernel/syscalls/flistxattr/flistxattr02.c new file +22
-0+ } +} + +static void cleanup (void ) +{ +if (fd1 >0 &&close (fd1)) +tst_res (TWARN |TERRNO ,"failed to close file" ); +} + +static struct tst_test test = { + .tid ="flistxattr02" , + .needs_tmpdir =1 , + .needs_root =1 , + .test = verify_flistxattr, + .tcnt =ARRAY_SIZE (tc), + .setup = setup, + .cleanup = cleanup, +}; + +#else /* HAVE_SYS_XATTR_H */ +TST_TEST_TCONF ("<sys/xattr.h> does not exist." ); +#endif testcases/kernel/syscalls/flistxattr/flistxattr03.c new file +30
-0@@ -0,0 +1,111 @@ +/* +* 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: flistxattr03 +* +* Description: +* flistxattr is identical to listxattr. an empty buffer of size zero +* can return the current size of the list of extended attribute names, +* which can be used to estimate a suitable buffer. +*/ + +#include "config.h" +#include <errno.h> +#include <sys/types.h> + +#ifdef HAVE_SYS_XATTR_H
testcases/kernel/syscalls/flistxattr/flistxattr03.c line 40
Quoted 10 lines
testcases/kernel/syscalls/flistxattr/flistxattr03.c new file +10
-0+#include <sys/xattr.h> +#endif + +#include "tst_test.h" + +#ifdef HAVE_SYS_XATTR_H + +#define SECURITY_KEY "security.ltptest" +#define VALUE "test" +#define VALUE_SIZE 4
^ (sizeof(VALUE) - 1)
testcases/kernel/syscalls/flistxattr/flistxattr03.c line 49
Quoted 9 lines
testcases/kernel/syscalls/flistxattr/flistxattr03.c new file +9
-0+ +static int fd[] = {0 ,0 }; + +static int check_suitable_buf (const int file,long size) +{ +int n; +char buf[size]; + + n =flistxattr (file, buf, size);
^
sizeof(buf) is a bit safe (will stay correct even if somebody changes the code around)
testcases/kernel/syscalls/flistxattr/flistxattr03.c line 53
Quoted 4 lines
testcases/kernel/syscalls/flistxattr/flistxattr03.c new file +4
-0+if (n ==-1 ) +return 0 ; +else +return 1 ;
return n != -1;
testcases/kernel/syscalls/flistxattr/flistxattr03.c line 58
Quoted 5 lines
testcases/kernel/syscalls/flistxattr/flistxattr03.c new file +5
-0+} + +static void verify_flistxattr (unsigned int n) +{ +const int file = fd[n];
Hmm, why don't you pass the fd[n] directly? It's not that file is that shorter or easier to read.
Quoted 17 lines
testcases/kernel/syscalls/flistxattr/flistxattr03.c new file +17
-0+TEST (flistxattr (file,NULL ,0 )); +if (TEST_RETURN ==-1 ) { +tst_res (TFAIL |TERRNO ,"flistxattr() failed" ); +return ; + } + +if (check_suitable_buf (file,TEST_RETURN )) +tst_res (TPASS ,"flistxattr() succeed with suitable buffer" ); +else +tst_res (TFAIL ,"flistxattr() failed with small buffer" ); +} + +static void setup (void ) +{ +int ret; + + fd[0 ] =SAFE_OPEN ("testfile1" ,O_RDWR |O_CREAT ,0644 );
testcases/kernel/syscalls/flistxattr/flistxattr03.c line 86
Quoted 10 lines
testcases/kernel/syscalls/flistxattr/flistxattr03.c new file +10
-0+ + fd[1 ] =SAFE_OPEN ("testfile2" ,O_RDWR |O_CREAT ,0644 ); + + ret =fsetxattr (fd[1 ],SECURITY_KEY ,VALUE ,VALUE_SIZE ,XATTR_CREATE ); +if (ret ==-1 ) { +if (errno ==ENOTSUP ) { +tst_brk (TCONF ,"no xattr support in fs or " +"mounted without user_xattr option" ); + }else { +tst_brk (TBROK |TERRNO ,"fsetxattr() failed" );
Again no need for the else branch.
Quoted 31 lines
testcases/kernel/syscalls/flistxattr/flistxattr03.c new file +25
-0+ } + } +} + +static void cleanup (void ) +{ +if (fd[0 ] >0 &&close (fd[0 ])) +tst_res (TWARN |TERRNO ,"failed to close file" ); +if (fd[1 ] >0 &&close (fd[1 ])) +tst_res (TWARN |TERRNO ,"failed to close file" ); +} + +static struct tst_test test = { + .tid ="flistxattr03" , + .needs_tmpdir =1 , + .needs_root =1 , + .test = verify_flistxattr, + .tcnt =ARRAY_SIZE (fd), + .setup = setup, + .cleanup = cleanup, +}; + +#else /* HAVE_SYS_XATTR_H */ +TST_TEST_TCONF ("<sys/xattr.h> does not exist." ); +#endif testcases/kernel/syscalls/listxattr/Makefile new file +0
-0
testcases/kernel/syscalls/listxattr/Makefile line 3
Quoted 3 lines
testcases/kernel/syscalls/listxattr/Makefile new file +3
-0@@ -0,0 +1,23 @@ +# +# Copyright (c) 2016 Fujitsu Ltd. +# Author: Xiao Yang <[email protected]>
Here again, update the copyright line.
Quoted 57 lines
testcases/kernel/syscalls/listxattr/Makefile new file +19
-0+# 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.mktestcases/kernel/syscalls/listxattr/listxattr01.c new file +32
-0@@ -0,0 +1,115 @@ +/* +* 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: listxattr01 +* +* Description: +* The testcase checks the basic functionality of the listxattr(2). +* listxattr(2) retrieves the list of extended attribute names +* associated with the file itself in the filesystem. +* +*/ + +#include "config.h" +#include <errno.h> +#include <sys/types.h> +#include <string.h> + +#ifdef HAVE_SYS_XATTR_H
testcases/kernel/syscalls/listxattr/listxattr01.c line 42
Quoted 10 lines
testcases/kernel/syscalls/listxattr/listxattr01.c new file +10
-0+# include <sys/xattr.h> +#endif + +#include "tst_test.h" + +#ifdef HAVE_SYS_XATTR_H + +#define SECURITY_KEY1 "security.ltptest1" +#define VALUE "test" +#define VALUE_SIZE 4
^ (sizeof(VALUE) - 1)
testcases/kernel/syscalls/listxattr/listxattr01.c line 43
Quoted 1 line
testcases/kernel/syscalls/listxattr/listxattr01.c new file +1
-0+#define KEY_SIZE 17
(sizeof(SECURITY_KEY1) - 1)
Quoted 9 lines
testcases/kernel/syscalls/listxattr/listxattr01.c new file +9
-0+ +static void set_xattr (const char *path,const char *key) +{ +int n; + + n =setxattr (path, key,VALUE ,VALUE_SIZE ,XATTR_CREATE ); +if (n ==-1 ) { +if (errno ==ENOTSUP ) { + tst_brk(TCONF,
testcases/kernel/syscalls/listxattr/listxattr01.c line 62
Quoted 10 lines
testcases/kernel/syscalls/listxattr/listxattr01.c new file +10
-0+"no xattr support in fs or mounted " + "without user_xattr option"); + } + +if (errno ==EEXIST ) { +tst_brk (TBROK ,"exist attribute %s" , key); + }else { +tst_brk (TBROK |TERRNO , +"setxattr() failed" ); + }
Here again, why do we treat EEXIST differently?
Quoted 29 lines
testcases/kernel/syscalls/listxattr/listxattr01.c new file +29
-0+ } +} + +static int has_attribute (const char *list,int llen,const char *attr) +{ +int i; + +for (i =0 ; i < llen; i +=strlen (list + i) +1 ) { +if (!strcmp (list + i, attr)) +return 1 ; + } +return 0 ; +} + +static void verify_listxattr (void ) +{ +int size =64 ; +char buf[size]; + +TEST (listxattr ("testfile" , buf, size)); +if (TEST_RETURN ==-1 ) { +tst_res (TFAIL |TERRNO ,"listxattr() failed" ); +return ; + } + +if (!has_attribute (buf, size,SECURITY_KEY1 )) { +tst_res (TFAIL ,"missing attribute %s" , +SECURITY_KEY1 ); +return ;
testcases/kernel/syscalls/listxattr/listxattr01.c line 101
Quoted 10 lines
testcases/kernel/syscalls/listxattr/listxattr01.c new file +10
-0+ } + +tst_res (TPASS ,"listxattr() succeeded" ); +} + +static void setup (void ) +{ +SAFE_TOUCH ("testfile" ,0644 ,NULL ); + +set_xattr ("testfile" ,SECURITY_KEY1 );
^ This should proabaly be macro: #define TESTFILE "testfile"
Quoted 20 lines
testcases/kernel/syscalls/listxattr/listxattr01.c new file +14
-0+} + +static struct tst_test test = { + .tid ="listxattr01" , + .needs_tmpdir =1 , + .needs_root =1 , + .test_all = verify_listxattr, + .setup = setup, +}; + +#else +TST_TEST_TCONF ("<sys/xattr.h> does not exist." ); +#endif /* HAVE_SYS_XATTR_H */ +testcases/kernel/syscalls/listxattr/listxattr02.c new file +0
-0
testcases/kernel/syscalls/listxattr/listxattr02.c line 3
Quoted 3 lines
testcases/kernel/syscalls/listxattr/listxattr02.c new file +3
-0@@ -0,0 +1,119 @@ +/* +* Copyright (c) 2016 Fujitsu Ltd. +* Author: Xiao Yang <[email protected]>
Here again, copyright.
Quoted 34 lines
testcases/kernel/syscalls/listxattr/listxattr02.c new file +34
-0+* 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: listxattr02 +* +* Description: +* 1) listxattr(2) fails if the size of the list buffer is too small +* to hold the result. +* 2) listxattr(2) fails if path is an empty string. +* 3) listxattr(2) fails when attempted to read from a invalid address. +* 4) listxattr(2) fails if path is longer than allowed. +* +* Expected Result: +* 1) listxattr(2) should return -1 and set errno to ERANGE. +* 2) listxattr(2) should return -1 and set errno to ENOENT. +* 3) listxattr(2) should return -1 and set errno to EFAULT. +* 4) listxattr(2) should return -1 and set errno to ENAMETOOLONG. +*/ + +#include "config.h" +#include <errno.h> +#include <sys/types.h> + +#ifdef HAVE_SYS_XATTR_H
testcases/kernel/syscalls/listxattr/listxattr02.c line 48
Quoted 10 lines
testcases/kernel/syscalls/listxattr/listxattr02.c new file +10
-0+# include <sys/xattr.h> +#endif + +#include "tst_test.h" + +#ifdef HAVE_SYS_XATTR_H + +#define SECURITY_KEY "security.ltptest" +#define VALUE "test" +#define VALUE_SIZE 4
^ (sizeof(VALUE) - 1)
Quoted 4 lines
testcases/kernel/syscalls/listxattr/listxattr02.c new file +4
-0+char longpathname[PATH_MAX +2 ]; + +static struct test_case { + const char *path;
testcases/kernel/syscalls/listxattr/listxattr02.c line 63
Quoted 10 lines
testcases/kernel/syscalls/listxattr/listxattr02.c new file +10
-0+size_t size; +int exp_err; +} tc[] = { +/* test1 */ + {"testfile", 1, ERANGE}, +/* test2 */ + {"", 20, ENOENT}, +/* test3 */ + {(char *)-1, 20, EFAULT}, +/* test4 */
Useless comments.
testcases/kernel/syscalls/listxattr/listxattr02.c line 72
Quoted 9 lines
testcases/kernel/syscalls/listxattr/listxattr02.c new file +9
-0+ {longpathname, 20, ENAMETOOLONG} +}; + +static void verify_listxattr (unsigned int n) +{ +struct test_case *t = tc + n; +char buf[t->size]; + +TEST (listxattr (t->path, buf, t->size));
^ sizeof(buf)
testcases/kernel/syscalls/listxattr/listxattr02.c line 74
Quoted 2 lines
testcases/kernel/syscalls/listxattr/listxattr02.c new file +2
-0+if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"listxattr() succeeded unexpectedly" );
Again do a return; here and the rest of the code does not need to be inside of an else block.
Quoted 17 lines
testcases/kernel/syscalls/listxattr/listxattr02.c new file +17
-0+ }else { +if (t->exp_err !=TEST_ERRNO ) { +tst_res (TFAIL |TTERRNO ,"listxattr() failed " +"unexpectedlly, expected %s" , +tst_strerrno (t->exp_err)); + }else { +tst_res (TPASS |TTERRNO , +"listxattr() failed as expected" ); + } + } +} + +static void setup (void ) +{ +int n; + +SAFE_TOUCH ("testfile" ,0644 ,NULL );
testcases/kernel/syscalls/listxattr/listxattr02.c line 101
Quoted 10 lines
testcases/kernel/syscalls/listxattr/listxattr02.c new file +10
-0+ + + n =setxattr ("testfile" ,SECURITY_KEY ,VALUE ,VALUE_SIZE ,XATTR_CREATE ); +if (n ==-1 ) { +if (errno ==ENOTSUP ) { +tst_brk (TCONF ,"no xattr support in fs or " +"mounted without user_xattr option" ); + }else { +tst_brk (TBROK |TERRNO ,"setxattr() failed" ); + }
Again, no need for the else branch.
testcases/kernel/syscalls/listxattr/listxattr02.c line 105
Quoted 4 lines
testcases/kernel/syscalls/listxattr/listxattr02.c new file +4
-0+ } + +memset (&longpathname,'a' ,sizeof (longpathname) -1 ); + longpathname[sizeof (longpathname)] ='\0' ;
Again off-by-one and no needed.
Quoted 20 lines
testcases/kernel/syscalls/listxattr/listxattr02.c new file +14
-0+} + +static struct tst_test test = { + .tid ="listxattr02" , + .needs_tmpdir =1 , + .needs_root =1 , + .test = verify_listxattr, + .tcnt =ARRAY_SIZE (tc), + .setup = setup, +}; + +#else /* HAVE_SYS_XATTR_H */ +TST_TEST_TCONF ("<sys/xattr.h> does not exist." ); +#endif testcases/kernel/syscalls/listxattr/listxattr03.c new file +0
-0
testcases/kernel/syscalls/listxattr/listxattr03.c line 3
Quoted 3 lines
testcases/kernel/syscalls/listxattr/listxattr03.c new file +3
-0@@ -0,0 +1,101 @@ +/* +* Copyright (c) 2016 Fujitsu Ltd. +* Author: Xiao Yang <[email protected]>
Again, the copyright.
Quoted 16 lines
testcases/kernel/syscalls/listxattr/listxattr03.c new file +16
-0+* 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: listxattr03 +* +* Description:
testcases/kernel/syscalls/listxattr/listxattr03.c line 30
Quoted 10 lines
testcases/kernel/syscalls/listxattr/listxattr03.c new file +10
-0+* An empty buffer of size zero can return the current size of the list +* of extended attribute names, which can be used to estimate a suitable buffer. +*/ + +#include "config.h" +#include <errno.h> +#include <sys/types.h> + +#ifdef HAVE_SYS_XATTR_H +#include <sys/xattr.h>
^
should ideally be indented by single space after the #
testcases/kernel/syscalls/listxattr/listxattr03.c line 38
Quoted 9 lines
testcases/kernel/syscalls/listxattr/listxattr03.c new file +9
-0+#endif + +#include "tst_test.h" + +#ifdef HAVE_SYS_XATTR_H + +#define SECURITY_KEY "security.ltptest" +#define VALUE "test" +#define VALUE_SIZE 4
^ (sizeof(VALUE)-1)
testcases/kernel/syscalls/listxattr/listxattr03.c line 48
Quoted 8 lines
testcases/kernel/syscalls/listxattr/listxattr03.c new file +8
-0+static const char *const filename[] = {"testfile1" ,"testfile2" }; + +static int check_suitable_buf (const char *name,long size) +{ +int n; +char buf[size]; + + n =listxattr (name, buf, size);
^ sizeof(buf)
testcases/kernel/syscalls/listxattr/listxattr03.c line 50
Quoted 4 lines
testcases/kernel/syscalls/listxattr/listxattr03.c new file +4
-0+if (n ==-1 ) +return 0 ; +else +return 1 ;
return n != -1;
Quoted 23 lines
testcases/kernel/syscalls/listxattr/listxattr03.c new file +23
-0+} + +static void verify_listxattr (unsigned int n) +{ +const char *name = filename[n]; + +TEST (listxattr (name,NULL ,0 )); +if (TEST_RETURN ==-1 ) { +tst_res (TFAIL |TERRNO ,"listxattr() failed" ); +return ; + } + +if (check_suitable_buf (name,TEST_RETURN )) +tst_res (TPASS ,"listxattr() succeed with suitable buffer" ); +else +tst_res (TFAIL ,"listxattr() failed with small buffer" ); +} + +static void setup (void ) +{ +int ret; + +SAFE_TOUCH (filename[0 ],0644 ,NULL );
testcases/kernel/syscalls/listxattr/listxattr03.c line 85
Quoted 10 lines
testcases/kernel/syscalls/listxattr/listxattr03.c new file +10
-0+ +SAFE_TOUCH (filename[1 ],0644 ,NULL ); + + ret =setxattr (filename[1 ],SECURITY_KEY ,VALUE ,VALUE_SIZE ,XATTR_CREATE ); +if (ret ==-1 ) { +if (errno ==ENOTSUP ) { +tst_brk (TCONF ,"no xattr support in fs or " +"mounted without user_xattr option" ); + }else { +tst_brk (TBROK |TERRNO ,"setxattr() failed" );
Again no need for the else block.
Quoted 22 lines
testcases/kernel/syscalls/listxattr/listxattr03.c new file +16
-0+ } + } +} + +static struct tst_test test = { + .tid ="listxattr03" , + .needs_tmpdir =1 , + .needs_root =1 , + .test = verify_listxattr, + .tcnt =ARRAY_SIZE (filename), + .setup = setup, +}; + +#else /* HAVE_SYS_XATTR_H */ +TST_TEST_TCONF ("<sys/xattr.h> does not exist." ); +#endif Signature · 5 lines
1.9.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]