[LTP] [PATCH 3/5] Add fchmodat2_01 test
Cyril Hrubis
chrubis@suse.cz
Thu Jul 11 14:12:47 CEST 2024
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
More information about the ltp
mailing list