diff mbox series

[v2,05/10] setxattr03: add setxattrat variant

Message ID 20251007-xattrat-v2-5-bf458fa66358@suse.com
State Changes Requested
Delegated to: Andrea Cervesato
Headers show
Series setxattrat coverage | expand

Checks

Context Check Description
ltpci/debian_oldstable_gcc fail failure
ltpci/debian_stable_s390x-linux-gnu-gcc_s390x success success
ltpci/debian_stable_powerpc64le-linux-gnu-gcc_ppc64el success success
ltpci/debian_stable_aarch64-linux-gnu-gcc_arm64 success success
ltpci/ubuntu_jammy_gcc success success
ltpci/quay-io-centos-centos_stream9_gcc success success
ltpci/debian_stable_gcc success success
ltpci/ubuntu_bionic_gcc success success
ltpci/opensuse-leap_latest_gcc success success
ltpci/debian_testing_clang success success
ltpci/fedora_latest_clang success success
ltpci/alpine_latest_gcc success success
ltpci/debian_testing_gcc success success
ltpci/debian_oldstable_clang success success
ltpci/debian_stable_gcc success success
ltpci/opensuse-archive_42-2_gcc success success
ltpci/debian_oldstable_gcc success success

Commit Message

Andrea Cervesato Oct. 7, 2025, 6:46 a.m. UTC
From: Andrea Cervesato <andrea.cervesato@suse.com>

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 testcases/kernel/syscalls/setxattr/setxattr03.c | 35 +++++++++++++++++++------
 1 file changed, 27 insertions(+), 8 deletions(-)

Comments

Cyril Hrubis Oct. 7, 2025, 3:11 p.m. UTC | #1
Hi!
>  	if (!TST_RET) {
>  		tst_res(TFAIL, "%s succeeded unexpectedly", tc[i].desc);
> @@ -143,10 +156,15 @@ static void setup(void)
>  	if (set_append_on(append_fd))
>  		tst_brk(TBROK | TERRNO, "Set %s append-only failed",
>  			APPEND_FILE);
> +
> +	tmpdir_fd = SAFE_OPEN(tst_tmpdir_path(), O_DIRECTORY);

Here as well. Maybe we should use AT_FDCWD in one test and return value
from SAFE_OPEN(".", O_DIRECTORY) in the other, so that we test different
codepaths in the kernel.
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/setxattr/setxattr03.c b/testcases/kernel/syscalls/setxattr/setxattr03.c
index 0b5b48a55..2465edd69 100644
--- a/testcases/kernel/syscalls/setxattr/setxattr03.c
+++ b/testcases/kernel/syscalls/setxattr/setxattr03.c
@@ -12,7 +12,12 @@ 
  */
 
 #define _GNU_SOURCE
+
 #include "config.h"
+#include "tst_test.h"
+
+#ifdef HAVE_SYS_XATTR_H
+
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -24,14 +29,10 @@ 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifdef HAVE_SYS_XATTR_H
-# include <sys/xattr.h>
-#endif
 #include "lapi/fs.h"
+#include "lapi/xattr.h"
+#include <sys/xattr.h>
 
-#include "tst_test.h"
-
-#if defined HAVE_SYS_XATTR_H
 #define XATTR_TEST_KEY "user.testkey"
 #define XATTR_TEST_VALUE "this is a test value"
 #define XATTR_TEST_VALUE_SIZE (sizeof(XATTR_TEST_VALUE) - 1)
@@ -76,11 +77,23 @@  static struct test_case tc[] = {
 
 static int immu_fd;
 static int append_fd;
+static int tmpdir_fd = -1;
 
 static void verify_setxattr(unsigned int i)
 {
-	TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value, tc[i].size,
-			tc[i].flags));
+	if (tst_variant) {
+		struct xattr_args args = {
+			.value = (uint64_t)tc[i].value,
+			.size = tc[i].size,
+			.flags = tc[i].flags,
+		};
+
+		TEST(setxattrat(tmpdir_fd, tc[i].fname, AT_SYMLINK_NOFOLLOW,
+			tc[i].key, &args, sizeof(args)));
+	} else {
+		TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value, tc[i].size,
+				tc[i].flags));
+	}
 
 	if (!TST_RET) {
 		tst_res(TFAIL, "%s succeeded unexpectedly", tc[i].desc);
@@ -143,10 +156,15 @@  static void setup(void)
 	if (set_append_on(append_fd))
 		tst_brk(TBROK | TERRNO, "Set %s append-only failed",
 			APPEND_FILE);
+
+	tmpdir_fd = SAFE_OPEN(tst_tmpdir_path(), O_DIRECTORY);
 }
 
 static void cleanup(void)
 {
+	if (tmpdir_fd != -1)
+		SAFE_CLOSE(tmpdir_fd);
+
 	if ((immu_fd > 0) && set_immutable_off(immu_fd))
 		tst_res(TWARN | TERRNO, "Unset %s immutable failed",
 			 IMMU_FILE);
@@ -167,6 +185,7 @@  static struct tst_test test = {
 	.cleanup = cleanup,
 	.test = verify_setxattr,
 	.tcnt = ARRAY_SIZE(tc),
+	.test_variants = 2,
 	.needs_tmpdir = 1,
 	.needs_root = 1,
 };