public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 3/8] setxattr01: add setxattrat variant
Date: Thu, 6 Mar 2025 13:46:10 +0100	[thread overview]
Message-ID: <Z8mZEusCgpf6JTKz@yuki.lan> (raw)
In-Reply-To: <20250127-xattrat-v1-3-c3ee31e2543b@suse.com>

Hi!
> diff --git a/testcases/kernel/syscalls/setxattr/setxattr01.c b/testcases/kernel/syscalls/setxattr/setxattr01.c
> index de3ea67ec4000905651f20e2684a6b0aef493da7..67b053c4a2593df6cd2800c5450b5951ff78ae0d 100644
> --- a/testcases/kernel/syscalls/setxattr/setxattr01.c
> +++ b/testcases/kernel/syscalls/setxattr/setxattr01.c
> @@ -36,6 +36,8 @@
>  # include <sys/xattr.h>
>  #endif
>  #include "tst_test.h"
> +#include "lapi/syscalls.h"
> +#include "lapi/xattr.h"
>  
>  #ifdef HAVE_SYS_XATTR_H
>  #define XATTR_NAME_MAX 255
> @@ -45,11 +47,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;
> @@ -128,44 +132,65 @@ 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 = tc[i].value,
> +			.size = tc[i].size,
> +			.flags = tc[i].flags,
> +		};
> +
> +		TEST(tst_syscall(__NR_setxattrat,
> +			mnt_fd, FNAME_REL, AT_SYMLINK_NOFOLLOW,
> +			tc[i].key, &args, sizeof(args)));

The setxattrat() function should be put into the lapi/setxattr.h and
enabled only if configure script didn't find setxattrat() in the
sys/setxattr.h. That way we will switch to the system definition of the
function once it's available.

Any time we are adding tests for syscalls that are not in the libc now
but will end up there in the future we have to do this:

* Add AC_CHECK_FUNC() into configure
* Add syscall wrapper inside ifndef HAVE_FUNC block into respective lapi header
* Include the lapi header in the test
* Call the function as func() and not by tst_syscall(__NR_func, ...)

> +	} else {
> +		sysname = "setxattr";
> +
> +		TEST(setxattr(
> +			FNAME,
> +			tc[i].key, *tc[i].value, tc[i].size,
> +			tc[i].flags));
> +	}

This pattern repeats in several tests, so it would make more sense to
write a wrapper that would call the respective syscall based on
tst_variant and put it into a common header. i.e.

static inline int call_setxattr(const char *fname, const char *name,
                                const void *value, size_t line, int flags)
{
	if (tst_variant) {
		struct xattr_args args = {
			.value = tc[i].value,
			.size = tc[i].size,
			.flags = tc[i].flags,
		};

		return setxattrat(...);
	} else {
		return setxattr(...);
	}
}

>  	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;
>  	}
>  
> @@ -173,7 +198,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)
> @@ -194,12 +219,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.43.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

  reply	other threads:[~2025-03-06 12:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-27 14:08 [LTP] [PATCH 0/8] setxattrat coverage Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 1/8] syscalls: add *xattrat syscalls Andrea Cervesato
2025-01-31  9:09   ` Petr Vorel
2025-01-27 14:08 ` [LTP] [PATCH 2/8] lapi: add struct xattr_args fallback Andrea Cervesato
2025-01-31  8:36   ` Petr Vorel
2025-01-27 14:08 ` [LTP] [PATCH 3/8] setxattr01: add setxattrat variant Andrea Cervesato
2025-03-06 12:46   ` Cyril Hrubis [this message]
2025-01-27 14:08 ` [LTP] [PATCH 4/8] setxattr02: " Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 5/8] setxattr03: " Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 6/8] lapi: add safe *xattrat macros Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 7/8] Add setxattrat01 test Andrea Cervesato
2025-01-27 14:08 ` [LTP] [PATCH 8/8] Add setxattrat02 test Andrea Cervesato

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=Z8mZEusCgpf6JTKz@yuki.lan \
    --to=chrubis@suse.cz \
    --cc=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