diff mbox series

[1/5] dup01.c: use TST_EXP_FD macro and add inode check

Message ID 20230427120800.27849-1-akumar@suse.de
State Accepted
Headers show
Series [1/5] dup01.c: use TST_EXP_FD macro and add inode check | expand

Commit Message

Avinesh Kumar April 27, 2023, 12:07 p.m. UTC
- 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(-)

Comments

Petr Vorel May 2, 2023, 11:18 a.m. UTC | #1
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);
>  }
Avinesh Kumar May 5, 2023, 4:55 a.m. UTC | #2
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
Petr Vorel May 29, 2023, 5:42 a.m. UTC | #3
Hi Avinesh,

merged this one. Thanks!

Kind regards,
Petr
diff mbox series

Patch

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)