From: Cyril H. <su...@li...> - 2013-10-31 02:51:09
|
The branch, master, has been updated via 2d127a3fcdbe19b892e3a3ee348c95f4a4fde374 (commit) via 3aa27d974dcf44e16228fd2d649c842ca667de2a (commit) via 4f305454e656739f609bc90a8118fd2c270ee1f2 (commit) from b3c1c0fc2373b27227f268c88945ead56eedb067 (commit) - Log ----------------------------------------------------------------- commit 2d127a3fcdbe19b892e3a3ee348c95f4a4fde374 Author: Zeng Linggang <zen...@cn...> Date: Fri Oct 25 18:43:16 2013 +0800 chown/chown04.c: Add ELOOP EROFS Add ELOOP, EROFS error number test in chown04.c for chown(2) Signed-off-by: Zeng Linggang <zen...@cn...> Signed-off-by: Wanlong Gao <gao...@cn...> commit 3aa27d974dcf44e16228fd2d649c842ca667de2a Author: Wang, Xiaoguang <wan...@cn...> Date: Fri Oct 25 16:13:40 2013 +0800 chmod/chmod06.c: add ELOOP, EROFS error number test for chmod(2) Signed-off-by: Xiaoguang Wang <wan...@cn...> Signed-off-by: Wanlong Gao <gao...@cn...> commit 4f305454e656739f609bc90a8118fd2c270ee1f2 Author: Zeng Linggang <zen...@cn...> Date: Mon Oct 28 09:32:06 2013 +0800 chdir/chdir01.c: Add ELOOP error number test Add ELOOP error number test in chdir01.c for chdir(2) Signed-off-by: Zeng Linggang <zen...@cn...> Signed-off-by: Wanlong Gao <gao...@cn...> ----------------------------------------------------------------------- Summary of changes: runtest/ltplite | 2 +- runtest/stress.part3 | 2 +- runtest/syscalls | 6 +- testcases/kernel/syscalls/chdir/chdir01.c | 21 ++++++++- testcases/kernel/syscalls/chmod/chmod06.c | 65 +++++++++++++++++++++++++++- testcases/kernel/syscalls/chown/chown04.c | 58 ++++++++++++++++++++++++- 6 files changed, 141 insertions(+), 13 deletions(-) diff --git a/runtest/ltplite b/runtest/ltplite index 60140e2..a6f57e2 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -110,7 +110,7 @@ chmod07 chmod07 chown01 chown01 chown02 chown02 chown03 export change_owner=$LTPROOT/testcases/bin/change_owner;chown03 -chown04 cp -p $LTPROOT/testcases/bin/change_owner $TMPDIR;chown04 +chown04 cp -p $LTPROOT/testcases/bin/change_owner $TMPDIR;chown04 -D DEVICE -T DEVICE_FS_TYPE chown05 chown05 chroot01 chroot01 diff --git a/runtest/stress.part3 b/runtest/stress.part3 index 7e7f1b7..2962cc4 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -52,7 +52,7 @@ chmod07 chmod07 chown01 chown01 chown02 chown02 chown03 export change_owner=$LTPROOT/testcases/bin/change_owner;chown03 -chown04 cp -p $LTPROOT/testcases/bin/change_owner $TMPDIR;chown04 +chown04 cp -p $LTPROOT/testcases/bin/change_owner $TMPDIR;chown04 -D DEVICE -T DEVICE_FS_TYPE chown05 chown05 chroot01 chroot01 diff --git a/runtest/syscalls b/runtest/syscalls index 0486b95..b4bb201 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -54,7 +54,7 @@ chmod02 chmod02 chmod03 chmod03 chmod04 chmod04 chmod05 chmod05 -chmod06 chmod06 +chmod06 chmod06 -D DEVICE -T DEVICE_FS_TYPE chmod07 chmod07 chown01 chown01 @@ -63,8 +63,8 @@ chown02 chown02 chown02_16 chown02_16 chown03 chown03 chown03_16 chown03_16 -chown04 chown04 -chown04_16 chown04_16 +chown04 chown04 -D DEVICE -T DEVICE_FS_TYPE +chown04_16 chown04_16 -D DEVICE -T DEVICE_FS_TYPE chown05 chown05 chown05_16 chown05_16 diff --git a/testcases/kernel/syscalls/chdir/chdir01.c b/testcases/kernel/syscalls/chdir/chdir01.c index 04fb8b4..c4e74fb 100644 --- a/testcases/kernel/syscalls/chdir/chdir01.c +++ b/testcases/kernel/syscalls/chdir/chdir01.c @@ -59,9 +59,9 @@ #include "safe_macros.h" char *TCID = "chdir01"; -int TST_TOTAL = 1; +int TST_TOTAL = 2; -int exp_enos[] = { ENOTDIR, 0 }; +int exp_enos[] = { ENOTDIR, ELOOP, 0 }; void setup(void); void cleanup(void); @@ -120,6 +120,23 @@ int main(int ac, char **av) SAFE_CHDIR(cleanup, ".."); + /* ELOOP */ + SAFE_SYMLINK(cleanup, "test_eloop1", "test_eloop2"); + SAFE_SYMLINK(cleanup, "test_eloop2", "test_eloop1"); + + TEST(chdir("test_eloop1")); + + if (TEST_RETURN != -1) { + tst_resm(TFAIL, "call succeeded unexpectedly"); + } else if (TEST_ERRNO != ELOOP) { + tst_resm(TFAIL | TTERRNO, + "failed unexpectedly; wanted ELOOP"); + } else { + tst_resm(TPASS, "failed as expected with ELOOP"); + } + + SAFE_UNLINK(cleanup, "test_eloop1"); + SAFE_UNLINK(cleanup, "test_eloop2"); } cleanup(); diff --git a/testcases/kernel/syscalls/chmod/chmod06.c b/testcases/kernel/syscalls/chmod/chmod06.c index 0745f02..0dd2433 100644 --- a/testcases/kernel/syscalls/chmod/chmod06.c +++ b/testcases/kernel/syscalls/chmod/chmod06.c @@ -92,9 +92,11 @@ #include <sys/types.h> #include <sys/stat.h> #include <sys/mman.h> +#include <sys/mount.h> #include "test.h" #include "usctest.h" +#include "safe_macros.h" #define MODE_RWX (S_IRWXU|S_IRWXG|S_IRWXO) #define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) @@ -102,16 +104,33 @@ #define TEST_FILE1 "tfile_1" #define TEST_FILE2 "testdir_1/tfile_2" #define TEST_FILE3 "t_file/tfile_3" +#define TEST_FILE4 "test_file4" +#define MNT_POINT "mntpoint" + +#define DIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \ + S_IXGRP|S_IROTH|S_IXOTH) int setup1(); /* setup function to test chmod for EPERM */ int setup2(); /* setup function to test chmod for EACCES */ int setup3(); /* setup function to test chmod for ENOTDIR */ int longpath_setup(); /* setup function to test chmod for ENAMETOOLONG */ +static void help(); char *test_home; /* variable to hold TESTHOME env. */ char Longpathname[PATH_MAX + 2]; char High_address_node[64]; +static char *fstype = "ext2"; +static char *device; +static int dflag; +static int mount_flag; + +static option_t options[] = { + {"T:", NULL, &fstype}, + {"D:", &dflag, &device}, + {NULL, NULL, NULL} +}; + struct test_case_t { /* test case struct. to hold ref. test cond's */ char *pathname; mode_t mode; @@ -140,8 +159,10 @@ struct test_case_t { /* test case struct. to hold ref. test cond's */ { "", FILE_MODE, ENOENT, NULL}, /* Pathname contains a regular file. */ - { -TEST_FILE3, FILE_MODE, ENOTDIR, setup3},}; + {TEST_FILE3, FILE_MODE, ENOTDIR, setup3}, + {MNT_POINT, FILE_MODE, EROFS, NULL}, + {TEST_FILE4, FILE_MODE, ELOOP, NULL}, +}; char *TCID = "chmod06"; int TST_TOTAL = sizeof(test_cases) / sizeof(*test_cases); @@ -162,9 +183,16 @@ int main(int ac, char **av) char nobody_uid[] = "nobody"; struct passwd *ltpuser; - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) + msg = parse_opts(ac, av, options, help); + if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); + /* Check for mandatory option of the testcase */ + if (!dflag) { + tst_brkm(TBROK, NULL, "you must specify the device " + "used for mounting with -D option"); + } + setup(); TEST_EXP_ENOS(exp_enos); @@ -240,6 +268,19 @@ void setup() tst_tmpdir(); + tst_mkfs(NULL, device, fstype, NULL); + + SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE); + + /* + * mount a read-only file system for test EROFS + */ + if (mount(device, MNT_POINT, fstype, MS_RDONLY, NULL) < 0) { + tst_brkm(TBROK | TERRNO, cleanup, + "mount device:%s failed", device); + } + mount_flag = 1; + bad_addr = mmap(0, 1, PROT_NONE, MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0); if (bad_addr == MAP_FAILED) @@ -249,6 +290,13 @@ void setup() for (i = 0; i < TST_TOTAL; i++) if (test_cases[i].setupfunc != NULL) test_cases[i].setupfunc(); + + /* + * create two symbolic links who point to each other for + * test ELOOP. + */ + SAFE_SYMLINK(cleanup, "test_file4", "test_file5"); + SAFE_SYMLINK(cleanup, "test_file5", "test_file4"); } /* @@ -355,5 +403,16 @@ void cleanup() if (chmod(DIR_TEMP, MODE_RWX) == -1) tst_resm(TBROK | TERRNO, "chmod(%s) failed", DIR_TEMP); + if (mount_flag && umount(MNT_POINT) < 0) { + tst_brkm(TBROK | TERRNO, NULL, + "umount device:%s failed", device); + } tst_rmdir(); } + +static void help(void) +{ + printf("-T type : specifies the type of filesystem to be mounted. " + "Default ext2.\n"); + printf("-D device : device used for mounting.\n"); +} diff --git a/testcases/kernel/syscalls/chown/chown04.c b/testcases/kernel/syscalls/chown/chown04.c index f45afc5..47b54bb 100644 --- a/testcases/kernel/syscalls/chown/chown04.c +++ b/testcases/kernel/syscalls/chown/chown04.c @@ -88,24 +88,41 @@ #include <sys/types.h> #include <sys/stat.h> #include <sys/mman.h> +#include <sys/mount.h> #include "test.h" #include "usctest.h" +#include "safe_macros.h" #define MODE_RWX (S_IRWXU|S_IRWXG|S_IRWXO) #define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) +#define DIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \ + S_IXGRP|S_IROTH|S_IXOTH) #define DIR_TEMP "testdir_1" #define TEST_FILE1 "tfile_1" #define TEST_FILE2 (DIR_TEMP "/tfile_2") #define TEST_FILE3 "t_file/tfile_3" +#define TEST_FILE4 "test_eloop1" +#define TEST_FILE5 "mntpoint" void setup1(); void setup2(); void setup3(); void longpath_setup(); +static void help(void); char Longpathname[PATH_MAX + 2]; char high_address_node[64]; +static char *fstype = "ext2"; +static char *device; +static int dflag; +static int mount_flag; + +static option_t options[] = { + {"T:", NULL, &fstype}, + {"D:", &dflag, &device}, + {NULL, NULL, NULL} +}; struct test_case_t { char *pathname; @@ -119,11 +136,14 @@ struct test_case_t { (char *)-1, EFAULT, NULL}, { Longpathname, ENAMETOOLONG, longpath_setup}, { "", ENOENT, NULL}, { -TEST_FILE3, ENOTDIR, setup3},}; + TEST_FILE3, ENOTDIR, setup3}, { + TEST_FILE4, ELOOP, NULL}, { + TEST_FILE5, EROFS, NULL},}; char *TCID = "chown04"; int TST_TOTAL = sizeof(test_cases) / sizeof(*test_cases); -int exp_enos[] = { EPERM, EACCES, EFAULT, ENAMETOOLONG, ENOENT, ENOTDIR, 0 }; +int exp_enos[] = { EPERM, EACCES, EFAULT, ENAMETOOLONG, ENOENT, ENOTDIR, + ELOOP, EROFS, 0 }; struct passwd *ltpuser; @@ -141,8 +161,13 @@ int main(int ac, char **av) uid_t user_id; gid_t group_id; - if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) + msg = parse_opts(ac, av, options, help); + if (msg != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); + if (!dflag) { + tst_brkm(TBROK, NULL, "you must specify the device used for " + "mounting with -D option"); + } setup(); @@ -185,9 +210,12 @@ int main(int ac, char **av) void setup() { int i; + int fd; tst_require_root(NULL); + tst_mkfs(NULL, device, fstype, NULL); + tst_sig(FORK, DEF_HANDLER, cleanup); ltpuser = getpwnam("nobody"); @@ -208,6 +236,19 @@ void setup() test_cases[3].pathname = bad_addr; + SAFE_SYMLINK(cleanup, "test_eloop1", "test_eloop2"); + SAFE_SYMLINK(cleanup, "test_eloop2", "test_eloop1"); + + SAFE_SETEUID(cleanup, 0); + SAFE_MKDIR(cleanup, "mntpoint", DIR_MODE); + if (mount(device, "mntpoint", fstype, MS_RDONLY, NULL) < 0) { + tst_brkm(TBROK | TERRNO, cleanup, + "mount device:%s failed", device); + } + mount_flag = 1; + + SAFE_SETEUID(cleanup, ltpuser->pw_uid); + for (i = 0; i < TST_TOTAL; i++) if (test_cases[i].setupfunc != NULL) test_cases[i].setupfunc(); @@ -290,7 +331,18 @@ void cleanup() if (seteuid(0) == -1) tst_resm(TWARN | TERRNO, "seteuid(0) failed"); + if (mount_flag && umount("mntpoint") < 0) { + tst_brkm(TBROK | TERRNO, NULL, + "umount device:%s failed", device); + } tst_rmdir(); } + +static void help(void) +{ + printf("-T type : specifies the type of filesystem to be mounted. " + "Default ext2.\n"); + printf("-D device : device used for mounting.\n"); +} hooks/post-receive -- ltp |