diff mbox series

[2/5] dup02.c: Simplify using TST_EXP macro and doc rewording

Message ID 20230427120800.27849-2-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
Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 testcases/kernel/syscalls/dup/dup02.c | 29 +++++----------------------
 1 file changed, 5 insertions(+), 24 deletions(-)
diff mbox series

Patch

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 = {