[LTP] [PATCH v2 10/10] Add setxattrat02 test

Cyril Hrubis chrubis@suse.cz
Wed Oct 8 12:02:58 CEST 2025


Hi!
> +} tcases[] = {
> +	{
> +		.dfd = &invalid_fd,
> +		.args = &args,
> +		.args_size = sizeof(struct xattr_args),
> +		.exp_errno = EBADF,
> +		.reason = "Invalid directory file descriptor",
> +	},

Maybe it would make sense to use tst_fd to hammer the syscall with all
kinds of strange file descriptors.

> +	{
> +		.dfd = &tmpdir_fd,
> +		.at_flags = -1,
> +		.args = &args,
> +		.args_size = sizeof(struct xattr_args),
> +		.exp_errno = EINVAL,
> +		.reason = "Invalid AT flags",
> +	},
> +	{
> +		.dfd = &tmpdir_fd,
> +		.at_flags = AT_SYMLINK_NOFOLLOW + 1,
> +		.args = &args,
> +		.args_size = sizeof(struct xattr_args),
> +		.exp_errno = EINVAL,
> +		.reason = "Out of bound AT flags",
> +	},
> +	{
> +		.dfd = &tmpdir_fd,
> +		.args = &null_args,
> +		.args_size = sizeof(struct xattr_args),
> +		.exp_errno = EINVAL,
> +		.reason = "Invalid arguments",
> +	},
> +	{
> +		.dfd = &tmpdir_fd,
> +		.args = &args,
> +		.args_size = SIZE_MAX,
> +		.exp_errno = E2BIG,
> +		.reason = "Arguments size is too big",
> +	},
> +	{
> +		.dfd = &tmpdir_fd,
> +		.args = &args,
> +		.args_size = sizeof(struct xattr_args) - 1,
> +		.exp_errno = EINVAL,
> +		.reason = "Invalid arguments size",
> +	},
> +};
> +
> +static void run(unsigned int i)
> +{
> +	struct tcase *tc = &tcases[i];
> +
> +	args->flags = XATTR_CREATE;
> +	args->value = (uint64_t)XATTR_TEST_VALUE;
> +	args->size = XATTR_TEST_VALUE_SIZE;
> +
> +	TST_EXP_FAIL(tst_syscall(__NR_setxattrat,
> +		tc->dfd, FNAME, tc->at_flags, XATTR_TEST_KEY,
> +		tc->args, tc->args_size),
> +		tc->exp_errno, "%s", tc->reason);
> +}
> +
> +static void setup(void)
> +{
> +	char *tmpdir;
> +
> +	tmpdir = tst_tmpdir_path();
> +	tmpdir_fd = SAFE_OPEN(tmpdir, O_DIRECTORY);

Here as well, just use AT_FDCWD.

> +	SAFE_TOUCH(FNAME, 0777, NULL);
> +}
> +
> +static void cleanup(void)
> +{
> +	if (tmpdir_fd != -1)
> +		SAFE_CLOSE(tmpdir_fd);
> +
> +	SAFE_UNLINK(FNAME);
> +}
> +
> +static struct tst_test test = {
> +	.test = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.needs_root = 1,
> +	.needs_tmpdir = 1,
> +	.bufs = (struct tst_buffers []) {
> +		{&args, .size = sizeof(struct xattr_args)},
> +		{},
> +	}
> +};
> 
> -- 
> 2.51.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list