public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] flock02: Add test for EWOULDBLOCK errno
@ 2025-01-14 15:49 Avinesh Kumar
  2025-01-15  9:14 ` Andrea Cervesato via ltp
  0 siblings, 1 reply; 4+ messages in thread
From: Avinesh Kumar @ 2025-01-14 15:49 UTC (permalink / raw)
  To: ltp

Also fix a make check warning.

Signed-off-by: Avinesh Kumar <akumar@suse.de>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
Following up on https://lore.kernel.org/ltp/1934768.7Z3S40VBb9@localhost/

 testcases/kernel/syscalls/flock/flock02.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/flock/flock02.c b/testcases/kernel/syscalls/flock/flock02.c
index b8c7eee68..e2fe73a64 100644
--- a/testcases/kernel/syscalls/flock/flock02.c
+++ b/testcases/kernel/syscalls/flock/flock02.c
@@ -13,6 +13,7 @@
  * - EBADF if the file descriptor is invalid
  * - EINVAL if the argument operation does not include LOCK_SH,LOCK_EX,LOCK_UN
  * - EINVAL if an invalid combination of locking modes is used i.e LOCK_SH with LOCK_EX
+ * - EWOULDBLOCK if the file is locked and the LOCK_NB flag was selected
  */
 
 #include <errno.h>
@@ -31,13 +32,19 @@ static struct tcase {
 	{&badfd, LOCK_SH, EBADF},
 	{&fd, LOCK_NB, EINVAL},
 	{&fd, LOCK_SH | LOCK_EX, EINVAL},
+	{&fd, LOCK_NB | LOCK_EX, EWOULDBLOCK}
 };
 
-static void verify_flock(unsigned n)
+static void verify_flock(unsigned int n)
 {
 	struct tcase *tc = &tcases[n];
 
 	fd = SAFE_OPEN("testfile", O_RDWR);
+	int fd2 = SAFE_OPEN("testfile", O_RDWR);
+
+	if (tc->exp_err == EWOULDBLOCK)
+		flock(fd2, LOCK_EX);
+
 	TEST(flock(*tc->fd, tc->operation));
 	if (TST_RET == 0) {
 		tst_res(TFAIL | TTERRNO, "flock() succeeded unexpectedly");
@@ -53,6 +60,7 @@ static void verify_flock(unsigned n)
 	}
 
 	SAFE_CLOSE(fd);
+	SAFE_CLOSE(fd2);
 }
 
 static void setup(void)
-- 
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH] flock02: Add test for EWOULDBLOCK errno
  2025-01-14 15:49 [LTP] [PATCH] flock02: Add test for EWOULDBLOCK errno Avinesh Kumar
@ 2025-01-15  9:14 ` Andrea Cervesato via ltp
  2025-01-15 14:54   ` [LTP] [PATCH v2] " Avinesh Kumar
  0 siblings, 1 reply; 4+ messages in thread
From: Andrea Cervesato via ltp @ 2025-01-15  9:14 UTC (permalink / raw)
  To: Avinesh Kumar, ltp

Hi Avinesh,

On 1/14/25 16:49, Avinesh Kumar wrote:
> Also fix a make check warning.
>
> Signed-off-by: Avinesh Kumar <akumar@suse.de>
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
> Following up on https://lore.kernel.org/ltp/1934768.7Z3S40VBb9@localhost/
>
>   testcases/kernel/syscalls/flock/flock02.c | 10 +++++++++-
>   1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/testcases/kernel/syscalls/flock/flock02.c b/testcases/kernel/syscalls/flock/flock02.c
> index b8c7eee68..e2fe73a64 100644
> --- a/testcases/kernel/syscalls/flock/flock02.c
> +++ b/testcases/kernel/syscalls/flock/flock02.c
> @@ -13,6 +13,7 @@
>    * - EBADF if the file descriptor is invalid
>    * - EINVAL if the argument operation does not include LOCK_SH,LOCK_EX,LOCK_UN
>    * - EINVAL if an invalid combination of locking modes is used i.e LOCK_SH with LOCK_EX
> + * - EWOULDBLOCK if the file is locked and the LOCK_NB flag was selected
>    */
>   
>   #include <errno.h>
> @@ -31,13 +32,19 @@ static struct tcase {
>   	{&badfd, LOCK_SH, EBADF},
>   	{&fd, LOCK_NB, EINVAL},
>   	{&fd, LOCK_SH | LOCK_EX, EINVAL},
> +	{&fd, LOCK_NB | LOCK_EX, EWOULDBLOCK}
>   };
>   
> -static void verify_flock(unsigned n)
> +static void verify_flock(unsigned int n)
>   {
>   	struct tcase *tc = &tcases[n];
>   
>   	fd = SAFE_OPEN("testfile", O_RDWR);
> +	int fd2 = SAFE_OPEN("testfile", O_RDWR);
We can initialize fd2 at the beginning of verify_flock() with -1, open 
it only when tc->exp_err is EWOULDBLOCK and close it only when it's not 
-1. So we avoid to open one more testfile also for the other testcases.
> +
> +	if (tc->exp_err == EWOULDBLOCK)
> +		flock(fd2, LOCK_EX);
> +
>   	TEST(flock(*tc->fd, tc->operation));
>   	if (TST_RET == 0) {
>   		tst_res(TFAIL | TTERRNO, "flock() succeeded unexpectedly");
> @@ -53,6 +60,7 @@ static void verify_flock(unsigned n)
>   	}
>   
>   	SAFE_CLOSE(fd);
> +	SAFE_CLOSE(fd2);
>   }
>   
>   static void setup(void)
With that small thing:

Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>


Kind regards,
Andrea

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [LTP] [PATCH v2] flock02: Add test for EWOULDBLOCK errno
  2025-01-15  9:14 ` Andrea Cervesato via ltp
@ 2025-01-15 14:54   ` Avinesh Kumar
  2025-01-31 10:11     ` Petr Vorel
  0 siblings, 1 reply; 4+ messages in thread
From: Avinesh Kumar @ 2025-01-15 14:54 UTC (permalink / raw)
  To: ltp

Also fix a make check warning.

Signed-off-by: Avinesh Kumar <akumar@suse.de>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/kernel/syscalls/flock/flock02.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/flock/flock02.c b/testcases/kernel/syscalls/flock/flock02.c
index b8c7eee68..5c27c81a2 100644
--- a/testcases/kernel/syscalls/flock/flock02.c
+++ b/testcases/kernel/syscalls/flock/flock02.c
@@ -13,6 +13,7 @@
  * - EBADF if the file descriptor is invalid
  * - EINVAL if the argument operation does not include LOCK_SH,LOCK_EX,LOCK_UN
  * - EINVAL if an invalid combination of locking modes is used i.e LOCK_SH with LOCK_EX
+ * - EWOULDBLOCK if the file is locked and the LOCK_NB flag was selected
  */
 
 #include <errno.h>
@@ -31,13 +32,21 @@ static struct tcase {
 	{&badfd, LOCK_SH, EBADF},
 	{&fd, LOCK_NB, EINVAL},
 	{&fd, LOCK_SH | LOCK_EX, EINVAL},
+	{&fd, LOCK_NB | LOCK_EX, EWOULDBLOCK}
 };
 
-static void verify_flock(unsigned n)
+static void verify_flock(unsigned int n)
 {
+	int fd2 = -1;
 	struct tcase *tc = &tcases[n];
 
 	fd = SAFE_OPEN("testfile", O_RDWR);
+
+	if (tc->exp_err == EWOULDBLOCK) {
+		fd2 = SAFE_OPEN("testfile", O_RDWR);
+		flock(fd2, LOCK_EX);
+	}
+
 	TEST(flock(*tc->fd, tc->operation));
 	if (TST_RET == 0) {
 		tst_res(TFAIL | TTERRNO, "flock() succeeded unexpectedly");
@@ -53,6 +62,8 @@ static void verify_flock(unsigned n)
 	}
 
 	SAFE_CLOSE(fd);
+	if (fd2 != -1)
+		SAFE_CLOSE(fd2);
 }
 
 static void setup(void)
-- 
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v2] flock02: Add test for EWOULDBLOCK errno
  2025-01-15 14:54   ` [LTP] [PATCH v2] " Avinesh Kumar
@ 2025-01-31 10:11     ` Petr Vorel
  0 siblings, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2025-01-31 10:11 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi all,

v2 merged also with Andrea's RBT.
Thanks!

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-01-31 10:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-14 15:49 [LTP] [PATCH] flock02: Add test for EWOULDBLOCK errno Avinesh Kumar
2025-01-15  9:14 ` Andrea Cervesato via ltp
2025-01-15 14:54   ` [LTP] [PATCH v2] " Avinesh Kumar
2025-01-31 10:11     ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox