All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] utime/utime06.c: cleanup
@ 2014-06-12  9:31 Zeng Linggang
  2014-06-12  9:32 ` [LTP] [PATCH 2/2] utime/utime06.c: add EPERM and EROFS errno testes Zeng Linggang
  0 siblings, 1 reply; 3+ messages in thread
From: Zeng Linggang @ 2014-06-12  9:31 UTC (permalink / raw)
  To: ltp-list

* Delete some useless comments.

* Delete some useless variable value.

* Test without fork().

* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/utime/utime06.c | 290 ++++++------------------------
 1 file changed, 53 insertions(+), 237 deletions(-)

diff --git a/testcases/kernel/syscalls/utime/utime06.c b/testcases/kernel/syscalls/utime/utime06.c
index a1a9230..2dd68d8 100644
--- a/testcases/kernel/syscalls/utime/utime06.c
+++ b/testcases/kernel/syscalls/utime/utime06.c
@@ -1,78 +1,31 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ *	07/2001 John George
  *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program;  if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 /*
- * Test Name: utime06
- *
  * Test Description:
  * 1. 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 null.
  *	 - The user ID of the process is not "root".
- *	 - The file is not owned by the user ID of the process.
- *	 - The user ID of the process does not have write access to the
- *	   file.
  * 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.
- *
- * Expected Result:
- * 1. utime should fail with -1 return value and sets errno EACCES.
- * 2. utime should fail with -1 return value and sets errno ENOENT.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *	if errno set == expected errno
- *		Issue sys call fails with expected return value and errno.
- *	Otherwise,
- *		Issue sys call fails with unexpected errno.
- *   Otherwise,
- *	Issue sys call returns unexpected value.
- *
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory(s)/file(s) created.
- *
- * Usage:  <for command-line>
- *  utime06 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions:
- *  This test must be executed by root.
- *   nobody and bin must be valid users.
  */
 
 #include <errno.h>
@@ -90,230 +43,93 @@
 
 #include "test.h"
 #include "usctest.h"
+#include "safe_macros.h"
 
-#define LTPUSER1        "nobody"
-#define LTPUSER2        "bin"
 #define TEMP_FILE	"tmp_file"
-#define FILE_MODE	S_IRUSR | S_IRGRP | S_IROTH
 
 char *TCID = "utime06";
-int TST_TOTAL = 2;
-time_t curr_time;		/* current time in seconds */
-time_t tloc;			/* argument var. for time() */
-int exp_enos[] = { EACCES, ENOENT, 0 };
+static int exp_enos[] = { EACCES, ENOENT, 0 };
 
-struct passwd *ltpuser;		/* password struct for ltpusers */
-uid_t user_uid;			/* user id of ltpuser */
-gid_t group_gid;		/* group id of ltpuser */
-int status;
+static struct passwd *ltpuser;
 
-int setup1();			/* setup function to test error EACCES */
-int no_setup();
-
-struct test_case_t {		/* test case struct. to hold ref. test cond's */
+struct test_case_t {
 	char *pathname;
-	char *desc;
 	int exp_errno;
-	int (*setupfunc) ();
 } Test_cases[] = {
-	{
-	TEMP_FILE, "Permission denied to modify file time", EACCES, setup1},
-	{
-	"", "Specified file doesn't exist", ENOENT, no_setup}, {
-	NULL, NULL, 0, NULL}
+	{TEMP_FILE, EACCES},
+	{"", ENOENT},
 };
 
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
+int TST_TOTAL = ARRAY_SIZE(Test_cases);
+static void setup(void);
+static void utime_verify(const struct test_case_t *);
+static void cleanup(void);
 
 int main(int ac, char **av)
 {
 	int lc;
 	const char *msg;
-	char *file_name;	/* testfile name */
-	char *test_desc;	/* test specific error message */
-	int ind;		/* counter to test different test conditions */
-	int pid;
+	int i;
 
 	msg = parse_opts(ac, av, NULL, NULL);
-	if (msg != NULL) {
+	if (msg != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-	}
-
 	setup();
 
-	/* set the expected errnos... */
-	TEST_EXP_ENOS(exp_enos);
-
-	pid = FORK_OR_VFORK();
-
-	if (pid == -1) {
-		tst_brkm(TBROK, cleanup, "fork() failed");
-	} else if (pid == 0) {
-		if ((ltpuser = getpwnam(LTPUSER1)) == NULL) {
-			tst_brkm(TBROK, cleanup, "%s not found in /etc/passwd",
-				 LTPUSER1);
-		}
-
-		/* get uid of user */
-		user_uid = ltpuser->pw_uid;
-
-		seteuid(user_uid);
-
-		for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-			tst_count = 0;
-
-			for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-				file_name = Test_cases[ind].pathname;
-				test_desc = Test_cases[ind].desc;
-
-				/*
-				 * Call utime(2) to test different test
-				 * conditions. Verify that it fails with -1
-				 * return value and sets appropriate errno.
-				 */
-				TEST(utime(file_name, NULL));
-
-				/* Check return code from utime(2) */
-				if (TEST_RETURN == -1) {
-					TEST_ERROR_LOG(TEST_ERRNO);
-					if (TEST_ERRNO ==
-					    Test_cases[ind].exp_errno) {
-						tst_resm(TPASS, "utime() "
-							 "fails, %s, errno:%d",
-							 test_desc, TEST_ERRNO);
-					} else {
-						tst_resm(TFAIL, "utime(2) "
-							 "fails, %s, errno:%d, "
-							 "expected errno:%d",
-							 test_desc, TEST_ERRNO,
-							 Test_cases
-							 [ind].exp_errno);
-					}
-				} else {
-					tst_resm(TFAIL,
-						 "utime(2) returned %ld, "
-						 "expected -1, errno:%d",
-						 TEST_RETURN,
-						 Test_cases[ind].exp_errno);
-				}
-			}
-
-			tst_count++;	/* incr TEST_LOOP counter */
-
-		}
-	} else {
-		waitpid(pid, &status, 0);
-		_exit(0);	/*
-				 * Exit here and let the child clean up.
-				 * This allows the errno information set
-				 * by the TEST_ERROR_LOG macro and the
-				 * PASS/FAIL status to be preserved for
-				 * use during cleanup.
-				 */
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		tst_count = 0;
+		for (i = 0; i < TST_TOTAL; i++)
+			utime_verify(&Test_cases[i]);
 	}
 
 	cleanup();
 	tst_exit();
-
 }
 
-/*
- * void
- * setup() - performs all ONE TIME setup for this test.
- *  Create a temporary directory and change directory to it.
- *  Invoke individual test setup functions according to the order
- *  set in test struct. definition.
- */
-void setup(void)
+static void setup(void)
 {
-	int ind;
+	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	/* Check that the test process id is non-super/root  */
-	if (geteuid() != 0) {
-		tst_brkm(TBROK, NULL, "Must be root for this test!");
-		tst_exit();
-	}
+	tst_require_root(NULL);
 
 	TEST_PAUSE;
 
 	tst_tmpdir();
 
-	/* call individual setup functions */
-	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-		Test_cases[ind].setupfunc();
-	}
-}
+	SAFE_TOUCH(cleanup, TEMP_FILE, 0644, NULL);
 
-/*
- * int
- * no_setup() - Some test conditions for utime(2) do not any setup.
- *              Hence, this function just returns 0.
- */
-int no_setup(void)
-{
-	return 0;
-}
+	TEST_EXP_ENOS(exp_enos);
 
-/*
- * int
- * setup1() - setup function for a test condition for which utime(2)
- *		returns -1 and sets errno to EACCES.
- *  Create a testfile under temporary directory and change the ownership of
- *  testfile to "bin".
- */
-int setup1(void)
-{
-	int fildes;		/* file handle for temp file */
+	ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
 
-	/* Creat a temporary file under above directory */
-	if ((fildes = creat(TEMP_FILE, FILE_MODE)) == -1) {
-		tst_brkm(TBROK, cleanup, "creat(%s, %#o) Failed, errno=%d :%s",
-			 TEMP_FILE, FILE_MODE, errno, strerror(errno));
-	}
+	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
+}
 
-	/* Close the temporary file created */
-	if (close(fildes) < 0) {
-		tst_brkm(TBROK, cleanup, "close(%s) Failed, errno=%d : %s:",
-			 TEMP_FILE, errno, strerror(errno));
-	}
+static void utime_verify(const struct test_case_t *test)
+{
+	TEST(utime(test->pathname, NULL));
 
-	if ((ltpuser = getpwnam(LTPUSER2)) == NULL) {
-		tst_brkm(TBROK, cleanup, "%s not found in /etc/passwd",
-			 LTPUSER2);
+	if (TEST_RETURN != -1) {
+		tst_resm(TFAIL, "utime succeeded unexpectedly");
+		return;
 	}
 
-	/* get uid/gid of user accordingly */
-	user_uid = ltpuser->pw_uid;
-	group_gid = ltpuser->pw_gid;
-
-	if (chown(TEMP_FILE, user_uid, group_gid) < 0) {
-		tst_brkm(TBROK, cleanup, "chown() of %s failed, error %d",
-			 TEMP_FILE, errno);
+	if (TEST_ERRNO == test->exp_errno) {
+		tst_resm(TPASS | TTERRNO, "utime failed as expected");
+	} else {
+		tst_resm(TFAIL | TTERRNO,
+			 "utime failed unexpectedly; expected: %d - %s",
+			 test->exp_errno, strerror(test->exp_errno));
 	}
-
-	return 0;
 }
 
-/*
- * void
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *  Remove the test directory and testfile created in the setup.
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	seteuid(0);
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
+	if (seteuid(0) != 0)
+		tst_resm(TWARN | TERRNO, "seteuid failed");
+
 	TEST_CLEANUP;
 
 	tst_rmdir();
-
 }
-- 
1.9.3




------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [LTP] [PATCH 2/2] utime/utime06.c: add EPERM and EROFS errno testes
  2014-06-12  9:31 [LTP] [PATCH 1/2] utime/utime06.c: cleanup Zeng Linggang
@ 2014-06-12  9:32 ` Zeng Linggang
  2014-06-13  1:56   ` Zeng Linggang
  0 siblings, 1 reply; 3+ messages in thread
From: Zeng Linggang @ 2014-06-12  9:32 UTC (permalink / raw)
  To: ltp-list

Add EPERM and EROFS errno testes for utime(2).

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 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, &times, 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");
+}
-- 
1.9.3




------------------------------------------------------------------------------
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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH 2/2] utime/utime06.c: add EPERM and EROFS errno testes
  2014-06-12  9:32 ` [LTP] [PATCH 2/2] utime/utime06.c: add EPERM and EROFS errno testes Zeng Linggang
@ 2014-06-13  1:56   ` Zeng Linggang
  0 siblings, 0 replies; 3+ messages in thread
From: Zeng Linggang @ 2014-06-13  1:56 UTC (permalink / raw)
  To: ltp-list

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 <zenglg.jy@cn.fujitsu.com>
> ---
>  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, &times, 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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-06-13  1:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-12  9:31 [LTP] [PATCH 1/2] utime/utime06.c: cleanup Zeng Linggang
2014-06-12  9:32 ` [LTP] [PATCH 2/2] utime/utime06.c: add EPERM and EROFS errno testes Zeng Linggang
2014-06-13  1:56   ` Zeng Linggang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.