Skip to contentSkip to conversation

Cleanup syscalls/utime test messages

PATCH New Nicolas Joly 2 participants 5 messages Nov 15, 2015 – Nov 30, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Cleanup syscalls/utime test messages

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.

Signature · 15 lines
Nicolas Joly

Cluster & Computing Group
Biology IT Center
Institut Pasteur, Paris.
-------------- next part --------------
commit 0ac8109dc3ce43f37a1141cd8f352690b5800123
Author: Nicolas Joly <[email protected]>
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 <[email protected]>
testcases/kernel/syscalls/utime/utime01.c +11 -16
index 4bb33e9..2eb49d4 100644
@@ -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");
 	}
 
 	/*
testcases/kernel/syscalls/utime/utime02.c +12 -18
index 2a68bd5..c5e49ce 100644
@@ -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");
 	}
 
 	/*
testcases/kernel/syscalls/utime/utime03.c +14 -21
index 1ff939b..9877be3 100644
@@ -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");
 	}
 
 	/*
testcases/kernel/syscalls/utime/utime04.c +7 -12
index 0287296..373f3a7 100644
@@ -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 */
testcases/kernel/syscalls/utime/utime05.c +7 -11
index 275f4fa..7f120e5 100644
@@ -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 */
#1 lore raw

PATCH 1/1 Cleanup syscalls/utime test messages

Quoted 15 lines
testcases/kernel/syscalls/utime/utime01.c +1 -2
index 4bb33e9..2eb49d4 100644
@@ -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

testcases/kernel/syscalls/utime/utime01.c int main(int ac, char **av) · line 150

Quoted 9 lines
testcases/kernel/syscalls/utime/utime01.c +2 -3
@@ -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?

testcases/kernel/syscalls/utime/utime01.c int main(int ac, char **av) · line 160

Quoted 12 lines
testcases/kernel/syscalls/utime/utime01.c +2 -3
 			/*
@@ -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.

Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH 1/1 Cleanup syscalls/utime test messages

Quoted 33 lines · Cyril Hrubis
Quoted 15 lines
testcases/kernel/syscalls/utime/utime01.c +1 -2
index 4bb33e9..2eb49d4 100644
@@ -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

testcases/kernel/syscalls/utime/utime01.c int main(int ac, char **av) · line 150

Quoted 9 lines
testcases/kernel/syscalls/utime/utime01.c +2 -3
@@ -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.

Quoted 3 lines

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 ;)

Quoted 13 lines

testcases/kernel/syscalls/utime/utime01.c int main(int ac, char **av) · line 160

Quoted 10 lines
testcases/kernel/syscalls/utime/utime01.c +2 -3
@@ -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:

Quoted 3 lines

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.

Signature · 5 lines
Nicolas Joly

Cluster & Computing Group
Biology IT Center
Institut Pasteur, Paris.
#3 lore raw

PATCH 1/1 Cleanup syscalls/utime test messages

Quoted 1 line · Nicolas Joly

On Thu, Nov 19, 2015 at 05:00:51PM +0100, Cyril Hrubis wrote:

[...]

Quoted 20 lines
Quoted 3 lines

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 ;)

Quoted 13 lines

Review int main(int ac, char **av) · line 160

Quoted 10 lines
(quoted diff) +2 -3
@@ -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:

Quoted 7 lines
Quoted 3 lines

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.

Signature · 16 lines
Nicolas Joly

Cluster & Computing Group
Biology IT Center
Institut Pasteur, Paris.
-------------- next part --------------
commit bcad1e1a7d0a8c82d6dfe32f38232126a3afb5ea
Author: Nicolas Joly <[email protected]>
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 <[email protected]>
testcases/kernel/syscalls/utime/utime01.c +7 -28
index 4bb33e9..505f875 100644
@@ -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
testcases/kernel/syscalls/utime/utime02.c +9 -34

88 lines not on this page · raw message

testcases/kernel/syscalls/utime/utime03.c +13 -52

119 lines not on this page · raw message

testcases/kernel/syscalls/utime/utime04.c +5 -18
index 0287296..5253f76 100644
@@ -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;
testcases/kernel/syscalls/utime/utime05.c +7 -23
index 275f4fa..b2d2450 100644
@@ -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;
#4 lore raw

PATCH 1/1 Cleanup syscalls/utime test messages

Hi!

Quoted 3 lines

Finally got some spare time to setup this ...

New version attached, that address all concerns.

Pushed, thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]