dup01.c: use TST_EXP_FD macro and add inode check
PATCH 1/5 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
--- testcases/kernel/syscalls/dup/dup01.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
testcases/kernel/syscalls/dup/dup01.c +15 -10
@@ -7,27 +7,32 @@* */ +/*\ +* [Description] +* +* Verify that dup(2) syscall executes successfully and allocates +* a new file descriptor which refers to the same open file as oldfd. +*/ +#include "tst_test.h" static int fd; +static struct stat buf1, buf2;static void verify_dup (void ) { -TEST (dup (fd)); - -if (TST_RET <-1 ) { -tst_res (TFAIL ,"Invalid dup() return value %ld" ,TST_RET ); - }else if (TST_RET ==-1 ) { -tst_res (TFAIL |TTERRNO ,"dup(%d) Failed" , fd); - }else { -tst_res (TPASS ,"dup(%d) returned %ld" , fd,TST_RET ); -SAFE_CLOSE (TST_RET ); - } +TST_EXP_FD (dup (fd),"dup(%d)" , fd); + +SAFE_FSTAT (TST_RET , &buf2); +TST_EXP_EQ_LU (buf1.st_ino, buf2.st_ino); + +SAFE_CLOSE (TST_RET ); }static void setup (void ) { fd =SAFE_OPEN ("dupfile" ,O_RDWR |O_CREAT ,0700 ); +SAFE_FSTAT (fd, &buf1); }static void cleanup (void )
Signature · 5 lines
2.40.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/5 dup02.c: Simplify using TST_EXP macro and doc rewording
--- testcases/kernel/syscalls/dup/dup02.c | 29 +++++---------------------- 1 file changed, 5 insertions(+), 24 deletions(-)
testcases/kernel/syscalls/dup/dup02.c +5 -24
@@ -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 = {
Signature · 5 lines
2.40.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 3/5 dup03.c: use TST_EXP macro and make check fixes
In reply to Avinesh Kumar- use TST_EXP_FAIL2() macro for expected failure check
- make check fixes: change vars to static
- reword doc comment
--- testcases/kernel/syscalls/dup/dup03.c | 34 +++++++-------------------- 1 file changed, 8 insertions(+), 26 deletions(-)
testcases/kernel/syscalls/dup/dup03.c +8 -26
@@ -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 );
Signature · 5 lines
2.40.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 4/5 dup04.c: use TST_EXP_FD macro and make check fixes
In reply to Avinesh Kumar+ updade copyright
--- testcases/kernel/syscalls/dup/dup04.c | 44 ++++++++------------------- 1 file changed, 12 insertions(+), 32 deletions(-)
testcases/kernel/syscalls/dup/dup04.c +12 -32
@@ -1,12 +1,12 @@// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. -* * 06/1994 AUTHOR: Richard Logan CO-PILOT: William Roske +* Copyright (c) 2023 SUSE LLC */ /*\ -* [DESCRIPTION] +* [Description] * * Basic test for dup(2) of a system pipe descriptor. */
@@ -17,38 +17,18 @@#include "tst_test.h" -int fd[2 ]; +static int fd[2 ];static void run (void ) { -TEST (dup (fd[0 ])); - -if (TST_RET ==-1 ) -tst_res (TFAIL |TTERRNO , -"dup of read side of pipe failed" ); -else { -tst_res (TPASS , -"dup(%d) read side of syspipe returned %ld" , - fd[0 ],TST_RET ); - -SAFE_CLOSE (TST_RET ); - } - -TEST (dup (fd[1 ])); - -if (TST_RET ==-1 ) { -tst_res (TFAIL |TTERRNO , -"dup of write side of pipe failed" ); - }else { -tst_res (TPASS , -"dup(%d) write side of syspipe returned %ld" , - fd[1 ],TST_RET ); - -SAFE_CLOSE (TST_RET ); - } +TST_EXP_FD (dup (fd[0 ]),"dup(%d) read end of the pipe" , fd[0 ]); +SAFE_CLOSE (TST_RET ); + +TST_EXP_FD (dup (fd[1 ]),"dup(%d) write end of the pipe" , fd[1 ]); +SAFE_CLOSE (TST_RET ); } -void setup (void ) +static void setup (void ) { fd[0 ] =-1 ;
@@ -56,7 +36,7 @@ void setup(void) }static struct tst_test test = { - .test_all = run, - .setup = setup, - .needs_tmpdir =1 , + .test_all = run, + .setup = setup, + .needs_tmpdir =1 , };
Signature · 5 lines
2.40.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 5/5 dup05.c: use TST_EXP_FD() macro and make check fixes
In reply to Avinesh Kumar+ update copyright.
+ use SAFE_OPEN() and SAFE_CLOSE()
--- testcases/kernel/syscalls/dup/dup05.c | 40 ++++++++++----------------- 1 file changed, 15 insertions(+), 25 deletions(-)
testcases/kernel/syscalls/dup/dup05.c +15 -25
@@ -1,55 +1,45 @@// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. -* * 06/1994 AUTHOR: Richard Logan CO-PILOT: William Roske +* Copyright (c) 2023 SUSE LLC */ /*\ -* [DESCRIPTION] +* [Description] * * Basic test for dup(2) of a named pipe descriptor */ -#include <stdio.h> +#include "tst_test.h" -char Fname[255 ]; -int fd; +#define Fname "dupfile" + +static int fd;static void run (void ) { -TEST (dup (fd)); - -if (TST_RET ==-1 ) { -tst_res (TFAIL |TTERRNO ,"dup failed" ); - }else { -tst_res (TPASS ,"dup returned %ld" , -TST_RET ); - -SAFE_CLOSE (TST_RET ); - } +TST_EXP_FD (dup (fd),"dup(%d)" , fd); +SAFE_CLOSE (TST_RET ); } -void setup (void ) +static void setup (void ) { fd =-1 ; -sprintf (Fname,"dupfile" );SAFE_MKFIFO (Fname,0777 ); -if ((fd =open (Fname,O_RDWR ,0700 )) ==-1 ) -tst_brk (TBROK ,"open failed" ); + fd =SAFE_OPEN (Fname,O_RDWR ,0700 ); } -void cleanup (void ) +static void cleanup (void ) {if (fd !=-1 ) -if (close (fd) ==-1 ) -tst_res (TWARN |TERRNO ,"close failed" ); +SAFE_CLOSE (fd); }static struct tst_test test = { - .test_all = run, - .setup = setup, - .cleanup = cleanup, + .test_all = run, + .setup = setup, + .cleanup = cleanup, .needs_tmpdir =1 , };
Signature · 5 lines
2.40.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 5/5] dup05.c: use TST_EXP_FD() macro and make check fixes
Hi Avinesh,
I slightly modified some of the commits and merged the patchset. Thanks!
Quoted 2 lines
+ update copyright.
+ useSAFE_OPEN()andSAFE_CLOSE()
...
Quoted 3 lines
/*\
- * [DESCRIPTION]
+ * [Description]
+1
testcases/kernel/syscalls/dup/dup05.c line 16
Quoted 10 lines
*
* Basic test for dup(2) of a named pipe descriptor */testcases/kernel/syscalls/dup/dup05.c +2
-3-#include <stdio.h> +#include "tst_test.h" -char Fname[255 ]; -int fd; +#define Fname "dupfile"
FYI I renamed to FNAME (don't hesitate to rename constants which aren't lowercase or variables with very long name (expected_errno => exp_err - used widely in LTP).
Quoted 13 lines
testcases/kernel/syscalls/dup/dup05.c +2
-8+ +static int fd;static void run (void ) { -TEST (dup (fd)); - -if (TST_RET ==-1 ) { -tst_res (TFAIL |TTERRNO ,"dup failed" ); - }else { -tst_res (TPASS ,"dup returned %ld" , -TST_RET ); -
testcases/kernel/syscalls/dup/dup05.c line 28
Quoted 10 lines
testcases/kernel/syscalls/dup/dup05.c +3
-3-SAFE_CLOSE (TST_RET ); - } +TST_EXP_FD (dup (fd),"dup(%d)" , fd); +SAFE_CLOSE (TST_RET ); } -void setup (void ) +static void setup (void ) { fd =-1 ;
FYI I moved -1 to declaration:
static int fd = -1;
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Avinesh,
Quoted 2 lines
--- testcases/kernel/syscalls/dup/dup01.c | 25 +++++++++++++++----------
...
testcases/kernel/syscalls/dup/dup01.c line 24
Quoted 3 lines
static void
verify_dup(void)
{testcases/kernel/syscalls/dup/dup01.c +1
-0+TST_EXP_FD (dup (fd),"dup(%d)" , fd);
IMHO only this is enough:
TST_EXP_FD(dup(fd));
Kind regards,
Petr
Quoted 6 lines
testcases/kernel/syscalls/dup/dup01.c +5
-0+ +SAFE_FSTAT (TST_RET , &buf2); +TST_EXP_EQ_LU (buf1.st_ino, buf2.st_ino); + +SAFE_CLOSE (TST_RET ); }
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Petr,
Quoted 5 lines
testcases/kernel/syscalls/dup/dup01.c line 24
Quoted 1 line
testcases/kernel/syscalls/dup/dup01.c +1
-0+TST_EXP_FD (dup (fd),"dup(%d)" , fd);IMHO only this is enough:
TST_EXP_FD(dup(fd));
okay, please update when you merge, if everything else is fine.
Thank you,
Avinesh
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Avinesh,
merged this one. Thanks!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp