[LTP] [PATCH v2 3/8] Add ioctl_pidfd01 test
Andrea Cervesato
andrea.cervesato@suse.de
Fri Jul 4 13:30:41 CEST 2025
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that ioctl() raises the right errors when an application provides
the wrong file descriptor.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 2 +
testcases/kernel/syscalls/ioctl/.gitignore | 1 +
testcases/kernel/syscalls/ioctl/ioctl_pidfd01.c | 58 +++++++++++++++++++++++++
3 files changed, 61 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 582422ac9ca8ccae598c626a11cf6ee7c30f0e3a..7f6312ce5fa241a778d8dda7f8ee9edd0a8800e6 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -612,6 +612,8 @@ ioctl_ficlonerange01 ioctl_ficlonerange01
ioctl_ficlonerange02 ioctl_ficlonerange02
ioctl_fiemap01 ioctl_fiemap01
+ioctl_pidfd01 ioctl_pidfd01
+
inotify_init1_01 inotify_init1_01
inotify_init1_02 inotify_init1_02
diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore
index 53a82bb5770ba196811965150fd262ec5d4a6e01..aa952c1a7bae0ae2dbb04de0595f10d508b6759a 100644
--- a/testcases/kernel/syscalls/ioctl/.gitignore
+++ b/testcases/kernel/syscalls/ioctl/.gitignore
@@ -29,3 +29,4 @@
/ioctl_ficlonerange01
/ioctl_ficlonerange02
/ioctl_fiemap01
+/ioctl_pidfd01
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd01.c b/testcases/kernel/syscalls/ioctl/ioctl_pidfd01.c
new file mode 100644
index 0000000000000000000000000000000000000000..dbece2b611ecea2e253bd5e784b196f4e0ee73f2
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd01.c
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Verify that ioctl() raises the right errors when an application provides
+ * the wrong file descriptor.
+ */
+
+#include "tst_test.h"
+#include "lapi/pidfd.h"
+#include "lapi/ioctl.h"
+
+static int exp_errnos[] = {
+ EINVAL,
+ EBADF,
+ ENOTTY,
+};
+
+static struct pidfd_info *info;
+
+static void test_bad_pidfd(struct tst_fd *fd_in)
+{
+ if (fd_in->type == TST_FD_PIDFD) {
+ tst_res(TINFO, "Skipping pidfd: SUCCESS");
+ return;
+ }
+
+ TST_EXP_FAIL_ARR(ioctl(fd_in->fd, PIDFD_GET_INFO, info),
+ exp_errnos, ARRAY_SIZE(exp_errnos),
+ "ioctl(%s, PIDFD_GET_INFO, info)",
+ tst_fd_desc(fd_in));
+}
+
+static void run(void)
+{
+ TST_FD_FOREACH(fd) {
+ tst_res(TINFO, "%s -> ...", tst_fd_desc(&fd));
+ test_bad_pidfd(&fd);
+ }
+}
+
+static void setup(void)
+{
+ info->mask = PIDFD_INFO_EXIT;
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .forks_child = 1,
+ .min_kver = "6.15",
+ .bufs = (struct tst_buffers []) {
+ {&info, .size = sizeof(*info)},
+ {}
+ }
+};
--
2.50.0
More information about the ltp
mailing list