Skip to content

Commit cd49c9d

Browse files
Avineshpevik
authored andcommitted
dup02.c: Simplify using TST_EXP macro and doc rewording
Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Avinesh Kumar <[email protected]> Signed-off-by: Petr Vorel <[email protected]>
1 parent 5b3c76e commit cd49c9d

File tree

1 file changed

+7
-27
lines changed
  • testcases/kernel/syscalls/dup

1 file changed

+7
-27
lines changed

testcases/kernel/syscalls/dup/dup02.c

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@
22
/*
33
* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
44
* Copyright (c) 2020 SUSE LLC
5-
*
65
* 03/30/1992 AUTHOR: Richard Logan CO-PILOT: William Roske
7-
*
86
*/
7+
98
/*\
109
* [Description]
11-
* Negative test for dup(2) with bad fds.
1210
*
13-
* [Algorithm]
14-
* Call dup(2) with invalid argument and make sure it returns -1 with errno set
15-
* to EBADF.
11+
* Verify that dup(2) syscall fails with errno EBADF when called with
12+
* invalid value for oldfd argument.
1613
*/
1714

1815
#include "tst_test.h"
1916

2017
static struct tcase {
2118
int fd;
22-
int expected_errno;
19+
int exp_err;
2320
} tcases[] = {
2421
{-1, EBADF},
2522
{1500, EBADF},
@@ -29,27 +26,10 @@ static void run(unsigned int n)
2926
{
3027
struct tcase *tc = &tcases[n];
3128

32-
TEST(dup(tc->fd));
33-
34-
if (TST_RET < -1) {
35-
tst_res(TFAIL | TTERRNO, "Invalid dup() return value %ld",
36-
TST_RET);
37-
return;
38-
}
39-
40-
if (TST_RET == -1) {
41-
if (tc->expected_errno == TST_ERR) {
42-
tst_res(TPASS | TTERRNO, "dup(%d) failed as expected",
43-
tc->fd);
44-
} else {
45-
tst_res(TFAIL | TTERRNO, "dup(%d) failed unexpectedly",
46-
tc->fd);
47-
}
48-
return;
49-
}
29+
TST_EXP_FAIL2(dup(tc->fd), tc->exp_err, "dup(%d)", tc->fd);
5030

51-
tst_res(TFAIL, "dup(%d) succeeded unexpectedly", tc->fd);
52-
SAFE_CLOSE(TST_RET);
31+
if (TST_RET != -1)
32+
SAFE_CLOSE(TST_RET);
5333
}
5434

5535
static struct tst_test test = {

0 commit comments

Comments
 (0)