ltp.lists.linux.it archive mirror
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/5] dup01.c: use TST_EXP_FD macro and add inode check
@ 2023-04-27 12:07 Avinesh Kumar
  2023-04-27 12:07 ` [LTP] [PATCH 2/5] dup02.c: Simplify using TST_EXP macro and doc rewording Avinesh Kumar
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Avinesh Kumar @ 2023-04-27 12:07 UTC (permalink / raw)
  To: ltp

- simplify using TST_EXP_FD() macro
- add inode comparison check for the newly allocated file descriptor
- add test description

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/dup/dup01.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/testcases/kernel/syscalls/dup/dup01.c b/testcases/kernel/syscalls/dup/dup01.c
index 74e24cc02..ce6f39ed3 100644
--- a/testcases/kernel/syscalls/dup/dup01.c
+++ b/testcases/kernel/syscalls/dup/dup01.c
@@ -7,27 +7,32 @@
  *
  */
 
+/*\
+ * [Description]
+ *
+ * Verify that dup(2) syscall executes successfully and allocates
+ * a new file descriptor which refers to the same open file as oldfd.
+ */
+
 #include "tst_test.h"
 
 static int fd;
+static struct stat buf1, buf2;
 
 static void verify_dup(void)
 {
-	TEST(dup(fd));
-
-	if (TST_RET < -1) {
-		tst_res(TFAIL, "Invalid dup() return value %ld", TST_RET);
-	} else if (TST_RET == -1) {
-		tst_res(TFAIL | TTERRNO, "dup(%d) Failed", fd);
-	} else {
-		tst_res(TPASS, "dup(%d) returned %ld", fd, TST_RET);
-		SAFE_CLOSE(TST_RET);
-	}
+	TST_EXP_FD(dup(fd), "dup(%d)", fd);
+
+	SAFE_FSTAT(TST_RET, &buf2);
+	TST_EXP_EQ_LU(buf1.st_ino, buf2.st_ino);
+
+	SAFE_CLOSE(TST_RET);
 }
 
 static void setup(void)
 {
 	fd = SAFE_OPEN("dupfile", O_RDWR | O_CREAT, 0700);
+	SAFE_FSTAT(fd, &buf1);
 }
 
 static void cleanup(void)
-- 
2.40.0


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

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

* [LTP] [PATCH 2/5] dup02.c: Simplify using TST_EXP macro and doc rewording
  2023-04-27 12:07 [LTP] [PATCH 1/5] dup01.c: use TST_EXP_FD macro and add inode check Avinesh Kumar
@ 2023-04-27 12:07 ` Avinesh Kumar
  2023-04-27 12:07 ` [LTP] [PATCH 3/5] dup03.c: use TST_EXP macro and make check fixes Avinesh Kumar
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Avinesh Kumar @ 2023-04-27 12:07 UTC (permalink / raw)
  To: ltp

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/dup/dup02.c | 29 +++++----------------------
 1 file changed, 5 insertions(+), 24 deletions(-)

diff --git a/testcases/kernel/syscalls/dup/dup02.c b/testcases/kernel/syscalls/dup/dup02.c
index 528bcdbc1..1bb1d5be3 100644
--- a/testcases/kernel/syscalls/dup/dup02.c
+++ b/testcases/kernel/syscalls/dup/dup02.c
@@ -8,11 +8,9 @@
  */
 /*\
  * [Description]
- * Negative test for dup(2) with bad fds.
  *
- * [Algorithm]
- * Call dup(2) with invalid argument and make sure it returns -1 with errno set
- * to EBADF.
+ * Verify that dup(2) syscall fails with errno EBADF when called with
+ * invalid value for oldfd argument.
  */
 
 #include "tst_test.h"
@@ -29,27 +27,10 @@ static void run(unsigned int n)
 {
 	struct tcase *tc = &tcases[n];
 
-	TEST(dup(tc->fd));
+	TST_EXP_FAIL2(dup(tc->fd), tc->expected_errno, "dup(%d)", tc->fd);
 
-	if (TST_RET < -1) {
-		tst_res(TFAIL | TTERRNO, "Invalid dup() return value %ld",
-			TST_RET);
-		return;
-	}
-
-	if (TST_RET == -1) {
-		if (tc->expected_errno == TST_ERR) {
-			tst_res(TPASS | TTERRNO, "dup(%d) failed as expected",
-				tc->fd);
-		} else {
-			tst_res(TFAIL | TTERRNO, "dup(%d) failed unexpectedly",
-				tc->fd);
-		}
-		return;
-	}
-
-	tst_res(TFAIL, "dup(%d) succeeded unexpectedly", tc->fd);
-	SAFE_CLOSE(TST_RET);
+	if (TST_RET != -1)
+		SAFE_CLOSE(TST_RET);
 }
 
 static struct tst_test test = {
-- 
2.40.0


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

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

* [LTP] [PATCH 3/5] dup03.c: use TST_EXP macro and make check fixes
  2023-04-27 12:07 [LTP] [PATCH 1/5] dup01.c: use TST_EXP_FD macro and add inode check Avinesh Kumar
  2023-04-27 12:07 ` [LTP] [PATCH 2/5] dup02.c: Simplify using TST_EXP macro and doc rewording Avinesh Kumar
@ 2023-04-27 12:07 ` Avinesh Kumar
  2023-04-27 12:07 ` [LTP] [PATCH 4/5] dup04.c: use TST_EXP_FD " Avinesh Kumar
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Avinesh Kumar @ 2023-04-27 12:07 UTC (permalink / raw)
  To: ltp

- use TST_EXP_FAIL2() macro for expected failure check
- make check fixes: change vars to static
- reword doc comment

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/dup/dup03.c | 34 +++++++--------------------
 1 file changed, 8 insertions(+), 26 deletions(-)

diff --git a/testcases/kernel/syscalls/dup/dup03.c b/testcases/kernel/syscalls/dup/dup03.c
index 0e99813f4..d59e61f2b 100644
--- a/testcases/kernel/syscalls/dup/dup03.c
+++ b/testcases/kernel/syscalls/dup/dup03.c
@@ -6,48 +6,30 @@
  */
 /*\
  * [Description]
- * Negative test for dup(2) (too many fds).
  *
- * [Algorithm]
- * Open the maximum allowed number of file descriptors and then try to call
- * dup() once more and verify it fails with EMFILE.
+ * Verify that dup(2) syscall fails with errno EMFILE when the per-process
+ * limit on the number of open file descriptors has been reached.
  */
 
 #include <stdlib.h>
 #include "tst_test.h"
 
-int *fd;
-int nfds;
+static int *fd;
+static int nfds;
 
 static void run(void)
 {
-	TEST(dup(fd[0]));
+	TST_EXP_FAIL2(dup(fd[0]), EMFILE, "dup(%d)", fd[0]);
 
-	if (TST_RET < -1) {
-		tst_res(TFAIL, "Invalid dup() return value %ld", TST_RET);
-		return;
-	}
-
-	if (TST_RET == -1) {
-		if (TST_ERR == EMFILE)
-			tst_res(TPASS | TTERRNO, "dup() failed as expected");
-		else
-			tst_res(TFAIL | TTERRNO, "dup() failed unexpectedly");
-		return;
-	}
-
-	tst_res(TFAIL, "dup() succeeded unexpectedly");
-	SAFE_CLOSE(TST_RET);
+	if (TST_RET != -1)
+		SAFE_CLOSE(TST_RET);
 }
 
 static void setup(void)
 {
 	long maxfds;
 
-	maxfds = sysconf(_SC_OPEN_MAX);
-	if (maxfds == -1)
-		tst_brk(TBROK, "sysconf(_SC_OPEN_MAX) failed");
-
+	maxfds = SAFE_SYSCONF(_SC_OPEN_MAX);
 	fd = SAFE_MALLOC(maxfds * sizeof(int));
 
 	fd[0] = SAFE_OPEN("dupfile", O_RDWR | O_CREAT, 0700);
-- 
2.40.0


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

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

* [LTP] [PATCH 4/5] dup04.c: use TST_EXP_FD macro and make check fixes
  2023-04-27 12:07 [LTP] [PATCH 1/5] dup01.c: use TST_EXP_FD macro and add inode check Avinesh Kumar
  2023-04-27 12:07 ` [LTP] [PATCH 2/5] dup02.c: Simplify using TST_EXP macro and doc rewording Avinesh Kumar
  2023-04-27 12:07 ` [LTP] [PATCH 3/5] dup03.c: use TST_EXP macro and make check fixes Avinesh Kumar
@ 2023-04-27 12:07 ` Avinesh Kumar
  2023-04-27 12:08 ` [LTP] [PATCH 5/5] dup05.c: use TST_EXP_FD() " Avinesh Kumar
  2023-05-02 11:18 ` [LTP] [PATCH 1/5] dup01.c: use TST_EXP_FD macro and add inode check Petr Vorel
  4 siblings, 0 replies; 9+ messages in thread
From: Avinesh Kumar @ 2023-04-27 12:07 UTC (permalink / raw)
  To: ltp

+ updade copyright

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/dup/dup04.c | 44 ++++++++-------------------
 1 file changed, 12 insertions(+), 32 deletions(-)

diff --git a/testcases/kernel/syscalls/dup/dup04.c b/testcases/kernel/syscalls/dup/dup04.c
index 8d45f7a9c..053fb40c2 100644
--- a/testcases/kernel/syscalls/dup/dup04.c
+++ b/testcases/kernel/syscalls/dup/dup04.c
@@ -1,12 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
  * 06/1994 AUTHOR: Richard Logan CO-PILOT: William Roske
+ * Copyright (c) 2023 SUSE LLC
  */
 
 /*\
- * [DESCRIPTION]
+ * [Description]
  *
  * Basic test for dup(2) of a system pipe descriptor.
  */
@@ -17,38 +17,18 @@
 
 #include "tst_test.h"
 
-int fd[2];
+static int fd[2];
 
 static void run(void)
 {
-	TEST(dup(fd[0]));
-
-	if (TST_RET == -1)
-		tst_res(TFAIL | TTERRNO,
-			 "dup of read side of pipe failed");
-	else {
-		tst_res(TPASS,
-			 "dup(%d) read side of syspipe returned %ld",
-			 fd[0], TST_RET);
-
-		SAFE_CLOSE(TST_RET);
-	}
-
-	TEST(dup(fd[1]));
-
-	if (TST_RET == -1) {
-		tst_res(TFAIL | TTERRNO,
-			 "dup of write side of pipe failed");
-	} else {
-		tst_res(TPASS,
-			 "dup(%d) write side of syspipe returned %ld",
-			 fd[1], TST_RET);
-
-		SAFE_CLOSE(TST_RET);
-	}
+	TST_EXP_FD(dup(fd[0]), "dup(%d) read end of the pipe", fd[0]);
+	SAFE_CLOSE(TST_RET);
+
+	TST_EXP_FD(dup(fd[1]), "dup(%d) write end of the pipe", fd[1]);
+	SAFE_CLOSE(TST_RET);
 }
 
-void setup(void)
+static void setup(void)
 {
 	fd[0] = -1;
 
@@ -56,7 +36,7 @@ void setup(void)
 }
 
 static struct tst_test test = {
-        .test_all = run,
-        .setup = setup,
-        .needs_tmpdir = 1,
+	.test_all = run,
+	.setup = setup,
+	.needs_tmpdir = 1,
 };
-- 
2.40.0


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

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

* [LTP] [PATCH 5/5] dup05.c: use TST_EXP_FD() macro and make check fixes
  2023-04-27 12:07 [LTP] [PATCH 1/5] dup01.c: use TST_EXP_FD macro and add inode check Avinesh Kumar
                   ` (2 preceding siblings ...)
  2023-04-27 12:07 ` [LTP] [PATCH 4/5] dup04.c: use TST_EXP_FD " Avinesh Kumar
@ 2023-04-27 12:08 ` Avinesh Kumar
  2023-05-29 18:20   ` Petr Vorel
  2023-05-02 11:18 ` [LTP] [PATCH 1/5] dup01.c: use TST_EXP_FD macro and add inode check Petr Vorel
  4 siblings, 1 reply; 9+ messages in thread
From: Avinesh Kumar @ 2023-04-27 12:08 UTC (permalink / raw)
  To: ltp

+ update copyright.
+ use SAFE_OPEN() and SAFE_CLOSE()

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/dup/dup05.c | 40 ++++++++++-----------------
 1 file changed, 15 insertions(+), 25 deletions(-)

diff --git a/testcases/kernel/syscalls/dup/dup05.c b/testcases/kernel/syscalls/dup/dup05.c
index 362f3e170..375fa36a7 100644
--- a/testcases/kernel/syscalls/dup/dup05.c
+++ b/testcases/kernel/syscalls/dup/dup05.c
@@ -1,55 +1,45 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
  * 06/1994 AUTHOR: Richard Logan CO-PILOT: William Roske
+ * Copyright (c) 2023 SUSE LLC
  */
 
 /*\
- * [DESCRIPTION]
+ * [Description]
  *
  * Basic test for dup(2) of a named pipe descriptor
  */
-#include <stdio.h>
+
 #include "tst_test.h"
 
-char Fname[255];
-int fd;
+#define Fname "dupfile"
+
+static int fd;
 
 static void run(void)
 {
-	TEST(dup(fd));
-
-	if (TST_RET == -1) {
-		tst_res(TFAIL | TTERRNO, "dup failed");
-	} else {
-		tst_res(TPASS, "dup returned %ld",
-			 TST_RET);
-
-		SAFE_CLOSE(TST_RET);
-	}
+	TST_EXP_FD(dup(fd), "dup(%d)", fd);
+	SAFE_CLOSE(TST_RET);
 }
 
-void setup(void)
+static void setup(void)
 {
 	fd = -1;
 
-	sprintf(Fname, "dupfile");
 	SAFE_MKFIFO(Fname, 0777);
-	if ((fd = open(Fname, O_RDWR, 0700)) == -1)
-		tst_brk(TBROK, "open failed");
+	fd = SAFE_OPEN(Fname, O_RDWR, 0700);
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
 	if (fd != -1)
-		if (close(fd) == -1)
-			tst_res(TWARN | TERRNO, "close failed");
+		SAFE_CLOSE(fd);
 }
 
 static struct tst_test test = {
-        .test_all = run,
-        .setup = setup,
-        .cleanup = cleanup,
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
 	.needs_tmpdir = 1,
 };
-- 
2.40.0


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

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

* Re: [LTP] [PATCH 1/5] dup01.c: use TST_EXP_FD macro and add inode check
  2023-04-27 12:07 [LTP] [PATCH 1/5] dup01.c: use TST_EXP_FD macro and add inode check Avinesh Kumar
                   ` (3 preceding siblings ...)
  2023-04-27 12:08 ` [LTP] [PATCH 5/5] dup05.c: use TST_EXP_FD() " Avinesh Kumar
@ 2023-05-02 11:18 ` Petr Vorel
  2023-05-05  4:55   ` Avinesh Kumar
  4 siblings, 1 reply; 9+ messages in thread
From: Petr Vorel @ 2023-05-02 11:18 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi Avinesh,

> ---
>  testcases/kernel/syscalls/dup/dup01.c | 25 +++++++++++++++----------
...
>  static void verify_dup(void)
>  {
> +	TST_EXP_FD(dup(fd), "dup(%d)", fd);
IMHO only this is enough:
TST_EXP_FD(dup(fd));

Kind regards,
Petr

> +
> +	SAFE_FSTAT(TST_RET, &buf2);
> +	TST_EXP_EQ_LU(buf1.st_ino, buf2.st_ino);
> +
> +	SAFE_CLOSE(TST_RET);
>  }

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

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

* Re: [LTP] [PATCH 1/5] dup01.c: use TST_EXP_FD macro and add inode check
  2023-05-02 11:18 ` [LTP] [PATCH 1/5] dup01.c: use TST_EXP_FD macro and add inode check Petr Vorel
@ 2023-05-05  4:55   ` Avinesh Kumar
  2023-05-29  5:42     ` Petr Vorel
  0 siblings, 1 reply; 9+ messages in thread
From: Avinesh Kumar @ 2023-05-05  4:55 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi Petr,

> > +	TST_EXP_FD(dup(fd), "dup(%d)", fd);
> 
> IMHO only this is enough:
> TST_EXP_FD(dup(fd));
> 
okay, please update when you merge, if everything else is fine.

Thank you,
Avinesh




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

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

* Re: [LTP] [PATCH 1/5] dup01.c: use TST_EXP_FD macro and add inode check
  2023-05-05  4:55   ` Avinesh Kumar
@ 2023-05-29  5:42     ` Petr Vorel
  0 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2023-05-29  5:42 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi Avinesh,

merged this one. Thanks!

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH 5/5] dup05.c: use TST_EXP_FD() macro and make check fixes
  2023-04-27 12:08 ` [LTP] [PATCH 5/5] dup05.c: use TST_EXP_FD() " Avinesh Kumar
@ 2023-05-29 18:20   ` Petr Vorel
  0 siblings, 0 replies; 9+ messages in thread
From: Petr Vorel @ 2023-05-29 18:20 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi Avinesh,

I slightly modified some of the commits and merged the patchset.
Thanks!

> + update copyright.
> + use SAFE_OPEN() and SAFE_CLOSE()


...
>  /*\
> - * [DESCRIPTION]
> + * [Description]
+1

>   *
>   * Basic test for dup(2) of a named pipe descriptor
>   */
> -#include <stdio.h>
> +
>  #include "tst_test.h"

> -char Fname[255];
> -int fd;
> +#define Fname "dupfile"
FYI I renamed to FNAME (don't hesitate to rename constants which aren't
lowercase or variables with very long name (expected_errno => exp_err - used
widely in LTP).

> +
> +static int fd;

>  static void run(void)
>  {
> -	TEST(dup(fd));
> -
> -	if (TST_RET == -1) {
> -		tst_res(TFAIL | TTERRNO, "dup failed");
> -	} else {
> -		tst_res(TPASS, "dup returned %ld",
> -			 TST_RET);
> -
> -		SAFE_CLOSE(TST_RET);
> -	}
> +	TST_EXP_FD(dup(fd), "dup(%d)", fd);
> +	SAFE_CLOSE(TST_RET);
>  }

> -void setup(void)
> +static void setup(void)
>  {
>  	fd = -1;
FYI I moved -1 to declaration:
static int fd = -1;

Kind regards,
Petr

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

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

end of thread, other threads:[~2023-05-29 18:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-27 12:07 [LTP] [PATCH 1/5] dup01.c: use TST_EXP_FD macro and add inode check Avinesh Kumar
2023-04-27 12:07 ` [LTP] [PATCH 2/5] dup02.c: Simplify using TST_EXP macro and doc rewording Avinesh Kumar
2023-04-27 12:07 ` [LTP] [PATCH 3/5] dup03.c: use TST_EXP macro and make check fixes Avinesh Kumar
2023-04-27 12:07 ` [LTP] [PATCH 4/5] dup04.c: use TST_EXP_FD " Avinesh Kumar
2023-04-27 12:08 ` [LTP] [PATCH 5/5] dup05.c: use TST_EXP_FD() " Avinesh Kumar
2023-05-29 18:20   ` Petr Vorel
2023-05-02 11:18 ` [LTP] [PATCH 1/5] dup01.c: use TST_EXP_FD macro and add inode check Petr Vorel
2023-05-05  4:55   ` Avinesh Kumar
2023-05-29  5:42     ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).