Message ID | 20231016123320.9865-3-chrubis@suse.cz (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add tst_fd iterator API | expand |
Hello, Cyril Hrubis <chrubis@suse.cz> writes: > TODO: > - readahead() on /proc/self/maps seems to succeed > - readahead() on pipe write end, O_PATH file and open_tree() fd returns EBADFD > > Are these to be expected? > > Signed-off-by: Cyril Hrubis <chrubis@suse.cz> > --- > .../kernel/syscalls/readahead/readahead01.c | 54 ++++++++++--------- > 1 file changed, 29 insertions(+), 25 deletions(-) > > diff --git a/testcases/kernel/syscalls/readahead/readahead01.c b/testcases/kernel/syscalls/readahead/readahead01.c > index bdef7945d..6dd5086e5 100644 > --- a/testcases/kernel/syscalls/readahead/readahead01.c > +++ b/testcases/kernel/syscalls/readahead/readahead01.c > @@ -30,43 +30,47 @@ > > 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]); Would it make more sense to just close one of the ends? Or to open a file with write only? I wonder whether we still need test_bad_fd at all? Perhaps all the cases should be integrated into TST_FD_FOREACH? The rest looks good. > > - 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]; > + int exp_errno = EINVAL; > > - 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 two succeed */ > + case TST_FD_FILE: > + case TST_FD_MEMFD: > + return; > + case TST_FD_PIPE_WRITE: > + case TST_FD_OPEN_TREE: > + case TST_FD_PATH: > + exp_errno = EBADF; > + break; > + 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]); > + TST_EXP_FAIL(readahead(fd->fd, 0, getpagesize()), exp_errno, > + "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) > -- > 2.41.0
diff --git a/testcases/kernel/syscalls/readahead/readahead01.c b/testcases/kernel/syscalls/readahead/readahead01.c index bdef7945d..6dd5086e5 100644 --- a/testcases/kernel/syscalls/readahead/readahead01.c +++ b/testcases/kernel/syscalls/readahead/readahead01.c @@ -30,43 +30,47 @@ 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]; + int exp_errno = EINVAL; - 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 two succeed */ + case TST_FD_FILE: + case TST_FD_MEMFD: + return; + case TST_FD_PIPE_WRITE: + case TST_FD_OPEN_TREE: + case TST_FD_PATH: + exp_errno = EBADF; + break; + 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]); + TST_EXP_FAIL(readahead(fd->fd, 0, getpagesize()), exp_errno, + "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)
TODO: - readahead() on /proc/self/maps seems to succeed - readahead() on pipe write end, O_PATH file and open_tree() fd returns EBADFD Are these to be expected? Signed-off-by: Cyril Hrubis <chrubis@suse.cz> --- .../kernel/syscalls/readahead/readahead01.c | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-)