Add ELOOP and EROFS error number tests for lchown(2) Signed-off-by: Zeng Linggang <[email protected]> --- runtest/ltplite | 1 + runtest/stress.part3 | 1 + runtest/syscalls | 2 + testcases/kernel/syscalls/.gitignore | 2 + testcases/kernel/syscalls/lchown/lchown03.c | 169 ++++++++++++++++++++++++++++ 5 files changed, 175 insertions(+) create mode 100644 testcases/kernel/syscalls/lchown/lchown03.c
diff --git a/runtest/ltplite b/runtest/ltplite index 9a8a78c..c34c589 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -373,6 +373,7 @@ kill12 kill12 lchown01 lchown01 lchown02 lchown02 +lchown03 lchown03 -D $LTP_DEV -T $LTP_DEV_FS_TYPE link01 symlink01 -T link01 link02 link02 diff --git a/runtest/stress.part3 b/runtest/stress.part3 index 458d267..27667d2 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -306,6 +306,7 @@ kill12 kill12 lchown01 lchown01 lchown02 lchown02 +lchown03 lchown03 -D $LTP_DEV -T $LTP_DEV_FS_TYPE link01 symlink01 -T link01 link02 link02 diff --git a/runtest/syscalls b/runtest/syscalls index 794f140..aec49ad 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -475,7 +475,9 @@ kill12 kill12 lchown01 lchown01 lchown01_16 lchown01_16 lchown02 lchown02 +lchown03 lchown03 -D $LTP_DEV -T $LTP_DEV_FS_TYPE lchown02_16 lchown02_16 +lchown03_16 lchown03_16 -D $LTP_DEV -T $LTP_DEV_FS_TYPE link01 symlink01 -T link01 link02 link02 diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore index cf446b0..d461569 100644 --- a/testcases/kernel/syscalls/.gitignore +++ b/testcases/kernel/syscalls/.gitignore @@ -444,6 +444,8 @@ /lchown/lchown01_16 /lchown/lchown02 /lchown/lchown02_16 +/lchown/lchown03 +/lchown/lchown03_16 /link/link02 /link/link03 /link/link04 diff --git a/testcases/kernel/syscalls/lchown/lchown03.c b/testcases/kernel/syscalls/lchown/lchown03.c new file mode 100644 index 0000000..1044aa1 --- /dev/null +++ b/testcases/kernel/syscalls/lchown/lchown03.c @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2014 Fujitsu Ltd. + * Author: Zeng Linggang <[email protected]> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +/* + * Test Description: + * Verify that, + * 1. lchown() fails with -1 return value and sets errno to ELOOP + * if too many symbolic links were encountered in resolving path. + * 2. lchown() fails with -1 return value and sets errno to EROFS + * if the file is on a read-only file system. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <string.h> +#include <signal.h> +#include <grp.h> +#include <pwd.h> +#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 DIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \ + S_IXGRP|S_IROTH|S_IXOTH) +#define TEST_EROFS "mntpoint" + +static char test_eloop[PATH_MAX] = "."; +static char *fstype = "ext2"; +static char *device; +static int mount_flag; + +static option_t options[] = { + {"T:", NULL, &fstype}, + {"D:", NULL, &device}, + {NULL, NULL, NULL} +}; + +static struct test_case_t { + char *pathname; + int exp_errno; +} test_cases[] = { + {test_eloop, ELOOP}, + {TEST_EROFS, EROFS}, +}; + +char *TCID = "lchown03"; +int TST_TOTAL = ARRAY_SIZE(test_cases); +static int exp_enos[] = { ELOOP, EROFS, 0 }; + +static void setup(void); +static void lchown_verify(const struct test_case_t *); +static void cleanup(void); +static void help(void); + +int main(int argc, char *argv[]) +{ + int lc; + int i; + char *msg; + + msg = parse_opts(argc, argv, options, help); + if (msg != NULL) + tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); + + if (!device) { + tst_brkm(TBROK, NULL, + "you must specify the device used for mounting with " + "-D option"); + } + + setup(); + + TEST_EXP_ENOS(exp_enos); + + for (lc = 0; TEST_LOOPING(lc); lc++) { + tst_count = 0; + for (i = 0; i < TST_TOTAL; i++) + lchown_verify(&test_cases[i]); + } + + cleanup(); + tst_exit(); +} + +static void setup(void) +{ + int i; + + tst_require_root(NULL); + + tst_sig(NOFORK, DEF_HANDLER, cleanup); + + TEST_PAUSE; + + tst_tmpdir(); + + SAFE_MKDIR(cleanup, "test_eloop", DIR_MODE); + SAFE_SYMLINK(cleanup, "../test_eloop", "test_eloop/test_eloop"); + for (i = 0; i < 43; i++) + strcat(test_eloop, "/test_eloop"); + + tst_mkfs(NULL, device, fstype, NULL); + SAFE_MKDIR(cleanup, TEST_EROFS, DIR_MODE); + if (mount(device, TEST_EROFS, fstype, MS_RDONLY, NULL) < 0) { + tst_brkm(TBROK | TERRNO, cleanup, + "mount device:%s failed", device); + } + mount_flag = 1; +} + +static void lchown_verify(const struct test_case_t *test) +{ + TEST(lchown(test->pathname, geteuid(), getegid())); + + if (TEST_RETURN != -1) { + tst_resm(TFAIL, "lchown() returned %ld, expected -1, errno=%d", + TEST_RETURN, test->exp_errno); + return; + } + + TEST_ERROR_LOG(TEST_ERRNO); + + if (TEST_ERRNO == test->exp_errno) { + tst_resm(TPASS | TTERRNO, "lchown() failed as expected"); + } else { + tst_resm(TFAIL | TTERRNO, + "lchown() failed unexpectedly; expected: %d - %s", + test->exp_errno, + strerror(test->exp_errno)); + } +} + +static void cleanup(void) +{ + TEST_CLEANUP; + + if (mount_flag && umount(TEST_EROFS) < 0) + tst_resm(TWARN | TERRNO, "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"); +} -- 1.8.4.2 ------------------------------------------------------------------------------ Managing the Performance of Cloud-Based Applications Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. Read the Whitepaper. http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
