[LTP] [PATCH v2] fcntl40.c: Test fcntl using F_CREATED_QUERY
Andrea Cervesato
andrea.cervesato@suse.com
Mon Mar 3 09:24:25 CET 2025
Hi Wei,
On 3/1/25 07:31, Wei Gao via ltp wrote:
> Signed-off-by: Wei Gao <wegao@suse.com>
There's a double Signed-off signature.
> This is new test case for fcntl using new F_CREATED_QUERY operation.
> Based on a kernel selftest.
>
> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
> include/lapi/fcntl.h | 8 ++++
> runtest/syscalls | 2 +
> testcases/kernel/syscalls/fcntl/.gitignore | 2 +
> testcases/kernel/syscalls/fcntl/fcntl40.c | 52 ++++++++++++++++++++++
> 4 files changed, 64 insertions(+)
> create mode 100644 testcases/kernel/syscalls/fcntl/fcntl40.c
>
> diff --git a/include/lapi/fcntl.h b/include/lapi/fcntl.h
> index 761331798..7c0502488 100644
> --- a/include/lapi/fcntl.h
> +++ b/include/lapi/fcntl.h
> @@ -154,6 +154,14 @@
> # define RENAME_WHITEOUT (1 << 2)
> #endif
>
> +#ifndef F_LINUX_SPECIFIC_BASE
> +#define F_LINUX_SPECIFIC_BASE 1024
> +#endif
> +
> +#ifndef F_CREATED_QUERY
> +#define F_CREATED_QUERY (F_LINUX_SPECIFIC_BASE + 4)
> +#endif
> +
> /* splice, vmsplice, tee */
>
> #ifndef SPLICE_F_NONBLOCK
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 5cd1ae656..5ba2315d1 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -364,6 +364,8 @@ fcntl38 fcntl38
> fcntl38_64 fcntl38_64
> fcntl39 fcntl39
> fcntl39_64 fcntl39_64
> +fcntl40 fcntl40
> +fcntl40_64 fcntl40_64
>
> fdatasync01 fdatasync01
> fdatasync02 fdatasync02
> diff --git a/testcases/kernel/syscalls/fcntl/.gitignore b/testcases/kernel/syscalls/fcntl/.gitignore
> index e60176973..e3486ee45 100644
> --- a/testcases/kernel/syscalls/fcntl/.gitignore
> +++ b/testcases/kernel/syscalls/fcntl/.gitignore
> @@ -72,3 +72,5 @@
> /fcntl38_64
> /fcntl39
> /fcntl39_64
> +/fcntl40
> +/fcntl40_64
> diff --git a/testcases/kernel/syscalls/fcntl/fcntl40.c b/testcases/kernel/syscalls/fcntl/fcntl40.c
> new file mode 100644
> index 000000000..2e4bef3e2
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fcntl/fcntl40.c
> @@ -0,0 +1,52 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2024 SUSE Wei Gao <wegao@suse.com>
> + */
> +
> +/*\
> + * Basic test for fcntl using F_CREATED_QUERY.
> + * Verify if the fcntl() syscall is recognizing whether a file has been
> + * created or not via O_CREAT when O_CLOEXEC is also used.
> + *
> + * Test is based on a kernel selftests.
> + */
> +
> +#include "lapi/fcntl.h"
> +#include "tst_test.h"
> +
> +#define TEST_NAME "LTP_FCNTL_CREATED_QUERY_TEST"
> +
> +static void verify_fcntl(void)
> +{
> + int fd;
> +
> + fd = SAFE_OPEN("/dev/null", O_RDONLY | O_CLOEXEC);
> +
> + /* We didn't create "/dev/null". */
> + SAFE_FCNTL(fd, F_CREATED_QUERY, 0);
We are missing the main check here: fctnl() should return 1 if we
created file via O_CREAT | O_EXCL and 0 if we didn't.
Se we should use TST_EXP_EQ_LI() in this case.
> + SAFE_CLOSE(fd);
> +
> + fd = SAFE_OPEN(TEST_NAME, O_CREAT | O_RDONLY | O_CLOEXEC, 0600);
> +
> + SAFE_FCNTL(fd, F_CREATED_QUERY, 0);
Here as well.
> + SAFE_CLOSE(fd);
> +
> + fd = SAFE_OPEN(TEST_NAME, O_RDONLY | O_CLOEXEC);
> +
> + /* We're opening it again, so no positive creation check. */
> + SAFE_FCNTL(fd, F_CREATED_QUERY, 0);
Here as well.
> + SAFE_CLOSE(fd);
> + SAFE_UNLINK(TEST_NAME);
> +
> + tst_res(TPASS, "fcntl F_CREATED_QUERY check pass");
And this is not needed anymore.
> +}
> +
> +static struct tst_test test = {
> + .test_all = verify_fcntl,
> + .needs_tmpdir = 1,
> + .min_kver = "6.12",
> + .tags = (const struct tst_tag[]) {
> + {"linux-git", "d0fe8920cbe4"},
> + {}
> + }
> +};
More information about the ltp
mailing list