Please ignore these two patches. I will send some new's. Sorry for that. Best regards, Zeng On Thu, 2014-06-12 at 17:32 +0800, Zeng Linggang wrote: > Add EPERM and EROFS errno testes for utime(2). > > Signed-off-by: Zeng Linggang <[email protected]> > --- > testcases/kernel/syscalls/utime/utime06.c | 84 > +++++++++++++++++++++++++++---- > 1 file changed, 73 insertions(+), 11 deletions(-) > > diff --git a/testcases/kernel/syscalls/utime/utime06.c > b/testcases/kernel/syscalls/utime/utime06.c > index 2dd68d8..1406bd0 100644 > --- a/testcases/kernel/syscalls/utime/utime06.c > +++ b/testcases/kernel/syscalls/utime/utime06.c > @@ -26,6 +26,13 @@ > * - The user ID of the process is not "root". > * 2. Verify that the system call utime() fails to set the modification > * and access times of a file if the specified file doesn't exist. > + * 3. Verify that the system call utime() fails to set the modification > + * and access times of a file to the current time, under the following > + * constraints, > + * - The times argument is not null. > + * - The user ID of the process is not "root". > + * 4. Verify that the system call utime() fails to set the modification > + * and access times of a file that resides on a read-only file system. > */ > > #include <errno.h> > @@ -40,30 +47,50 @@ > #include <wait.h> > #include <sys/stat.h> > #include <sys/types.h> > +#include <sys/mount.h> > > #include "test.h" > #include "usctest.h" > #include "safe_macros.h" > > #define TEMP_FILE "tmp_file" > +#define MNT_POINT "mntpoint" > > char *TCID = "utime06"; > -static int exp_enos[] = { EACCES, ENOENT, 0 }; > - > +static int exp_enos[] = { EACCES, ENOENT, EPERM, EROFS, 0 }; > static struct passwd *ltpuser; > +static const struct utimbuf times; > +static char *fstype = "ext2"; > +static char *device; > +static int mount_flag; > + > +static void setup_nobody(void); > +static void cleanup_nobody(void); > + > +static option_t options[] = { > + {"T:", NULL, &fstype}, > + {"D:", NULL, &device}, > + {NULL, NULL, NULL} > +}; > > struct test_case_t { > char *pathname; > int exp_errno; > + const struct utimbuf *times; > + void (*setup_func)(void); > + void (*cleanup_func)(void); > } Test_cases[] = { > - {TEMP_FILE, EACCES}, > - {"", ENOENT}, > + {TEMP_FILE, EACCES, NULL, setup_nobody, cleanup_nobody}, > + {"", ENOENT, NULL, NULL, NULL}, > + {TEMP_FILE, EPERM, ×, setup_nobody, cleanup_nobody}, > + {MNT_POINT, EROFS, NULL, NULL, NULL}, > }; > > int TST_TOTAL = ARRAY_SIZE(Test_cases); > static void setup(void); > static void utime_verify(const struct test_case_t *); > static void cleanup(void); > +static void help(void); > > int main(int ac, char **av) > { > @@ -71,10 +98,16 @@ int main(int ac, char **av) > const char *msg; > int i; > > - msg = parse_opts(ac, av, NULL, NULL); > + msg = parse_opts(ac, av, 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(); > > for (lc = 0; TEST_LOOPING(lc); lc++) { > @@ -101,14 +134,26 @@ static void setup(void) > > TEST_EXP_ENOS(exp_enos); > > - ltpuser = SAFE_GETPWNAM(cleanup, "nobody"); > + tst_mkfs(NULL, device, fstype, NULL); > + SAFE_MKDIR(cleanup, MNT_POINT, 0644); > + if (mount(device, MNT_POINT, fstype, MS_RDONLY, NULL) < 0) { > + tst_brkm(TBROK | TERRNO, cleanup, > + "mount device:%s failed", device); > + } > + mount_flag = 1; > > - SAFE_SETEUID(cleanup, ltpuser->pw_uid); > + ltpuser = SAFE_GETPWNAM(cleanup, "nobody"); > } > > static void utime_verify(const struct test_case_t *test) > { > - TEST(utime(test->pathname, NULL)); > + if (test->setup_func != NULL) > + test->setup_func(); > + > + TEST(utime(test->pathname, test->times)); > + > + if (test->cleanup_func != NULL) > + test->cleanup_func(); > > if (TEST_RETURN != -1) { > tst_resm(TFAIL, "utime succeeded unexpectedly"); > @@ -124,12 +169,29 @@ static void utime_verify(const struct test_case_t *test) > } > } > > -static void cleanup(void) > +static void setup_nobody(void) > +{ > + SAFE_SETEUID(cleanup, ltpuser->pw_uid); > +} > + > +static void cleanup_nobody(void) > { > - if (seteuid(0) != 0) > - tst_resm(TWARN | TERRNO, "seteuid failed"); > + SAFE_SETEUID(cleanup, 0); > +} > > +static void cleanup(void) > +{ > TEST_CLEANUP; > > + if (mount_flag && umount(MNT_POINT) < 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"); > +}
------------------------------------------------------------------------------ HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions Find What Matters Most in Your Big Data with HPCC Systems Open Source. Fast. Scalable. Simple. Ideal for Dirty Data. Leverages Graph Analysis for Fast Processing & Easy Data Exploration http://p.sf.net/sfu/hpccsystems _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
