Add chmod08 test
PATCH v2 1/1 Add chmod08 test
From: Andrea Cervesato <[email protected]>
This test has been extracted from symlink01 and it verifies that chmod() is working correctly on symlink() generated files.
Signed-off-by Andrea Cervesato <[email protected]>
--- testcases/kernel/syscalls/chmod/chmod08.c | 61 +++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 testcases/kernel/syscalls/chmod/chmod08.c
testcases/kernel/syscalls/chmod/chmod08.c new file +61 -0
@@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. +* Author: David Fenner +* Copilot: Jon Hendrickson +* Copyright (C) 2024 Andrea Cervesato [email protected] +*/ + +/*\ +* [Description] +* +* This test verifies that chmod() is working correctly on symlink() +* generated files. +*/ + +#include "tst_test.h" + +#define PERMS 01777 +#define TESTFILE "myobject" + +static char testfile[PATH_MAX ]; + +static void run (void ) +{ +char *symname ="my_symlink0" ; +struct stat oldsym_stat; +struct stat newsym_stat; + +SAFE_TOUCH (testfile,0644 ,NULL ); +SAFE_SYMLINK (testfile, symname); +SAFE_STAT (symname, &oldsym_stat); + +TST_EXP_PASS (chmod (symname,PERMS )); +SAFE_STAT (symname, &newsym_stat); + +TST_EXP_EQ_LI (newsym_stat.st_mode &PERMS ,PERMS ); +TST_EXP_EXPR (oldsym_stat.st_mode != newsym_stat.st_mode, +"file mode has changed" ); + +SAFE_UNLINK (symname); +remove (testfile); +} + +static void setup (void ) +{ +int tmplen; +char *tmpdir; + + tmpdir =tst_get_tmpdir (); + tmplen =strlen (tmpdir); + + testfile[tmplen] ='/' ; +memcpy (testfile, tmpdir, tmplen); +memcpy (testfile + tmplen +1 ,TESTFILE ,strlen (TESTFILE )); +} + +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_tmpdir =1 , +};
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 43 lines
Signed-off-by Andrea Cervesato <[email protected]>--- testcases/kernel/syscalls/chmod/chmod08.c | 61 +++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 testcases/kernel/syscalls/chmod/chmod08.ctestcases/kernel/syscalls/chmod/chmod08.c new file +31
-0@@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. +* Author: David Fenner +* Copilot: Jon Hendrickson +* Copyright (C) 2024 Andrea Cervesato [email protected] +*/ + +/*\ +* [Description] +* +* This test verifies that chmod() is working correctly on symlink() +* generated files. +*/ + +#include "tst_test.h" + +#define PERMS 01777 +#define TESTFILE "myobject" + +static char testfile[PATH_MAX ]; + +static void run (void ) +{ +char *symname ="my_symlink0" ; +struct stat oldsym_stat; +struct stat newsym_stat; + +SAFE_TOUCH (testfile,0644 ,NULL ); +SAFE_SYMLINK (testfile, symname); +SAFE_STAT (symname, &oldsym_stat);
testcases/kernel/syscalls/chmod/chmod08.c line 41
Quoted 10 lines
testcases/kernel/syscalls/chmod/chmod08.c new file +10
-0+ +TST_EXP_PASS (chmod (symname,PERMS )); +SAFE_STAT (symname, &newsym_stat); + +TST_EXP_EQ_LI (newsym_stat.st_mode &PERMS ,PERMS ); +TST_EXP_EXPR (oldsym_stat.st_mode != newsym_stat.st_mode, +"file mode has changed" ); + +SAFE_UNLINK (symname); +remove (testfile);
This should be SAFE_UNLINK() as well.
testcases/kernel/syscalls/chmod/chmod08.c line 54
Quoted 13 lines
testcases/kernel/syscalls/chmod/chmod08.c new file +13
-0+} + +static void setup (void ) +{ +int tmplen; +char *tmpdir; + + tmpdir =tst_get_tmpdir (); + tmplen =strlen (tmpdir); + + testfile[tmplen] ='/' ; +memcpy (testfile, tmpdir, tmplen); +memcpy (testfile + tmplen +1 ,TESTFILE ,strlen (TESTFILE ));
This can easily overflow. If you want to use absolute path you should allocate the buffer based on the tmpdir lenght...
Quoted 13 lines
testcases/kernel/syscalls/chmod/chmod08.c new file +7
-0+} + +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_tmpdir =1 , +};Signature · 5 lines
2.35.3 -- 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