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/5] Add fchmodat2_01 test
Date: Thu, 11 Jul 2024 14:12:47 +0200	[thread overview]
Message-ID: <Zo_MP7ymBzHmq511@yuki> (raw)
In-Reply-To: <20240521-fchmodat2-v1-3-191b4a986202@suse.com>

Hi!
> diff --git a/testcases/kernel/syscalls/fchmodat2/fchmodat2.h b/testcases/kernel/syscalls/fchmodat2/fchmodat2.h
> new file mode 100644
> index 000000000..676d491cf
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fchmodat2/fchmodat2.h
> @@ -0,0 +1,32 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +#ifndef FCHMODAT2_H

Missing #define FCHMODAT2_H

> +
> +#include "tst_test.h"
> +#include "lapi/syscalls.h"
> +#include "tst_safe_file_at.h"
> +
> +static inline int fchmodat2(int dfd, const char *filename, mode_t mode, int flags)
> +{
> +	int ret;
> +
> +	ret = tst_syscall(__NR_fchmodat2, dfd, filename, mode, flags);
> +	if (ret == -1)
> +		tst_brk(TBROK | TERRNO, "%s(%d,%s,%d,%d) error",
> +			__func__, dfd, filename, mode, flags);
> +
> +	return ret;
> +}


This should probably go into lapi.

> +static inline void verify_mode(int dirfd, const char *path, mode_t mode)
> +{
> +	struct stat st;
> +
> +	SAFE_FSTATAT(dirfd, path, &st, AT_SYMLINK_NOFOLLOW);
> +	TST_EXP_EQ_LI(st.st_mode, mode);
> +}
> +
> +#endif
> diff --git a/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c b/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
> new file mode 100644
> index 000000000..9f4960a0c
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fchmodat2/fchmodat2_01.c
> @@ -0,0 +1,54 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This test verifies that fchmodat2() syscall is properly working with
> + * AT_SYMLINK_NOFOLLOW on regular files.
> + */
> +
> +#include "fchmodat2.h"
> +#include "lapi/fcntl.h"
> +
> +#define MNTPOINT "mntpoint"
> +#define FNAME "myfile"
> +
> +static int fd_dir = -1;
> +
> +static void run(void)
> +{
> +	SAFE_CHMOD(MNTPOINT"/"FNAME, 0640);
> +
> +	TST_EXP_PASS(fchmodat2(fd_dir, FNAME, 0700, AT_SYMLINK_NOFOLLOW));
> +	verify_mode(fd_dir, FNAME, S_IFREG | 0700);
> +}
> +
> +static void setup(void)
> +{
> +	fd_dir = SAFE_OPEN(MNTPOINT, O_PATH | O_DIRECTORY, 0640);
> +
> +	SAFE_TOUCH(MNTPOINT"/"FNAME, 0640, NULL);
> +}
> +
> +static void cleanup(void)
> +{
> +	if (fd_dir != -1)
> +		SAFE_CLOSE(fd_dir);
> +}
> +
> +static struct tst_test test = {
> +	.test_all = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.min_kver = "6.6",
> +	.mntpoint = MNTPOINT,
> +	.format_device = 1,
> +	.all_filesystems = 1,
> +	.skip_filesystems = (const char *const []) {
> +		"fuse",
> +		NULL
> +	},
> +};
> 
> -- 
> 2.35.3
> 
> 
> -- 
> 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:[~2024-07-11 12:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-21  6:15 [LTP] [PATCH 0/5] Add fchmodat2 testing suite Andrea Cervesato
2024-05-21  6:15 ` [LTP] [PATCH 1/5] Add SAFE_SYMLINKAT macro Andrea Cervesato
2024-05-21  6:15 ` [LTP] [PATCH 2/5] Add fchmodat2 syscall definitions Andrea Cervesato
2024-05-21  6:15 ` [LTP] [PATCH 3/5] Add fchmodat2_01 test Andrea Cervesato
2024-07-11 12:12   ` Cyril Hrubis [this message]
2024-05-21  6:15 ` [LTP] [PATCH 4/5] Add fchmodat2_02 test Andrea Cervesato
2024-07-11 12:16   ` Cyril Hrubis
2024-05-21  6:15 ` [LTP] [PATCH 5/5] Add fchmodat2_03 test Andrea Cervesato
2024-07-11 12:18   ` 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=Zo_MP7ymBzHmq511@yuki \
    --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