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

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).