Simplify and convert some of rename tests to new LTP API
v2 cover Simplify and convert some of rename tests to new LTP API
Rewriting some of rename tests using new LPT API and removing rename02.c file as same testcase is covered in rename01.c.
Avinesh Kumar (9):
Rewrite rename01.c using new LTP API
Remove rename02.c
Rewrite rename03.c using new LTP API
Rewrite rename04.c using new LTP API
Rewrite rename05.c using new LTP API
Rewrite rename06.c using new LTP API
Rewrite rename07.c using new LTP API
Rewrite rename08.c using new LTP API
Rewrite rename10.c using new LTP API
runtest/syscalls | 1 - testcases/kernel/syscalls/rename/.gitignore | 1 - testcases/kernel/syscalls/rename/rename01.c | 259 +++++------------- testcases/kernel/syscalls/rename/rename02.c | 192 -------------- testcases/kernel/syscalls/rename/rename03.c | 274 ++++---------------- testcases/kernel/syscalls/rename/rename04.c | 201 +++----------- testcases/kernel/syscalls/rename/rename05.c | 189 ++------------ testcases/kernel/syscalls/rename/rename06.c | 182 ++----------- testcases/kernel/syscalls/rename/rename07.c | 166 ++---------- testcases/kernel/syscalls/rename/rename08.c | 200 ++------------ testcases/kernel/syscalls/rename/rename10.c | 182 ++----------- 11 files changed, 264 insertions(+), 1583 deletions(-) delete mode 100644 testcases/kernel/syscalls/rename/rename02.c
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/9 Rewrite rename01.c using new LTP API
--- testcases/kernel/syscalls/rename/rename01.c | 259 +++++--------------- 1 file changed, 58 insertions(+), 201 deletions(-)
testcases/kernel/syscalls/rename/rename01.c +58 -201
@@ -1,218 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* -* Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]> */ -/* -* NAME -* rename01 -* -* DESCRIPTION -* This test will verify the rename(2) syscall basic functionality. -* Verify rename() works when the "new" file or directory does not exist. +/*\ +* [Description] * -* ALGORITHM -* Setup: -* Setup signal handling. -* Create temporary directory. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* 1. "old" is plain file, new does not exists -* create the "old" file, make sure the "new" file -* dose not exist -* rename the "old" to the "new" file -* verify the "new" file points to the "old" file -* verify the "old" file does not exist -* -* 2. "old" is a directory,"new" does not exists -* create the "old" directory, make sure "new" -* dose not exist -* rename the "old" to the "new" -* verify the "new" points to the "old" -* verify the "old" does not exist -* Cleanup: -* Print errno log and/or timing stats if options given -* Delete the temporary directory created. -* -* USAGE -* rename01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -f : Turn off functionality Testing. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* None. +* Verify rename() when the newpath file or directory does not exist. */ -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <unistd.h> -#include <errno.h> -#include "test.h" -#include "safe_macros.h" - -void setup (); -void cleanup (); +#include <sys/stat.h> +#include <stdio.h> +#include "tst_test.h" -char *TCID ="rename01" ; -int TST_TOTAL =2 ; +#define SWAP (a, b) do { \ + const char *tmp__ = a; \ + a = b; \ + b = tmp__; \ +} while (0) -char fname[255 ], mname[255 ]; -char fdir[255 ], mdir[255 ]; -struct stat buf1; -dev_t f_olddev, d_olddev; -ino_t f_oldino, d_oldino; +static const char *old_file_name ="oldfile" ; +static const char *old_dir_name ="olddir" ; +static const char *new_file_name ="newfile" ; +static const char *new_dir_name ="newdir" ; -struct test_case_t { -char *name1; -char *name2; -char *desc; -dev_t *olddev; -ino_t *oldino; -}TC [] = { -/* comment goes here */ - { - fname, mname,"file" , &f_olddev, &f_oldino}, -/* comment goes here */ - { - fdir, mdir,"directory" , &d_olddev, &d_oldino} -}; +static struct stat old_file_st, old_dir_st, new_file_st, new_dir_st; -int main (int ac,char **av) +static void setup (void ) { -int lc; -int i; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/* -* perform global setup for test -*/ -setup (); - -/* -* check looping state if -i option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -/* loop through the test cases */ -for (i =0 ; i <TST_TOTAL ; i++) { - -TEST (rename (TC [i].name1,TC [i].name2)); - -if (TEST_RETURN ==-1 ) { -tst_resm (TFAIL ,"call failed unexpectedly" ); -continue ; - } - -SAFE_STAT (cleanup,TC [i].name2, &buf1); - -/* -* verify the new file or directory is the -* same as the old one -*/ -if (buf1.st_dev != *TC [i].olddev || - buf1.st_ino != *TC [i].oldino) { -tst_resm (TFAIL ,"rename() failed: the " -"new %s points to a different " -"inode/location" ,TC [i].desc); -continue ; - } -/* -* verify that the old file or directory -* does not exist -*/ -if (stat (fname, &buf1) !=-1 ) { -tst_resm (TFAIL ,"the old %s still " -"exists" ,TC [i].desc); -continue ; - } - -tst_resm (TPASS ,"functionality is correct " -"for renaming a %s" ,TC [i].desc); - } -/* reset things in case we are looping */ -SAFE_RENAME (cleanup, mname, fname); - -SAFE_RENAME (cleanup, mdir, fdir); - } - -cleanup (); -tst_exit (); +SAFE_TOUCH (old_file_name,0700 ,NULL ); +SAFE_MKDIR (old_dir_name,00770 ); +SAFE_STAT (old_file_name, &old_file_st); +SAFE_STAT (old_dir_name, &old_dir_st); } -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) +static void run (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* Create a temporary directory and make it current. */ -tst_tmpdir (); - -sprintf (fname,"./tfile_%d" ,getpid ()); -sprintf (mname,"./rnfile_%d" ,getpid ()); -sprintf (fdir,"./tdir_%d" ,getpid ()); -sprintf (mdir,"./rndir_%d" ,getpid ()); - -SAFE_TOUCH (cleanup, fname,0700 ,NULL ); - -SAFE_STAT (cleanup, fname, &buf1); - - f_olddev = buf1.st_dev; - f_oldino = buf1.st_ino; - -/* create "old" directory */ -SAFE_MKDIR (cleanup, fdir,00770 ); - -SAFE_STAT (cleanup, fdir, &buf1); - - d_olddev = buf1.st_dev; - d_oldino = buf1.st_ino; +TST_EXP_PASS (rename (old_file_name, new_file_name), +"rename(%s, %s)" , + old_file_name, new_file_name); +TST_EXP_PASS (rename (old_dir_name, new_dir_name), +"rename(%s, %s)" , + old_dir_name, new_dir_name); + +SAFE_STAT (new_file_name, &new_file_st); +SAFE_STAT (new_dir_name, &new_dir_st); + +TST_EXP_EQ_LI (old_file_st.st_dev, new_file_st.st_dev); +TST_EXP_EQ_LI (old_file_st.st_ino, new_file_st.st_ino); + +TST_EXP_EQ_LI (old_dir_st.st_dev, new_dir_st.st_dev); +TST_EXP_EQ_LI (old_dir_st.st_ino, new_dir_st.st_ino); + +TST_EXP_FAIL (stat (old_file_name, &old_file_st), +ENOENT , +"stat(%s, &old_file_st)" , + old_file_name); +TST_EXP_FAIL (stat (old_dir_name, &old_dir_st), +ENOENT , +"stat(%s, &old_dir_st)" , + old_dir_name); + +SWAP (old_file_name, new_file_name); +SWAP (old_dir_name, new_dir_name); } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -/* -* Remove the temporary directory. -*/ -tst_rmdir (); -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_tmpdir =1 +};
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/9] Rewrite rename01.c using new LTP API
Hello,
Quoted 96 lines · Avinesh Kumar
Signed-off-by Avinesh Kumar <[email protected]>--- testcases/kernel/syscalls/rename/rename01.c | 259 +++++--------------- 1 file changed, 58 insertions(+), 201 deletions(-)testcases/kernel/syscalls/rename/rename01.c +8
-72@@ -1,218 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* -* Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]> */ -/* -* NAME -* rename01 -* -* DESCRIPTION -* This test will verify the rename(2) syscall basic functionality. -* Verify rename() works when the "new" file or directory does not exist. +/*\ +* [Description] * -* ALGORITHM -* Setup: -* Setup signal handling. -* Create temporary directory. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* 1. "old" is plain file, new does not exists -* create the "old" file, make sure the "new" file -* dose not exist -* rename the "old" to the "new" file -* verify the "new" file points to the "old" file -* verify the "old" file does not exist -* -* 2. "old" is a directory,"new" does not exists -* create the "old" directory, make sure "new" -* dose not exist -* rename the "old" to the "new" -* verify the "new" points to the "old" -* verify the "old" does not exist -* Cleanup: -* Print errno log and/or timing stats if options given -* Delete the temporary directory created. -* -* USAGE -* rename01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -f : Turn off functionality Testing. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* None. +* Verify rename() when the newpath file or directory does not exist. */ -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <unistd.h> -#include <errno.h> -#include "test.h" -#include "safe_macros.h" - -void setup (); -void cleanup (); +#include <sys/stat.h>
testcases/kernel/syscalls/rename/rename01.c line 22
Quoted 10 lines
testcases/kernel/syscalls/rename/rename01.c +7
-2+#include <stdio.h> +#include "tst_test.h" -char *TCID ="rename01" ; -int TST_TOTAL =2 ; +#define SWAP (a, b) do { \ + const char *tmp__ = a; \ + a = b; \ + b = tmp__; \ +} while (0)
This doesn't need to be a macro (which don't have type or name collision checking and confuse some tooling etc.). It's actually the same number of lines to write it inline as well, i.e.
char *tmp;
tmp = a;
a = b;
b = tmp;
tmp = c;
c = d;
d = tmp;
However if you don't want to write it inline I'd prefer a function which takes const *const *char.
Otherwise looks good.
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/9] Rewrite rename01.c using new LTP API
Quoted 121 lines · IST Richard Palethorpe
Hello,
Quoted 96 lines · Avinesh Kumar
Signed-off-by Avinesh Kumar <[email protected]>--- testcases/kernel/syscalls/rename/rename01.c | 259 +++++--------------- 1 file changed, 58 insertions(+), 201 deletions(-)testcases/kernel/syscalls/rename/rename01.c +8
-72@@ -1,218 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* -* Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]> */ -/* -* NAME -* rename01 -* -* DESCRIPTION -* This test will verify the rename(2) syscall basic functionality. -* Verify rename() works when the "new" file or directory does not exist. +/*\ +* [Description] * -* ALGORITHM -* Setup: -* Setup signal handling. -* Create temporary directory. -* Pause for SIGUSR1 if option specified. -* -* Test: -* Loop if the proper options are given. -* 1. "old" is plain file, new does not exists -* create the "old" file, make sure the "new" file -* dose not exist -* rename the "old" to the "new" file -* verify the "new" file points to the "old" file -* verify the "old" file does not exist -* -* 2. "old" is a directory,"new" does not exists -* create the "old" directory, make sure "new" -* dose not exist -* rename the "old" to the "new" -* verify the "new" points to the "old" -* verify the "old" does not exist -* Cleanup: -* Print errno log and/or timing stats if options given -* Delete the temporary directory created. -* -* USAGE -* rename01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -f : Turn off functionality Testing. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* None. +* Verify rename() when the newpath file or directory does not exist. */ -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <unistd.h> -#include <errno.h> -#include "test.h" -#include "safe_macros.h" - -void setup (); -void cleanup (); +#include <sys/stat.h> testcases/kernel/syscalls/rename/rename01.c line 22
Quoted 10 lines
testcases/kernel/syscalls/rename/rename01.c +7
-2+#include <stdio.h> +#include "tst_test.h" -char *TCID ="rename01" ; -int TST_TOTAL =2 ; +#define SWAP (a, b) do { \ + const char *tmp__ = a; \ + a = b; \ + b = tmp__; \ +} while (0)This doesn't need to be a macro (which don't have type or name collision checking and confuse some tooling etc.). It's actually the same number of lines to write it inline as well, i.e.
char *tmp;
tmp = a;
a = b;
b = tmp;
Quoted 7 lines
tmp = c;
c = d;
d = tmp;However if you don't want to write it inline I'd prefer a function which takes const *const *char.
Thanks Richie! I have changed it to inline in updated patch.
Quoted 3 lines
Otherwise looks good.
--
Avinesh
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/9 Remove rename02.c
In reply to Avinesh Kumarrename02.c is redundant as same testcase is covered in rename01.c
--- runtest/syscalls | 1 - testcases/kernel/syscalls/rename/.gitignore | 1 - testcases/kernel/syscalls/rename/rename02.c | 192 -------------------- 3 files changed, 194 deletions(-) delete mode 100644 testcases/kernel/syscalls/rename/rename02.c
runtest/syscalls +0 -1
@@ -1132,7 +1132,6 @@ removexattr02 removexattr02 rename01 rename01 rename01A symlink01 -T rename01 -rename02 rename02 rename03 rename03 rename04 rename04 rename05 rename05
testcases/kernel/syscalls/rename/.gitignore +0 -1
@@ -1,5 +1,4 @@ /rename01 -/rename02 /rename03 /rename04 /rename05
testcases/kernel/syscalls/rename/rename02.c deleted +0 -192
192 lines not on this page · raw message
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 3/9 Rewrite rename03.c using new LTP API
In reply to Avinesh Kumar--- testcases/kernel/syscalls/rename/rename03.c | 274 ++++---------------- 1 file changed, 56 insertions(+), 218 deletions(-)
testcases/kernel/syscalls/rename/rename03.c +56 -218
@@ -1,230 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* -* Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]> */ -/* -* NAME -* rename03 -* -* DESCRIPTION -* This test will verify that rename(2) functions correctly -* when the "new" file or directory exists -* -* ALGORITHM -* Setup: -* Setup signal handling. -* Create temporary directory. -* Pause for SIGUSR1 if option specified. +/*\ +* [Description] * -* Test: -* Loop if the proper options are given. -* 1. both old and new file exist -* create the "old" file and the "new" file -* rename the "old" to the "new" file -* verify the "new" file points to the "old" file -* verify the "old" file does not exists -* 2. both old file and new directory exist -* create the "old" and the "new" directory -* rename the "old" to the "new" directory -* verify the "new" points to the "old" directory -* verify the "old" does not exists -* Cleanup: -* Print errno log and/or timing stats if options given -* Delete the temporary directory created. -* -* USAGE -* rename03 [-c n] [-f] [-i n] [-I x] [-p x] [-t] -* where, -c n : Run n copies concurrently. -* -f : Turn off functionality Testing. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* None. -*/ -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <unistd.h> -#include <errno.h> - -#include "test.h" -#include "safe_macros.h" - -void setup (); -void setup2 (); -void cleanup (); - -char *TCID ="rename03" ; -int TST_TOTAL =2 ; - -char fname[255 ], mname[255 ]; -char fdir[255 ], mdir[255 ]; -struct stat buf1, buf2; -dev_t f_olddev, d_olddev; -ino_t f_oldino, d_oldino; - -struct test_case_t { -char *name1; -char *name2; -char *desc; -dev_t *olddev; -ino_t *oldino; -}TC [] = { - { - fname, mname,"file" , &f_olddev, &f_oldino}, { - fdir, mdir,"directory" , &d_olddev, &d_oldino} -}; - -int main (int ac,char **av) -{ -int lc; -int i; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); -/* -* perform global setup for test -*/ -setup (); - -/* -* check looping state if -i option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -/* set up the files and directories for the tests */ -setup2 (); - -/* loop through the test cases */ -for (i =0 ; i <TST_TOTAL ; i++) { - -TEST (rename (TC [i].name1,TC [i].name2)); - -if (TEST_RETURN ==-1 ) { -tst_resm (TFAIL ,"call failed unexpectedly" ); -continue ; - } - -SAFE_STAT (cleanup,TC [i].name2, &buf2); - -/* -* verify the new file or directory is the -* same as the old one -*/ -if (buf2.st_dev != *TC [i].olddev || - buf2.st_ino != *TC [i].oldino) { -tst_resm (TFAIL ,"rename() failed: the " -"new %s points to a different " -"inode/location" ,TC [i].desc); -continue ; - } -/* -* verify that the old file or directory -* does not exist -*/ -if (stat (fname, &buf2) !=-1 ) { -tst_resm (TFAIL ,"the old %s still " -"exists" ,TC [i].desc); -continue ; - } - -tst_resm (TPASS ,"functionality is correct " -"for renaming a %s" ,TC [i].desc); - } - -/* reset things in case we are looping */ - -/* unlink the new file */ -SAFE_UNLINK (cleanup, mname); - -/* remove the new directory */ -SAFE_RMDIR (cleanup, mdir); - } - -cleanup (); -tst_exit (); - -} - -/* -* setup() - performs all ONE TIME setup for this test. +* Verify rename(2) functions correctly when the newpath +* file or directory (empty) exists. */ -void setup (void ) -{ -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; +#include <sys/stat.h> +#include <stdio.h> +#include "tst_test.h" -/* Create a temporary directory and make it current. */ -tst_tmpdir (); +#define OLD_FILE_NAME "oldfile" +#define NEW_FILE_NAME "newfile" +#define OLD_DIR_NAME "olddir" +#define NEW_DIR_NAME "newdir" -sprintf (fname,"./tfile_%d" ,getpid ()); -sprintf (mname,"./rnfile_%d" ,getpid ()); -sprintf (fdir,"./tdir_%d" ,getpid ()); -sprintf (mdir,"./rndir_%d" ,getpid ()); -} +static struct stat old_file_st, old_dir_st, new_file_st, new_dir_st; -/* -* setup2() - set up the files and directories for the tests -*/ -void setup2 (void ) +static void run (void ) { -SAFE_TOUCH (cleanup, fname,0700 ,NULL ); - -SAFE_STAT (cleanup, fname, &buf1); - -/* save original file's dev and ino */ - f_olddev = buf1.st_dev; - f_oldino = buf1.st_ino; - -SAFE_TOUCH (cleanup, mname,0700 ,NULL ); - -/* create "old" directory */ -SAFE_MKDIR (cleanup, fdir,00770 ); -SAFE_STAT (cleanup, fdir, &buf1); - - d_olddev = buf1.st_dev; - d_oldino = buf1.st_ino; - -/* create another directory */ -SAFE_MKDIR (cleanup, mdir,00770 ); +SAFE_TOUCH (OLD_FILE_NAME ,0700 ,NULL ); +SAFE_MKDIR (OLD_DIR_NAME ,00770 ); +SAFE_TOUCH (NEW_FILE_NAME ,0700 ,NULL ); +SAFE_MKDIR (NEW_DIR_NAME ,00770 ); + +SAFE_STAT (OLD_FILE_NAME , &old_file_st); +SAFE_STAT (OLD_DIR_NAME , &old_dir_st); + +TST_EXP_PASS (rename (OLD_FILE_NAME ,NEW_FILE_NAME ), +"rename(%s, %s)" , +OLD_FILE_NAME ,NEW_FILE_NAME ); +TST_EXP_PASS (rename (OLD_DIR_NAME ,NEW_DIR_NAME ), +"rename(%s, %s)" , +OLD_DIR_NAME ,NEW_DIR_NAME ); + +SAFE_STAT (NEW_FILE_NAME , &new_file_st); +SAFE_STAT (NEW_DIR_NAME , &new_dir_st); + +TST_EXP_EQ_LI (old_file_st.st_dev, new_file_st.st_dev); +TST_EXP_EQ_LI (old_file_st.st_ino, new_file_st.st_ino); + +TST_EXP_EQ_LI (old_dir_st.st_dev, new_dir_st.st_dev); +TST_EXP_EQ_LI (old_dir_st.st_ino, new_dir_st.st_ino); + +TST_EXP_FAIL (stat (OLD_FILE_NAME , &old_file_st), +ENOENT , +"stat(%s, &old_file_st)" , +OLD_FILE_NAME ); +TST_EXP_FAIL (stat (OLD_DIR_NAME , &old_dir_st), +ENOENT , +"stat(%s, &old_dir_st)" , +OLD_DIR_NAME ); + +SAFE_UNLINK (NEW_FILE_NAME ); +SAFE_RMDIR (NEW_DIR_NAME ); } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -/* -* Remove the temporary directory. -*/ -tst_rmdir (); -} +static struct tst_test test = { + .test_all = run, + .needs_tmpdir =1 +};
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/9] Rewrite rename03.c using new LTP API
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 4/9 Rewrite rename04.c using new LTP API
In reply to Avinesh Kumar--- testcases/kernel/syscalls/rename/rename04.c | 201 ++++---------------- 1 file changed, 33 insertions(+), 168 deletions(-)
testcases/kernel/syscalls/rename/rename04.c +33 -168
@@ -1,182 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* -* Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]> */ -/* -* NAME -* rename04 -* -* DESCRIPTION -* This test will verify that rename(2) failed when newpath is -* a non-empty directory and return EEXIST or ENOTEMPTY -* -* ALGORITHM -* Setup: -* Setup signal handling. -* Create temporary directory. -* Pause for SIGUSR1 if option specified. -* create the "old" directory and the "new" directory -* create a file uner the "new" directory -* -* Test: -* Loop if the proper options are given. -* rename the "old" to the "new" directory -* verify rename() failed and returned ENOTEMPTY -* -* Cleanup: -* Print errno log and/or timing stats if options given -* Delete the temporary directory created. -* -* USAGE -* rename04 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer +/*\ +* [Description] * -* RESTRICTIONS -* None. +* Verify that rename() fails with EEXIST or ENOTEMPTY when +* newpath is a non-empty directory. */ -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <unistd.h> -#include <errno.h> -#include "test.h" -#include "safe_macros.h" +#include <stdio.h> +#include "tst_test.h" -void setup (); -void cleanup (); +#define DIR1 "dir1" +#define DIR2 "dir2" +#define TEMP_FILE DIR2"/tmpfile" -char *TCID ="rename04" ; -int TST_TOTAL =1 ; - -int fd; -char tstfile[40 ]; -char fdir[255 ], mdir[255 ]; -struct stat buf1, buf2; -dev_t olddev, olddev1; -ino_t oldino, oldino1; - -int main (int ac,char **av) +static void setup (void ) { -int lc; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/* -* perform global setup for test -*/ -setup (); - -/* -* check looping state if -i option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -/* rename a directory to a non-empty directory */ - -/* Call rename(2) */ -TEST (rename (fdir, mdir)); - -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"rename(%s, %s) succeeded unexpectedly" , - fdir, mdir); -continue ; - } - -if (TEST_ERRNO ==ENOTEMPTY ) { -tst_resm (TPASS ,"rename() returned ENOTEMPTY" ); - }else if (TEST_ERRNO ==EEXIST ) { -tst_resm (TPASS ,"rename() returned EEXIST" ); - }else { -tst_resm (TFAIL ,"Expected ENOTEMPTY or EEXIST got %d" , -TEST_ERRNO ); - } - - } - -/* -* cleanup and exit -*/ -cleanup (); -tst_exit (); - +SAFE_MKDIR (DIR1 ,00770 ); +SAFE_MKDIR (DIR2 ,00770 ); +SAFE_TOUCH (TEMP_FILE ,0700 ,NULL ); } -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) +static void run (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* Create a temporary directory and make it current. */ -tst_tmpdir (); - -sprintf (fdir,"./tdir_%d" ,getpid ()); -sprintf (mdir,"./rndir_%d" ,getpid ()); -sprintf (tstfile,"%s/tstfile_%d" , mdir,getpid ()); - -/* create "old" directory */ -SAFE_MKDIR (cleanup, fdir,00770 ); - -SAFE_STAT (cleanup, fdir, &buf1); - -/* save "old"'s dev and ino */ - olddev = buf1.st_dev; - oldino = buf1.st_ino; - -/* create another directory */ -SAFE_MKDIR (cleanup, mdir,00770 ); - -SAFE_TOUCH (cleanup, tstfile,0700 ,NULL ); - -SAFE_STAT (cleanup, mdir, &buf2); - -/* save "new"'s dev and ino */ - olddev1 = buf2.st_dev; - oldino1 = buf2.st_ino; +TEST (rename (DIR1 ,DIR2 )); + +if (TST_RET ==-1 &&TST_ERR ==ENOTEMPTY ) +tst_res (TPASS ,"rename() failed with ENOTEMPTY" ); +else if (TST_RET ==-1 &&TST_ERR ==EEXIST ) +tst_res (TPASS ,"rename() failed with EEXIST" ); +else if (TST_RET ==0 ) +tst_res (TFAIL ,"rename() succeeded unexpectedly" ); +else +tst_res (TFAIL ,"rename() failed, but not with expected errno" ); } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -/* -* Remove the temporary directory. -*/ -tst_rmdir (); -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_tmpdir =1 +};
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 4/9] Rewrite rename04.c using new LTP API
Hello,
Quoted 197 lines · Avinesh Kumar
Signed-off-by Avinesh Kumar <[email protected]>--- testcases/kernel/syscalls/rename/rename04.c | 201 ++++---------------- 1 file changed, 33 insertions(+), 168 deletions(-)testcases/kernel/syscalls/rename/rename04.c +19
-156@@ -1,182 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* -* Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]> */ -/* -* NAME -* rename04 -* -* DESCRIPTION -* This test will verify that rename(2) failed when newpath is -* a non-empty directory and return EEXIST or ENOTEMPTY -* -* ALGORITHM -* Setup: -* Setup signal handling. -* Create temporary directory. -* Pause for SIGUSR1 if option specified. -* create the "old" directory and the "new" directory -* create a file uner the "new" directory -* -* Test: -* Loop if the proper options are given. -* rename the "old" to the "new" directory -* verify rename() failed and returned ENOTEMPTY -* -* Cleanup: -* Print errno log and/or timing stats if options given -* Delete the temporary directory created. -* -* USAGE -* rename04 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer +/*\ +* [Description] * -* RESTRICTIONS -* None. +* Verify that rename() fails with EEXIST or ENOTEMPTY when +* newpath is a non-empty directory. */ -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <unistd.h> -#include <errno.h> -#include "test.h" -#include "safe_macros.h" +#include <stdio.h> +#include "tst_test.h" -void setup (); -void cleanup (); +#define DIR1 "dir1" +#define DIR2 "dir2" +#define TEMP_FILE DIR2"/tmpfile" -char *TCID ="rename04" ; -int TST_TOTAL =1 ; - -int fd; -char tstfile[40 ]; -char fdir[255 ], mdir[255 ]; -struct stat buf1, buf2; -dev_t olddev, olddev1; -ino_t oldino, oldino1; - -int main (int ac,char **av) +static void setup (void ) { -int lc; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/* -* perform global setup for test -*/ -setup (); - -/* -* check looping state if -i option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -/* rename a directory to a non-empty directory */ - -/* Call rename(2) */ -TEST (rename (fdir, mdir)); - -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"rename(%s, %s) succeeded unexpectedly" , - fdir, mdir); -continue ; - } - -if (TEST_ERRNO ==ENOTEMPTY ) { -tst_resm (TPASS ,"rename() returned ENOTEMPTY" ); - }else if (TEST_ERRNO ==EEXIST ) { -tst_resm (TPASS ,"rename() returned EEXIST" ); - }else { -tst_resm (TFAIL ,"Expected ENOTEMPTY or EEXIST got %d" , -TEST_ERRNO ); - } - - } - -/* -* cleanup and exit -*/ -cleanup (); -tst_exit (); - +SAFE_MKDIR (DIR1 ,00770 ); +SAFE_MKDIR (DIR2 ,00770 ); +SAFE_TOUCH (TEMP_FILE ,0700 ,NULL ); } -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) +static void run (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* Create a temporary directory and make it current. */ -tst_tmpdir (); - -sprintf (fdir,"./tdir_%d" ,getpid ()); -sprintf (mdir,"./rndir_%d" ,getpid ()); -sprintf (tstfile,"%s/tstfile_%d" , mdir,getpid ()); - -/* create "old" directory */ -SAFE_MKDIR (cleanup, fdir,00770 ); - -SAFE_STAT (cleanup, fdir, &buf1); - -/* save "old"'s dev and ino */ - olddev = buf1.st_dev; - oldino = buf1.st_ino; - -/* create another directory */ -SAFE_MKDIR (cleanup, mdir,00770 ); - -SAFE_TOUCH (cleanup, tstfile,0700 ,NULL ); - -SAFE_STAT (cleanup, mdir, &buf2); - -/* save "new"'s dev and ino */ - olddev1 = buf2.st_dev; - oldino1 = buf2.st_ino; +TEST (rename (DIR1 ,DIR2 ));
testcases/kernel/syscalls/rename/rename04.c line 41
Quoted 10 lines
testcases/kernel/syscalls/rename/rename04.c +9
-0+ +if (TST_RET ==-1 &&TST_ERR ==ENOTEMPTY ) +tst_res (TPASS ,"rename() failed with ENOTEMPTY" ); +else if (TST_RET ==-1 &&TST_ERR ==EEXIST ) +tst_res (TPASS ,"rename() failed with EEXIST" ); +else if (TST_RET ==0 ) +tst_res (TFAIL ,"rename() succeeded unexpectedly" ); +else +tst_res (TFAIL ,"rename() failed, but not with expected errno");
You can print the errno name with tst_res(TFAIL | TERRNO, ...)
Quoted 8 lines
testcases/kernel/syscalls/rename/rename04.c +0
-6} -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{
testcases/kernel/syscalls/rename/rename04.c line 46
Quoted 10 lines
testcases/kernel/syscalls/rename/rename04.c +4
-6- -/* -* Remove the temporary directory. -*/ -tst_rmdir (); -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_tmpdir =1
I suppose all these tests should be done on all file systems as well. Renaming is implemented differently on each filesystem.
Quoted 3 lines
+};
Signature · 1 line
2.36.1
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 4/9] Rewrite rename04.c using new LTP API
Quoted 205 lines · IST Richard Palethorpe
Hello,
Quoted 201 lines · Avinesh Kumar
Signed-off-by Avinesh Kumar <[email protected]>--- testcases/kernel/syscalls/rename/rename04.c | 201 ++++---------------- 1 file changed, 33 insertions(+), 168 deletions(-)testcases/kernel/syscalls/rename/rename04.c +23
-156@@ -1,182 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* -* Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]> */ -/* -* NAME -* rename04 -* -* DESCRIPTION -* This test will verify that rename(2) failed when newpath is -* a non-empty directory and return EEXIST or ENOTEMPTY -* -* ALGORITHM -* Setup: -* Setup signal handling. -* Create temporary directory. -* Pause for SIGUSR1 if option specified. -* create the "old" directory and the "new" directory -* create a file uner the "new" directory -* -* Test: -* Loop if the proper options are given. -* rename the "old" to the "new" directory -* verify rename() failed and returned ENOTEMPTY -* -* Cleanup: -* Print errno log and/or timing stats if options given -* Delete the temporary directory created. -* -* USAGE -* rename04 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer +/*\ +* [Description] * -* RESTRICTIONS -* None. +* Verify that rename() fails with EEXIST or ENOTEMPTY when +* newpath is a non-empty directory. */ -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <unistd.h> -#include <errno.h> -#include "test.h" -#include "safe_macros.h" +#include <stdio.h> +#include "tst_test.h" -void setup (); -void cleanup (); +#define DIR1 "dir1" +#define DIR2 "dir2" +#define TEMP_FILE DIR2"/tmpfile" -char *TCID ="rename04" ; -int TST_TOTAL =1 ; - -int fd; -char tstfile[40 ]; -char fdir[255 ], mdir[255 ]; -struct stat buf1, buf2; -dev_t olddev, olddev1; -ino_t oldino, oldino1; - -int main (int ac,char **av) +static void setup (void ) { -int lc; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/* -* perform global setup for test -*/ -setup (); - -/* -* check looping state if -i option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -/* rename a directory to a non-empty directory */ - -/* Call rename(2) */ -TEST (rename (fdir, mdir)); - -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"rename(%s, %s) succeeded unexpectedly" , - fdir, mdir); -continue ; - } - -if (TEST_ERRNO ==ENOTEMPTY ) { -tst_resm (TPASS ,"rename() returned ENOTEMPTY" ); - }else if (TEST_ERRNO ==EEXIST ) { -tst_resm (TPASS ,"rename() returned EEXIST" ); - }else { -tst_resm (TFAIL ,"Expected ENOTEMPTY or EEXIST got %d" , -TEST_ERRNO ); - } - - } - -/* -* cleanup and exit -*/ -cleanup (); -tst_exit (); - +SAFE_MKDIR (DIR1 ,00770 ); +SAFE_MKDIR (DIR2 ,00770 ); +SAFE_TOUCH (TEMP_FILE ,0700 ,NULL ); } -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) +static void run (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* Create a temporary directory and make it current. */ -tst_tmpdir (); - -sprintf (fdir,"./tdir_%d" ,getpid ()); -sprintf (mdir,"./rndir_%d" ,getpid ()); -sprintf (tstfile,"%s/tstfile_%d" , mdir,getpid ()); - -/* create "old" directory */ -SAFE_MKDIR (cleanup, fdir,00770 ); - -SAFE_STAT (cleanup, fdir, &buf1); - -/* save "old"'s dev and ino */ - olddev = buf1.st_dev; - oldino = buf1.st_ino; - -/* create another directory */ -SAFE_MKDIR (cleanup, mdir,00770 ); - -SAFE_TOUCH (cleanup, tstfile,0700 ,NULL ); - -SAFE_STAT (cleanup, mdir, &buf2); - -/* save "new"'s dev and ino */ - olddev1 = buf2.st_dev; - oldino1 = buf2.st_ino; +TEST (rename (DIR1 ,DIR2 )); + +if (TST_RET ==-1 &&TST_ERR ==ENOTEMPTY ) +tst_res (TPASS ,"rename() failed with ENOTEMPTY" ); +else if (TST_RET ==-1 &&TST_ERR ==EEXIST )
Quoted 8 lines
testcases/kernel/syscalls/rename/rename04.c
Quoted 6 lines
testcases/kernel/syscalls/rename/rename04.c +5
-0+tst_res (TPASS ,"rename() failed with EEXIST" ); + else if (TST_RET == 0) + tst_res(TFAIL, "rename() succeeded unexpectedly"); + else + tst_res(TFAIL, "rename() failed, but not with expected errno");You can print the errno name with
tst_res(TFAIL | TERRNO, ...)
Updated in the v3 patch.
Quoted 14 lines
Quoted 14 lines
testcases/kernel/syscalls/rename/rename04.c +0
-11} -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -/* -* Remove the temporary directory. -*/ -tst_rmdir ();
Quoted 8 lines
testcases/kernel/syscalls/rename/rename04.c line 46
Quoted 5 lines
testcases/kernel/syscalls/rename/rename04.c +4
-1-} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_tmpdir =1 I suppose all these tests should be done on all file systems as well. Renaming is implemented differently on each filesystem.
Good point! I have enabled these tests on all filesystems in v3
Quoted 5 lines
Quoted 2 lines
+};
--
Avinesh
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 5/9 Rewrite rename05.c using new LTP API
In reply to Avinesh Kumar--- testcases/kernel/syscalls/rename/rename05.c | 189 +++----------------- 1 file changed, 23 insertions(+), 166 deletions(-)
testcases/kernel/syscalls/rename/rename05.c +23 -166
@@ -1,179 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* -* Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]> */ -/* -* NAME -* rename05 -* -* DESCRIPTION -* This test will verify that rename(2) fails with EISDIR -* -* ALGORITHM -* Setup: -* Setup signal handling. -* Create temporary directory. -* Pause for SIGUSR1 if option specified. -* create the "old" file and the "new" directory -* rename the "old" file to the "new" directory -* -* Test: -* Loop if the proper options are given. -* verify rename() failed and returned EISDIR -* -* Cleanup: -* Print errno log and/or timing stats if options given -* Delete the temporary directory created. -* -* USAGE -* rename05 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* None. +/*\ +* [Description] +* Verify that rename(2) fails with EISDIR when +* oldpath is not a directory and newpath is an existing directory. */ -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <unistd.h> -#include <errno.h> - -#include "test.h" -#include "safe_macros.h" -void setup (); -void cleanup (); +#include <stdio.h> +#include "tst_test.h" -char *TCID ="rename05" ; -int TST_TOTAL =1 ; +#define TEMP_FILE "tmpfile" +#define TEMP_DIR "tmpdir" -int fd; -char fname[255 ], mdir[255 ]; -struct stat buf1, buf2; -dev_t olddev, olddev1; -ino_t oldino, oldino1; - -int main (int ac,char **av) +static void setup (void ) { -int lc; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/* -* perform global setup for test -*/ -setup (); - -/* -* check looping state if -i option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -/* attempt to rename a file to a directory */ -/* Call rename(2) */ -TEST (rename (fname, mdir)); - -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"rename(%s, %s) succeed unexpected" , - fname, mdir); -continue ; - } - -if (errno !=EISDIR ) { -tst_resm (TFAIL ,"Expected EISDIR got %d" ,TEST_ERRNO ); - }else { -tst_resm (TPASS ,"rename() returned EISDIR" ); - } - } - -/* -* cleanup and exit -*/ -cleanup (); -tst_exit (); - +SAFE_TOUCH (TEMP_FILE ,0700 ,NULL ); +SAFE_MKDIR (TEMP_DIR ,00770 ); } -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) +static void run (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* Create a temporary directory and make it current. */ -tst_tmpdir (); - -sprintf (mdir,"./rndir_%d" ,getpid ()); -sprintf (fname,"./tfile_%d" ,getpid ()); - -/* create "old" file */ -SAFE_TOUCH (cleanup, fname,0700 ,NULL ); -SAFE_STAT (cleanup, fname, &buf1); - -/* save "old"'s dev and ino */ - olddev = buf1.st_dev; - oldino = buf1.st_ino; - -/* create another directory */ -if (stat (mdir, &buf2) !=-1 ) { -tst_brkm (TBROK , cleanup,"tmp directory %s found!" , mdir); - } - -SAFE_MKDIR (cleanup, mdir,00770 ); - -SAFE_STAT (cleanup, mdir, &buf2); - -/* save "new"'s dev and ino */ - olddev1 = buf2.st_dev; - oldino1 = buf2.st_ino; +TST_EXP_FAIL (rename (TEMP_FILE ,TEMP_DIR ), +EISDIR ); } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -/* -* Remove the temporary directory. -*/ -tst_rmdir (); - -/* -* Exit with return code appropriate for results. -*/ - -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_tmpdir =1 +};
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 6/9 Rewrite rename06.c using new LTP API
In reply to Avinesh Kumar--- testcases/kernel/syscalls/rename/rename06.c | 182 +++----------------- 1 file changed, 23 insertions(+), 159 deletions(-)
testcases/kernel/syscalls/rename/rename06.c +23 -159
@@ -1,173 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* -* Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]> */ -/* -* NAME -* rename06 -* -* DESCRIPTION -* This test will verify that rename(2) failed in EINVAL -* -* ALGORITHM -* Setup: -* Setup signal handling. -* Create temporary directory. -* Pause for SIGUSR1 if option specified. -* create the "old" directory -* create the "new" directory under the "old" directory -* -* Test: -* Loop if the proper options are given. -* rename the "old" to the "new" directory -* verify rename() failed and returned EINVAL -* -* Cleanup: -* Print errno log and/or timing stats if options given -* Delete the temporary directory created. -* -* USAGE -* rename06 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. +/*\ +* [Description] * -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* None. +* Verify that rename(2) fails with EINVAL when +* an attempt is made to make a directory a subdirectory of itself. */ -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <unistd.h> -#include <errno.h> - -#include "test.h" -#include "safe_macros.h" - -void setup (); -void cleanup (); -char *TCID ="rename06" ; -int TST_TOTAL =1 ; +#include <stdio.h> +#include "tst_test.h" -int fd; -char fdir[255 ], mdir[255 ]; -struct stat buf1, buf2; -dev_t olddev, olddev1; -ino_t oldino, oldino1; +#define DIR1 "dir1" +#define DIR2 DIR1"/dir2" -int main (int ac,char **av) +static void setup (void ) { -int lc; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/* -* perform global setup for test -*/ -setup (); - -/* -* check looping state if -i option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -/* rename a directory to a subdirectory of itself */ -/* Call rename(2) */ -TEST (rename (fdir, mdir)); - -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"rename(%s, %s) succeed unexpected" , - fdir, mdir); -continue ; - } - -if (errno !=EINVAL ) { -tst_resm (TFAIL ,"Expected EINVAL got %d" ,TEST_ERRNO ); - }else { -tst_resm (TPASS ,"rename() returned EINVAL" ); - } - } - -cleanup (); -tst_exit (); - +SAFE_MKDIR (DIR1 ,00770 ); +SAFE_MKDIR (DIR2 ,00770 ); } -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) +static void run (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* Create a temporary directory and make it current. */ -tst_tmpdir (); - -sprintf (fdir,"./tdir_%d" ,getpid ()); -sprintf (mdir,"%s/rndir_%d" , fdir,getpid ()); - -/* create "old" directory */ -if (stat (fdir, &buf1) !=-1 ) { -tst_brkm (TBROK , cleanup,"tmp directory %s found!" , fdir); - } -SAFE_MKDIR (cleanup, fdir,00770 ); -SAFE_STAT (cleanup, fdir, &buf1); -/* save "old"'s dev and ino */ - olddev = buf1.st_dev; - oldino = buf1.st_ino; - -/* create another directory */ -if (stat (mdir, &buf2) !=-1 ) { -tst_brkm (TBROK , cleanup,"tmp directory %s found!" , mdir); - } -SAFE_MKDIR (cleanup, mdir,00770 ); - -SAFE_STAT (cleanup, mdir, &buf2); - -/* save "new"'s dev and ino */ - olddev1 = buf2.st_dev; - oldino1 = buf2.st_ino; +TST_EXP_FAIL (rename (DIR1 ,DIR2 ), +EINVAL ); } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -/* -* Remove the temporary directory. -*/ -tst_rmdir (); -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_tmpdir =1 +};
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 7/9 Rewrite rename07.c using new LTP API
In reply to Avinesh Kumar--- testcases/kernel/syscalls/rename/rename07.c | 166 +++----------------- 1 file changed, 25 insertions(+), 141 deletions(-)
testcases/kernel/syscalls/rename/rename07.c +25 -141
@@ -1,154 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* NAME -* rename07 -* -* DESCRIPTION -* This test will verify that rename(2) failed in ENOTDIR -* -* CALLS -* stat,open,rename,mkdir,close -* -* ALGORITHM -* Setup: -* Setup signal handling. -* Create temporary directory. -* Pause for SIGUSR1 if option specified. -* create the "old" directory and the "new" file -* rename the "old" directory to the "new" file -* -* Test: -* Loop if the proper options are given. -* verify rename() failed and returned ENOTDIR -* -* Cleanup: -* Print errno log and/or timing stats if options given -* Delete the temporary directory created.* -* USAGE -* rename07 [-c n] [-e] [-i n] [-I x] [-p x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]> +*/ + +/*\ +* [Description] * -* HISTORY -* 07/2001 Ported by Wayne Boyer +* Verify that rename(2) fails with ENOTDIR, when +* oldpath is a directory and newpath exists but is not a directory. * -* RESTRICTIONS -* None. */ -#include <sys/types.h> -#include <fcntl.h> -#include <sys/stat.h> -#include <unistd.h> -#include <errno.h> - -#include "test.h" -#include "safe_macros.h" - -void setup (); -void cleanup (); -char *TCID ="rename07" ; -int TST_TOTAL =1 ; +#include <stdio.h> +#include "tst_test.h" -int fd; -char mname[255 ], fdir[255 ]; -struct stat buf1, buf2; -dev_t olddev, olddev1; -ino_t oldino, oldino1; +#define TEMP_DIR "tmpdir" +#define TEMP_FILE "tmpfile" -int main (int ac,char **av) +static void setup (void ) { -int lc; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/* -* perform global setup for test -*/ -setup (); - -/* -* check looping state if -i option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -/* rename a directory to a file */ -/* Call rename(2) */ -TEST (rename (fdir, mname)); - -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"rename(%s, %s) succeeded unexpectedly" , - fdir, mname); -continue ; - } - -if (TEST_ERRNO !=ENOTDIR ) { -tst_resm (TFAIL ,"Expected ENOTDIR got %d" ,TEST_ERRNO ); - }else { -tst_resm (TPASS ,"rename() returned ENOTDIR" ); - } - } - -cleanup (); -tst_exit (); - +SAFE_MKDIR (TEMP_DIR ,00770 ); +SAFE_TOUCH (TEMP_FILE ,0700 ,NULL ); } -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) +static void run (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* Create a temporary directory and make it current. */ -tst_tmpdir (); - -sprintf (fdir,"./rndir_%d" ,getpid ()); -sprintf (mname,"./tfile_%d" ,getpid ()); - -/* create "old" directory */ -if (stat (fdir, &buf1) !=-1 ) { -tst_brkm (TBROK , cleanup,"tmp directory %s found!" , fdir); - } - -SAFE_MKDIR (cleanup, fdir,00770 ); - -SAFE_STAT (cleanup, fdir, &buf1); - -/* save "old"'s dev and ino */ - olddev = buf1.st_dev; - oldino = buf1.st_ino; - -SAFE_TOUCH (cleanup, mname,0700 ,NULL ); - -SAFE_STAT (cleanup, mname, &buf2); - -/* save "new"'s dev and ino */ - olddev1 = buf2.st_dev; - oldino1 = buf2.st_ino; +TST_EXP_FAIL (rename (TEMP_DIR ,TEMP_FILE ), +ENOTDIR ); } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -/* -* Remove the temporary directory. -*/ -tst_rmdir (); -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_tmpdir =1 +};
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 8/9 Rewrite rename08.c using new LTP API
In reply to Avinesh Kumar--- testcases/kernel/syscalls/rename/rename08.c | 200 +++----------------- 1 file changed, 24 insertions(+), 176 deletions(-)
testcases/kernel/syscalls/rename/rename08.c +24 -176
@@ -1,190 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* -* Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]> */ -/* -* NAME -* rename08 -* -* DESCRIPTION -* This test will verify that rename(2) syscall failed in EFAULT -* -* ALGORITHM -* Setup: -* Setup signal handling. -* Create temporary directory. -* Pause for SIGUSR1 if option specified. -* Create a valid file to use in the rename() call. -* -* Test: -* Loop if the proper options are given. -* 1. "old" is a valid file, newpath points to address -* outside allocated address space -* rename the "old" to the "new" file -* verify rename() failed with error EFAULT -* -* 2. "old" points to address outside allocated address space -* ,"new" is a valid file -* rename the "old" to the "new" -* verify rename() failed with error EFAULT -* -* 3. oldpath and newpath are all NULL -* try to rename NULL to NULL -* verify rename() failed with error EFAULT -* Cleanup: -* Print errno log and/or timing stats if options given -* Delete the temporary directory created.* -* USAGE -* rename08 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer +/*\ +* [Description] * -* RESTRICTIONS -* None. +* Verify that rename(2) fails with EFAULT, when +* oldpath or newpath points outside of accessible address space. */ -#include <sys/types.h> -#include <fcntl.h> -#include <sys/mman.h> -#include <unistd.h> -#include <errno.h> -#include "test.h" +#include <stdio.h> +#include "tst_test.h" -void setup (); -void cleanup (); +#define TEMP_FILE "tmpfile" +#define INVALID_PATH (void *)-1 -char *TCID ="rename08" ; - -char *bad_addr =0 ; - -int fd; -char fname[255 ]; - -struct test_case_t { -char *fd; -char *fd2; -int error; -}TC [] = { -#if !defined(UCLINUX) -/* "new" file is invalid - EFAULT */ - { - fname, (char *)-1 ,EFAULT }, -/* "old" file is invalid - EFAULT */ - { - (char *)-1 , fname,EFAULT }, -#endif -/* both files are NULL - EFAULT */ - { -NULL ,NULL ,EFAULT } -}; - -int TST_TOTAL =ARRAY_SIZE (TC ); - -int main (int ac,char **av) +static void setup (void ) { -int lc; -int i; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -/* -* check looping state if -i option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -/* loop through the test cases */ -for (i =0 ; i <TST_TOTAL ; i++) { - -TEST (rename (TC [i].fd,TC [i].fd2)); - -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"call succeeded unexpectedly" ); -continue ; - } - -if (TEST_ERRNO ==TC [i].error) { -tst_resm (TPASS ,"expected failure - " -"errno = %d : %s" ,TEST_ERRNO , -strerror (TEST_ERRNO )); - }else { -tst_resm (TFAIL ,"unexpected error - %d : %s - " -"expected %d" ,TEST_ERRNO , -strerror (TEST_ERRNO ),TC [i].error); - } - } - } - -cleanup (); -tst_exit (); - +SAFE_TOUCH (TEMP_FILE ,0700 ,NULL ); } -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) +static void run (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* Create a temporary directory and make it current. */ -tst_tmpdir (); - -sprintf (fname,"./tfile_%d" ,getpid ()); - -SAFE_TOUCH (cleanup, fname,0700 ,NULL ); - -#if !defined(UCLINUX ) - bad_addr =mmap (0 ,1 ,PROT_NONE , -MAP_PRIVATE_EXCEPT_UCLINUX |MAP_ANONYMOUS ,0 ,0 ); -if (bad_addr ==MAP_FAILED ) { -tst_brkm (TBROK , cleanup,"mmap failed" ); - } -TC [0 ].fd2 = bad_addr; -TC [1 ].fd = bad_addr; -#endif +TST_EXP_FAIL (rename (INVALID_PATH ,TEMP_FILE ), +EFAULT ); +TST_EXP_FAIL (rename (TEMP_FILE ,INVALID_PATH ), +EFAULT ); } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -/* -* Remove the temporary directory. -*/ -tst_rmdir (); -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_tmpdir =1 +};
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 9/9 Rewrite rename10.c using new LTP API
In reply to Avinesh Kumar--- testcases/kernel/syscalls/rename/rename10.c | 182 +++----------------- 1 file changed, 22 insertions(+), 160 deletions(-)
testcases/kernel/syscalls/rename/rename10.c +22 -160
@@ -1,175 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* -* Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]> */ -/* -* NAME -* rename10 -* -* DESCRIPTION -* This test will verify that rename(2) syscall fails with ENAMETOOLONG -* and ENOENT -* -* ALGORITHM -* Setup: -* Setup signal handling. -* Create temporary directory. -* Pause for SIGUSR1 if option specified. -* create the "old" file -* -* Test: -* Loop if the proper options are given. -* 1. rename the "old" to the "new" file -* verify rename() failed with error ENAMETOOLONG -* -* 2. "new" path contains a directory that does not exist -* rename the "old" to the "new" -* verify rename() failed with error ENOENT -* Cleanup: -* Print errno log and/or timing stats if options given -* Delete the temporary directory created.* -* -* USAGE -* rename10 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. +/*\ +* [Description] * -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* None. +* Verify that rename(2) fails with ENAMETOOLONG, when +* oldpath or newpath is too long. */ -#include <sys/types.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> - -#include "test.h" - -void setup (); -void cleanup (); -char *TCID ="rename10" ; -int TST_TOTAL =2 ; +#include <stdio.h> +#include "tst_test.h" -char badmname[] = -"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz" ; +#define TEMP_FILE "tmpfile" -int fd; -char fname[255 ], mname[255 ]; -char mdir[255 ]; - -struct test_case_t { -char *fd1; -char *fd2; -int error; -}TC [] = { -/* badmname is too long for a file name - ENAMETOOLONG */ - { - fname, badmname,ENAMETOOLONG }, -/* mname contains a directory component which does not exist - ENOENT */ - { - fname, mname,ENOENT } -}; +static char long_path[PATH_MAX +2 ] = {[0 ...PATH_MAX +1 ] ='a' }; -int main (int ac,char **av) +static void setup (void ) { -int lc; -int i; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/* -* perform global setup for test -*/ -setup (); - -/* -* check looping state if -i option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -/* loop through the test cases */ -for (i =0 ; i <TST_TOTAL ; i++) { - -TEST (rename (TC [i].fd1,TC [i].fd2)); - -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"call succeeded unexpectedly" ); -continue ; - } - -if (TEST_ERRNO ==TC [i].error) { -tst_resm (TPASS ,"expected failure - " -"errno = %d : %s" ,TEST_ERRNO , -strerror (TEST_ERRNO )); - }else { -tst_resm (TFAIL ,"unexpected error - %d : %s - " -"expected %d" ,TEST_ERRNO , -strerror (TEST_ERRNO ),TC [i].error); - } - } - } - -cleanup (); -tst_exit (); - +SAFE_TOUCH (TEMP_FILE ,0700 ,NULL ); } -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) +static void run (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* Create a temporary directory and make it current. */ -tst_tmpdir (); - -sprintf (fname,"./tfile_%d" ,getpid ()); -sprintf (mdir,"./rndir_%d" ,getpid ()); -sprintf (mname,"%s/rnfile_%d" , mdir,getpid ()); - -SAFE_TOUCH (cleanup, fname,0700 ,NULL ); +TST_EXP_FAIL (rename (TEMP_FILE , long_path), +ENAMETOOLONG ); } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -/* -* Remove the temporary directory. -*/ -tst_rmdir (); -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_tmpdir =1 +};
Signature · 5 lines
2.36.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 9/9] Rewrite rename10.c using new LTP API
Hello,
Quoted 105 lines · Avinesh Kumar
Signed-off-by Avinesh Kumar <[email protected]>--- testcases/kernel/syscalls/rename/rename10.c | 182 +++----------------- 1 file changed, 22 insertions(+), 160 deletions(-)testcases/kernel/syscalls/rename/rename10.c +11
-76@@ -1,175 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* -* Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]> */ -/* -* NAME -* rename10 -* -* DESCRIPTION -* This test will verify that rename(2) syscall fails with ENAMETOOLONG -* and ENOENT -* -* ALGORITHM -* Setup: -* Setup signal handling. -* Create temporary directory. -* Pause for SIGUSR1 if option specified. -* create the "old" file -* -* Test: -* Loop if the proper options are given. -* 1. rename the "old" to the "new" file -* verify rename() failed with error ENAMETOOLONG -* -* 2. "new" path contains a directory that does not exist -* rename the "old" to the "new" -* verify rename() failed with error ENOENT -* Cleanup: -* Print errno log and/or timing stats if options given -* Delete the temporary directory created.* -* -* USAGE -* rename10 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. +/*\ +* [Description] * -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* None. +* Verify that rename(2) fails with ENAMETOOLONG, when +* oldpath or newpath is too long. */ -#include <sys/types.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> - -#include "test.h" - -void setup (); -void cleanup (); -char *TCID ="rename10" ; -int TST_TOTAL =2 ; +#include <stdio.h> +#include "tst_test.h" -char badmname[] = -"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz" ; +#define TEMP_FILE "tmpfile" -int fd; -char fname[255 ], mname[255 ]; -char mdir[255 ]; - -struct test_case_t { -char *fd1; -char *fd2;
testcases/kernel/syscalls/rename/rename10.c line 20
Quoted 10 lines
testcases/kernel/syscalls/rename/rename10.c +1
-9-int error; -} TC[] = { -/* badmname is too long for a file name - ENAMETOOLONG */ - { - fname, badmname, ENAMETOOLONG}, -/* mname contains a directory component which does not exist - ENOENT */ - { - fname, mname, ENOENT} -}; +static char long_path[PATH_MAX +2 ] = {[0 ...PATH_MAX +1 ] ='a' };
PATH_MAX is actually the minimum number of bytes the system is allowed to set as the maximum path length. Meaning it can accept more. However it seems what we are actually testing here is NAME_MAX which is only 255 and can't be bigger than 255 according to POSIX.
So I think we should be testing what happens when 256 chars are passed as a filename (not including null terminating char).
Quoted 94 lines
testcases/kernel/syscalls/rename/rename10.c +10
-75-int main (int ac,char **av) +static void setup (void ) { -int lc; -int i; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/* -* perform global setup for test -*/ -setup (); - -/* -* check looping state if -i option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -/* loop through the test cases */ -for (i =0 ; i <TST_TOTAL ; i++) { - -TEST (rename (TC [i].fd1,TC [i].fd2)); - -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"call succeeded unexpectedly" ); -continue ; - } - -if (TEST_ERRNO ==TC [i].error) { -tst_resm (TPASS ,"expected failure - " -"errno = %d : %s" ,TEST_ERRNO , -strerror (TEST_ERRNO )); - }else { -tst_resm (TFAIL ,"unexpected error - %d : %s - " -"expected %d" ,TEST_ERRNO , -strerror (TEST_ERRNO ),TC [i].error); - } - } - } - -cleanup (); -tst_exit (); - +SAFE_TOUCH (TEMP_FILE ,0700 ,NULL ); } -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) +static void run (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* Create a temporary directory and make it current. */ -tst_tmpdir (); - -sprintf (fname,"./tfile_%d" ,getpid ()); -sprintf (mdir,"./rndir_%d" ,getpid ()); -sprintf (mname,"%s/rnfile_%d" , mdir,getpid ()); - -SAFE_TOUCH (cleanup, fname,0700 ,NULL ); +TST_EXP_FAIL (rename (TEMP_FILE , long_path), +ENAMETOOLONG ); } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -/* -* Remove the temporary directory. -*/ -tst_rmdir (); -} +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_tmpdir =1 +};Signature · 1 line
2.36.1
Like the rest of these tests this should be run on all filesystems as well. I guess if it fails on exFAT or something like that. Then we can filter out those filesystems because not every FS Linux supports may be POSIX compliant. However we probably want to make sure the main ones are (e.g. xfs, btrfs, ext4).
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 9/9] Rewrite rename10.c using new LTP API
Quoted 125 lines · IST Richard Palethorpe
Hello,
Quoted 105 lines · Avinesh Kumar
Signed-off-by Avinesh Kumar <[email protected]>--- testcases/kernel/syscalls/rename/rename10.c | 182 +++----------------- 1 file changed, 22 insertions(+), 160 deletions(-)testcases/kernel/syscalls/rename/rename10.c +11
-76@@ -1,175 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* -* Copyright (c) International Business Machines Corp., 2001 -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* Copyright (c) International Business Machines Corp., 2001 +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]> */ -/* -* NAME -* rename10 -* -* DESCRIPTION -* This test will verify that rename(2) syscall fails with ENAMETOOLONG -* and ENOENT -* -* ALGORITHM -* Setup: -* Setup signal handling. -* Create temporary directory. -* Pause for SIGUSR1 if option specified. -* create the "old" file -* -* Test: -* Loop if the proper options are given. -* 1. rename the "old" to the "new" file -* verify rename() failed with error ENAMETOOLONG -* -* 2. "new" path contains a directory that does not exist -* rename the "old" to the "new" -* verify rename() failed with error ENOENT -* Cleanup: -* Print errno log and/or timing stats if options given -* Delete the temporary directory created.* -* -* USAGE -* rename10 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. +/*\ +* [Description] * -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* None. +* Verify that rename(2) fails with ENAMETOOLONG, when +* oldpath or newpath is too long. */ -#include <sys/types.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> - -#include "test.h" - -void setup (); -void cleanup (); -char *TCID ="rename10" ; -int TST_TOTAL =2 ; +#include <stdio.h> +#include "tst_test.h" -char badmname[] = -"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz" ; +#define TEMP_FILE "tmpfile" -int fd; -char fname[255 ], mname[255 ]; -char mdir[255 ]; - -struct test_case_t { -char *fd1; -char *fd2;testcases/kernel/syscalls/rename/rename10.c line 20
Quoted 10 lines
testcases/kernel/syscalls/rename/rename10.c +1
-9-int error; -} TC[] = { -/* badmname is too long for a file name - ENAMETOOLONG */ - { - fname, badmname, ENAMETOOLONG}, -/* mname contains a directory component which does not exist - ENOENT */ - { - fname, mname, ENOENT} -}; +static char long_path[PATH_MAX +2 ] = {[0 ...PATH_MAX +1 ] ='a' };
PATH_MAXis actually the minimum number of bytes the system is allowed to set as the maximum path length. Meaning it can accept more. However it seems what we are actually testing here isNAME_MAXwhich is only 255 and can't be bigger than 255 according to POSIX.
Quoted 3 lines
So I think we should be testing what happens when 256 chars are passed as a filename (not including null terminating char).
Ah, Thank you, I think I have understood it now. Updated the patch using NAME_MAX in v3.
Quoted 90 lines
Quoted 90 lines
testcases/kernel/syscalls/rename/rename10.c +8
-75-int main (int ac,char **av) +static void setup (void ) { -int lc; -int i; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); - -/* -* perform global setup for test -*/ -setup (); - -/* -* check looping state if -i option given -*/ -for (lc =0 ;TEST_LOOPING (lc); lc++) { - - tst_count =0 ; - -/* loop through the test cases */ -for (i =0 ; i <TST_TOTAL ; i++) { - -TEST (rename (TC [i].fd1,TC [i].fd2)); - -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"call succeeded unexpectedly" ); -continue ; - } - -if (TEST_ERRNO ==TC [i].error) { -tst_resm (TPASS ,"expected failure - " -"errno = %d : %s" ,TEST_ERRNO , -strerror (TEST_ERRNO )); - }else { -tst_resm (TFAIL ,"unexpected error - %d : %s - " -"expected %d" ,TEST_ERRNO , -strerror (TEST_ERRNO ),TC [i].error); - } - } - } - -cleanup (); -tst_exit (); - +SAFE_TOUCH (TEMP_FILE ,0700 ,NULL ); } -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) +static void run (void ) { - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* Create a temporary directory and make it current. */ -tst_tmpdir (); - -sprintf (fname,"./tfile_%d" ,getpid ()); -sprintf (mdir,"./rndir_%d" ,getpid ()); -sprintf (mname,"%s/rnfile_%d" , mdir,getpid ()); - -SAFE_TOUCH (cleanup, fname,0700 ,NULL ); +TST_EXP_FAIL (rename (TEMP_FILE , long_path), +ENAMETOOLONG ); } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) -{ - -/* -* Remove the temporary directory. -*/ -tst_rmdir (); -} +static struct tst_test test = { + .setup = setup, + .test_all = run,
Quoted 8 lines
testcases/kernel/syscalls/rename/rename10.c line 37
Quoted 2 lines
testcases/kernel/syscalls/rename/rename10.c +2
-0+ .needs_tmpdir = 1 +};Like the rest of these tests this should be run on all filesystems as well. I guess if it fails on exFAT or something like that. Then we can filter out those filesystems because not every FS Linux supports may be POSIX compliant. However we probably want to make sure the main ones are (e.g. xfs, btrfs, ext4).
Enabled the tests on all filesystems in v3.
Quoted 2 lines
--
Avinesh
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp