All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] Cleanup syscalls/utime test messages
@ 2015-11-15 10:09 Nicolas Joly
  2015-11-19 16:00 ` Cyril Hrubis
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Joly @ 2015-11-15 10:09 UTC (permalink / raw)
  To: ltp


Hi,

Please find a small patch that cleanup utime(2) syscalls tests to use
TTERRNO/TERRNO in messages instead of home made versions with
TEST_ERRNO/errno.

Regards.

-- 
Nicolas Joly

Cluster & Computing Group
Biology IT Center
Institut Pasteur, Paris.
-------------- next part --------------
commit 0ac8109dc3ce43f37a1141cd8f352690b5800123
Author: Nicolas Joly <njoly@pasteur.fr>
Date:   Sun Nov 15 11:04:57 2015 +0100

    syscalls/utime: Cleanup.
    
    Use TERRNO/TTERRNO in messages instead of home made versions.
    
    Signed-off-by: Nicolas Joly <njoly@pasteur.fr>

diff --git a/testcases/kernel/syscalls/utime/utime01.c b/testcases/kernel/syscalls/utime/utime01.c
index 4bb33e9..2eb49d4 100644
--- a/testcases/kernel/syscalls/utime/utime01.c
+++ b/testcases/kernel/syscalls/utime/utime01.c
@@ -131,8 +131,7 @@ int main(int ac, char **av)
 		TEST(utime(TEMP_FILE, NULL));
 
 		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "utime(%s) Failed, errno=%d : %s",
-				 TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO));
+			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
 		} else {
 			/*
 			 * Sleep for a second so that mod time and
@@ -146,10 +145,9 @@ int main(int ac, char **av)
 			 * utime(2)
 			 */
 			if ((pres_time = time(&tloc)) < 0) {
-				tst_brkm(TFAIL, cleanup, "time() "
+				tst_brkm(TFAIL|TERRNO, cleanup, "time() "
 					 "failed to get present time "
-					 "after utime, error=%d",
-					 errno);
+					 "after utime");
 			}
 
 			/*
@@ -157,9 +155,8 @@ int main(int ac, char **av)
 			 * temporary file using stat(2).
 			 */
 			if (stat(TEMP_FILE, &stat_buf) < 0) {
-				tst_brkm(TFAIL, cleanup, "stat(2) of "
-					 "%s failed, error:%d",
-					 TEMP_FILE, TEST_ERRNO);
+				tst_brkm(TFAIL|TERRNO, cleanup, "stat(2) of "
+					 "%s failed", TEMP_FILE);
 			}
 			modf_time = stat_buf.st_mtime;
 			access_time = stat_buf.st_atime;
@@ -205,22 +202,20 @@ void setup(void)
 
 	/* 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));
+		tst_brkm(TBROK|TERRNO, cleanup,
+			 "creat(%s, %#o) Failed", TEMP_FILE, FILE_MODE);
 	}
 
 	/* Close the temporary file created */
 	if (close(fildes) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "close(%s) Failed, errno=%d : %s:",
-			 TEMP_FILE, errno, strerror(errno));
+		tst_brkm(TBROK|TERRNO, cleanup,
+			 "close(%s) failed", TEMP_FILE);
 	}
 
 	/* Get the current time */
 	if ((curr_time = time(&tloc)) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "time() failed to get current time, errno=%d", errno);
+		tst_brkm(TBROK|TERRNO, cleanup,
+			 "time() failed to get current time");
 	}
 
 	/*
diff --git a/testcases/kernel/syscalls/utime/utime02.c b/testcases/kernel/syscalls/utime/utime02.c
index 2a68bd5..c5e49ce 100644
--- a/testcases/kernel/syscalls/utime/utime02.c
+++ b/testcases/kernel/syscalls/utime/utime02.c
@@ -137,8 +137,7 @@ int main(int ac, char **av)
 		TEST(utime(TEMP_FILE, NULL));
 
 		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "utime(%s) Failed, errno=%d : %s",
-				 TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO));
+			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
 		} else {
 			/*
 			 * Sleep for a second so that mod time and
@@ -152,10 +151,9 @@ int main(int ac, char **av)
 			 * utime(2)
 			 */
 			if ((pres_time = time(&tloc)) < 0) {
-				tst_brkm(TFAIL, cleanup, "time() "
+				tst_brkm(TFAIL|TERRNO, cleanup, "time() "
 					 "failed to get present time "
-					 "after utime, error=%d",
-					 errno);
+					 "after utime");
 			}
 
 			/*
@@ -163,9 +161,8 @@ int main(int ac, char **av)
 			 * temporary file using stat(2).
 			 */
 			if (stat(TEMP_FILE, &stat_buf) < 0) {
-				tst_brkm(TFAIL, cleanup, "stat(2) of "
-					 "%s failed, errno:%d",
-					 TEMP_FILE, TEST_ERRNO);
+				tst_brkm(TFAIL|TERRNO, cleanup, "stat(2) of "
+					 "%s failed", TEMP_FILE);
 			}
 			modf_time = stat_buf.st_mtime;
 			access_time = stat_buf.st_atime;
@@ -208,9 +205,8 @@ void setup(void)
 	/* Switch to nobody user for correct error code collection */
 	ltpuser = getpwnam(nobody_uid);
 	if (setuid(ltpuser->pw_uid) == -1) {
-		tst_resm(TINFO, "setuid failed to "
+		tst_resm(TINFO|TERRNO, "setuid failed to "
 			 "to set the effective uid to %d", ltpuser->pw_uid);
-		perror("setuid");
 	}
 
 	/* Pause if that option was specified
@@ -224,22 +220,20 @@ void setup(void)
 
 	/* 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));
+		tst_brkm(TBROK|TERRNO, cleanup,
+			 "creat(%s, %#o) failed", TEMP_FILE, FILE_MODE);
 	}
 
 	/* Close the temporary file created */
 	if (close(fildes) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "close(%s) Failed, errno=%d : %s:",
-			 TEMP_FILE, errno, strerror(errno));
+		tst_brkm(TBROK|TERRNO, cleanup,
+			 "close(%s) failed", TEMP_FILE);
 	}
 
 	/* Get the current time */
 	if ((curr_time = time(&tloc)) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "time() failed to get current time, errno=%d", errno);
+		tst_brkm(TBROK|TERRNO, cleanup,
+			 "time() failed to get current time");
 	}
 
 	/*
diff --git a/testcases/kernel/syscalls/utime/utime03.c b/testcases/kernel/syscalls/utime/utime03.c
index 1ff939b..9877be3 100644
--- a/testcases/kernel/syscalls/utime/utime03.c
+++ b/testcases/kernel/syscalls/utime/utime03.c
@@ -162,10 +162,8 @@ int main(int ac, char **av)
 			TEST(utime(TEMP_FILE, NULL));
 
 			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL,
-					 "utime(%s) Failed, errno=%d : %s",
-					 TEMP_FILE, TEST_ERRNO,
-					 strerror(TEST_ERRNO));
+				tst_resm(TFAIL|TTERRNO,
+					 "utime(%s) failed", TEMP_FILE);
 			} else {
 				/*
 				 * Sleep for a second so that mod time
@@ -179,11 +177,9 @@ int main(int ac, char **av)
 				 * calling utime(2)
 				 */
 				if ((pres_time = time(&tloc)) < 0) {
-					tst_brkm(TFAIL, cleanup,
+					tst_brkm(TFAIL|TERRNO, cleanup,
 						 "time() failed to get "
-						 "present time after "
-						 "utime, error=%d",
-						 errno);
+						 "present time after utime");
 				}
 
 				/*
@@ -266,16 +262,14 @@ void setup(void)
 
 	/* 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));
+		tst_brkm(TBROK|TERRNO, cleanup,
+			 "creat(%s, %#o) failed", TEMP_FILE, FILE_MODE);
 	}
 
 	/* Close the temporary file created */
 	if (close(fildes) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "close(%s) Failed, errno=%d : %s:",
-			 TEMP_FILE, errno, strerror(errno));
+		tst_brkm(TBROK|TERRNO, cleanup,
+			 "close(%s) failed", TEMP_FILE);
 	}
 
 	/*
@@ -283,9 +277,8 @@ void setup(void)
 	 * umask value may be different.
 	 */
 	if (chmod(TEMP_FILE, FILE_MODE) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "chmod(%s) Failed, errno=%d : %s:",
-			 TEMP_FILE, errno, strerror(errno));
+		tst_brkm(TBROK|TERRNO, cleanup,
+			 "chmod(%s) failed", TEMP_FILE);
 	}
 
 	if (chmod(tmpd, 0711) != 0) {
@@ -306,14 +299,14 @@ void setup(void)
 	 * pathname to that of user_uid and group_gid.
 	 */
 	if (chown(TEMP_FILE, user_uid, group_gid) < 0) {
-		tst_brkm(TBROK, cleanup, "chown() of %s failed, error %d",
-			 TEMP_FILE, errno);
+		tst_brkm(TBROK|TERRNO, cleanup, "chown() of %s failed",
+			 TEMP_FILE);
 	}
 
 	/* Get the current time */
 	if ((curr_time = time(&tloc)) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "time() failed to get current time, errno=%d", errno);
+		tst_brkm(TBROK|TERRNO, cleanup,
+			 "time() failed to get current time");
 	}
 
 	/*
diff --git a/testcases/kernel/syscalls/utime/utime04.c b/testcases/kernel/syscalls/utime/utime04.c
index 0287296..373f3a7 100644
--- a/testcases/kernel/syscalls/utime/utime04.c
+++ b/testcases/kernel/syscalls/utime/utime04.c
@@ -116,18 +116,15 @@ int main(int ac, char **av)
 		TEST(utime(TEMP_FILE, &times));
 
 		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "utime(%s) Failed, errno=%d : %s",
-				 TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO));
+			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
 		} else {
 			/*
 			 * Get the modification and access times of
 			 * temporary file using stat(2).
 			 */
 			if (stat(TEMP_FILE, &stat_buf) < 0) {
-				tst_brkm(TFAIL, cleanup,
-					 "stat(2) of %s failed, "
-					 "error:%d", TEMP_FILE,
-					 TEST_ERRNO);
+				tst_brkm(TFAIL|TERRNO, cleanup,
+					 "stat(2) of %s failed", TEMP_FILE);
 			}
 			modf_time = stat_buf.st_mtime;
 			access_time = stat_buf.st_atime;
@@ -171,16 +168,14 @@ void setup(void)
 
 	/* 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));
+		tst_brkm(TBROK|TERRNO, cleanup,
+			 "creat(%s, %#o) failed", TEMP_FILE, FILE_MODE);
 	}
 
 	/* Close the temporary file created */
 	if (close(fildes) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "close(%s) Failed, errno=%d : %s:",
-			 TEMP_FILE, errno, strerror(errno));
+		tst_brkm(TBROK|TERRNO, cleanup,
+			 "close(%s) failed", TEMP_FILE);
 	}
 
 	/* Initialize the modification and access time in the times arg */
diff --git a/testcases/kernel/syscalls/utime/utime05.c b/testcases/kernel/syscalls/utime/utime05.c
index 275f4fa..7f120e5 100644
--- a/testcases/kernel/syscalls/utime/utime05.c
+++ b/testcases/kernel/syscalls/utime/utime05.c
@@ -122,17 +122,15 @@ int main(int ac, char **av)
 		TEST(utime(TEMP_FILE, &times));
 
 		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "utime(%s) Failed, errno=%d : %s",
-				 TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO));
+			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
 		} else {
 			/*
 			 * Get the modification and access times of
 			 * temporary file using stat(2).
 			 */
 			if (stat(TEMP_FILE, &stat_buf) < 0) {
-				tst_brkm(TFAIL, cleanup, "stat(2) of "
-					 "%s failed, error:%d",
-					 TEMP_FILE, TEST_ERRNO);
+				tst_brkm(TFAIL|TERRNO, cleanup, "stat(2) of "
+					 "%s failed", TEMP_FILE);
 			}
 			modf_time = stat_buf.st_mtime;
 			access_time = stat_buf.st_atime;
@@ -184,16 +182,14 @@ void setup(void)
 
 	/* 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));
+		tst_brkm(TBROK|TERRNO, cleanup,
+			 "creat(%s, %#o) failed", TEMP_FILE, FILE_MODE);
 	}
 
 	/* Close the temporary file created */
 	if (close(fildes) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "close(%s) Failed, errno=%d : %s:",
-			 TEMP_FILE, errno, strerror(errno));
+		tst_brkm(TBROK|TERRNO, cleanup,
+			 "close(%s) failed", TEMP_FILE);
 	}
 
 	/* Initialize the modification and access time in the times arg */

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

* [LTP] [PATCH] Cleanup syscalls/utime test messages
  2015-11-15 10:09 [LTP] [PATCH] Cleanup syscalls/utime test messages Nicolas Joly
@ 2015-11-19 16:00 ` Cyril Hrubis
  2015-11-21  9:41   ` Nicolas Joly
  0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2015-11-19 16:00 UTC (permalink / raw)
  To: ltp

> diff --git a/testcases/kernel/syscalls/utime/utime01.c b/testcases/kernel/syscalls/utime/utime01.c
> index 4bb33e9..2eb49d4 100644
> --- a/testcases/kernel/syscalls/utime/utime01.c
> +++ b/testcases/kernel/syscalls/utime/utime01.c
> @@ -131,8 +131,7 @@ int main(int ac, char **av)
>  		TEST(utime(TEMP_FILE, NULL));
>  
>  		if (TEST_RETURN == -1) {
> -			tst_resm(TFAIL, "utime(%s) Failed, errno=%d : %s",
> -				 TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO));
> +			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
>  		} else {
>  			/*
>  			 * Sleep for a second so that mod time and
> @@ -146,10 +145,9 @@ int main(int ac, char **av)
>  			 * utime(2)
>  			 */
>  			if ((pres_time = time(&tloc)) < 0) {
> -				tst_brkm(TFAIL, cleanup, "time() "
> +				tst_brkm(TFAIL|TERRNO, cleanup, "time() "
>  					 "failed to get present time "
> -					 "after utime, error=%d",
> -					 errno);
> +					 "after utime");

This part of code is not 100% correct, since time() returns precisely
(time_t)-1 on failure. If time_t is typedefed in system to unsigned it
will never be true. And it looks like it's defined to be long int at the
moment hence 4 bytes on 32bit arch and 8 bytes on 64bit arch, but that
may change because of 2038. Heh, and the test fails if you set time
before 01-01-1970 (yep, looks like it could be done since time_t is
signed type), not that it matters that much though.

Lookig at the time man page the only error defined for time is EFAULT
when you pass wrong pointer to it. So I would just remove the check for
failure for all time() calls. What do you think?

>  
>  			/*
> @@ -157,9 +155,8 @@ int main(int ac, char **av)
>  			 * temporary file using stat(2).
>  			 */
>  			if (stat(TEMP_FILE, &stat_buf) < 0) {
> -				tst_brkm(TFAIL, cleanup, "stat(2) of "
> -					 "%s failed, error:%d",
> -					 TEMP_FILE, TEST_ERRNO);
> +				tst_brkm(TFAIL|TERRNO, cleanup, "stat(2) of "
> +					 "%s failed", TEMP_FILE);
>  			}

Hint: we have safe macros so this could be easily done with just:

      SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);

      And the same for creat(), close(), etc.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH] Cleanup syscalls/utime test messages
  2015-11-19 16:00 ` Cyril Hrubis
@ 2015-11-21  9:41   ` Nicolas Joly
  2015-11-28  9:26     ` Nicolas Joly
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Joly @ 2015-11-21  9:41 UTC (permalink / raw)
  To: ltp

On Thu, Nov 19, 2015 at 05:00:51PM +0100, Cyril Hrubis wrote:
> > diff --git a/testcases/kernel/syscalls/utime/utime01.c b/testcases/kernel/syscalls/utime/utime01.c
> > index 4bb33e9..2eb49d4 100644
> > --- a/testcases/kernel/syscalls/utime/utime01.c
> > +++ b/testcases/kernel/syscalls/utime/utime01.c
> > @@ -131,8 +131,7 @@ int main(int ac, char **av)
> >  		TEST(utime(TEMP_FILE, NULL));
> >  
> >  		if (TEST_RETURN == -1) {
> > -			tst_resm(TFAIL, "utime(%s) Failed, errno=%d : %s",
> > -				 TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO));
> > +			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
> >  		} else {
> >  			/*
> >  			 * Sleep for a second so that mod time and
> > @@ -146,10 +145,9 @@ int main(int ac, char **av)
> >  			 * utime(2)
> >  			 */
> >  			if ((pres_time = time(&tloc)) < 0) {
> > -				tst_brkm(TFAIL, cleanup, "time() "
> > +				tst_brkm(TFAIL|TERRNO, cleanup, "time() "
> >  					 "failed to get present time "
> > -					 "after utime, error=%d",
> > -					 errno);
> > +					 "after utime");
> 
> This part of code is not 100% correct, since time() returns precisely
> (time_t)-1 on failure. If time_t is typedefed in system to unsigned it
> will never be true. And it looks like it's defined to be long int at the
> moment hence 4 bytes on 32bit arch and 8 bytes on 64bit arch, but that
> may change because of 2038. Heh, and the test fails if you set time
> before 01-01-1970 (yep, looks like it could be done since time_t is
> signed type), not that it matters that much though.
> 
> Lookig at the time man page the only error defined for time is EFAULT
> when you pass wrong pointer to it. So I would just remove the check for
> failure for all time() calls. What do you think?

Fine. My cleanup was mostly mecanical to remove most errno direct use
... I did not check for anything else ;)

> > @@ -157,9 +155,8 @@ int main(int ac, char **av)
> >  			 * temporary file using stat(2).
> >  			 */
> >  			if (stat(TEMP_FILE, &stat_buf) < 0) {
> > -				tst_brkm(TFAIL, cleanup, "stat(2) of "
> > -					 "%s failed, error:%d",
> > -					 TEMP_FILE, TEST_ERRNO);
> > +				tst_brkm(TFAIL|TERRNO, cleanup, "stat(2) of "
> > +					 "%s failed", TEMP_FILE);
> >  			}
> 
> Hint: we have safe macros so this could be easily done with just:
> 
>       SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
> 
>       And the same for creat(), close(), etc.

That's even simplier indeed.

Will try to setup a new version that include both.

-- 
Nicolas Joly

Cluster & Computing Group
Biology IT Center
Institut Pasteur, Paris.

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

* [LTP] [PATCH] Cleanup syscalls/utime test messages
  2015-11-21  9:41   ` Nicolas Joly
@ 2015-11-28  9:26     ` Nicolas Joly
  2015-11-30 16:52       ` Cyril Hrubis
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Joly @ 2015-11-28  9:26 UTC (permalink / raw)
  To: ltp

On Sat, Nov 21, 2015 at 10:41:24AM +0100, Nicolas Joly wrote:
> On Thu, Nov 19, 2015 at 05:00:51PM +0100, Cyril Hrubis wrote:
[...]
> > Lookig at the time man page the only error defined for time is EFAULT
> > when you pass wrong pointer to it. So I would just remove the check for
> > failure for all time() calls. What do you think?
> 
> Fine. My cleanup was mostly mecanical to remove most errno direct use
> ... I did not check for anything else ;)
> 
> > > @@ -157,9 +155,8 @@ int main(int ac, char **av)
> > >  			 * temporary file using stat(2).
> > >  			 */
> > >  			if (stat(TEMP_FILE, &stat_buf) < 0) {
> > > -				tst_brkm(TFAIL, cleanup, "stat(2) of "
> > > -					 "%s failed, error:%d",
> > > -					 TEMP_FILE, TEST_ERRNO);
> > > +				tst_brkm(TFAIL|TERRNO, cleanup, "stat(2) of "
> > > +					 "%s failed", TEMP_FILE);
> > >  			}
> > 
> > Hint: we have safe macros so this could be easily done with just:
> > 
> >       SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
> > 
> >       And the same for creat(), close(), etc.
> 
> That's even simplier indeed.
> 
> Will try to setup a new version that include both.

Finally got some spare time to setup this ...

New version attached, that address all concerns.

-- 
Nicolas Joly

Cluster & Computing Group
Biology IT Center
Institut Pasteur, Paris.
-------------- next part --------------
commit bcad1e1a7d0a8c82d6dfe32f38232126a3afb5ea
Author: Nicolas Joly <njoly@pasteur.fr>
Date:   Sat Nov 28 10:19:46 2015 +0100

    syscalls/utime: Cleanup.
    
    Avoid errno direct use, call safe macros instead.
    Simplify time() calls which should never fail.
    
    Signed-off-by: Nicolas Joly <njoly@pasteur.fr>

diff --git a/testcases/kernel/syscalls/utime/utime01.c b/testcases/kernel/syscalls/utime/utime01.c
index 4bb33e9..505f875 100644
--- a/testcases/kernel/syscalls/utime/utime01.c
+++ b/testcases/kernel/syscalls/utime/utime01.c
@@ -82,6 +82,7 @@
 
 #include "test.h"
 #include "tst_fs_type.h"
+#include "safe_macros.h"
 
 #define TEMP_FILE	"tmp_file"
 #define FILE_MODE	S_IRUSR | S_IRGRP | S_IROTH
@@ -89,7 +90,6 @@
 char *TCID = "utime01";
 int TST_TOTAL = 1;
 time_t curr_time;		/* current time in seconds */
-time_t tloc;
 
 void setup();			/* Main setup function of test */
 void cleanup();			/* cleanup function for the test */
@@ -131,8 +131,7 @@ int main(int ac, char **av)
 		TEST(utime(TEMP_FILE, NULL));
 
 		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "utime(%s) Failed, errno=%d : %s",
-				 TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO));
+			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
 		} else {
 			/*
 			 * Sleep for a second so that mod time and
@@ -145,22 +144,13 @@ int main(int ac, char **av)
 			 * Get the current time now, after calling
 			 * utime(2)
 			 */
-			if ((pres_time = time(&tloc)) < 0) {
-				tst_brkm(TFAIL, cleanup, "time() "
-					 "failed to get present time "
-					 "after utime, error=%d",
-					 errno);
-			}
+			pres_time = time(NULL);
 
 			/*
 			 * Get the modification and access times of
 			 * temporary file using stat(2).
 			 */
-			if (stat(TEMP_FILE, &stat_buf) < 0) {
-				tst_brkm(TFAIL, cleanup, "stat(2) of "
-					 "%s failed, error:%d",
-					 TEMP_FILE, TEST_ERRNO);
-			}
+			SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
 			modf_time = stat_buf.st_mtime;
 			access_time = stat_buf.st_atime;
 
@@ -204,24 +194,13 @@ void setup(void)
 	tst_tmpdir();
 
 	/* 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));
-	}
+	fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE);
 
 	/* Close the temporary file created */
-	if (close(fildes) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "close(%s) Failed, errno=%d : %s:",
-			 TEMP_FILE, errno, strerror(errno));
-	}
+	SAFE_CLOSE(cleanup, fildes);
 
 	/* Get the current time */
-	if ((curr_time = time(&tloc)) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "time() failed to get current time, errno=%d", errno);
-	}
+	curr_time = time(NULL);
 
 	/*
 	 * Sleep for a second so that mod time and access times will be
diff --git a/testcases/kernel/syscalls/utime/utime02.c b/testcases/kernel/syscalls/utime/utime02.c
index 2a68bd5..d2ec958 100644
--- a/testcases/kernel/syscalls/utime/utime02.c
+++ b/testcases/kernel/syscalls/utime/utime02.c
@@ -85,6 +85,7 @@
 
 #include "test.h"
 #include "tst_fs_type.h"
+#include "safe_macros.h"
 
 #define TEMP_FILE	"tmp_file"
 #define FILE_MODE	S_IRUSR | S_IRGRP | S_IROTH
@@ -92,7 +93,6 @@
 char *TCID = "utime02";
 int TST_TOTAL = 1;
 time_t curr_time;		/* current time in seconds */
-time_t tloc;
 
 char nobody_uid[] = "nobody";
 struct passwd *ltpuser;
@@ -137,8 +137,7 @@ int main(int ac, char **av)
 		TEST(utime(TEMP_FILE, NULL));
 
 		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "utime(%s) Failed, errno=%d : %s",
-				 TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO));
+			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
 		} else {
 			/*
 			 * Sleep for a second so that mod time and
@@ -151,22 +150,13 @@ int main(int ac, char **av)
 			 * Get the current time now, after calling
 			 * utime(2)
 			 */
-			if ((pres_time = time(&tloc)) < 0) {
-				tst_brkm(TFAIL, cleanup, "time() "
-					 "failed to get present time "
-					 "after utime, error=%d",
-					 errno);
-			}
+			pres_time = time(NULL);
 
 			/*
 			 * Get the modification and access times of
 			 * temporary file using stat(2).
 			 */
-			if (stat(TEMP_FILE, &stat_buf) < 0) {
-				tst_brkm(TFAIL, cleanup, "stat(2) of "
-					 "%s failed, errno:%d",
-					 TEMP_FILE, TEST_ERRNO);
-			}
+			SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
 			modf_time = stat_buf.st_mtime;
 			access_time = stat_buf.st_atime;
 
@@ -206,12 +196,8 @@ void setup(void)
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
 	/* Switch to nobody user for correct error code collection */
-	ltpuser = getpwnam(nobody_uid);
-	if (setuid(ltpuser->pw_uid) == -1) {
-		tst_resm(TINFO, "setuid failed to "
-			 "to set the effective uid to %d", ltpuser->pw_uid);
-		perror("setuid");
-	}
+	ltpuser = SAFE_GETPWNAM(NULL, nobody_uid);
+	SAFE_SETUID(NULL, ltpuser->pw_uid);
 
 	/* Pause if that option was specified
 	 * TEST_PAUSE contains the code to fork the test with the -i option.
@@ -223,24 +209,13 @@ void setup(void)
 	tst_tmpdir();
 
 	/* 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));
-	}
+	fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE);
 
 	/* Close the temporary file created */
-	if (close(fildes) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "close(%s) Failed, errno=%d : %s:",
-			 TEMP_FILE, errno, strerror(errno));
-	}
+	SAFE_CLOSE(cleanup, fildes);
 
 	/* Get the current time */
-	if ((curr_time = time(&tloc)) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "time() failed to get current time, errno=%d", errno);
-	}
+	curr_time = time(NULL);
 
 	/*
 	 * Sleep for a second so that mod time and access times will be
diff --git a/testcases/kernel/syscalls/utime/utime03.c b/testcases/kernel/syscalls/utime/utime03.c
index 1ff939b..6d9cabe 100644
--- a/testcases/kernel/syscalls/utime/utime03.c
+++ b/testcases/kernel/syscalls/utime/utime03.c
@@ -90,6 +90,7 @@
 
 #include "test.h"
 #include "tst_fs_type.h"
+#include "safe_macros.h"
 
 #define TEMP_FILE	"tmp_file"
 #define FILE_MODE	S_IRWXU | S_IRGRP | S_IWGRP| S_IROTH | S_IWOTH
@@ -99,7 +100,6 @@
 char *TCID = "utime03";
 int TST_TOTAL = 1;
 time_t curr_time;		/* current time in seconds */
-time_t tloc;
 
 struct passwd *ltpuser;		/* password struct for ltpusers */
 uid_t user_uid;			/* user id of ltpuser */
@@ -162,10 +162,8 @@ int main(int ac, char **av)
 			TEST(utime(TEMP_FILE, NULL));
 
 			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL,
-					 "utime(%s) Failed, errno=%d : %s",
-					 TEMP_FILE, TEST_ERRNO,
-					 strerror(TEST_ERRNO));
+				tst_resm(TFAIL|TTERRNO,
+					 "utime(%s) failed", TEMP_FILE);
 			} else {
 				/*
 				 * Sleep for a second so that mod time
@@ -178,25 +176,14 @@ int main(int ac, char **av)
 				 * Get the current time now, after
 				 * calling utime(2)
 				 */
-				if ((pres_time = time(&tloc)) < 0) {
-					tst_brkm(TFAIL, cleanup,
-						 "time() failed to get "
-						 "present time after "
-						 "utime, error=%d",
-						 errno);
-				}
+				pres_time = time(NULL);
 
 				/*
 				 * Get the modification and access
 				 * times of temporary file using
 				 * stat(2).
 				 */
-				if (stat(TEMP_FILE, &stat_buf) < 0) {
-					tst_brkm(TFAIL, cleanup,
-						 "stat(2) of %s failed, "
-						 "error:%d", TEMP_FILE,
-						 TEST_ERRNO);
-				}
+				SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
 				modf_time = stat_buf.st_mtime;
 				access_time = stat_buf.st_atime;
 
@@ -260,42 +247,22 @@ void setup(void)
 	tst_tmpdir();
 
 	/* get the name of the temporary directory */
-	if ((tmpd = getcwd(tmpd, 0)) == NULL) {
-		tst_brkm(TBROK, NULL, "getcwd failed");
-	}
+	tmpd = SAFE_GETCWD(NULL, tmpd, 0);
 
 	/* 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));
-	}
+	fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE);
 
 	/* Close the temporary file created */
-	if (close(fildes) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "close(%s) Failed, errno=%d : %s:",
-			 TEMP_FILE, errno, strerror(errno));
-	}
+	SAFE_CLOSE(cleanup, fildes);
 
 	/*
 	 * Make sure that specified Mode permissions set as
 	 * umask value may be different.
 	 */
-	if (chmod(TEMP_FILE, FILE_MODE) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "chmod(%s) Failed, errno=%d : %s:",
-			 TEMP_FILE, errno, strerror(errno));
-	}
+	SAFE_CHMOD(cleanup, TEMP_FILE, FILE_MODE);
+	SAFE_CHMOD(cleanup, tmpd, 0711);
 
-	if (chmod(tmpd, 0711) != 0) {
-		tst_brkm(TBROK, cleanup, "chmod() failed");
-	}
-
-	if ((ltpuser = getpwnam(LTPUSER2)) == NULL) {
-		tst_brkm(TBROK, cleanup, "%s not found in /etc/passwd",
-			 LTPUSER2);
-	}
+	ltpuser = SAFE_GETPWNAM(cleanup, LTPUSER2);
 
 	/* get uid/gid of user accordingly */
 	user_uid = ltpuser->pw_uid;
@@ -305,16 +272,10 @@ void setup(void)
 	 * Change the ownership of test directory/file specified by
 	 * pathname to that of user_uid and group_gid.
 	 */
-	if (chown(TEMP_FILE, user_uid, group_gid) < 0) {
-		tst_brkm(TBROK, cleanup, "chown() of %s failed, error %d",
-			 TEMP_FILE, errno);
-	}
+	SAFE_CHOWN(cleanup, TEMP_FILE, user_uid, group_gid);
 
 	/* Get the current time */
-	if ((curr_time = time(&tloc)) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "time() failed to get current time, errno=%d", errno);
-	}
+	curr_time = time(NULL);
 
 	/*
 	 * Sleep for a second so that mod time and access times will be
diff --git a/testcases/kernel/syscalls/utime/utime04.c b/testcases/kernel/syscalls/utime/utime04.c
index 0287296..5253f76 100644
--- a/testcases/kernel/syscalls/utime/utime04.c
+++ b/testcases/kernel/syscalls/utime/utime04.c
@@ -80,6 +80,7 @@
 #include <signal.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define TEMP_FILE	"tmp_file"
 #define FILE_MODE	S_IRUSR | S_IRGRP | S_IROTH
@@ -116,19 +117,13 @@ int main(int ac, char **av)
 		TEST(utime(TEMP_FILE, &times));
 
 		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "utime(%s) Failed, errno=%d : %s",
-				 TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO));
+			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
 		} else {
 			/*
 			 * Get the modification and access times of
 			 * temporary file using stat(2).
 			 */
-			if (stat(TEMP_FILE, &stat_buf) < 0) {
-				tst_brkm(TFAIL, cleanup,
-					 "stat(2) of %s failed, "
-					 "error:%d", TEMP_FILE,
-					 TEST_ERRNO);
-			}
+			SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
 			modf_time = stat_buf.st_mtime;
 			access_time = stat_buf.st_atime;
 
@@ -170,18 +165,10 @@ void setup(void)
 	tst_tmpdir();
 
 	/* 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));
-	}
+	fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE);
 
 	/* Close the temporary file created */
-	if (close(fildes) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "close(%s) Failed, errno=%d : %s:",
-			 TEMP_FILE, errno, strerror(errno));
-	}
+	SAFE_CLOSE(cleanup, fildes);
 
 	/* Initialize the modification and access time in the times arg */
 	times.actime = NEW_TIME;
diff --git a/testcases/kernel/syscalls/utime/utime05.c b/testcases/kernel/syscalls/utime/utime05.c
index 275f4fa..b2d2450 100644
--- a/testcases/kernel/syscalls/utime/utime05.c
+++ b/testcases/kernel/syscalls/utime/utime05.c
@@ -83,6 +83,7 @@
 #include <pwd.h>
 
 #include "test.h"
+#include "safe_macros.h"
 
 #define TEMP_FILE	"tmp_file"
 #define FILE_MODE	S_IRUSR | S_IRGRP | S_IROTH
@@ -122,18 +123,13 @@ int main(int ac, char **av)
 		TEST(utime(TEMP_FILE, &times));
 
 		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "utime(%s) Failed, errno=%d : %s",
-				 TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO));
+			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
 		} else {
 			/*
 			 * Get the modification and access times of
 			 * temporary file using stat(2).
 			 */
-			if (stat(TEMP_FILE, &stat_buf) < 0) {
-				tst_brkm(TFAIL, cleanup, "stat(2) of "
-					 "%s failed, error:%d",
-					 TEMP_FILE, TEST_ERRNO);
-			}
+			SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
 			modf_time = stat_buf.st_mtime;
 			access_time = stat_buf.st_atime;
 
@@ -171,30 +167,18 @@ void setup(void)
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
 	/* Switch to nobody user for correct error code collection */
-	ltpuser = getpwnam(nobody_uid);
-	if (setuid(ltpuser->pw_uid) == -1) {
-		tst_resm(TINFO, "setuid failed to "
-			 "to set the effective uid to %d", ltpuser->pw_uid);
-		perror("setuid");
-	}
+	ltpuser = SAFE_GETPWNAM(NULL, nobody_uid);
+	SAFE_SETUID(NULL, ltpuser->pw_uid);
 
 	TEST_PAUSE;
 
 	tst_tmpdir();
 
 	/* 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));
-	}
+	fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE);
 
 	/* Close the temporary file created */
-	if (close(fildes) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "close(%s) Failed, errno=%d : %s:",
-			 TEMP_FILE, errno, strerror(errno));
-	}
+	SAFE_CLOSE(cleanup, fildes);
 
 	/* Initialize the modification and access time in the times arg */
 	times.actime = NEW_TIME;

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

* [LTP] [PATCH] Cleanup syscalls/utime test messages
  2015-11-28  9:26     ` Nicolas Joly
@ 2015-11-30 16:52       ` Cyril Hrubis
  0 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2015-11-30 16:52 UTC (permalink / raw)
  To: ltp

Hi!
> Finally got some spare time to setup this ...
> 
> New version attached, that address all concerns.

Pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2015-11-30 16:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-15 10:09 [LTP] [PATCH] Cleanup syscalls/utime test messages Nicolas Joly
2015-11-19 16:00 ` Cyril Hrubis
2015-11-21  9:41   ` Nicolas Joly
2015-11-28  9:26     ` Nicolas Joly
2015-11-30 16:52       ` Cyril Hrubis

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.