Add tst_fd iterator API
Subsystems (2)
v3 cover Add tst_fd iterator API
Changes in v3:
- Made use of newly introduced API to specify an array of possible errors
Jan and Amir please check if the error sets are not missing anything
- Fixed a few minor problems as pointed out by Peter
Changes in v2:
- Changed the API into iterator rather than a funciton callback
- Added a lot more fd types
- Added splice test
Cyril Hrubis (4):
lib: Add tst_fd iterator
syscalls: readahead01: Make use of tst_fd
syscalls: accept: Add tst_fd test
syscalls: splice07: New splice tst_fd iterator test
include/tst_fd.h | 61 ++++ include/tst_test.h | 1 + lib/tst_fd.c | 325 ++++++++++++++++++ runtest/syscalls | 2 + testcases/kernel/syscalls/accept/.gitignore | 1 + testcases/kernel/syscalls/accept/accept01.c | 8 - testcases/kernel/syscalls/accept/accept03.c | 60 ++++ .../kernel/syscalls/readahead/readahead01.c | 52 +-- testcases/kernel/syscalls/splice/.gitignore | 1 + testcases/kernel/syscalls/splice/splice07.c | 70 ++++ 10 files changed, 548 insertions(+), 33 deletions(-) create mode 100644 include/tst_fd.h create mode 100644 lib/tst_fd.c create mode 100644 testcases/kernel/syscalls/accept/accept03.c create mode 100644 testcases/kernel/syscalls/splice/splice07.c
Signature · 1 line
2.43.0
PATCH v3 1/4 lib: Add tst_fd iterator
Which allows tests to loop over different types of file descriptors
--- include/tst_fd.h | 61 +++++++++ include/tst_test.h | 1 + lib/tst_fd.c | 325 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 387 insertions(+) create mode 100644 include/tst_fd.h create mode 100644 lib/tst_fd.c
include/tst_fd.h new file +61 -0
@@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +/* +* Copyright (C) 2023 Cyril Hrubis <[email protected]> +*/ + +#ifndef TST_FD_H__ +#define TST_FD_H__ + +enum tst_fd_type { +TST_FD_FILE , +TST_FD_PATH , +TST_FD_DIR , +TST_FD_DEV_ZERO , +TST_FD_PROC_MAPS , +TST_FD_PIPE_READ , +TST_FD_PIPE_WRITE , +TST_FD_UNIX_SOCK , +TST_FD_INET_SOCK , +TST_FD_EPOLL , +TST_FD_EVENTFD , +TST_FD_SIGNALFD , +TST_FD_TIMERFD , +TST_FD_PIDFD , +TST_FD_FANOTIFY , +TST_FD_INOTIFY , +TST_FD_USERFAULTFD , +TST_FD_PERF_EVENT , +TST_FD_IO_URING , +TST_FD_BPF_MAP , +TST_FD_FSOPEN , +TST_FD_FSPICK , +TST_FD_OPEN_TREE , +TST_FD_MEMFD , +TST_FD_MEMFD_SECRET , +TST_FD_MAX , +}; + +struct tst_fd { +enum tst_fd_type type; +int fd; +/* used by the library, do not touch! */ +long priv; +}; + +#define TST_FD_INIT {.type = TST_FD_FILE, .fd = -1} + +/* +* Advances the iterator to the next fd type, returns zero at the end. +*/ +int tst_fd_next (struct tst_fd *fd); + +#define TST_FD_FOREACH (fd) \ + for (struct tst_fd fd = TST_FD_INIT; tst_fd_next(&fd); ) + +/* +* Returns human readable name for the file descriptor type. +*/ +const char *tst_fd_desc (struct tst_fd *fd); + +#endif /* TST_FD_H__ */
include/tst_test.h +1 -0
@@ -44,6 +44,7 @@#include "tst_taint.h" #include "tst_memutils.h" #include "tst_arch.h" +#include "tst_fd.h" /* * Reports testcase result.
lib/tst_fd.c new file +325 -0
325 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [LTP] [PATCH v3 1/4] lib: Add tst_fd iterator
Hi,
...
Quoted 4 lines
lib/tst_fd.c new file +1
-0@@ -0,0 +1,325 @@ +// SPDX-License-Identifier: GPL-2.0-or-later
...
lib/tst_fd.c line 114
Quoted 6 lines
lib/tst_fd.c new file +6
-0+static void open_eventfd (struct tst_fd *fd) +{ + fd->fd =eventfd (0 ,0 ); + +if (fd->fd <0 ) { + tst_res(TCONF | TERRNO,
very nit: this could be on single line, without brackets.
lib/tst_fd.c line 121
Quoted 7 lines
lib/tst_fd.c new file +7
-0+ "Skipping %s", tst_fd_desc(fd)); + } +} + +static void open_signalfd (struct tst_fd *fd) +{ +sigset_t sfd_mask;
nit: space here saves checkpatch warning.
Quoted 4 lines
lib/tst_fd.c new file +4
-0+sigemptyset (&sfd_mask); + + fd->fd =signalfd (-1 , &sfd_mask,0 ); +if (fd->fd <0 ) {
lib/tst_fd.c line 135
Quoted 10 lines
lib/tst_fd.c new file +10
-0+tst_res (TCONF |TERRNO , +"Skipping %s" ,tst_fd_desc (fd)); + } +} + +static void open_timerfd (struct tst_fd *fd) +{ + fd->fd =timerfd_create (CLOCK_REALTIME ,0 ); +if (fd->fd <0 ) { + tst_res(TCONF | TERRNO,
Here as well.
lib/tst_fd.c line 117
Quoted 3 lines
lib/tst_fd.c new file +3
-0+ "Skipping %s", tst_fd_desc(fd)); + } +}
...
Obviously ready to merge, thanks!
Kind regards,
Petr
Re: [LTP] [PATCH v3 1/4] lib: Add tst_fd iterator
Hi all,
[ removed kernel folks to not bother them with our old distros ]
Quoted 1 line
Obviously ready to merge, thanks!
I'm sorry, there are still 2 build failures [1] even with my attempt to fix it [2]:
Both Leap 42.2 and Ubuntu Bionic fail to build on:
In file included from ../include/lapi/io_uring.h:17:0,
from tst_fd.c:21:
/usr/include/sys/mount.h:35:3: error: expected identifier before numeric constant
MS_RDONLY = 1, /* Mount read-only. */
^
I found quite useful to have new LTP for these old distros, but if it's too much pain I'm ok to drop them. I'm not even sure if it's possible to fix it. The only way to do that would be for these old distros (which cannot combine these two headers) to also avoid BPF and io_uring. Code below compiles [3], but I don't think myself it's a good solution even if we polish the check (transform into m4 macro).
OTOH fsopen haven't been defined in <sys/mount.h> yet in libc (checked: glibc, musl, uclibc-ng, bionic), thus the effect would be that we'd just use <linux/mount.h> instead of <sys/mount.h> in lib/*.c. And mount() related tests which test <sys/mount.h> (or use lapi/mount.h) could not include <linux/mount.h> nor <linux/io_uring.h> nor <lapi/bpf.h>. Of course, we can't keep these two old distros too long.
Kind regards,
Petr
[1] https://github.com/pevik/ltp/actions/runs/7534892435
[2] https://lore.kernel.org/ltp/[email protected]/
[3] https://github.com/pevik/ltp/actions/runs/7535285434
Quoted 2 lines
Kind regards,
Petr
lapi/fsmount.h +3 -4
@@ -11,12 +11,11 @@#include "config.h" #include <sys/syscall.h> #include <sys/types.h> -#include <sys/mount.h> -#ifndef HAVE_FSOPEN -# ifdef HAVE_LINUX_MOUNT_H +#if !defined(HAVE_FSOPEN ) && defined(HAVE_LINUX_MOUNT_H )# include <linux/mount.h> -# endif +#else +# include <sys/mount.h> #endif #include "lapi/fcntl.h"
tst_fd.h +2 -0
@@ -26,8 +26,10 @@ enum tst_fd_type { TST_FD_INOTIFY,TST_FD_USERFAULTFD ,TST_FD_PERF_EVENT , +#if defined(HAVE_FSOPEN) || !defined(HAVE_LINUX_MOUNT_H)TST_FD_IO_URING ,TST_FD_BPF_MAP , +#endifTST_FD_FSOPEN ,TST_FD_FSPICK , TST_FD_OPEN_TREE,
tst_fd.c +8 -1
@@ -18,9 +18,12 @@#include "tst_safe_macros.h" #include "lapi/pidfd.h" +#include "lapi/fsmount.h" + +#if defined(HAVE_FSOPEN ) || !defined(HAVE_LINUX_MOUNT_H )#include "lapi/io_uring.h" #include "lapi/bpf.h" -#include "lapi/fsmount.h" +#endif #include "tst_fd.h"
@@ -190,6 +193,7 @@ static void open_perf_event(struct tst_fd *fd) } } +#if defined(HAVE_FSOPEN ) || !defined(HAVE_LINUX_MOUNT_H )static void open_io_uring (struct tst_fd *fd) {struct io_uring_params uring_params = {};
@@ -216,6 +220,7 @@ static void open_bpf_map(struct tst_fd *fd) "Skipping %s", tst_fd_desc(fd)); } } +#endif static void open_fsopen (struct tst_fd *fd) {
@@ -281,8 +286,10 @@ static struct tst_fd_desc fd_desc[] = { [TST_FD_INOTIFY] = {.open_fd = open_inotify, .desc = "inotify"}, [TST_FD_USERFAULTFD] = {.open_fd = open_userfaultfd, .desc = "userfaultfd"}, [TST_FD_PERF_EVENT] = {.open_fd = open_perf_event, .desc = "perf event"}, +#if defined(HAVE_FSOPEN ) || !defined(HAVE_LINUX_MOUNT_H ) [TST_FD_IO_URING] = {.open_fd = open_io_uring, .desc = "io uring"}, [TST_FD_BPF_MAP] = {.open_fd = open_bpf_map, .desc = "bpf map"}, +#endif [TST_FD_FSOPEN] = {.open_fd = open_fsopen, .desc = "fsopen"}, [TST_FD_FSPICK] = {.open_fd = open_fspick, .desc = "fspick"}, [TST_FD_OPEN_TREE] = {.open_fd = open_open_tree, .desc = "open_tree"},
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 1/4] lib: Add tst_fd iterator
Hi!
Quoted 5 lines
In file included from
../include/lapi/io_uring.h:17:0,from tst_fd.c:21:
/usr/include/sys/mount.h:35:3: error: expected identifier before numeric constant
MS_RDONLY= 1, /* Mount read-only. */
^
Looks like the best solution for now is:
include/lapi/io_uring.h +0 -1
@@ -14,7 +14,6 @@#include <sys/types.h> #include <sys/uio.h> #include <stdlib.h> -#include <linux/fs.h> #include "lapi/syscalls.h"
As far as I can tell the only reason this header is included is the __kernel_rwf_t definition which has a fallback definition just a few lines below.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 1/4] lib: Add tst_fd iterator
Quoted 22 lines
Hi!
Quoted 5 lines
In file included from
../include/lapi/io_uring.h:17:0,from tst_fd.c:21:
/usr/include/sys/mount.h:35:3: error: expected identifier before numeric constant
MS_RDONLY= 1, /* Mount read-only. */
^Looks like the best solution for now is:
include/lapi/io_uring.h +0
-1@@ -14,7 +14,6 @@#include <sys/types.h> #include <sys/uio.h> #include <stdlib.h> -#include <linux/fs.h> #include "lapi/syscalls.h"
Quoted 3 lines
As far as I can tell the only reason this header is included is the
__kernel_rwf_tdefinition which has a fallback definition just a few lines below.
Great!
Feel free to merge with my ack before the patchset + whole patchset.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3 1/4] lib: Add tst_fd iterator
Hi!
Thanks everyone for the reviews, pushed.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 2/4 syscalls: readahead01: Make use of tst_fd
In reply to Cyril Hrubis--- .../kernel/syscalls/readahead/readahead01.c | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-)
testcases/kernel/syscalls/readahead/readahead01.c +27 -25
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2012 Linux Test Project, Inc. +* Copyright (C) 2023-2024 Cyril Hrubis <[email protected]> */ /*\
@@ -30,43 +31,44 @@static void test_bad_fd (void ) { -char tempname[PATH_MAX ] ="readahead01_XXXXXX" ; -int fd; +int fd[2 ]; + +TST_EXP_FAIL (readahead (-1 ,0 ,getpagesize ()),EBADF , +"readahead() with fd = -1" ); -tst_res (TINFO ,"%s -1" , __func__); -TST_EXP_FAIL (readahead (-1 ,0 ,getpagesize ()),EBADF ); +SAFE_PIPE (fd); +SAFE_CLOSE (fd[0 ]); +SAFE_CLOSE (fd[1 ]); -tst_res (TINFO ,"%s O_WRONLY" , __func__); - fd =mkstemp (tempname); -if (fd ==-1 ) -tst_res (TFAIL |TERRNO ,"mkstemp failed" ); -SAFE_CLOSE (fd); - fd =SAFE_OPEN (tempname,O_WRONLY ); -TST_EXP_FAIL (readahead (fd,0 ,getpagesize ()),EBADF ); -SAFE_CLOSE (fd); -unlink (tempname); +TST_EXP_FAIL (readahead (fd[0 ],0 ,getpagesize ()),EBADF , +"readahead() with invalid fd" ); } -static void test_invalid_fd (void ) +static void test_invalid_fd (struct tst_fd *fd) { -int fd[2 ]; -tst_res (TINFO ,"%s pipe" , __func__); -SAFE_PIPE (fd); -TST_EXP_FAIL (readahead (fd[0 ],0 ,getpagesize ()),EINVAL ); -SAFE_CLOSE (fd[0 ]); -SAFE_CLOSE (fd[1 ]); +switch (fd->type) { +/* These succeed */ +case TST_FD_FILE : +case TST_FD_MEMFD : +case TST_FD_PROC_MAPS : +return ; +default : +break ; + } -tst_res (TINFO ,"%s socket" , __func__); - fd[0 ] =SAFE_SOCKET (AF_INET ,SOCK_STREAM ,0 ); -TST_EXP_FAIL (readahead (fd[0 ],0 ,getpagesize ()),EINVAL ); -SAFE_CLOSE (fd[0 ]); +int exp_errnos[] = {EBADF ,EINVAL ,ESPIPE }; + +TST_EXP_FAIL_ARR (readahead (fd->fd,0 ,getpagesize ()), exp_errnos, +"readahead() on %s" ,tst_fd_desc (fd)); }static void test_readahead (void ) {test_bad_fd (); -test_invalid_fd (); + +TST_FD_FOREACH (fd) + test_invalid_fd(&fd); }static void setup (void )
Signature · 1 line
2.43.0
Re: [LTP] [PATCH v3 2/4] syscalls: readahead01: Make use of tst_fd
Re: [PATCH v3 2/4] syscalls: readahead01: Make use of tst_fd
In reply to Cyril HrubisQuoted 2 lines · Cyril Hrubis
Signed-off-by Cyril Hrubis <[email protected]>Reviewed-by Richard Palethorpe <[email protected]>
Looks good to me. Feel free to add:
Honza
Quoted 89 lines
--- .../kernel/syscalls/readahead/readahead01.c | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-)testcases/kernel/syscalls/readahead/readahead01.c +27
-25@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2012 Linux Test Project, Inc. +* Copyright (C) 2023-2024 Cyril Hrubis <[email protected]> */ /*\ @@ -30,43 +31,44 @@static void test_bad_fd (void ) { -char tempname[PATH_MAX ] ="readahead01_XXXXXX" ; -int fd; +int fd[2 ]; + +TST_EXP_FAIL (readahead (-1 ,0 ,getpagesize ()),EBADF , +"readahead() with fd = -1" ); -tst_res (TINFO ,"%s -1" , __func__); -TST_EXP_FAIL (readahead (-1 ,0 ,getpagesize ()),EBADF ); +SAFE_PIPE (fd); +SAFE_CLOSE (fd[0 ]); +SAFE_CLOSE (fd[1 ]); -tst_res (TINFO ,"%s O_WRONLY" , __func__); - fd =mkstemp (tempname); -if (fd ==-1 ) -tst_res (TFAIL |TERRNO ,"mkstemp failed" ); -SAFE_CLOSE (fd); - fd =SAFE_OPEN (tempname,O_WRONLY ); -TST_EXP_FAIL (readahead (fd,0 ,getpagesize ()),EBADF ); -SAFE_CLOSE (fd); -unlink (tempname); +TST_EXP_FAIL (readahead (fd[0 ],0 ,getpagesize ()),EBADF , +"readahead() with invalid fd" ); } -static void test_invalid_fd (void ) +static void test_invalid_fd (struct tst_fd *fd) { -int fd[2 ]; -tst_res (TINFO ,"%s pipe" , __func__); -SAFE_PIPE (fd); -TST_EXP_FAIL (readahead (fd[0 ],0 ,getpagesize ()),EINVAL ); -SAFE_CLOSE (fd[0 ]); -SAFE_CLOSE (fd[1 ]); +switch (fd->type) { +/* These succeed */ +case TST_FD_FILE : +case TST_FD_MEMFD : +case TST_FD_PROC_MAPS : +return ; +default : +break ; + } -tst_res (TINFO ,"%s socket" , __func__); - fd[0 ] =SAFE_SOCKET (AF_INET ,SOCK_STREAM ,0 ); -TST_EXP_FAIL (readahead (fd[0 ],0 ,getpagesize ()),EINVAL ); -SAFE_CLOSE (fd[0 ]); +int exp_errnos[] = {EBADF ,EINVAL ,ESPIPE }; + +TST_EXP_FAIL_ARR (readahead (fd->fd,0 ,getpagesize ()), exp_errnos, +"readahead() on %s" ,tst_fd_desc (fd)); }static void test_readahead (void ) {test_bad_fd (); -test_invalid_fd (); + +TST_FD_FOREACH (fd) + test_invalid_fd(&fd); }static void setup (void )Signature · 1 line
2.43.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v3 3/4 syscalls: accept: Add tst_fd test
In reply to Cyril Hrubis--- runtest/syscalls | 1 + testcases/kernel/syscalls/accept/.gitignore | 1 + testcases/kernel/syscalls/accept/accept01.c | 8 --- testcases/kernel/syscalls/accept/accept03.c | 60 +++++++++++++++++++++ 4 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 testcases/kernel/syscalls/accept/accept03.c
runtest/syscalls +1 -0
@@ -3,6 +3,7 @@ abort01 abort01 accept01 accept01 accept02 accept02 +accept03 accept03 accept4_01 accept4_01
testcases/kernel/syscalls/accept/.gitignore +1 -0
@@ -1,2 +1,3 @@ /accept01 /accept02 +/accept03
testcases/kernel/syscalls/accept/accept01.c +0 -8
@@ -26,7 +26,6 @@struct sockaddr_in sin0, sin1, fsin1;int invalid_socketfd =400 ;/* anything that is not an open file */ -int devnull_fd;int socket_fd;int udp_fd;
@@ -45,10 +44,6 @@ static struct test_case { (struct sockaddr *)&fsin1,sizeof (fsin1),EBADF ,"bad file descriptor" }, - { -PF_INET ,SOCK_STREAM ,0 , &devnull_fd, (struct sockaddr *)&fsin1, -sizeof (fsin1),ENOTSOCK ,"fd is not socket" - }, {PF_INET ,SOCK_STREAM ,0 , &socket_fd, (struct sockaddr *)3 ,sizeof (fsin1),EINVAL ,"invalid socket buffer"
@@ -73,8 +68,6 @@ static void test_setup(void) sin0.sin_port =0 ; sin0.sin_addr.s_addr =INADDR_ANY ; - devnull_fd =SAFE_OPEN ("/dev/null" ,O_WRONLY ); - socket_fd =SAFE_SOCKET (PF_INET ,SOCK_STREAM ,0 );SAFE_BIND (socket_fd, (struct sockaddr *)&sin0,sizeof (sin0));
@@ -88,7 +81,6 @@ static void test_setup(void)static void test_cleanup (void ) { -SAFE_CLOSE (devnull_fd);SAFE_CLOSE (socket_fd);SAFE_CLOSE (udp_fd); }
testcases/kernel/syscalls/accept/accept03.c new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [LTP] [PATCH v3 3/4] syscalls: accept: Add tst_fd test
Re: [PATCH v3 3/4] syscalls: accept: Add tst_fd test
In reply to Cyril HrubisQuoted 2 lines · Cyril Hrubis
Signed-off-by Cyril Hrubis <[email protected]>Reviewed-by Richard Palethorpe <[email protected]>
Makes sense to me. Feel free to add:
Honza
Quoted 137 lines
--- runtest/syscalls | 1 + testcases/kernel/syscalls/accept/.gitignore | 1 + testcases/kernel/syscalls/accept/accept01.c | 8 --- testcases/kernel/syscalls/accept/accept03.c | 60 +++++++++++++++++++++ 4 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 testcases/kernel/syscalls/accept/accept03.cruntest/syscalls +1
-0@@ -3,6 +3,7 @@ abort01 abort01 accept01 accept01 accept02 accept02 +accept03 accept03 accept4_01 accept4_01testcases/kernel/syscalls/accept/.gitignore +1
-0@@ -1,2 +1,3 @@ /accept01 /accept02 +/accept03testcases/kernel/syscalls/accept/accept01.c +0
-8@@ -26,7 +26,6 @@struct sockaddr_in sin0, sin1, fsin1;int invalid_socketfd =400 ;/* anything that is not an open file */ -int devnull_fd;int socket_fd;int udp_fd;@@ -45,10 +44,6 @@ static struct test_case { (struct sockaddr *)&fsin1,sizeof (fsin1),EBADF ,"bad file descriptor" }, - { -PF_INET ,SOCK_STREAM ,0 , &devnull_fd, (struct sockaddr *)&fsin1, -sizeof (fsin1),ENOTSOCK ,"fd is not socket" - }, {PF_INET ,SOCK_STREAM ,0 , &socket_fd, (struct sockaddr *)3 ,sizeof (fsin1),EINVAL ,"invalid socket buffer" @@ -73,8 +68,6 @@ static void test_setup(void) sin0.sin_port =0 ; sin0.sin_addr.s_addr =INADDR_ANY ; - devnull_fd =SAFE_OPEN ("/dev/null" ,O_WRONLY ); - socket_fd =SAFE_SOCKET (PF_INET ,SOCK_STREAM ,0 );SAFE_BIND (socket_fd, (struct sockaddr *)&sin0,sizeof (sin0));@@ -88,7 +81,6 @@ static void test_setup(void)static void test_cleanup (void ) { -SAFE_CLOSE (devnull_fd);SAFE_CLOSE (socket_fd);SAFE_CLOSE (udp_fd); }testcases/kernel/syscalls/accept/accept03.c new file +60
-0@@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +/* +* Copyright (C) 2023-2024 Cyril Hrubis <[email protected]> +*/ + +/*\ +* [Description] +* +* Verify that accept() returns ENOTSOCK or EBADF for non-socket file +* descriptors. The EBADF is returned in the case that the file descriptor has +* not a file associated with it, which is for example in the case of O_PATH +* opened file. +*/ + +#include <sys/socket.h> +#include <netinet/in.h> + +#include "tst_test.h" + +void check_accept (struct tst_fd *fd) +{ +struct sockaddr_in addr = { + .sin_family =AF_INET , + .sin_port =0 , + .sin_addr = {.s_addr =INADDR_ANY }, + }; + +socklen_t size =sizeof (addr); + +int exp_errno =ENOTSOCK ; + +switch (fd->type) { +case TST_FD_UNIX_SOCK : +case TST_FD_INET_SOCK : +return ; +/* +* With these two we fail even before we get to the do_accept() because +* the fd does not have a struct file associated. +*/ +case TST_FD_OPEN_TREE : +case TST_FD_PATH : + exp_errno =EBADF ; +default : +break ; + } + +TST_EXP_FAIL2 (accept (fd->fd, (void *)&addr, &size), + exp_errno,"accept() on %s" ,tst_fd_desc (fd)); +} + +static void verify_accept (void ) +{ +TST_FD_FOREACH (fd) + check_accept(&fd); +} + +static struct tst_test test = { + .test_all = verify_accept, +};Signature · 1 line
2.43.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v3 4/4 syscalls: splice07: New splice tst_fd iterator test
In reply to Cyril HrubisWe loop over all possible combinations of file descriptors in the test and filter out combinations that actually make sense and either block or attempt to copy data.
The rest of invalid options produce either EINVAL or EBADF.
--- runtest/syscalls | 1 + testcases/kernel/syscalls/splice/.gitignore | 1 + testcases/kernel/syscalls/splice/splice07.c | 70 +++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 testcases/kernel/syscalls/splice/splice07.c
runtest/syscalls +1 -0
@@ -1516,6 +1516,7 @@ splice03 splice03 splice04 splice04 splice05 splice05 splice06 splice06 +splice07 splice07 tee01 tee01 tee02 tee02
testcases/kernel/syscalls/splice/.gitignore +1 -0
@@ -4,3 +4,4 @@ /splice04 /splice05 /splice06 +/splice07
testcases/kernel/syscalls/splice/splice07.c new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v3 4/4] syscalls: splice07: New splice tst_fd iterator test
Quoted 9 lines · Cyril Hrubis
We loop over all possible combinations of file descriptors in the test and filter out combinations that actually make sense and either block or attempt to copy data.
The rest of invalid options produce either EINVAL or EBADF.
Signed-off-by Cyril Hrubis <[email protected]>Reviewed-by Richard Palethorpe <[email protected]>Reviewed-by Petr Vorel <[email protected]>
Looks good to me. Feel free to add:
Honza
Quoted 107 lines
--- runtest/syscalls | 1 + testcases/kernel/syscalls/splice/.gitignore | 1 + testcases/kernel/syscalls/splice/splice07.c | 70 +++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 testcases/kernel/syscalls/splice/splice07.cruntest/syscalls +1
-0@@ -1516,6 +1516,7 @@ splice03 splice03 splice04 splice04 splice05 splice05 splice06 splice06 +splice07 splice07 tee01 tee01 tee02 tee02testcases/kernel/syscalls/splice/.gitignore +1
-0@@ -4,3 +4,4 @@ /splice04 /splice05 /splice06 +/splice07testcases/kernel/syscalls/splice/splice07.c new file +70
-0@@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +/* +* Copyright (C) 2023-2024 Cyril Hrubis <[email protected]> +*/ + +/*\ +* [Description] +* +* Iterate over all kinds of file descriptors and feed splice() with all possible +* combinations where at least one file descriptor is invalid. We do expect the +* syscall to fail either with EINVAL or EBADF. +*/ + +#define _GNU_SOURCE + +#include <sys/socket.h> +#include <netinet/in.h> + +#include "tst_test.h" + +static void check_splice (struct tst_fd *fd_in,struct tst_fd *fd_out) +{ +/* These combinations just hang since the pipe is empty */ +if (fd_in->type ==TST_FD_PIPE_READ ) { +switch (fd_out->type) { +case TST_FD_FILE : +case TST_FD_PIPE_WRITE : +case TST_FD_UNIX_SOCK : +case TST_FD_INET_SOCK : +case TST_FD_MEMFD : +return ; +default : +break ; + } + } + +if (fd_out->type ==TST_FD_PIPE_WRITE ) { +switch (fd_in->type) { +/* While these combinations succeeed */ +case TST_FD_FILE : +case TST_FD_MEMFD : +return ; +/* And this complains about socket not being connected */ +case TST_FD_INET_SOCK : +return ; +default : +break ; + } + } + +const int exp_errnos[] = {EBADF ,EINVAL }; + +TST_EXP_FAIL2_ARR (splice (fd_in->fd,NULL , fd_out->fd,NULL ,1 ,0 ), + exp_errnos,"splice() on %s -> %s" , +tst_fd_desc (fd_in),tst_fd_desc (fd_out)); +} + +static void verify_splice (void ) +{ +TST_FD_FOREACH (fd_in) { +tst_res (TINFO ,"%s -> ..." ,tst_fd_desc (&fd_in)); + TST_FD_FOREACH(fd_out) + check_splice(&fd_in, &fd_out); + } +} + +static struct tst_test test = { + .test_all = verify_splice, +};Signature · 1 line
2.43.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR