[LTP] [PATCH 3/5] dup03.c: use TST_EXP macro and make check fixes

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


- 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



More information about the ltp mailing list