* [LTP] [PATCH v1] fcntl40.c: Test fcntl using F_CREATED_QUERY
@ 2024-12-28 11:44 Wei Gao via ltp
2025-02-20 12:34 ` Andrea Cervesato via ltp
2025-03-01 6:31 ` [LTP] [PATCH v2] " Wei Gao via ltp
0 siblings, 2 replies; 8+ messages in thread
From: Wei Gao via ltp @ 2024-12-28 11:44 UTC (permalink / raw)
To: ltp
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 ded035ee8..43e493eb1 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -363,6 +363,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..ef03becef
--- /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>
+ */
+
+/*\
+ * [Description]
+ *
+ * Basic test for fcntl using F_CREATED_QUERY.
+ *
+ * It is based on the following kernel commit:
+ * commit d0fe8920cbe42547798fd806f078eeaaba05df18
+ * Author: Christian Brauner brauner@kernel.org
+ * Date: Wed Jul 24 15:15:36 2024 +0200
+ */
+
+#include "lapi/fcntl.h"
+#include "tst_test.h"
+
+static void verify_fcntl(void)
+{
+ for (int i = 0; i < 101; i++) {
+ int fd;
+ char path[PATH_MAX];
+
+ fd = SAFE_OPEN("/dev/null", O_RDONLY | O_CLOEXEC);
+
+ /* We didn't create "/dev/null". */
+ TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 0);
+ close(fd);
+
+ sprintf(path, "aaaa_%d", i);
+ fd = SAFE_OPEN(path, O_CREAT | O_RDONLY | O_CLOEXEC, 0600);
+
+ /* We created "aaaa_%d". */
+ TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 1);
+ close(fd);
+
+ fd = SAFE_OPEN(path, O_RDONLY | O_CLOEXEC);
+
+ /* We're opening it again, so no positive creation check. */
+ TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 0);
+ close(fd);
+ unlink(path);
+ }
+}
+
+static struct tst_test test = {
+ .test_all = verify_fcntl,
+ .needs_tmpdir = 1,
+ .min_kver = "6.12",
+};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [LTP] [PATCH v1] fcntl40.c: Test fcntl using F_CREATED_QUERY
2024-12-28 11:44 [LTP] [PATCH v1] fcntl40.c: Test fcntl using F_CREATED_QUERY Wei Gao via ltp
@ 2025-02-20 12:34 ` Andrea Cervesato via ltp
2025-03-01 6:31 ` [LTP] [PATCH v2] " Wei Gao via ltp
1 sibling, 0 replies; 8+ messages in thread
From: Andrea Cervesato via ltp @ 2025-02-20 12:34 UTC (permalink / raw)
To: Wei Gao, ltp
Hi!
A main comment about selftests ports is due to the way we should pay an
extra attention to the code we are merging in LTP.
The LTP code base is different and we need to double check if the
selftests make sense and we are correctly using available LTP API.
The documentation is also important and we should take a closer look to
the description.
Some comments below.
On 12/28/24 12:44, Wei Gao via ltp wrote:
> Signed-off-by: Wei Gao <wegao@suse.com>
There's no commit description
> ---
> 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 ded035ee8..43e493eb1 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -363,6 +363,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..ef03becef
> --- /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>
> + */
> +
> +/*\
> + * [Description]
Now we don't need this anymore
> + *
> + * 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."
> + *
> + * It is based on the following kernel commit:
> + * commit d0fe8920cbe42547798fd806f078eeaaba05df18
> + * Author: Christian Brauner brauner@kernel.org
> + * Date: Wed Jul 24 15:15:36 2024 +0200
To write if test is based on a kernel selftests is enough. The git tag
should be pointed in the "struct tst_test" via ".tags".
> + */
> +
> +#include "lapi/fcntl.h"
> +#include "tst_test.h"
> +
> +static void verify_fcntl(void)
> +{
> + for (int i = 0; i < 101; i++) {
This has been probably added by selftest devs due to make sure fcntl()
is working correctly when multiple files are created.
I think in our case is not really useful, but we might have 2 options at
this point:
1. we keep the loop, but we don't spam text messages in the stdout.
Which means we probably need to remove TST_EXP_EQ_LI and to process
multiple results at once
2. we remove the loop and we test it only on a single file
I'm more for the 2nd option.
> + int fd;
> + char path[PATH_MAX];
> +
> + fd = SAFE_OPEN("/dev/null", O_RDONLY | O_CLOEXEC);
> +
> + /* We didn't create "/dev/null". */
> + TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 0);
SAFE_FCNTL()
> + close(fd);
SAFE_CLOSE()
> +
> + sprintf(path, "aaaa_%d", i);
There's no need for this if we use a single file. We can just define a
TEST_NAME macro on top and use that everywhere
> + fd = SAFE_OPEN(path, O_CREAT | O_RDONLY | O_CLOEXEC, 0600);
> +
> + /* We created "aaaa_%d". */
> + TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 1);
SAFE_FCNTL()
> + close(fd);
SAFE_CLOSE()
> +
> + fd = SAFE_OPEN(path, O_RDONLY | O_CLOEXEC);
> +
> + /* We're opening it again, so no positive creation check. */
> + TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 0);
SAFE_FCNTL()
> + close(fd);
SAFE_CLOSE()
> + unlink(path);
SAFE_UNLINK()
> + }
> +}
> +
> +static struct tst_test test = {
> + .test_all = verify_fcntl,
> + .needs_tmpdir = 1,
> + .min_kver = "6.12",
Here we need to define .tags , adding the kernel commit that introduced
the selftest.
> +};
Kind regards,
Andrea Cervesato
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [PATCH v2] fcntl40.c: Test fcntl using F_CREATED_QUERY
2024-12-28 11:44 [LTP] [PATCH v1] fcntl40.c: Test fcntl using F_CREATED_QUERY Wei Gao via ltp
2025-02-20 12:34 ` Andrea Cervesato via ltp
@ 2025-03-01 6:31 ` Wei Gao via ltp
2025-03-03 8:24 ` Andrea Cervesato via ltp
2025-04-01 7:56 ` [LTP] [PATCH v3] " Wei Gao via ltp
1 sibling, 2 replies; 8+ messages in thread
From: Wei Gao via ltp @ 2025-03-01 6:31 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
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);
+ SAFE_CLOSE(fd);
+
+ fd = SAFE_OPEN(TEST_NAME, O_CREAT | O_RDONLY | O_CLOEXEC, 0600);
+
+ SAFE_FCNTL(fd, F_CREATED_QUERY, 0);
+ 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);
+ SAFE_CLOSE(fd);
+ SAFE_UNLINK(TEST_NAME);
+
+ tst_res(TPASS, "fcntl F_CREATED_QUERY check pass");
+}
+
+static struct tst_test test = {
+ .test_all = verify_fcntl,
+ .needs_tmpdir = 1,
+ .min_kver = "6.12",
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "d0fe8920cbe4"},
+ {}
+ }
+};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [LTP] [PATCH v2] fcntl40.c: Test fcntl using F_CREATED_QUERY
2025-03-01 6:31 ` [LTP] [PATCH v2] " Wei Gao via ltp
@ 2025-03-03 8:24 ` Andrea Cervesato via ltp
2025-04-01 7:56 ` [LTP] [PATCH v3] " Wei Gao via ltp
1 sibling, 0 replies; 8+ messages in thread
From: Andrea Cervesato via ltp @ 2025-03-03 8:24 UTC (permalink / raw)
To: Wei Gao, ltp
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"},
> + {}
> + }
> +};
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [PATCH v3] fcntl40.c: Test fcntl using F_CREATED_QUERY
2025-03-01 6:31 ` [LTP] [PATCH v2] " Wei Gao via ltp
2025-03-03 8:24 ` Andrea Cervesato via ltp
@ 2025-04-01 7:56 ` Wei Gao via ltp
2025-04-02 10:29 ` Cyril Hrubis
2025-04-03 6:58 ` [LTP] [PATCH v4] " Wei Gao via ltp
1 sibling, 2 replies; 8+ messages in thread
From: Wei Gao via ltp @ 2025-04-01 7:56 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
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..882e0163f
--- /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". */
+ TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 0);
+ SAFE_CLOSE(fd);
+
+ fd = SAFE_OPEN(TEST_NAME, O_CREAT | O_RDONLY | O_CLOEXEC, 0600);
+
+ TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 1);
+ SAFE_CLOSE(fd);
+
+ fd = SAFE_OPEN(TEST_NAME, O_RDONLY | O_CLOEXEC);
+
+ /* We're opening it again, so no positive creation check. */
+ TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 0);
+ SAFE_CLOSE(fd);
+ SAFE_UNLINK(TEST_NAME);
+
+ /* tst_res(TPASS, "fcntl F_CREATED_QUERY check pass"); */
+}
+
+static struct tst_test test = {
+ .test_all = verify_fcntl,
+ .needs_tmpdir = 1,
+ .min_kver = "6.12",
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "d0fe8920cbe4"},
+ {}
+ }
+};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [LTP] [PATCH v3] fcntl40.c: Test fcntl using F_CREATED_QUERY
2025-04-01 7:56 ` [LTP] [PATCH v3] " Wei Gao via ltp
@ 2025-04-02 10:29 ` Cyril Hrubis
2025-04-03 6:58 ` [LTP] [PATCH v4] " Wei Gao via ltp
1 sibling, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2025-04-02 10:29 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi!
> +static void verify_fcntl(void)
> +{
> + int fd;
> +
> + fd = SAFE_OPEN("/dev/null", O_RDONLY | O_CLOEXEC);
> +
> + /* We didn't create "/dev/null". */
> + TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 0);
> + SAFE_CLOSE(fd);
> +
> + fd = SAFE_OPEN(TEST_NAME, O_CREAT | O_RDONLY | O_CLOEXEC, 0600);
> +
> + TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 1);
> + SAFE_CLOSE(fd);
> +
> + fd = SAFE_OPEN(TEST_NAME, O_RDONLY | O_CLOEXEC);
> +
> + /* We're opening it again, so no positive creation check. */
> + TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 0);
> + SAFE_CLOSE(fd);
> + SAFE_UNLINK(TEST_NAME);
> +
> + /* tst_res(TPASS, "fcntl F_CREATED_QUERY check pass"); */
Why is this line here? It's not even proper comment, just commented out
code. It should have been removed.
> +}
> +
> +static struct tst_test test = {
> + .test_all = verify_fcntl,
> + .needs_tmpdir = 1,
> + .min_kver = "6.12",
> + .tags = (const struct tst_tag[]) {
> + {"linux-git", "d0fe8920cbe4"},
This points to the kernel commit that added the test. Commit tags are
only for kernel commits that fixed a kernel bug, not for commits where
functionality was added.
> + {}
> + }
> +};
> --
> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [PATCH v4] fcntl40.c: Test fcntl using F_CREATED_QUERY
2025-04-01 7:56 ` [LTP] [PATCH v3] " Wei Gao via ltp
2025-04-02 10:29 ` Cyril Hrubis
@ 2025-04-03 6:58 ` Wei Gao via ltp
2025-04-07 11:31 ` Cyril Hrubis
1 sibling, 1 reply; 8+ messages in thread
From: Wei Gao via ltp @ 2025-04-03 6:58 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
This is new test case for fcntl using new F_CREATED_QUERY operation.
Based on a kernel selftest commit d0fe8920cbe4.
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 | 46 ++++++++++++++++++++++
4 files changed, 58 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..e90525fef
--- /dev/null
+++ b/testcases/kernel/syscalls/fcntl/fcntl40.c
@@ -0,0 +1,46 @@
+// 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 commit d0fe8920cbe4.
+ */
+
+#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". */
+ TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 0);
+ SAFE_CLOSE(fd);
+
+ fd = SAFE_OPEN(TEST_NAME, O_CREAT | O_RDONLY | O_CLOEXEC, 0600);
+
+ TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 1);
+ SAFE_CLOSE(fd);
+
+ fd = SAFE_OPEN(TEST_NAME, O_RDONLY | O_CLOEXEC);
+
+ /* We're opening it again, so no positive creation check. */
+ TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 0);
+ SAFE_CLOSE(fd);
+ SAFE_UNLINK(TEST_NAME);
+}
+
+static struct tst_test test = {
+ .test_all = verify_fcntl,
+ .needs_tmpdir = 1,
+ .min_kver = "6.12",
+};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [LTP] [PATCH v4] fcntl40.c: Test fcntl using F_CREATED_QUERY
2025-04-03 6:58 ` [LTP] [PATCH v4] " Wei Gao via ltp
@ 2025-04-07 11:31 ` Cyril Hrubis
0 siblings, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2025-04-07 11:31 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
Hi!
Applied, thanks.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-04-07 11:31 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-28 11:44 [LTP] [PATCH v1] fcntl40.c: Test fcntl using F_CREATED_QUERY Wei Gao via ltp
2025-02-20 12:34 ` Andrea Cervesato via ltp
2025-03-01 6:31 ` [LTP] [PATCH v2] " Wei Gao via ltp
2025-03-03 8:24 ` Andrea Cervesato via ltp
2025-04-01 7:56 ` [LTP] [PATCH v3] " Wei Gao via ltp
2025-04-02 10:29 ` Cyril Hrubis
2025-04-03 6:58 ` [LTP] [PATCH v4] " Wei Gao via ltp
2025-04-07 11:31 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox