Skip to content

Commit d09b1eb

Browse files
Avineshpevik
authored andcommitted
dup03.c: use TST_EXP macro and make check fixes
- use TST_EXP_FAIL2() macro for expected failure check - make check fixes: change vars to static - reword doc comment Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Avinesh Kumar <[email protected]>
1 parent cd49c9d commit d09b1eb

File tree

1 file changed

+8
-26
lines changed
  • testcases/kernel/syscalls/dup

1 file changed

+8
-26
lines changed

testcases/kernel/syscalls/dup/dup03.c

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,30 @@
66
*/
77
/*\
88
* [Description]
9-
* Negative test for dup(2) (too many fds).
109
*
11-
* [Algorithm]
12-
* Open the maximum allowed number of file descriptors and then try to call
13-
* dup() once more and verify it fails with EMFILE.
10+
* Verify that dup(2) syscall fails with errno EMFILE when the per-process
11+
* limit on the number of open file descriptors has been reached.
1412
*/
1513

1614
#include <stdlib.h>
1715
#include "tst_test.h"
1816

19-
int *fd;
20-
int nfds;
17+
static int *fd;
18+
static int nfds;
2119

2220
static void run(void)
2321
{
24-
TEST(dup(fd[0]));
22+
TST_EXP_FAIL2(dup(fd[0]), EMFILE, "dup(%d)", fd[0]);
2523

26-
if (TST_RET < -1) {
27-
tst_res(TFAIL, "Invalid dup() return value %ld", TST_RET);
28-
return;
29-
}
30-
31-
if (TST_RET == -1) {
32-
if (TST_ERR == EMFILE)
33-
tst_res(TPASS | TTERRNO, "dup() failed as expected");
34-
else
35-
tst_res(TFAIL | TTERRNO, "dup() failed unexpectedly");
36-
return;
37-
}
38-
39-
tst_res(TFAIL, "dup() succeeded unexpectedly");
40-
SAFE_CLOSE(TST_RET);
24+
if (TST_RET != -1)
25+
SAFE_CLOSE(TST_RET);
4126
}
4227

4328
static void setup(void)
4429
{
4530
long maxfds;
4631

47-
maxfds = sysconf(_SC_OPEN_MAX);
48-
if (maxfds == -1)
49-
tst_brk(TBROK, "sysconf(_SC_OPEN_MAX) failed");
50-
32+
maxfds = SAFE_SYSCONF(_SC_OPEN_MAX);
5133
fd = SAFE_MALLOC(maxfds * sizeof(int));
5234

5335
fd[0] = SAFE_OPEN("dupfile", O_RDWR | O_CREAT, 0700);

0 commit comments

Comments
 (0)