[LTP] [PATCH v4 7/7] Add file_attr04 test

Andrea Cervesato andrea.cervesato@suse.de
Tue Aug 5 15:03:20 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 | 59 +++++++++++++++++++++++
 3 files changed, 61 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..5ca872d2ae6b2f2359c36dbc9a51395fa5369495
--- /dev/null
+++ b/testcases/kernel/syscalls/file_attr/file_attr04.c
@@ -0,0 +1,59 @@
+// 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 int exp_errnos[] = {
+	ENOENT,
+	ENOTDIR,
+};
+
+static void test_invalid_fd(struct tst_fd *fd)
+{
+	memset(attr, 0, sizeof(*attr));
+
+	if (tst_variant) {
+		TST_EXP_FAIL_ARR(file_getattr(
+			fd->fd, FILENAME,
+			attr, FILE_ATTR_SIZE_LATEST,
+			0), exp_errnos, ARRAY_SIZE(exp_errnos));
+	} else {
+		TST_EXP_FAIL_ARR(file_setattr(
+			fd->fd, FILENAME,
+			attr, FILE_ATTR_SIZE_LATEST,
+			0), exp_errnos, ARRAY_SIZE(exp_errnos));
+	}
+}
+
+static void run(void)
+{
+	TST_FD_FOREACH(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