[LTP] [PATCH v5 7/7] Add file_attr04 test
Andrea Cervesato
andrea.cervesato@suse.de
Tue Aug 5 19:44:46 CEST 2025
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that `file_getattr` and `file_setattr` are correctly raising
an error when the wrong file descriptors types are passed to them.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/file_attr/.gitignore | 1 +
testcases/kernel/syscalls/file_attr/file_attr04.c | 62 +++++++++++++++++++++++
3 files changed, 64 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index c33987328d3d6ec96660260aaee4f9ca8c4f0aee..c9b46b8efe3217150ee0740e982ea5a133b3aa46 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -249,6 +249,7 @@ fsetxattr02 fsetxattr02
file_attr01 file_attr01
file_attr02 file_attr02
file_attr03 file_attr03
+file_attr04 file_attr04
#posix_fadvise test cases
posix_fadvise01 posix_fadvise01
diff --git a/testcases/kernel/syscalls/file_attr/.gitignore b/testcases/kernel/syscalls/file_attr/.gitignore
index b79a340b733f7407dc135c5c3b0a9cd0e003e6c9..3fcb9004dd301ef4ee8cc1067c6a3763acb8d299 100644
--- a/testcases/kernel/syscalls/file_attr/.gitignore
+++ b/testcases/kernel/syscalls/file_attr/.gitignore
@@ -1,3 +1,4 @@
file_attr01
file_attr02
file_attr03
+file_attr04
diff --git a/testcases/kernel/syscalls/file_attr/file_attr04.c b/testcases/kernel/syscalls/file_attr/file_attr04.c
new file mode 100644
index 0000000000000000000000000000000000000000..364fad08e339e713d590b166136dc1c506daac0d
--- /dev/null
+++ b/testcases/kernel/syscalls/file_attr/file_attr04.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2025 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Verify that `file_getattr` and `file_setattr` are correctly raising an error
+ * when the wrong file descriptors types are passed to them.
+ */
+
+#include "tst_test.h"
+#include "lapi/fs.h"
+
+#define FILENAME "ltp_file"
+
+static struct file_attr *attr;
+
+static void test_invalid_fd(struct tst_fd *fd)
+{
+ if (fd->type == TST_FD_DIR || fd->type == TST_FD_OPEN_TREE) {
+ tst_res(TCONF, "Skipping DIR fd");
+ return;
+ }
+
+ memset(attr, 0, sizeof(*attr));
+
+ if (tst_variant) {
+ TST_EXP_FAIL(file_getattr(
+ fd->fd, FILENAME,
+ attr, FILE_ATTR_SIZE_LATEST,
+ 0), ENOTDIR);
+ } else {
+ TST_EXP_FAIL(file_setattr(
+ fd->fd, FILENAME,
+ attr, FILE_ATTR_SIZE_LATEST,
+ 0), ENOTDIR);
+ }
+}
+
+static void run(void)
+{
+ TST_FD_FOREACH(fd) {
+ tst_res(TINFO, "%s -> ...", tst_fd_desc(&fd));
+ test_invalid_fd(&fd);
+ }
+}
+
+static void setup(void)
+{
+ SAFE_TOUCH(FILENAME, 0640, NULL);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .test_variants = 2,
+ .needs_tmpdir = 1,
+ .bufs = (struct tst_buffers []) {
+ {&attr, .size = sizeof(struct file_attr)},
+ {}
+ }
+};
--
2.50.1
More information about the ltp
mailing list