Skip to content

Commit 1d7b974

Browse files
Avineshpevik
authored andcommitted
dup01.c: use TST_EXP_FD macro and add inode check
- simplify using TST_EXP_FD() macro - add inode comparison check for the newly allocated file descriptor - add test description Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Avinesh Kumar <[email protected]>
1 parent 604701d commit 1d7b974

File tree

1 file changed

+15
-10
lines changed
  • testcases/kernel/syscalls/dup

1 file changed

+15
-10
lines changed

testcases/kernel/syscalls/dup/dup01.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,32 @@
77
*
88
*/
99

10+
/*\
11+
* [Description]
12+
*
13+
* Verify that dup(2) syscall executes successfully and allocates
14+
* a new file descriptor which refers to the same open file as oldfd.
15+
*/
16+
1017
#include "tst_test.h"
1118

1219
static int fd;
20+
static struct stat buf1, buf2;
1321

1422
static void verify_dup(void)
1523
{
16-
TEST(dup(fd));
17-
18-
if (TST_RET < -1) {
19-
tst_res(TFAIL, "Invalid dup() return value %ld", TST_RET);
20-
} else if (TST_RET == -1) {
21-
tst_res(TFAIL | TTERRNO, "dup(%d) Failed", fd);
22-
} else {
23-
tst_res(TPASS, "dup(%d) returned %ld", fd, TST_RET);
24-
SAFE_CLOSE(TST_RET);
25-
}
24+
TST_EXP_FD(dup(fd));
25+
26+
SAFE_FSTAT(TST_RET, &buf2);
27+
TST_EXP_EQ_LU(buf1.st_ino, buf2.st_ino);
28+
29+
SAFE_CLOSE(TST_RET);
2630
}
2731

2832
static void setup(void)
2933
{
3034
fd = SAFE_OPEN("dupfile", O_RDWR | O_CREAT, 0700);
35+
SAFE_FSTAT(fd, &buf1);
3136
}
3237

3338
static void cleanup(void)

0 commit comments

Comments
 (0)