setxattrat coverage
v2 cover setxattrat coverage
This is a patch-set meant to cover setxattrat() syscalls scenarios. There are two parts:
- cover errors and features which are already tested for setxattr() by adding a new setxattrat() test variant to setxattr() testing suite
- cover errors which are strictly related to the setxattrat() syscall
---
Changes in v2:
- correctly fallback and import struct xattr_args
- fallback setxattrat() only
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Andrea Cervesato (10):
lapi: add struct xattr_args fallback
lapi: add setxattrat() fallback definition
setxattr01: add setxattrat variant
setxattr02: add setxattrat variant
setxattr03: add setxattrat variant
lapi: add getxattrat() fallback
lapi: add removexattrat() fallback
lapi: add safe *xattrat macros
Add setxattrat01 test
Add setxattrat02 test
configure.ac | 5 + include/lapi/xattr.h | 156 +++++++++++++++++++++ testcases/kernel/syscalls/setxattr/setxattr01.c | 61 ++++++-- testcases/kernel/syscalls/setxattr/setxattr02.c | 79 ++++++++--- testcases/kernel/syscalls/setxattr/setxattr03.c | 35 +++-- testcases/kernel/syscalls/setxattrat/.gitignore | 2 + testcases/kernel/syscalls/setxattrat/Makefile | 8 ++ .../kernel/syscalls/setxattrat/setxattrat01.c | 150 ++++++++++++++++++++ .../kernel/syscalls/setxattrat/setxattrat02.c | 126 +++++++++++++++++ 9 files changed, 581 insertions(+), 41 deletions(-)
---
base-commit: d2550ffbbcfe163212cd7e9c132db65ae0fa06ed
change-id: 20250121-xattrat-1b1653ccea31
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/10 lapi: add struct xattr_args fallback
From: Andrea Cervesato <[email protected]>
--- configure.ac | 2 ++ include/lapi/xattr.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+)
configure.ac +2 -0
@@ -83,6 +83,7 @@ AC_CHECK_HEADERS_ONCE([ \ linux/tty.h \ linux/types.h \ linux/userfaultfd.h \ + linux/xattr.h \ netinet/sctp.h \ pthread.h \ sys/epoll.h \
@@ -266,6 +267,7 @@ AC_CHECK_TYPES([struct mnt_id_req],,,[#include <sys/mount.h>]) AC_CHECK_TYPES([struct statmount],,,[#include <sys/mount.h>]) AC_CHECK_MEMBERS([struct statmount.mnt_ns_id],,,[#include <unistd.h> #include <linux/mount.h>]) +AC_CHECK_TYPES([struct xattr_args],,,[#include <linux/xattr.h>]) AC_CHECK_TYPES([struct pidfd_info],,,[#include <sys/pidfd.h>]) AC_CHECK_TYPES([struct file_attr],,,[#include <linux/fs.h>])
include/lapi/xattr.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (c) 2025 Linux Test Project +*/ + +#ifndef LAPI_XATTR_H__ +#define LAPI_XATTR_H__ + +#include <stdint.h> +#include "config.h" + +#ifdef HAVE_LINUX_XATTR_H +# include <linux/xattr.h> +#endif + +#ifndef XATTR_CREATE +# define XATTR_CREATE 0x1/* set value, fail if attr already exists */ +#endif + +#ifndef XATTR_REPLACE +# define XATTR_REPLACE 0x2/* set value, fail if attr does not exist */ +#endif + +#ifndef HAVE_STRUCT_XATTR_ARGS +struct xattr_args { +uint64_t value; +uint32_t size; +uint32_t flags; +}; +#endif + +#endif /* LAPI_XATTR_H__ */
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 01/10] lapi: add struct xattr_args fallback
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/10 lapi: add setxattrat() fallback definition
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- configure.ac | 1 + include/lapi/xattr.h | 12 ++++++++++++ 2 files changed, 13 insertions(+)
configure.ac +1 -0
@@ -157,6 +157,7 @@ AC_CHECK_FUNCS_ONCE([ \ sendmmsg \ sethostid \ setns \ + setxattrat \ sigpending \ splice \ statx \
include/lapi/xattr.h +12 -0
@@ -7,7 +7,9 @@#define LAPI_XATTR_H__ #include <stdint.h> +#include <stddef.h> #include "config.h" +#include "lapi/syscalls.h" #ifdef HAVE_LINUX_XATTR_H # include <linux/xattr.h>
@@ -29,4 +31,14 @@ struct xattr_args { };#endif +#ifndef HAVE_FUNC_SETXATTRAT +static inline int setxattrat (int dfd,const char *pathname, +unsigned int at_flags,const char *name, +const struct xattr_args *uargs,size_t usize) +{ +return tst_syscall (__NR_setxattrat, dfd, pathname, at_flags, name, + uargs, usize); +} +#endif +#endif /* LAPI_XATTR_H__ */
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 02/10] lapi: add setxattrat() fallback definition
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 02/10] lapi: add setxattrat() fallback definition
In reply to Andrea CervesatoQuoted 35 lines · Andrea Cervesato
From: Andrea Cervesato <[email protected]>
Signed-off-by Andrea Cervesato <[email protected]>--- configure.ac | 1 + include/lapi/xattr.h | 12 ++++++++++++ 2 files changed, 13 insertions(+)configure.ac +1
-0@@ -157,6 +157,7 @@ AC_CHECK_FUNCS_ONCE([ \ sendmmsg \ sethostid \ setns \ + setxattrat \ sigpending \ splice \ statx \include/lapi/xattr.h +2
-0@@ -7,7 +7,9 @@#define LAPI_XATTR_H__ #include <stdint.h> +#include <stddef.h> #include "config.h" +#include "lapi/syscalls.h" #ifdef HAVE_LINUX_XATTR_H # include <linux/xattr.h>
include/lapi/xattr.h struct xattr_args { · line 34
Quoted 4 lines
include/lapi/xattr.h +1
-0@@ -29,4 +31,14 @@ struct xattr_args { };#endif +#ifndef HAVE_FUNC_SETXATTRAT
^
Actually that FUNC shouldn't be there, it's just HAVE_SETXATTRAT
Quoted 17 lines
include/lapi/xattr.h +9
-0+static inline int setxattrat (int dfd,const char *pathname, +unsigned int at_flags,const char *name, +const struct xattr_args *uargs,size_t usize) +{ +return tst_syscall (__NR_setxattrat, dfd, pathname, at_flags, name, + uargs, usize); +} +#endif +#endif /* LAPI_XATTR_H__ */ Signature · 6 lines
-- 2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 3/10 setxattr01: add setxattrat variant
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- testcases/kernel/syscalls/setxattr/setxattr01.c | 61 +++++++++++++++++++------ 1 file changed, 47 insertions(+), 14 deletions(-)
testcases/kernel/syscalls/setxattr/setxattr01.c +47 -14
@@ -20,6 +20,10 @@*/ #include "config.h" +#include "tst_test.h" + +#ifdef HAVE_SYS_XATTR_H +#include <sys/types.h> #include <sys/stat.h> #include <sys/wait.h>
@@ -30,12 +34,9 @@#include <stdio.h> #include <stdlib.h> #include <string.h> -#ifdef HAVE_SYS_XATTR_H -# include <sys/xattr.h> -#endif -#include "tst_test.h" +#include "lapi/xattr.h" +#include <sys/xattr.h> -#ifdef HAVE_SYS_XATTR_H #define XATTR_NAME_MAX 255#define XATTR_NAME_LEN (XATTR_NAME_MAX + 2)#define XATTR_SIZE_MAX 65536
@@ -43,11 +44,13 @@#define XATTR_TEST_VALUE "this is a test value"#define XATTR_TEST_VALUE_SIZE 20#define MNTPOINT "mntpoint" -#define FNAME MNTPOINT"/setxattr01testfile" +#define FNAME_REL "setxattr01testfile" +#define FNAME MNTPOINT"/"FNAME_RELstatic char long_key[XATTR_NAME_LEN ];static char *long_value;static char *xattr_value =XATTR_TEST_VALUE ; +static int mnt_fd =-1 ;struct test_case {char *key;
@@ -126,44 +129,64 @@ struct test_case tc[] = {static void verify_setxattr (unsigned int i) { +char *sysname; +/* some tests might require existing keys for each iteration */ if (tc[i].keyneeded) {SAFE_SETXATTR (FNAME , tc[i].key, *tc[i].value, tc[i].size,XATTR_CREATE ); } -TEST (setxattr (FNAME , tc[i].key, *tc[i].value, tc[i].size, tc[i].flags)); +if (tst_variant) { + sysname ="setxattrat" ; + +struct xattr_args args = { + .value = (uint64_t )tc[i].value, + .size = tc[i].size, + .flags = tc[i].flags, + }; + +TEST (setxattrat (mnt_fd,FNAME_REL ,AT_SYMLINK_NOFOLLOW , + tc[i].key, &args,sizeof (args))); + }else { + sysname ="setxattr" ; + +TEST (setxattr ( +FNAME , + tc[i].key, *tc[i].value, tc[i].size, + tc[i].flags)); + }if (TST_RET ==-1 &&TST_ERR ==EOPNOTSUPP ) -tst_brk (TCONF ,"setxattr(2) not supported" ); +tst_brk (TCONF ,"%s(2) not supported" , sysname);/* success */ if (!tc[i].exp_err) {if (TST_RET ) {tst_res (TFAIL |TTERRNO , -"setxattr(2) failed with %li" ,TST_RET ); +"%s(2) failed with %li" , sysname,TST_RET );return ; }/* this is needed for subsequent iterations */ SAFE_REMOVEXATTR (FNAME , tc[i].key); -tst_res (TPASS ,"setxattr(2) passed" ); +tst_res (TPASS ,"%s(2) passed" , sysname);return ; }if (TST_RET ==0 ) { -tst_res (TFAIL ,"setxattr(2) passed unexpectedly" ); +tst_res (TFAIL ,"%s(2) passed unexpectedly" , sysname);return ; }/* error */ if (tc[i].exp_err !=TST_ERR ) { -tst_res (TFAIL |TTERRNO ,"setxattr(2) should fail with %s" , -tst_strerrno (tc[i].exp_err)); +tst_res (TFAIL |TTERRNO ,"%s(2) should fail with %s" , + sysname,tst_strerrno (tc[i].exp_err));return ; }
@@ -171,7 +194,7 @@ static void verify_setxattr(unsigned int i)if (tc[i].keyneeded)SAFE_REMOVEXATTR (FNAME , tc[i].key); -tst_res (TPASS |TTERRNO ,"setxattr(2) failed" ); +tst_res (TPASS |TTERRNO ,"%s(2) failed" , sysname); }static void setup (void )
@@ -192,12 +215,22 @@ static void setup(void)if (!tc[i].key) tc[i].key =tst_get_bad_addr (NULL ); } + + mnt_fd =SAFE_OPEN (MNTPOINT ,O_DIRECTORY ); +} + +static void cleanup (void ) +{ +if (mnt_fd !=-1 ) +SAFE_CLOSE (mnt_fd); }static struct tst_test test = { .setup = setup, + .cleanup = cleanup, .test = verify_setxattr, .tcnt =ARRAY_SIZE (tc), + .test_variants =2 , .mntpoint =MNTPOINT , .mount_device =1 , .all_filesystems =1 ,
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 03/10] setxattr01: add setxattrat variant
Hi!
Looks good to me:
...
testcases/kernel/syscalls/setxattr/setxattr01.c struct test_case tc[] = { · line 161
Quoted 3 lines
testcases/kernel/syscalls/setxattr/setxattr01.c +1
-1if (TST_RET ==-1 &&TST_ERR ==EOPNOTSUPP ) -tst_brk (TCONF ,"setxattr(2) not supported" ); +tst_brk (TCONF ,"%s(2) not supported" , sysname);
Can we please, in a subsequent patch, convert this part to our standard approach where we check for the availability in the test setup and expect the syscalls to be present if kernel is new enough?
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 03/10] setxattr01: add setxattrat variant
Quoted 3 lines · Cyril Hrubis
Can we please, in a subsequent patch, convert this part to our standard approach where we check for the availability in the test setup and expect the syscalls to be present if kernel is new enough?
What do you think it's the best way? Some of these tests have multiple syscalls related to *xattrat and in this test in particular we are testing 2 syscalls. Maybe the best way would be to check for HAVE_FUNC_* declarations in this case, but then fallback function would fail anyway.
Signature · 7 lines
Andrea Cervesato SUSE QE Automation Engineer Linux [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 03/10] setxattr01: add setxattrat variant
Hi!
Quoted 7 lines
Quoted 3 lines
Can we please, in a subsequent patch, convert this part to our standard approach where we check for the availability in the test setup and expect the syscalls to be present if kernel is new enough?
What do you think it's the best way? Some of these tests have multiple syscalls related to *xattrat and in this test in particular we are testing 2 syscalls.
The same what we do for the rest of the syscalls, introduce a setxattrat_supported() helper into a shared header that would call tst_brk(TCONF, "") if kernel is older than the version the syscall was added to and we got ENOSYS.
We actually have to handle a few cases here:
For setxattrat:
- ENOSYS -> kernel too old
- EOPNOTSUPP -> filesystem does not support extended attributes
(e.g. vfat)
And as for filesystem support, it looks like TMPFS has CONFIG_TMPFS_XATTR option so it could be enabled or disabled, however they should be supported for native Linux filesystems such as ext, btrfs or xfs.
And we have to handle EOPNOTSUPP for setxattr() as well, so the test setup would look like:
if (tst_variant) setxattrat_supported(); else setxattr_supported();
At the moment the ENOSYS branch would be covered by the fallback function since it calls tst_syscall() but once the function gets added to libc the check would no longer happen, so we need to eventually handle the ENOSYS in the foo_supported() function as well.
Quoted 2 lines
Maybe the best way would be to check for HAVE_FUNC_* declarations in this case, but then fallback function would fail anyway.
No this does not work, the only way how to find out if a syscall is supported is to call it and check the return value.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 03/10] setxattr01: add setxattrat variant
Hi,
Quoted 26 lines · Cyril Hrubis
Hi!
Quoted 7 lines
Quoted 3 lines
Can we please, in a subsequent patch, convert this part to our standard approach where we check for the availability in the test setup and expect the syscalls to be present if kernel is new enough?
What do you think it's the best way? Some of these tests have multiple syscalls related to *xattrat and in this test in particular we are testing 2 syscalls.
The same what we do for the rest of the syscalls, introduce a
setxattrat_supported()helper into a shared header that would calltst_brk(TCONF, "")if kernel is older than the version the syscall was added to and we got ENOSYS.We actually have to handle a few cases here:
For setxattrat:
- ENOSYS -> kernel too old
- EOPNOTSUPP -> filesystem does not support extended attributes(e.g. vfat)And as for filesystem support, it looks like TMPFS has
CONFIG_TMPFS_XATTRoption so it could be enabled or disabled, however they should be supported for native Linux filesystems such as ext, btrfs or xfs.
Quoted 7 lines
And we have to handle EOPNOTSUPP for
setxattr()as well, so the test setup would look like:if (tst_variant) setxattrat_supported(); else setxattr_supported();
The problem I have with this approach is that the whole kernel implementation of setxattr() is based on setxattrat() and this test is just moving through the same code. I would like to give a bare minimum attention. At the same time, we need to test a syscall by calling it with the right data, on files, that is something we are already doing during the test. For instance, we don't have a "foo" run and we are just going around setup() which is really slow only for filesystems testing. In general, letting the syscall to fail inside test won't get much time.
Quoted 11 lines
At the moment the ENOSYS branch would be covered by the fallback function since it calls
tst_syscall()but once the function gets added to libc the check would no longer happen, so we need to eventually handle the ENOSYS in thefoo_supported()function as well.Quoted 2 lines
Maybe the best way would be to check for HAVE_FUNC_* declarations in this case, but then fallback function would fail anyway.
No this does not work, the only way how to find out if a syscall is supported is to call it and check the return value.
Signature · 7 lines
Andrea Cervesato SUSE QE Automation Engineer Linux [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 03/10] setxattr01: add setxattrat variant
Hi!
Quoted 8 lines
Quoted 8 lines
And as for filesystem support, it looks like TMPFS has
CONFIG_TMPFS_XATTRoption so it could be enabled or disabled, however they should be supported for native Linux filesystems such as ext, btrfs or xfs.And we have to handle EOPNOTSUPP for
setxattr()as well, so the test setup would look like:
Quoted 8 lines
Quoted 4 lines
if (tst_variant) setxattrat_supported(); else setxattr_supported();The problem I have with this approach is that the whole kernel implementation of
setxattr()is based onsetxattrat()and this test is just moving through the same code.
The problem at hand is that the *attrat() syscalls were added to 6.13, we are going to be stuck for a decade with kernels that does not support these. Which means that we have to make sure to check for ENOSYS for the at family of the xattr syscalls somewhere anyways and we have to make sure that the coverage for the older syscalls is sufficient too.
Quoted 6 lines
I would like to give a bare minimum attention. At the same time, we need to test a syscall by calling it with the right data, on files, that is something we are already doing during the test. For instance, we don't have a "foo" run and we are just going around
setup()which is really slow only for filesystems testing. In general, letting the syscall to fail inside test won't get much time.
Technically you can call the setxattrat() with a dummy parameters, they does not even have to be correct, because if the syscall is not supported in the kernel you will get ENOSYS as soon as the kernel attempts to fetch the handler form the syscall table.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 4/10 setxattr02: add setxattrat variant
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- testcases/kernel/syscalls/setxattr/setxattr02.c | 79 +++++++++++++++++++------ 1 file changed, 60 insertions(+), 19 deletions(-)
testcases/kernel/syscalls/setxattr/setxattr02.c +60 -19
@@ -19,6 +19,10 @@*/ #include "config.h" +#include "tst_test.h" + +#ifdef HAVE_SYS_XATTR_H +#include <sys/types.h> #include <sys/stat.h> #include <sys/sysmacros.h>
@@ -30,12 +34,10 @@#include <stdio.h> #include <stdlib.h> #include <string.h> -#ifdef HAVE_SYS_XATTR_H -# include <sys/xattr.h> -#endif -#include "tst_test.h" +#include "lapi/xattr.h" +#include "lapi/fcntl.h" +#include <sys/xattr.h> -#ifdef HAVE_SYS_XATTR_H #define XATTR_TEST_KEY "user.testkey"#define XATTR_TEST_VALUE "this is a test value"#define XATTR_TEST_VALUE_SIZE 20
@@ -49,6 +51,8 @@#define BLK "setxattr02blk"#define SOCK "setxattr02sock" +static int tmpdir_fd =-1 ; +struct test_case {char *fname;char *key;
@@ -120,39 +124,58 @@ static struct test_case tc[] = {static void verify_setxattr (unsigned int i) { +char *sysname; +/* some tests might require existing keys for each iteration */ if (tc[i].needskeyset) {SAFE_SETXATTR (tc[i].fname, tc[i].key, tc[i].value, tc[i].size, -XATTR_CREATE ); +XATTR_CREATE ); } -TEST (setxattr (tc[i].fname, tc[i].key, tc[i].value, tc[i].size, - tc[i].flags)); +if (tst_variant) { + sysname ="setxattrat" ; + +struct xattr_args args = { + .value = (uint64_t )tc[i].value, + .size = tc[i].size, + .flags = tc[i].flags, + }; + +int at_flags = tc[i].needskeyset ?0 :AT_SYMLINK_NOFOLLOW ; + +TEST (setxattrat (tmpdir_fd, tc[i].fname, at_flags, + tc[i].key, &args,sizeof (args))); + }else { + sysname ="setxattr" ; + +TEST (setxattr (tc[i].fname, tc[i].key, tc[i].value, tc[i].size, + tc[i].flags)); + }if (TST_RET ==-1 &&TST_ERR ==EOPNOTSUPP ) -tst_brk (TCONF ,"setxattr(2) not supported" ); +tst_brk (TCONF ,"%s(2) not supported" , sysname);/* success */ if (!tc[i].exp_err) {if (TST_RET ) {tst_res (TFAIL |TTERRNO , -"setxattr(2) on %s failed with %li" , - tc[i].fname +OFFSET ,TST_RET ); +"%s(2) on %s failed with %li" , + sysname, tc[i].fname +OFFSET ,TST_RET );return ; }/* this is needed for subsequent iterations */ SAFE_REMOVEXATTR (tc[i].fname, tc[i].key); -tst_res (TPASS ,"setxattr(2) on %s passed" , - tc[i].fname +OFFSET ); +tst_res (TPASS ,"%s(2) on %s passed" , + sysname, tc[i].fname +OFFSET );return ; }if (TST_RET ==0 ) { -tst_res (TFAIL ,"setxattr(2) on %s passed unexpectedly" , - tc[i].fname +OFFSET ); +tst_res (TFAIL ,"%s(2) on %s passed unexpectedly" , + sysname, tc[i].fname +OFFSET );return ; }
@@ -160,8 +183,8 @@ static void verify_setxattr(unsigned int i)if (tc[i].exp_err !=TST_ERR ) {tst_res (TFAIL |TTERRNO , -"setxattr(2) on %s should have failed with %s" , - tc[i].fname +OFFSET , +"%s(2) on %s should have failed with %s" , + sysname, tc[i].fname +OFFSET ,tst_strerrno (tc[i].exp_err));return ; }
@@ -170,8 +193,8 @@ static void verify_setxattr(unsigned int i)if (tc[i].needskeyset)SAFE_REMOVEXATTR (tc[i].fname, tc[i].key); -tst_res (TPASS |TTERRNO ,"setxattr(2) on %s failed" , - tc[i].fname +OFFSET ); +tst_res (TPASS |TTERRNO ,"%s(2) on %s failed" , + sysname, tc[i].fname +OFFSET ); }static void setup (void )
@@ -185,12 +208,30 @@ static void setup(void)SAFE_MKNOD (CHR ,S_IFCHR |0777 , dev);SAFE_MKNOD (BLK ,S_IFBLK |0777 ,0 );SAFE_MKNOD (SOCK ,S_IFSOCK |0777 ,0 ); + + tmpdir_fd =SAFE_OPEN (tst_tmpdir_path (),O_DIRECTORY ); +} + +static void cleanup (void ) +{ +if (tmpdir_fd !=-1 ) +SAFE_CLOSE (tmpdir_fd); + +SAFE_UNLINK (FILENAME ); +SAFE_RMDIR (DIRNAME ); +SAFE_UNLINK (SYMLINK ); +SAFE_UNLINK (FIFO ); +SAFE_UNLINK (CHR ); +SAFE_UNLINK (BLK ); +SAFE_UNLINK (SOCK ); }static struct tst_test test = { .setup = setup, + .cleanup = cleanup, .test = verify_setxattr, .tcnt =ARRAY_SIZE (tc), + .test_variants =2 , .needs_tmpdir =1 , .needs_root =1 , };
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 04/10] setxattr02: add setxattrat variant
Quoted 62 lines · Andrea Cervesato
From: Andrea Cervesato <[email protected]>
Signed-off-by Andrea Cervesato <[email protected]>--- testcases/kernel/syscalls/setxattr/setxattr02.c | 79 +++++++++++++++++++------ 1 file changed, 60 insertions(+), 19 deletions(-)testcases/kernel/syscalls/setxattr/setxattr02.c +12
-8@@ -19,6 +19,10 @@*/ #include "config.h" +#include "tst_test.h" + +#ifdef HAVE_SYS_XATTR_H +#include <sys/types.h> #include <sys/stat.h> #include <sys/sysmacros.h> @@ -30,12 +34,10 @@#include <stdio.h> #include <stdlib.h> #include <string.h> -#ifdef HAVE_SYS_XATTR_H -# include <sys/xattr.h> -#endif -#include "tst_test.h" +#include "lapi/xattr.h" +#include "lapi/fcntl.h" +#include <sys/xattr.h> -#ifdef HAVE_SYS_XATTR_H #define XATTR_TEST_KEY "user.testkey"#define XATTR_TEST_VALUE "this is a test value"#define XATTR_TEST_VALUE_SIZE 20@@ -49,6 +51,8 @@#define BLK "setxattr02blk"#define SOCK "setxattr02sock" +static int tmpdir_fd =-1 ; +struct test_case {char *fname;char *key;@@ -120,39 +124,58 @@ static struct test_case tc[] = {static void verify_setxattr (unsigned int i) { +char *sysname; +/* some tests might require existing keys for each iteration */ if (tc[i].needskeyset) {SAFE_SETXATTR (tc[i].fname, tc[i].key, tc[i].value, tc[i].size, -XATTR_CREATE ); +XATTR_CREATE ); } -TEST (setxattr (tc[i].fname, tc[i].key, tc[i].value, tc[i].size, - tc[i].flags));
testcases/kernel/syscalls/setxattr/setxattr02.c static struct test_case tc[] = { · line 144
Quoted 10 lines
testcases/kernel/syscalls/setxattr/setxattr02.c +10
-0+if (tst_variant) { + sysname ="setxattrat" ; + +struct xattr_args args = { + .value = (uint64_t )tc[i].value, + .size = tc[i].size, + .flags = tc[i].flags, + }; + +int at_flags = tc[i].needskeyset ?0 :AT_SYMLINK_NOFOLLOW ;
I do not get why this is needed.
In kernel:
SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
const char __user *, name, const void __user *, value, size_t, size, int, flags)
{
return path_setxattrat(AT_FDCWD, pathname, 0, name, value, size, flags);
^
the setxattr() the always sets the at_flags to 0
}
So shouldn't setxattrat() just work the same if we pass 0 there?
It's the lsetxattr() syscall that passes AT_SYMLINK_NOFOLLOW:
SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
const char __user *, name, const void __user *, value, size_t, size, int, flags)
{
return path_setxattrat(AT_FDCWD, pathname, AT_SYMLINK_NOFOLLOW, name,
value, size, flags);
}
testcases/kernel/syscalls/setxattr/setxattr02.c static void setup(void) · line 212
Quoted 7 lines
testcases/kernel/syscalls/setxattr/setxattr02.c +2
-0static void setup (void )@@ -185,12 +208,30 @@ static void setup(void)SAFE_MKNOD (CHR ,S_IFCHR |0777 , dev);SAFE_MKNOD (BLK ,S_IFBLK |0777 ,0 );SAFE_MKNOD (SOCK ,S_IFSOCK |0777 ,0 ); + + tmpdir_fd =SAFE_OPEN (tst_tmpdir_path (),O_DIRECTORY );
This is memleak, on the top of that can't we just use the AT_FDCWD instead? Or if you want to make sure that the syscall works with a real fd we can do SAFE_OPEN(".", O_DIRECTORY) instead....
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 5/10 setxattr03: add setxattrat variant
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- testcases/kernel/syscalls/setxattr/setxattr03.c | 35 +++++++++++++++++++------ 1 file changed, 27 insertions(+), 8 deletions(-)
testcases/kernel/syscalls/setxattr/setxattr03.c +27 -8
@@ -12,7 +12,12 @@*/ #define _GNU_SOURCE +#include "config.h" +#include "tst_test.h" + +#ifdef HAVE_SYS_XATTR_H +#include <sys/ioctl.h> #include <sys/types.h> #include <sys/stat.h>
@@ -24,14 +29,10 @@#include <stdio.h> #include <stdlib.h> #include <string.h> -#ifdef HAVE_SYS_XATTR_H -# include <sys/xattr.h> -#endif #include "lapi/fs.h" +#include "lapi/xattr.h" +#include <sys/xattr.h> -#include "tst_test.h" - -#if definedHAVE_SYS_XATTR_H #define XATTR_TEST_KEY "user.testkey"#define XATTR_TEST_VALUE "this is a test value"#define XATTR_TEST_VALUE_SIZE (sizeof(XATTR_TEST_VALUE) - 1)
@@ -76,11 +77,23 @@ static struct test_case tc[] = {static int immu_fd;static int append_fd; +static int tmpdir_fd =-1 ;static void verify_setxattr (unsigned int i) { -TEST (setxattr (tc[i].fname, tc[i].key, tc[i].value, tc[i].size, - tc[i].flags)); +if (tst_variant) { +struct xattr_args args = { + .value = (uint64_t )tc[i].value, + .size = tc[i].size, + .flags = tc[i].flags, + }; + +TEST (setxattrat (tmpdir_fd, tc[i].fname,AT_SYMLINK_NOFOLLOW , + tc[i].key, &args,sizeof (args))); + }else { +TEST (setxattr (tc[i].fname, tc[i].key, tc[i].value, tc[i].size, + tc[i].flags)); + }if (!TST_RET ) {tst_res (TFAIL ,"%s succeeded unexpectedly" , tc[i].desc);
@@ -143,10 +156,15 @@ static void setup(void)if (set_append_on (append_fd))tst_brk (TBROK |TERRNO ,"Set %s append-only failed" ,APPEND_FILE ); + + tmpdir_fd =SAFE_OPEN (tst_tmpdir_path (),O_DIRECTORY ); }static void cleanup (void ) { +if (tmpdir_fd !=-1 ) +SAFE_CLOSE (tmpdir_fd); +if ((immu_fd >0 ) &&set_immutable_off (immu_fd))tst_res (TWARN |TERRNO ,"Unset %s immutable failed" ,IMMU_FILE );
@@ -167,6 +185,7 @@ static struct tst_test test = { .cleanup = cleanup, .test = verify_setxattr, .tcnt = ARRAY_SIZE(tc), + .test_variants = 2, .needs_tmpdir = 1, .needs_root = 1, };
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 05/10] setxattr03: add setxattrat variant
Hi!
testcases/kernel/syscalls/setxattr/setxattr03.c static void setup(void) · line 160
Quoted 8 lines
testcases/kernel/syscalls/setxattr/setxattr03.c +2
-0if (!TST_RET ) {tst_res (TFAIL ,"%s succeeded unexpectedly" , tc[i].desc);@@ -143,10 +156,15 @@ static void setup(void)if (set_append_on (append_fd))tst_brk (TBROK |TERRNO ,"Set %s append-only failed" ,APPEND_FILE ); + + tmpdir_fd =SAFE_OPEN (tst_tmpdir_path (),O_DIRECTORY );
Here as well. Maybe we should use AT_FDCWD in one test and return value from SAFE_OPEN(".", O_DIRECTORY) in the other, so that we test different codepaths in the kernel.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 6/10 lapi: add getxattrat() fallback
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- configure.ac | 1 + include/lapi/xattr.h | 10 ++++++++++ 2 files changed, 11 insertions(+)
configure.ac +1 -0
@@ -125,6 +125,7 @@ AC_CHECK_FUNCS_ONCE([ \ getcpu \ getdents \ getdents64 \ + getxattrat \ io_pgetevents \ io_uring_setup \ io_uring_register \
include/lapi/xattr.h +10 -0
@@ -41,4 +41,14 @@ static inline int setxattrat(int dfd, const char *pathname, }#endif +#ifndef HAVE_FUNC_GETXATTRAT +static inline int getxattrat (int dfd,const char *pathname, +unsigned int at_flags,const char *name, +void *value,size_t size) +{ +return tst_syscall (__NR_getxattrat, dfd, pathname, at_flags, name, + value, size); +} +#endif +#endif /* LAPI_XATTR_H__ */
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 06/10] lapi: add getxattrat() fallback
Hi!
Quoted 1 line
+#ifndef
HAVE_FUNC_GETXATTRAT
^
Here as well no FUNC
Otherwise:
Quoted 17 lines
include/lapi/xattr.h +9
-0+static inline int getxattrat (int dfd,const char *pathname, +unsigned int at_flags,const char *name, +void *value,size_t size) +{ +return tst_syscall (__NR_getxattrat, dfd, pathname, at_flags, name, + value, size); +} +#endif +#endif /* LAPI_XATTR_H__ */ Signature · 6 lines
-- 2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 7/10 lapi: add removexattrat() fallback
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- configure.ac | 1 + include/lapi/xattr.h | 8 ++++++++ 2 files changed, 9 insertions(+)
configure.ac +1 -0
@@ -153,6 +153,7 @@ AC_CHECK_FUNCS_ONCE([ \ quotactl_fd \ rand_r \ recvmmsg \ + removexattrat \ renameat2 \ sched_getcpu \ sendmmsg \
include/lapi/xattr.h +8 -0
@@ -51,4 +51,12 @@ static inline int getxattrat(int dfd, const char *pathname, }#endif +#ifndef HAVE_FUNC_REMOVEXATTRAT +static inline int removexattrat (int dfd,const char *pathname, +unsigned int at_flags,const char *name) +{ +return tst_syscall (__NR_removexattrat, dfd, pathname, at_flags, name); +} +#endif +#endif /* LAPI_XATTR_H__ */
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 07/10] lapi: add removexattrat() fallback
Hi!
Quoted 1 line
+#ifndef
HAVE_FUNC_REMOVEXATTRAT
^
And here as well, otherwise:
Quoted 15 lines
include/lapi/xattr.h +7
-0+static inline int removexattrat (int dfd,const char *pathname, +unsigned int at_flags,const char *name) +{ +return tst_syscall (__NR_removexattrat, dfd, pathname, at_flags, name); +} +#endif +#endif /* LAPI_XATTR_H__ */ Signature · 6 lines
-- 2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 8/10 lapi: add safe *xattrat macros
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Introduce the following new safe macros:
- SAFE_SETXATTRAT
- SAFE_GETXATTRAT
- SAFE_REMOVEXATTRAT
--- include/lapi/xattr.h | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+)
include/lapi/xattr.h +94 -0
@@ -59,4 +59,98 @@ static inline int removexattrat(int dfd, const char *pathname, }#endif +int safe_setxattrat (const char *file,const int lineno, +int dfd,const char *path,int at_flags, +const char *key,struct xattr_args *args,size_t size) +{ +int rval; + + rval =setxattrat (dfd, path, at_flags, key, args, size); + +if (rval ==-1 ) { +if (errno ==ENOTSUP ) { +tst_brk_ (file, lineno,TCONF , +"no xattr support in fs, mounted without user_xattr option " +"or invalid namespace/name format" ); +return rval; + } + +tst_brk_ (file, lineno,TBROK |TERRNO , +"setxattrat(%d, %s, %d, %s, %p, %zu) failed" , + dfd, path, at_flags, key, args, size); + }else if (rval) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"Invalid setxattrat(%d, %s, %d, %s, %p, %zu) return value %d" , + dfd, path, at_flags, key, args, size, rval); + } + +return rval; +} + +#define SAFE_SETXATTRAT (dfd, path, at_flags, key, args, size) \ + safe_setxattrat(__FILE__, __LINE__, \ + (dfd), (path), (at_flags), (key), (args), (size)) + +int safe_getxattrat (const char *file,const int lineno, +int dfd,const char *path,int at_flags, +const char *key,struct xattr_args *args,size_t size) +{ +int rval; + + rval =getxattrat (dfd, path, at_flags, key, args, size); + +if (rval ==-1 ) { +if (errno ==ENOTSUP ) { +tst_brk_ (file, lineno,TCONF , +"no xattr support in fs, mounted without user_xattr option " +"or invalid namespace/name format" ); +return rval; + } + +tst_brk_ (file, lineno,TBROK |TERRNO , +"getxattrat(%d, %s, %d, %s, %p, %zu) failed" , + dfd, path, at_flags, key, args, size); + }else if (rval <0 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"Invalid getxattrat(%d, %s, %d, %s, %p, %zu) return value %d" , + dfd, path, at_flags, key, args, size, rval); + } + +return rval; +} + +#define SAFE_GETXATTRAT (dfd, path, at_flags, key, args, size) \ + safe_getxattrat(__FILE__, __LINE__, \ + (dfd), (path), (at_flags), (key), (args), (size)) + +int safe_removexattrat (const char *file,const int lineno, +int dfd,const char *path,int at_flags,const char *name) +{ +int rval; + + rval =removexattrat (dfd, path, at_flags, name); + +if (rval ==-1 ) { +if (errno ==ENOTSUP ) { +tst_brk_ (file, lineno,TCONF , +"no xattr support in fs or mounted without user_xattr option" ); +return rval; + } + +tst_brk_ (file, lineno,TBROK |TERRNO , +"removexattrat(%d, %s, %d, %s) failed" , + dfd, path, at_flags, name); + }else if (rval) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"Invalid removexattrat(%d, %s, %d, %s) return value %d" , + dfd, path, at_flags, name, rval); + } + +return rval; +} + +#define SAFE_REMOVEXATTRAT (dfd, path, at_flags, name) \ + safe_removexattrat(__FILE__, __LINE__, \ + (dfd), (path), (at_flags), (name)) +#endif /* LAPI_XATTR_H__ */
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 08/10] lapi: add safe *xattrat macros
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 9/10 Add setxattrat01 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Test if setxattrat() syscall is correctly following symlink, setting a xattr on a file.
--- testcases/kernel/syscalls/setxattrat/.gitignore | 1 + testcases/kernel/syscalls/setxattrat/Makefile | 8 ++ .../kernel/syscalls/setxattrat/setxattrat01.c | 150 +++++++++++++++++++++ 3 files changed, 159 insertions(+)
testcases/kernel/syscalls/setxattrat/.gitignore new file +1 -0
@@ -0,0 +1 @@ +setxattrat01
testcases/kernel/syscalls/setxattrat/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2025 SUSE LLC + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/setxattrat/setxattrat01.c new file +150 -0
150 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 09/10] Add setxattrat01 test
Hi!
Quoted 4 lines
+/*\
+ * [Description]
+ *
+ * Test ifsetxattrat()syscall is correctly following symlink, setting a
Quoted 8 lines
+ * xattr on a file.
+ *
+ * [Algorithm]
+ *
+ * - create a file and the symlink pointing to it
+ * - runsetxattrat()on the symlink following the pointing file
+ * - verify that file xattr has been set
+ * - verify that symlink xattr has not been set
Shouldn't this be a variant of a setxattr() test?
Quoted 4 lines
+ * - run
setxattrat()on the symlink withAT_SYMLINK_NOFOLLOW
+ * - verify that file xattr has not been set
+ * - verify that symlink xattr has been set
+ */
And this a variant of lsetxattr() test?
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 09/10] Add setxattrat01 test
Hi!
Quoted 14 lines · Cyril Hrubis
Hi!
Quoted 4 lines
+/*\
+ * [Description]
+ *
+ * Test ifsetxattrat()syscall is correctly following symlink, setting aQuoted 8 lines
+ * xattr on a file.
+ *
+ * [Algorithm]
+ *
+ * - create a file and the symlink pointing to it
+ * - runsetxattrat()on the symlink following the pointing file
+ * - verify that file xattr has been set
+ * - verify that symlink xattr has not been set
Quoted 8 lines
Shouldn't this be a variant of a
setxattr()test?Quoted 4 lines
+ * - run
setxattrat()on the symlink withAT_SYMLINK_NOFOLLOW
+ * - verify that file xattr has not been set
+ * - verify that symlink xattr has been set
+ */And this a variant of
lsetxattr()test?
This is the exact reason why I'm not yet 100% sure about coverage for setxattrat, since most of the tests can be just variants of other existing tests and most of the time we have code duplication.
After thinking carefully about this patch-set, I'm not sure to proceed anymore, since the kernel itself is using setxattrat() to implement setxattr() and lsetxattr().
Signature · 7 lines
Andrea Cervesato SUSE QE Automation Engineer Linux [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 10/10 Add setxattrat02 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Test if setxattrat() syscall is correctly raising errors when giving invalid inputs.
--- testcases/kernel/syscalls/setxattrat/.gitignore | 1 + .../kernel/syscalls/setxattrat/setxattrat02.c | 126 +++++++++++++++++++++ 2 files changed, 127 insertions(+)
testcases/kernel/syscalls/setxattrat/.gitignore +1 -0
@@ -1 +1,2 @@ setxattrat01 +setxattrat02
testcases/kernel/syscalls/setxattrat/setxattrat02.c new file +126 -0
126 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 10/10] Add setxattrat02 test
Hi!
testcases/kernel/syscalls/setxattrat/setxattrat02.c line 43
Quoted 8 lines
testcases/kernel/syscalls/setxattrat/setxattrat02.c new file +8
-0+} tcases[] = { + { + .dfd = &invalid_fd, + .args = &args, + .args_size = sizeof(struct xattr_args), + .exp_errno = EBADF, + .reason = "Invalid directory file descriptor", + },
Maybe it would make sense to use tst_fd to hammer the syscall with all kinds of strange file descriptors.
Quoted 49 lines
testcases/kernel/syscalls/setxattrat/setxattrat02.c new file +49
-0+ { + .dfd = &tmpdir_fd, + .at_flags = -1, + .args = &args, + .args_size = sizeof(struct xattr_args), + .exp_errno = EINVAL, + .reason = "Invalid AT flags", + }, + { + .dfd = &tmpdir_fd, + .at_flags = AT_SYMLINK_NOFOLLOW + 1, + .args = &args, + .args_size = sizeof(struct xattr_args), + .exp_errno = EINVAL, + .reason = "Out of bound AT flags", + }, + { + .dfd = &tmpdir_fd, + .args = &null_args, + .args_size = sizeof(struct xattr_args), + .exp_errno = EINVAL, + .reason = "Invalid arguments", + }, + { + .dfd = &tmpdir_fd, + .args = &args, + .args_size = SIZE_MAX, + .exp_errno = E2BIG, + .reason = "Arguments size is too big", + }, + { + .dfd = &tmpdir_fd, + .args = &args, + .args_size = sizeof(struct xattr_args) - 1, + .exp_errno = EINVAL, + .reason = "Invalid arguments size", + }, +}; + +static void run(unsigned int i) +{ + struct tcase *tc = &tcases[i]; + + args->flags = XATTR_CREATE; + args->value = (uint64_t)XATTR_TEST_VALUE; + args->size = XATTR_TEST_VALUE_SIZE; + + TST_EXP_FAIL(tst_syscall(__NR_setxattrat, + tc->dfd, FNAME, tc->at_flags, XATTR_TEST_KEY,
testcases/kernel/syscalls/setxattrat/setxattrat02.c line 102
Quoted 10 lines
testcases/kernel/syscalls/setxattrat/setxattrat02.c new file +10
-0+ tc->args, tc->args_size), + tc->exp_errno, "%s", tc->reason); +} + +static void setup (void ) +{ +char *tmpdir; + + tmpdir =tst_tmpdir_path (); + tmpdir_fd =SAFE_OPEN (tmpdir,O_DIRECTORY );
Here as well, just use AT_FDCWD.
Quoted 30 lines
testcases/kernel/syscalls/setxattrat/setxattrat02.c new file +23
-0+SAFE_TOUCH (FNAME ,0777 ,NULL ); +} + +static void cleanup (void ) +{ +if (tmpdir_fd !=-1 ) +SAFE_CLOSE (tmpdir_fd); + +SAFE_UNLINK (FNAME ); +} + +static struct tst_test test = { + .test = run, + .setup = setup, + .cleanup = cleanup, + .tcnt =ARRAY_SIZE (tcases), + .needs_root =1 , + .needs_tmpdir =1 , + .bufs = (struct tst_buffers []) { + {&args, .size =sizeof (struct xattr_args )}, + {}, + } +};Signature · 6 lines
-- 2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 10/10] Add setxattrat02 test
Hi,
Quoted 13 lines · Cyril Hrubis
Hi!
testcases/kernel/syscalls/setxattrat/setxattrat02.c line 43
Quoted 8 lines
testcases/kernel/syscalls/setxattrat/setxattrat02.c new file +8
-0+} tcases[] = { + { + .dfd = &invalid_fd, + .args = &args, + .args_size = sizeof(struct xattr_args), + .exp_errno = EBADF, + .reason = "Invalid directory file descriptor", + },Maybe it would make sense to use
tst_fdto hammer the syscall with all kinds of strange file descriptors.
This makes sense for a new test, in this test it's better to keep this approach.
Quoted 53 lines
Quoted 53 lines
testcases/kernel/syscalls/setxattrat/setxattrat02.c new file +53
-0+ { + .dfd = &tmpdir_fd, + .at_flags = -1, + .args = &args, + .args_size = sizeof(struct xattr_args), + .exp_errno = EINVAL, + .reason = "Invalid AT flags", + }, + { + .dfd = &tmpdir_fd, + .at_flags = AT_SYMLINK_NOFOLLOW + 1, + .args = &args, + .args_size = sizeof(struct xattr_args), + .exp_errno = EINVAL, + .reason = "Out of bound AT flags", + }, + { + .dfd = &tmpdir_fd, + .args = &null_args, + .args_size = sizeof(struct xattr_args), + .exp_errno = EINVAL, + .reason = "Invalid arguments", + }, + { + .dfd = &tmpdir_fd, + .args = &args, + .args_size = SIZE_MAX, + .exp_errno = E2BIG, + .reason = "Arguments size is too big", + }, + { + .dfd = &tmpdir_fd, + .args = &args, + .args_size = sizeof(struct xattr_args) - 1, + .exp_errno = EINVAL, + .reason = "Invalid arguments size", + }, +}; + +static void run(unsigned int i) +{ + struct tcase *tc = &tcases[i]; + + args->flags = XATTR_CREATE; + args->value = (uint64_t)XATTR_TEST_VALUE; + args->size = XATTR_TEST_VALUE_SIZE; + + TST_EXP_FAIL(tst_syscall(__NR_setxattrat, + tc->dfd, FNAME, tc->at_flags, XATTR_TEST_KEY, + tc->args, tc->args_size), + tc->exp_errno, "%s", tc->reason); +} +
Quoted 9 lines
testcases/kernel/syscalls/setxattrat/setxattrat02.c line 102
Quoted 6 lines
testcases/kernel/syscalls/setxattrat/setxattrat02.c new file +6
-0+static void setup (void ) +{ +char *tmpdir; + + tmpdir =tst_tmpdir_path (); + tmpdir_fd =SAFE_OPEN (tmpdir,O_DIRECTORY );Here as well, just use
AT_FDCWD.
Ok.
Quoted 30 lines
Quoted 30 lines
testcases/kernel/syscalls/setxattrat/setxattrat02.c new file +23
-0+SAFE_TOUCH (FNAME ,0777 ,NULL ); +} + +static void cleanup (void ) +{ +if (tmpdir_fd !=-1 ) +SAFE_CLOSE (tmpdir_fd); + +SAFE_UNLINK (FNAME ); +} + +static struct tst_test test = { + .test = run, + .setup = setup, + .cleanup = cleanup, + .tcnt =ARRAY_SIZE (tcases), + .needs_root =1 , + .needs_tmpdir =1 , + .bufs = (struct tst_buffers []) { + {&args, .size =sizeof (struct xattr_args )}, + {}, + } +};Signature · 6 lines
-- 2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 7 lines
Andrea Cervesato SUSE QE Automation Engineer Linux [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp