public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Andrea Cervesato <andrea.cervesato@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 03/10] setxattr01: add setxattrat variant
Date: Tue, 07 Oct 2025 08:46:55 +0200	[thread overview]
Message-ID: <20251007-xattrat-v2-3-bf458fa66358@suse.com> (raw)
In-Reply-To: <20251007-xattrat-v2-0-bf458fa66358@suse.com>

From: Andrea Cervesato <andrea.cervesato@suse.com>

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 testcases/kernel/syscalls/setxattr/setxattr01.c | 61 +++++++++++++++++++------
 1 file changed, 47 insertions(+), 14 deletions(-)

diff --git a/testcases/kernel/syscalls/setxattr/setxattr01.c b/testcases/kernel/syscalls/setxattr/setxattr01.c
index a405bf42e..ade405f37 100644
--- a/testcases/kernel/syscalls/setxattr/setxattr01.c
+++ b/testcases/kernel/syscalls/setxattr/setxattr01.c
@@ -20,6 +20,10 @@
  */
 
 #include "config.h"
+#include "tst_test.h"
+
+#ifdef HAVE_SYS_XATTR_H
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
@@ -30,12 +34,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifdef HAVE_SYS_XATTR_H
-# include <sys/xattr.h>
-#endif
-#include "tst_test.h"
+#include "lapi/xattr.h"
+#include <sys/xattr.h>
 
-#ifdef HAVE_SYS_XATTR_H
 #define XATTR_NAME_MAX 255
 #define XATTR_NAME_LEN (XATTR_NAME_MAX + 2)
 #define XATTR_SIZE_MAX 65536
@@ -43,11 +44,13 @@
 #define XATTR_TEST_VALUE "this is a test value"
 #define XATTR_TEST_VALUE_SIZE 20
 #define MNTPOINT "mntpoint"
-#define FNAME MNTPOINT"/setxattr01testfile"
+#define FNAME_REL "setxattr01testfile"
+#define FNAME MNTPOINT"/"FNAME_REL
 
 static char long_key[XATTR_NAME_LEN];
 static char *long_value;
 static char *xattr_value = XATTR_TEST_VALUE;
+static int mnt_fd = -1;
 
 struct test_case {
 	char *key;
@@ -126,44 +129,64 @@ struct test_case tc[] = {
 
 static void verify_setxattr(unsigned int i)
 {
+	char *sysname;
+
 	/* some tests might require existing keys for each iteration */
 	if (tc[i].keyneeded) {
 		SAFE_SETXATTR(FNAME, tc[i].key, *tc[i].value, tc[i].size,
 				XATTR_CREATE);
 	}
 
-	TEST(setxattr(FNAME, tc[i].key, *tc[i].value, tc[i].size, tc[i].flags));
+	if (tst_variant) {
+		sysname = "setxattrat";
+
+		struct xattr_args args = {
+			.value = (uint64_t)tc[i].value,
+			.size = tc[i].size,
+			.flags = tc[i].flags,
+		};
+
+		TEST(setxattrat(mnt_fd, FNAME_REL, AT_SYMLINK_NOFOLLOW,
+			tc[i].key, &args, sizeof(args)));
+	} else {
+		sysname = "setxattr";
+
+		TEST(setxattr(
+			FNAME,
+			tc[i].key, *tc[i].value, tc[i].size,
+			tc[i].flags));
+	}
 
 	if (TST_RET == -1 && TST_ERR == EOPNOTSUPP)
-		tst_brk(TCONF, "setxattr(2) not supported");
+		tst_brk(TCONF, "%s(2) not supported", sysname);
 
 	/* success */
 
 	if (!tc[i].exp_err) {
 		if (TST_RET) {
 			tst_res(TFAIL | TTERRNO,
-				"setxattr(2) failed with %li", TST_RET);
+				"%s(2) failed with %li", sysname, TST_RET);
 			return;
 		}
 
 		/* this is needed for subsequent iterations */
 		SAFE_REMOVEXATTR(FNAME, tc[i].key);
 
-		tst_res(TPASS, "setxattr(2) passed");
+		tst_res(TPASS, "%s(2) passed", sysname);
 
 		return;
 	}
 
 	if (TST_RET == 0) {
-		tst_res(TFAIL, "setxattr(2) passed unexpectedly");
+		tst_res(TFAIL, "%s(2) passed unexpectedly", sysname);
 		return;
 	}
 
 	/* error */
 
 	if (tc[i].exp_err != TST_ERR) {
-		tst_res(TFAIL | TTERRNO, "setxattr(2) should fail with %s",
-			tst_strerrno(tc[i].exp_err));
+		tst_res(TFAIL | TTERRNO, "%s(2) should fail with %s",
+			sysname, tst_strerrno(tc[i].exp_err));
 		return;
 	}
 
@@ -171,7 +194,7 @@ static void verify_setxattr(unsigned int i)
 	if (tc[i].keyneeded)
 		SAFE_REMOVEXATTR(FNAME, tc[i].key);
 
-	tst_res(TPASS | TTERRNO, "setxattr(2) failed");
+	tst_res(TPASS | TTERRNO, "%s(2) failed", sysname);
 }
 
 static void setup(void)
@@ -192,12 +215,22 @@ static void setup(void)
 		if (!tc[i].key)
 			tc[i].key = tst_get_bad_addr(NULL);
 	}
+
+	mnt_fd = SAFE_OPEN(MNTPOINT, O_DIRECTORY);
+}
+
+static void cleanup(void)
+{
+	if (mnt_fd != -1)
+		SAFE_CLOSE(mnt_fd);
 }
 
 static struct tst_test test = {
 	.setup = setup,
+	.cleanup = cleanup,
 	.test = verify_setxattr,
 	.tcnt = ARRAY_SIZE(tc),
+	.test_variants = 2,
 	.mntpoint = MNTPOINT,
 	.mount_device = 1,
 	.all_filesystems = 1,

-- 
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2025-10-07  6:49 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-07  6:46 [LTP] [PATCH v2 00/10] setxattrat coverage Andrea Cervesato
2025-10-07  6:46 ` [LTP] [PATCH v2 01/10] lapi: add struct xattr_args fallback Andrea Cervesato
2025-10-07 11:50   ` Cyril Hrubis
2025-10-07  6:46 ` [LTP] [PATCH v2 02/10] lapi: add setxattrat() fallback definition Andrea Cervesato
2025-10-07 12:05   ` Cyril Hrubis
2025-10-07 15:16   ` Cyril Hrubis
2025-10-07  6:46 ` Andrea Cervesato [this message]
2025-10-07 12:29   ` [LTP] [PATCH v2 03/10] setxattr01: add setxattrat variant Cyril Hrubis
2025-10-07 13:16     ` Andrea Cervesato via ltp
2025-10-07 14:35       ` Cyril Hrubis
2025-10-08 10:40         ` Andrea Cervesato via ltp
2025-10-08 12:16           ` Cyril Hrubis
2025-10-07  6:46 ` [LTP] [PATCH v2 04/10] setxattr02: " Andrea Cervesato
2025-10-07 12:40   ` Cyril Hrubis
2025-10-07  6:46 ` [LTP] [PATCH v2 05/10] setxattr03: " Andrea Cervesato
2025-10-07 15:11   ` Cyril Hrubis
2025-10-07  6:46 ` [LTP] [PATCH v2 06/10] lapi: add getxattrat() fallback Andrea Cervesato
2025-10-07 15:21   ` Cyril Hrubis
2025-10-07  6:46 ` [LTP] [PATCH v2 07/10] lapi: add removexattrat() fallback Andrea Cervesato
2025-10-07 15:26   ` Cyril Hrubis
2025-10-07  6:47 ` [LTP] [PATCH v2 08/10] lapi: add safe *xattrat macros Andrea Cervesato
2025-10-08  9:36   ` Cyril Hrubis
2025-10-07  6:47 ` [LTP] [PATCH v2 09/10] Add setxattrat01 test Andrea Cervesato
2025-10-08  9:44   ` Cyril Hrubis
2025-10-13  7:54     ` Andrea Cervesato via ltp
2025-10-07  6:47 ` [LTP] [PATCH v2 10/10] Add setxattrat02 test Andrea Cervesato
2025-10-08 10:02   ` Cyril Hrubis
2025-10-10 11:05     ` Andrea Cervesato via ltp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251007-xattrat-v2-3-bf458fa66358@suse.com \
    --to=andrea.cervesato@suse.de \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox