Add rename15 test
PATCH v3 1/1 Add rename15 test
From: Andrea Cervesato <[email protected]>
This test has been extracted from symlink01 and it verifies that rename() is working correctly on symlink() generated files, renaming symbolic link and checking if stat() information are preserved.
---
- tst_tmpdir_path/tst_tmpdir_mkpath usage
- use absolute paths
- add all_filesystems = 1
runtest/syscalls | 2 +- testcases/kernel/syscalls/rename/.gitignore | 1 + testcases/kernel/syscalls/rename/rename15.c | 109 ++++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/rename/rename15.c
runtest/syscalls +1 -1
@@ -1173,7 +1173,6 @@ removexattr01 removexattr01 removexattr02 removexattr02 rename01 rename01 -rename01A symlink01 -T rename01 rename03 rename03 rename04 rename04 rename05 rename05
@@ -1186,6 +1185,7 @@ rename11 rename11 rename12 rename12 rename13 rename13 rename14 rename14 +rename15 rename15 #renameat test cases renameat01 renameat01
testcases/kernel/syscalls/rename/.gitignore +1 -0
@@ -11,3 +11,4 @@ /rename12 /rename13 /rename14 +/rename15
testcases/kernel/syscalls/rename/rename15.c new file +109 -0
109 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 2 lines · Andrea Cervesato
From: Andrea Cervesato <[email protected]>
Quoted 173 lines
This test has been extracted from symlink01 and it verifies that
rename()is working correctly onsymlink()generated files, renaming symbolic link and checking ifstat()information are preserved.Signed-off-by Andrea Cervesato <[email protected]>---
- tst_tmpdir_path/tst_tmpdir_mkpath usage
- use absolute paths
- addall_filesystems= 1runtest/syscalls | 2 +- testcases/kernel/syscalls/rename/.gitignore | 1 + testcases/kernel/syscalls/rename/rename15.c | 109 ++++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/rename/rename15.cruntest/syscalls +1
-1@@ -1173,7 +1173,6 @@ removexattr01 removexattr01 removexattr02 removexattr02 rename01 rename01 -rename01A symlink01 -T rename01 rename03 rename03 rename04 rename04 rename05 rename05@@ -1186,6 +1185,7 @@ rename11 rename11 rename12 rename12 rename13 rename13 rename14 rename14 +rename15 rename15 #renameat test cases renameat01 renameat01testcases/kernel/syscalls/rename/.gitignore +1
-0@@ -11,3 +11,4 @@ /rename12 /rename13 /rename14 +/rename15testcases/kernel/syscalls/rename/rename15.c new file +30
-0@@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. +* Authors: David Fenner, Jon Hendrickson +* Copyright (C) 2024 Andrea Cervesato [email protected] +*/ + +/*\ +* [Description] +* +* This test verifies that rename() is working correctly on symlink() +* generated files. +*/ + +#include "tst_test.h" +#include "tst_tmpdir.h" + +#define MNTPOINT "mnt" +#define OLDNAME MNTPOINT"/msymlink0" +#define NEWNAME MNTPOINT"/asymlink0" +#define OBJNAME MNTPOINT"/object" + +static char *tmpdir; +static char *oldname; +static char *newname; +static char *objname; + +static void test_existing (void ) +{ + tst_res(TINFO, "Test rename() on symlink pointing to an existentpath");
testcases/kernel/syscalls/rename/rename15.c new file +19
-0+ +struct stat oldsym_stat; +struct stat newsym_stat; + +SAFE_SYMLINK (tmpdir, oldname); +SAFE_STAT (oldname, &oldsym_stat); + +SAFE_RENAME (oldname, newname); +SAFE_STAT (newname, &newsym_stat); + +TST_EXP_EQ_LI (oldsym_stat.st_ino, newsym_stat.st_ino); +TST_EXP_EQ_LI (oldsym_stat.st_dev, newsym_stat.st_dev); + +SAFE_UNLINK (newname); +} + +static void test_non_existing (void ) +{ + tst_res(TINFO, "Test rename() on symlink pointing to anon-existent path");
testcases/kernel/syscalls/rename/rename15.c new file +16
-0+ +struct stat path_stat; + +SAFE_SYMLINK ("this_path_doesnt_exist" , oldname); +TST_EXP_FAIL (stat (oldname, &path_stat),ENOENT ); + +SAFE_RENAME (oldname, newname); +TST_EXP_FAIL (stat (newname, &path_stat),ENOENT ); + +SAFE_UNLINK (newname); +} + +static void test_creat (void ) +{ + + tst_res(TINFO, "Test rename() on symlink pointing to a pathcreated lately");
testcases/kernel/syscalls/rename/rename15.c new file +44
-1+ +struct stat path_stat; + +SAFE_SYMLINK (objname, oldname); +TST_EXP_FAIL (stat (oldname, &path_stat),ENOENT ); + +tst_res (TINFO ,"Create object file" ); + +int fd; + + fd =SAFE_CREAT (objname,0700 ); +if (fd >=0 ) +SAFE_CLOSE (fd); + +SAFE_RENAME (oldname, newname); +TST_EXP_PASS (stat (newname, &path_stat)); + +SAFE_UNLINK (objname); +SAFE_UNLINK (newname); +} + +static void run (void ) +{ +test_existing (); +test_creat (); +test_non_existing (); +} + +static void setup (void ) +{ + tmpdir =tst_tmpdir_path (); + oldname =tst_tmpdir_mkpath (OLDNAME ); + newname =tst_tmpdir_mkpath (NEWNAME ); + objname =tst_tmpdir_mkpath (OBJNAME ); +} + +static struct tst_test test = { + .setup = setup, + .test_all = run, + .all_filesystems =1 , + .mntpoint =MNTPOINT , + .format_device =1 , + .needs_root =1 , +}; --2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 83 lines
This test has been extracted from symlink01 and it verifies that
rename()is working correctly onsymlink()generated files, renaming symbolic link and checking ifstat()information are preserved.Signed-off-by Andrea Cervesato <[email protected]>---
- tst_tmpdir_path/tst_tmpdir_mkpath usage
- use absolute paths
- addall_filesystems= 1runtest/syscalls | 2 +- testcases/kernel/syscalls/rename/.gitignore | 1 + testcases/kernel/syscalls/rename/rename15.c | 109 ++++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/rename/rename15.cruntest/syscalls +1
-1@@ -1173,7 +1173,6 @@ removexattr01 removexattr01 removexattr02 removexattr02 rename01 rename01 -rename01A symlink01 -T rename01 rename03 rename03 rename04 rename04 rename05 rename05@@ -1186,6 +1185,7 @@ rename11 rename11 rename12 rename12 rename13 rename13 rename14 rename14 +rename15 rename15 #renameat test cases renameat01 renameat01testcases/kernel/syscalls/rename/.gitignore +1
-0@@ -11,3 +11,4 @@ /rename12 /rename13 /rename14 +/rename15testcases/kernel/syscalls/rename/rename15.c new file +32
-0@@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. +* Authors: David Fenner, Jon Hendrickson +* Copyright (C) 2024 Andrea Cervesato [email protected] +*/ + +/*\ +* [Description] +* +* This test verifies that rename() is working correctly on symlink() +* generated files. +*/ + +#include "tst_test.h" +#include "tst_tmpdir.h" + +#define MNTPOINT "mnt" +#define OLDNAME MNTPOINT"/msymlink0" +#define NEWNAME MNTPOINT"/asymlink0" +#define OBJNAME MNTPOINT"/object" + +static char *tmpdir; +static char *oldname; +static char *newname; +static char *objname; + +static void test_existing (void ) +{ +tst_res (TINFO ,"Test rename() on symlink pointing to an existent path" ); + +struct stat oldsym_stat;
testcases/kernel/syscalls/rename/rename15.c line 42
Quoted 10 lines
testcases/kernel/syscalls/rename/rename15.c new file +10
-0+struct stat newsym_stat; + +SAFE_SYMLINK (tmpdir, oldname); +SAFE_STAT (oldname, &oldsym_stat); + +SAFE_RENAME (oldname, newname); +SAFE_STAT (newname, &newsym_stat); + +TST_EXP_EQ_LI (oldsym_stat.st_ino, newsym_stat.st_ino); +TST_EXP_EQ_LI (oldsym_stat.st_dev, newsym_stat.st_dev);
Here we should test that the oldname is not there anymore.
Quoted 4 lines
testcases/kernel/syscalls/rename/rename15.c new file +4
-0+SAFE_UNLINK (newname); +} + +static void test_non_existing (void )
testcases/kernel/syscalls/rename/rename15.c line 57
Quoted 10 lines
testcases/kernel/syscalls/rename/rename15.c new file +10
-0+{ +tst_res (TINFO ,"Test rename() on symlink pointing to a non-existent path" ); + +struct stat path_stat; + +SAFE_SYMLINK ("this_path_doesnt_exist" , oldname); +TST_EXP_FAIL (stat (oldname, &path_stat),ENOENT ); + +SAFE_RENAME (oldname, newname); +TST_EXP_FAIL (stat (newname, &path_stat),ENOENT );
I guess that we should use lstat() here to at least make sure that the symlinks are present when they should be.
Quoted 13 lines
testcases/kernel/syscalls/rename/rename15.c new file +13
-0+SAFE_UNLINK (newname); +} + +static void test_creat (void ) +{ + +tst_res (TINFO ,"Test rename() on symlink pointing to a path created lately" ); + +struct stat path_stat; + +SAFE_SYMLINK (objname, oldname); +TST_EXP_FAIL (stat (oldname, &path_stat),ENOENT ); +
testcases/kernel/syscalls/rename/rename15.c line 81
Quoted 10 lines
testcases/kernel/syscalls/rename/rename15.c new file +10
-0+tst_res (TINFO ,"Create object file" ); + +int fd; + + fd =SAFE_CREAT (objname,0700 ); +if (fd >=0 ) +SAFE_CLOSE (fd); + +SAFE_RENAME (oldname, newname); +TST_EXP_PASS (stat (newname, &path_stat));
Shouldn't we also check here that:
- oldname is not there anymore
- objname is still there
Quoted 33 lines
testcases/kernel/syscalls/rename/rename15.c new file +27
-0+SAFE_UNLINK (objname); +SAFE_UNLINK (newname); +} + +static void run (void ) +{ +test_existing (); +test_creat (); +test_non_existing (); +} + +static void setup (void ) +{ + tmpdir =tst_tmpdir_path (); + oldname =tst_tmpdir_mkpath (OLDNAME ); + newname =tst_tmpdir_mkpath (NEWNAME ); + objname =tst_tmpdir_mkpath (OBJNAME ); +} + +static struct tst_test test = { + .setup = setup, + .test_all = run, + .all_filesystems =1 , + .mntpoint =MNTPOINT , + .format_device =1 , + .needs_root =1 , +};Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp