[LTP] [PATCH 2/2] syscalls/fchmodat02: Move errnos check to fchmodat02
Li Wang
liwang@redhat.com
Tue Oct 17 14:40:12 CEST 2023
On Thu, Sep 21, 2023 at 1:23 PM Yang Xu <xuyang2018.jy@fujitsu.com> wrote:
> Check errnos for fchmodat().
>
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
> runtest/syscalls | 1 +
> testcases/kernel/syscalls/fchmodat/.gitignore | 1 +
> .../kernel/syscalls/fchmodat/fchmodat02.c | 66 +++++++++++++++++++
> 3 files changed, 68 insertions(+)
> create mode 100644 testcases/kernel/syscalls/fchmodat/fchmodat02.c
>
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 4f1ee1f34..5a6b4a64d 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -259,6 +259,7 @@ fchmod06 fchmod06
>
> #fchmodat test cases
> fchmodat01 fchmodat01
> +fchmodat02 fchmodat02
>
> fchown01 fchown01
> fchown01_16 fchown01_16
> diff --git a/testcases/kernel/syscalls/fchmodat/.gitignore
> b/testcases/kernel/syscalls/fchmodat/.gitignore
> index a9508bc5a..09d5c47d5 100644
> --- a/testcases/kernel/syscalls/fchmodat/.gitignore
> +++ b/testcases/kernel/syscalls/fchmodat/.gitignore
> @@ -1 +1,2 @@
> /fchmodat01
> +/fchmodat02
> diff --git a/testcases/kernel/syscalls/fchmodat/fchmodat02.c
> b/testcases/kernel/syscalls/fchmodat/fchmodat02.c
> new file mode 100644
> index 000000000..ad8e2aaf7
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fchmodat/fchmodat02.c
> @@ -0,0 +1,66 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) International Business Machines Corp., 2006
> + * Copyright (c) Linux Test Project, 2003-2023
> + * Author: Yi Yang <yyangcdl@cn.ibm.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * - fchmodat() fails with ENOTDIR if dir_fd is file descriptor to the
> file
> + * and pathname is relative path of the file.
> + *
> + * - fchmodat() fails with EBADF if dir_fd is invalid.
>
Generally, this test looks good, but I would still suggest covering more
ERROS check for chmodat :-).
> + */
> +
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include "tst_test.h"
> +
> +#define TESTDIR "fchmodatdir"
> +#define TESTFILE "fchmodatfile"
> +#define FILEPATH "fchmodatdir/fchmodatfile"
> +
> +static int dir_fd, file_fd;
> +static int bad_fd = -1;
> +
> +static struct tcase {
> + int *fd;
> + int exp_errno;
> +} tcases[] = {
> + {&file_fd, ENOTDIR},
> + {&bad_fd, EBADF},
> +};
> +
> +static void verify_fchmodat(unsigned int i)
> +{
> + struct tcase *tc = &tcases[i];
> +
> + TST_EXP_FAIL(fchmodat(*tc->fd, TESTFILE, 0600, 0),
> + tc->exp_errno, "fchmodat(%d, %s, 0600, 0)", *tc->fd,
> TESTFILE);
> +}
> +
> +static void setup(void)
> +{
> + SAFE_MKDIR(TESTDIR, 0700);
> + dir_fd = SAFE_OPEN(TESTDIR, O_DIRECTORY);
>
I didn't see why we need dir_fd in this testcase, we don't
even need to create the TESTDIR, right?
> + file_fd = SAFE_OPEN(FILEPATH, O_CREAT | O_RDWR, 0600);
> +}
> +
> +static void cleanup(void)
> +{
> + if (dir_fd > -1)
> + SAFE_CLOSE(dir_fd);
>
no needed.
+
> + if (file_fd > -1)
> + SAFE_CLOSE(file_fd);
> +}
> +
> +static struct tst_test test = {
> + .test = verify_fchmodat,
> + .tcnt = ARRAY_SIZE(tcases),
> + .setup = setup,
> + .cleanup = cleanup,
> + .needs_tmpdir = 1,
> +};
> --
> 2.39.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>
--
Regards,
Li Wang
More information about the ltp
mailing list