Message ID | 20240521-fchmodat2-v1-3-191b4a986202@suse.com |
---|---|
State | Accepted |
Headers | show |
Series | Add fchmodat2 testing suite | expand |
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
diff --git a/runtest/syscalls b/runtest/syscalls index cf06ee563..0a28530ed 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -264,6 +264,8 @@ fchmod06 fchmod06 fchmodat01 fchmodat01 fchmodat02 fchmodat02 +fchmodat2_01 fchmodat2_01 + fchown01 fchown01 fchown01_16 fchown01_16 fchown02 fchown02 diff --git a/testcases/kernel/syscalls/fchmodat2/.gitignore b/testcases/kernel/syscalls/fchmodat2/.gitignore new file mode 100644 index 000000000..47d5e2427 --- /dev/null +++ b/testcases/kernel/syscalls/fchmodat2/.gitignore @@ -0,0 +1 @@ +fchmodat2_01 diff --git a/testcases/kernel/syscalls/fchmodat2/Makefile b/testcases/kernel/syscalls/fchmodat2/Makefile new file mode 100644 index 000000000..8cf1b9024 --- /dev/null +++ b/testcases/kernel/syscalls/fchmodat2/Makefile @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com> + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk 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 + +#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; +} + +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 + }, +};