[LTP] [PATCH v2 7/7] Add ioctl_ficlone04 test
Andrea Cervesato
andrea.cervesato@suse.de
Tue Jul 23 09:15:07 CEST 2024
From: Andrea Cervesato <andrea.cervesato@suse.com>
This test verifies that ioctl() FICLONE/FICLONERANGE feature raises
the right error according with bad file descriptors.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/syscalls/ioctl/.gitignore | 1 +
testcases/kernel/syscalls/ioctl/ioctl_ficlone04.c | 108 ++++++++++++++++++++++
2 files changed, 109 insertions(+)
diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore
index 9f995b1ad..1f099ff95 100644
--- a/testcases/kernel/syscalls/ioctl/.gitignore
+++ b/testcases/kernel/syscalls/ioctl/.gitignore
@@ -25,5 +25,6 @@
/ioctl_ficlone01
/ioctl_ficlone02
/ioctl_ficlone03
+/ioctl_ficlone04
/ioctl_ficlonerange01
/ioctl_ficlonerange02
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_ficlone04.c b/testcases/kernel/syscalls/ioctl/ioctl_ficlone04.c
new file mode 100644
index 000000000..6be0b8d41
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl_ficlone04.c
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 Andrea Cervesato andrea.cervesato@suse.com
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies that ioctl() FICLONE/FICLONERANGE feature raises the right
+ * error according with bad file descriptors.
+ */
+
+#include "tst_test.h"
+#include "lapi/fs.h"
+
+static void test_bad_fd(struct tst_fd *fd_src, struct tst_fd *fd_dst)
+{
+ if (fd_src->type == TST_FD_FILE && fd_src->type == fd_dst->type) {
+ tst_res(TCONF, "Skipping file: SUCCESS");
+ return;
+ }
+
+ switch (fd_src->type) {
+ case TST_FD_DEV_ZERO:
+ case TST_FD_PROC_MAPS:
+ case TST_FD_PIPE_READ:
+ case TST_FD_PIPE_WRITE:
+ case TST_FD_UNIX_SOCK:
+ case TST_FD_INET_SOCK:
+ case TST_FD_EPOLL:
+ case TST_FD_EVENTFD:
+ case TST_FD_SIGNALFD:
+ case TST_FD_TIMERFD:
+ case TST_FD_PIDFD:
+ case TST_FD_FANOTIFY:
+ case TST_FD_INOTIFY:
+ case TST_FD_USERFAULTFD:
+ case TST_FD_PERF_EVENT:
+ case TST_FD_IO_URING:
+ case TST_FD_BPF_MAP:
+ case TST_FD_FSOPEN:
+ case TST_FD_FSPICK:
+ case TST_FD_OPEN_TREE:
+ case TST_FD_MEMFD:
+ case TST_FD_MEMFD_SECRET:
+ return;
+ default:
+ break;
+ }
+
+ int exp_errnos[2];
+
+ switch (fd_src->type) {
+ case TST_FD_FILE:
+ exp_errnos[0] = 0;
+ break;
+ case TST_FD_DIR:
+ exp_errnos[0] = EISDIR;
+ break;
+ case TST_FD_PATH:
+ case TST_FD_OPEN_TREE:
+ exp_errnos[0] = EBADF;
+ break;
+ case TST_FD_DEV_ZERO:
+ exp_errnos[0] = EXDEV;
+ break;
+ default:
+ exp_errnos[0] = EINVAL;
+ break;
+ }
+
+ switch (fd_dst->type) {
+ case TST_FD_FILE:
+ exp_errnos[1] = 0;
+ break;
+ case TST_FD_DIR:
+ exp_errnos[1] = EISDIR;
+ break;
+ case TST_FD_PATH:
+ case TST_FD_OPEN_TREE:
+ exp_errnos[1] = EBADF;
+ break;
+ default:
+ exp_errnos[1] = EXDEV;
+ break;
+ }
+
+ TST_EXP_FAIL2_ARR(ioctl(fd_dst->fd, FICLONE, fd_src->fd),
+ exp_errnos, ARRAY_SIZE(exp_errnos),
+ "ioctl(%s, FICLONE, %s)",
+ tst_fd_desc(fd_src),
+ tst_fd_desc(fd_dst));
+}
+
+static void run(void)
+{
+ TST_FD_FOREACH(fd_src) {
+ TST_FD_FOREACH(fd_dst)
+ test_bad_fd(&fd_src, &fd_dst);
+ }
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .min_kver = "4.5",
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+};
--
2.43.0
More information about the ltp
mailing list