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

Avinesh Kumar akumar@suse.de
Thu Apr 27 14:07:56 CEST 2023


- 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



More information about the ltp mailing list