fcntl40.c: Test fcntl using F_CREATED_QUERY
PATCH 1/1 fcntl40.c: Test fcntl using F_CREATED_QUERY
--- 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
include/lapi/fcntl.h +8 -0
@@ -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
runtest/syscalls +2 -0
@@ -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
testcases/kernel/syscalls/fcntl/.gitignore +2 -0
@@ -72,3 +72,5 @@ /fcntl38_64 /fcntl39 /fcntl39_64 +/fcntl40 +/fcntl40_64
testcases/kernel/syscalls/fcntl/fcntl40.c new file +52 -0
52 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/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.
Quoted 1 line · Wei Gao via ltp
Signed-off-by Wei Gao <[email protected]>
There's no commit description
Quoted 56 lines
--- 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.cinclude/lapi/fcntl.h +8
-0@@ -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 runtest/syscalls +2
-0@@ -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 fdatasync02testcases/kernel/syscalls/fcntl/.gitignore +2
-0@@ -72,3 +72,5 @@ /fcntl38_64 /fcntl39 /fcntl39_64 +/fcntl40 +/fcntl40_64testcases/kernel/syscalls/fcntl/fcntl40.c new file +0
-0
testcases/kernel/syscalls/fcntl/fcntl40.c line 7
Quoted 7 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +7
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024 SUSE Wei Gao <[email protected]> +*/ + +/*\ +* [Description]
Now we don't need this anymore
testcases/kernel/syscalls/fcntl/fcntl40.c line 9
Quoted 2 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +2
-0+* +* 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."
testcases/kernel/syscalls/fcntl/fcntl40.c line 14
Quoted 5 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +5
-0+* +* It is based on the following kernel commit: +* commit d0fe8920cbe42547798fd806f078eeaaba05df18 +* Author: Christian Brauner [email protected] +* 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".
testcases/kernel/syscalls/fcntl/fcntl40.c line 22
Quoted 8 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +8
-0+*/ + +#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.
testcases/kernel/syscalls/fcntl/fcntl40.c line 29
Quoted 7 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +7
-0+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()
testcases/kernel/syscalls/fcntl/fcntl40.c line 30
Quoted 1 line
testcases/kernel/syscalls/fcntl/fcntl40.c new file +1
-0+close (fd);
SAFE_CLOSE()
testcases/kernel/syscalls/fcntl/fcntl40.c line 32
Quoted 2 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +2
-0+ +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
testcases/kernel/syscalls/fcntl/fcntl40.c line 36
Quoted 4 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +4
-0+ 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()
testcases/kernel/syscalls/fcntl/fcntl40.c line 37
Quoted 1 line
testcases/kernel/syscalls/fcntl/fcntl40.c new file +1
-0+close (fd);
SAFE_CLOSE()
testcases/kernel/syscalls/fcntl/fcntl40.c line 42
Quoted 5 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +5
-0+ + 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()
testcases/kernel/syscalls/fcntl/fcntl40.c line 43
Quoted 1 line
testcases/kernel/syscalls/fcntl/fcntl40.c new file +1
-0+close (fd);
SAFE_CLOSE()
testcases/kernel/syscalls/fcntl/fcntl40.c line 44
Quoted 1 line
testcases/kernel/syscalls/fcntl/fcntl40.c new file +1
-0+unlink (path);
SAFE_UNLINK()
testcases/kernel/syscalls/fcntl/fcntl40.c line 51
Quoted 7 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +7
-0+ } +} + +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.
testcases/kernel/syscalls/fcntl/fcntl40.c line 52
Quoted 1 line
testcases/kernel/syscalls/fcntl/fcntl40.c new file +1
-0+};
Kind regards,
Andrea Cervesato
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/1 fcntl40.c: Test fcntl using F_CREATED_QUERY
In reply to Wei Gao via ltpThis is new test case for fcntl using new F_CREATED_QUERY operation. Based on a kernel selftest.
--- 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
include/lapi/fcntl.h +8 -0
@@ -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
runtest/syscalls +2 -0
@@ -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
testcases/kernel/syscalls/fcntl/.gitignore +2 -0
@@ -72,3 +72,5 @@ /fcntl38_64 /fcntl39 /fcntl39_64 +/fcntl40 +/fcntl40_64
testcases/kernel/syscalls/fcntl/fcntl40.c new file +52 -0
52 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wei,
Quoted 1 line · Wei Gao via ltp
Signed-off-by Wei Gao <[email protected]>
There's a double Signed-off signature.
Quoted 76 lines
This is new test case for fcntl using new
F_CREATED_QUERYoperation. Based on a kernel selftest.Signed-off-by Wei Gao <[email protected]>--- 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.cinclude/lapi/fcntl.h +8
-0@@ -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 runtest/syscalls +2
-0@@ -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 fdatasync02testcases/kernel/syscalls/fcntl/.gitignore +2
-0@@ -72,3 +72,5 @@ /fcntl38_64 /fcntl39 /fcntl39_64 +/fcntl40 +/fcntl40_64testcases/kernel/syscalls/fcntl/fcntl40.c new file +16
-0@@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024 SUSE Wei Gao <[email protected]> +*/ + +/*\ +* 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" +
testcases/kernel/syscalls/fcntl/fcntl40.c line 26
Quoted 10 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +10
-0+#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.
testcases/kernel/syscalls/fcntl/fcntl40.c line 31
Quoted 5 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +5
-0+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.
testcases/kernel/syscalls/fcntl/fcntl40.c line 37
Quoted 6 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +6
-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 );
Here as well.
testcases/kernel/syscalls/fcntl/fcntl40.c line 41
Quoted 4 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +4
-0+SAFE_CLOSE (fd); +SAFE_UNLINK (TEST_NAME ); + +tst_res (TPASS ,"fcntl F_CREATED_QUERY check pass" );
And this is not needed anymore.
Quoted 11 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +11
-0+} + +static struct tst_test test = { + .test_all = verify_fcntl, + .needs_tmpdir =1 , + .min_kver ="6.12" , + .tags = (const struct tst_tag []) { + {"linux-git" ,"d0fe8920cbe4" }, + {} + } +};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/1 fcntl40.c: Test fcntl using F_CREATED_QUERY
In reply to Wei Gao via ltpThis is new test case for fcntl using new F_CREATED_QUERY operation. Based on a kernel selftest.
--- 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
include/lapi/fcntl.h +8 -0
@@ -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
runtest/syscalls +2 -0
@@ -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
testcases/kernel/syscalls/fcntl/.gitignore +2 -0
@@ -72,3 +72,5 @@ /fcntl38_64 /fcntl39 /fcntl39_64 +/fcntl40 +/fcntl40_64
testcases/kernel/syscalls/fcntl/fcntl40.c new file +52 -0
52 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 13 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +13
-0+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 );
testcases/kernel/syscalls/fcntl/fcntl40.c line 41
Quoted 10 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +10
-0+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.
testcases/kernel/syscalls/fcntl/fcntl40.c line 49
Quoted 8 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +8
-0+} + +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.
Quoted 9 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +3
-0+ {} + } +};Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 1/1 fcntl40.c: Test fcntl using F_CREATED_QUERY
In reply to Wei Gao via ltpThis is new test case for fcntl using new F_CREATED_QUERY operation. Based on a kernel selftest commit d0fe8920cbe4.
--- 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
include/lapi/fcntl.h +8 -0
@@ -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
runtest/syscalls +2 -0
@@ -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
testcases/kernel/syscalls/fcntl/.gitignore +2 -0
@@ -72,3 +72,5 @@ /fcntl38_64 /fcntl39 /fcntl39_64 +/fcntl40 +/fcntl40_64
testcases/kernel/syscalls/fcntl/fcntl40.c new file +46 -0
46 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Applied, thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp