All of lore.kernel.org
 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 v3 4/6] Add file_attr01 test
Date: Tue, 5 Aug 2025 13:36:04 +0200	[thread overview]
Message-ID: <aJHspF_wL8Su93lV@yuki.lan> (raw)
In-Reply-To: <20250805-file_setattr_getattr-v3-4-67a7747d226c@suse.com>

Hi!
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -246,6 +246,8 @@ fallocate06 fallocate06
>  fsetxattr01 fsetxattr01
>  fsetxattr02 fsetxattr02
>  
> +file_attr01 file_attr01
> +
>  #posix_fadvise test cases
>  posix_fadvise01                      posix_fadvise01
>  posix_fadvise01_64                posix_fadvise01_64
> diff --git a/testcases/kernel/syscalls/file_attr/.gitignore b/testcases/kernel/syscalls/file_attr/.gitignore
> new file mode 100644
> index 0000000000000000000000000000000000000000..de06f204d34be482a6401f2a5e7931caa5e3ab12
> --- /dev/null
> +++ b/testcases/kernel/syscalls/file_attr/.gitignore
> @@ -0,0 +1 @@
> +file_attr01
> diff --git a/testcases/kernel/syscalls/file_attr/Makefile b/testcases/kernel/syscalls/file_attr/Makefile
> new file mode 100644
> index 0000000000000000000000000000000000000000..3b19b0ce6be00839038c405eea027b0102761e45
> --- /dev/null
> +++ b/testcases/kernel/syscalls/file_attr/Makefile
> @@ -0,0 +1,8 @@
> +# Copyright (c) 2025 - Linaro Limited. All rights reserved.
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +
> +top_srcdir		?= ../../../..
> +
> +include $(top_srcdir)/include/mk/testcases.mk
> +
> +include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/syscalls/file_attr/file_attr01.c b/testcases/kernel/syscalls/file_attr/file_attr01.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..597ce31fbb11c47754a264eba394be3c233c8663
> --- /dev/null
> +++ b/testcases/kernel/syscalls/file_attr/file_attr01.c
> @@ -0,0 +1,171 @@
> +// 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` syscalls are raising the
> + * correct errors according to the invalid input arguments. In particular:
> + *
> + * - EBADFD: Invalid file descriptor.
> + * - ENOENT: File doesn't exist
> + * - EFAULT: File name is NULL
> + * - EFAULT: File attributes is NULL
> + * - EINVAL: File attributes size is zero
> + * - E2BIG: File attributes size is too big
> + * - EINVAL: Invalid AT flags
> + */
> +
> +#include <string.h>
> +#include "tst_test.h"
> +#include "lapi/fs.h"
> +#include "lapi/fcntl.h"
> +
> +#define MNTPOINT "mntpoint"
> +#define FILENAME "ltp_file"
> +#define NO_FILENAME "ltp_file_doesnt_exist"
> +
> +static int valid_dfd = -1;
> +static int invalid_dfd = -1;
> +static char *valid_filename;
> +static char *invalid_filename;
> +static char *null_ptr;
> +static size_t zero;
> +static size_t valid_usize;
> +static size_t big_usize;
> +static struct file_attr *valid_file_attr;
> +
> +static struct tcase {
> +	int *dfd;
> +	char **filename;
> +	struct file_attr **ufattr;
> +	size_t *usize;
> +	int at_flags;
> +	int exp_errno;
> +	char *msg;
> +} tcases[] = {
> +	{
> +		.dfd = &invalid_dfd,

Hmm do we need a tst_fd iterator for this case?

> +		.filename = &valid_filename,
> +		.ufattr = &valid_file_attr,
> +		.usize = &valid_usize,
> +		.exp_errno = EBADF,
> +		.msg = "Invalid file descriptor",
> +	},
> +	{
> +		.dfd = &valid_dfd,
> +		.filename = &invalid_filename,
> +		.ufattr = &valid_file_attr,
> +		.usize = &valid_usize,
> +		.exp_errno = ENOENT,
> +		.msg = "File doesn't exist",
> +	},
> +	{
> +		.dfd = &valid_dfd,
> +		.filename = &null_ptr,
> +		.ufattr = &valid_file_attr,
> +		.usize = &valid_usize,
> +		.exp_errno = EFAULT,
> +		.msg = "Filename is NULL",
> +	},
> +	{
> +		.dfd = &valid_dfd,
> +		.filename = &valid_filename,
> +		.ufattr = (struct file_attr **)(&null_ptr),
> +		.usize = &valid_usize,
> +		.exp_errno = EFAULT,
> +		.msg = "File attributes is NULL",
> +	},
> +	{
> +		.dfd = &valid_dfd,
> +		.filename = &valid_filename,
> +		.ufattr = &valid_file_attr,
> +		.usize = &zero,
> +		.exp_errno = EINVAL,
> +		.msg = "File attributes size is zero",
> +	},
> +	{
> +		.dfd = &valid_dfd,
> +		.filename = &valid_filename,
> +		.ufattr = &valid_file_attr,
> +		.usize = &big_usize,
> +		.exp_errno = E2BIG,
> +		.msg = "File attributes size is too big",
> +	},
> +	{
> +		.dfd = &valid_dfd,
> +		.filename = &valid_filename,
> +		.ufattr = &valid_file_attr,
> +		.usize = &valid_usize,
> +		.at_flags = -1,
> +		.exp_errno = EINVAL,
> +		.msg = "Invalid AT flags",
> +	},
> +};
> +
> +static void run(unsigned int i)
> +{
> +	struct tcase *tc = &tcases[i];
> +
> +	if (tst_variant) {
> +		TST_EXP_FAIL(file_getattr(
> +			*tc->dfd, *tc->filename,
> +			*tc->ufattr, *tc->usize,
> +			tc->at_flags),
> +			tc->exp_errno,
> +			"%s", tc->msg);
> +	} else {
> +		TST_EXP_FAIL(file_setattr(
> +			*tc->dfd, *tc->filename,
> +			*tc->ufattr, *tc->usize,
> +			tc->at_flags),
> +			tc->exp_errno,
> +			"%s", tc->msg);
> +	}
> +}
> +
> +static void setup(void)
> +{
> +	valid_dfd = SAFE_OPEN(MNTPOINT, O_RDONLY);
> +
> +	SAFE_CHDIR(MNTPOINT);
> +	SAFE_TOUCH(FILENAME, 0777, NULL);
> +	SAFE_CHDIR("..");
> +
> +	memcpy(valid_filename, FILENAME, strlen(FILENAME));
> +	memcpy(invalid_filename, NO_FILENAME, strlen(NO_FILENAME));

The struct tst_buffers have .str member that if set copies the string,
so instead of .size = 32 you need to pass .str = FILENAME and .str
NO_FILENAME there.

> +	valid_usize = FILE_ATTR_SIZE_LATEST;
> +	big_usize = sysconf(_SC_PAGESIZE) + 100;

Do we need a small_usize that would be one less than smalles
FILE_ATTR_SIZE as well?

> +}
> +
> +static void cleanup(void)
> +{
> +	if (valid_dfd != -1)
> +		SAFE_CLOSE(valid_dfd);
> +}
> +
> +static struct tst_test test = {
> +	.test = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.mntpoint = MNTPOINT,
> +	.needs_root = 1,
> +	.mount_device = 1,
> +	.all_filesystems = 1,
> +	.test_variants = 2,
> +	.skip_filesystems = (const char *const []) {
> +		"fuse",
> +		"ntfs",
> +		"vfat",
> +		"exfat",
> +		NULL
> +	},
> +	.bufs = (struct tst_buffers []) {
> +		{&valid_filename, .size = 32},
> +		{&invalid_filename, .size = 32},
> +		{&valid_file_attr, .size = sizeof(struct file_attr)},
> +		{}
> +	}
> +};
> 
> -- 
> 2.50.1
> 
> 
> -- 
> 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-08-05 11:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-05  7:01 [LTP] [PATCH v3 0/6] file_setattr/file_getattr testing suite Andrea Cervesato
2025-08-05  7:01 ` [LTP] [PATCH v3 1/6] Update LTP to the latest syscalls Andrea Cervesato
2025-08-05  7:01 ` [LTP] [PATCH v3 2/6] fs: add struct fsxattr fallback definitions Andrea Cervesato
2025-08-05  7:01 ` [LTP] [PATCH v3 3/6] fs: add file_setattr/file_getattr " Andrea Cervesato
2025-08-05  7:01 ` [LTP] [PATCH v3 4/6] Add file_attr01 test Andrea Cervesato
2025-08-05 11:36   ` Cyril Hrubis [this message]
2025-08-05  7:01 ` [LTP] [PATCH v3 5/6] Add file_attr02 test Andrea Cervesato
2025-08-05 11:41   ` Cyril Hrubis
2025-08-05  7:01 ` [LTP] [PATCH v3 6/6] Add file_attr03 test Andrea Cervesato
2025-08-05 12:22   ` Cyril Hrubis

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=aJHspF_wL8Su93lV@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.