Skip to contentSkip to conversation

unshare01.c: TEST_RETURN is used wrong

PATCH In review Peng Haitao 3 participants 7 messages Feb 15, 2011 – Feb 16, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 unshare01.c: TEST_RETURN is used wrong

Hi Garrett,

---
 testcases/kernel/syscalls/unshare/unshare01.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/unshare/unshare01.c +3 -3
index e19d73d..9ae5e8f 100644
@@ -206,7 +206,7 @@ int main(int ac, char **av) {
 			}
 
 			pid1 = fork();
-			if (TEST_RETURN == -1) {
+			if (pid1 == -1) {
 				tst_brkm(TFAIL|TERRNO, cleanup,
 				    "fork failed");
 			} else if (pid1 == 0) {
@@ -249,7 +249,7 @@ int main(int ac, char **av) {
 			if (pid1 == -1) {
 				tst_brkm(TFAIL|TERRNO, cleanup,
 				    "fork() failed.");
-			} else if (TEST_RETURN == 0) {
+			} else if (pid1 == 0) {
 				TEST(unshare(CLONE_NEWNS));
 				if (TEST_RETURN == 0) {
 					printf("unshare call with CLONE_NEWNS "
@@ -299,4 +299,4 @@ int main(void)
 	tst_resm(TCONF, "unshare is undefined.");
 	tst_exit();
 }
-#endif
\ No newline at end of file
+#endif
Signature · 17 lines
1.7.3.1

-- 
Best Regards,
Peng Haitao


------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw
Quoted 12 lines · Peng Haitao

Hi Garrett,

---
 testcases/kernel/syscalls/unshare/unshare01.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/unshare/unshare01.c +0 -0
index e19d73d..9ae5e8f 100644

testcases/kernel/syscalls/unshare/unshare01.c int main(int ac, char **av) { · line 209

Quoted 5 lines
testcases/kernel/syscalls/unshare/unshare01.c +1 -1
@@ -206,7 +206,7 @@ int main(int ac, char **av) {
 			}
 
 			pid1 = fork();
-			if (TEST_RETURN == -1) {
+			if (pid1 == -1) {

Looking at the rest of that file, isn't the right fix to wrap 'pid1 = fork();' in a TEST() macro?

-serge

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#2 lore raw
Quoted 15 lines · Serge E. Hallyn
Quoted 14 lines · Peng Haitao

Hi Garrett,

---
 testcases/kernel/syscalls/unshare/unshare01.c |    6 +++---

 1 files changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/unshare/unshare01.c +0 -0
index e19d73d..9ae5e8f 100644
@@ -206,7 +206,7 @@ int main(int ac, char **av) {
                       }
 
Quoted 6 lines

testcases/kernel/syscalls/unshare/unshare01.c int main(int ac, char **av) { · line 209

Quoted 3 lines
testcases/kernel/syscalls/unshare/unshare01.c +1 -1
                       pid1 = fork();
-                     if (TEST_RETURN == -1) {
+                     if (pid1 == -1) {

Looking at the rest of that file, isn't the right fix to wrap 'pid1 = fork();' in a TEST() macro?

Hi Serge!
I would agree with you, but in my firm opinion this testcase
abuses TEST_ERRNO, etc way too much for no good reason.
I just didn't remember to follow through finishing off this file
for some odd reason.
Thanks,
-Garrett

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#3 lore raw
Quoted 6 lines · Garrett Cooper
Quoted 2 lines

Looking at the rest of that file, isn't the right fix to wrap 'pid1 = fork();' in a TEST() macro?

Hi Serge!
I would agree with you, but in my firm opinion this testcase
abuses TEST_ERRNO, etc way too much for no good reason.

Cool.

Quoted 2 lines

I just didn't remember to follow through finishing off this file
for some odd reason.

thanks,
-serge

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#4 lore raw
In reply to Peng Haitao
Quoted 30 lines · Peng Haitao

Hi Garrett,

---
 testcases/kernel/syscalls/unshare/unshare01.c |    6 +++---

 1 files changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/unshare/unshare01.c +2 -2
index e19d73d..9ae5e8f 100644
@@ -206,7 +206,7 @@ int main(int ac, char **av) {
                        }
 
                        pid1 = fork();
-                       if (TEST_RETURN == -1) {
+                       if (pid1 == -1) {
                                tst_brkm(TFAIL|TERRNO, cleanup,
                                    "fork failed");
                        } else if (pid1 == 0) {
@@ -249,7 +249,7 @@ int main(int ac, char **av) {
                        if (pid1 == -1) {
                                tst_brkm(TFAIL|TERRNO, cleanup,
                                    "fork() failed.");
-                       } else if (TEST_RETURN == 0) {
+                       } else if (pid1 == 0) {
                                TEST(unshare(CLONE_NEWNS));
                                if (TEST_RETURN == 0) {

                                       printf("unshare call with CLONE_NEWNS "

testcases/kernel/syscalls/unshare/unshare01.c int main(void) · line 302

Quoted 6 lines
testcases/kernel/syscalls/unshare/unshare01.c +1 -1
@@ -299,4 +299,4 @@ int main(void)
        tst_resm(TCONF, "unshare is undefined.");
        tst_exit();
  }
-#endif
\ No newline at end of file
+#endif

How about this?
Thanks,
-Garrett

testcases/kernel/syscalls/unshare/unshare01.c +31 -33
index e19d73d..a460248 100644
@@ -109,14 +109,14 @@ int  TST_TOTAL = 1;		   /* total number of tests in this file.   */
 /* Description: Performs all one time clean up for this test on successful    */
 /*	      completion,  premature exit or  failure. Closes all temporary */
 /*	      files, removes all temporary directories exits the test with  */
-/*	      appropriate TEST_RETURNurn code by calling tst_exit() function.       */
+/*	      appropriate return code by calling tst_exit() function.       */
 /*									    */
 /* Input:       None.							 */
 /*									    */
 /* Output:      None.							 */
 /*									    */
-/* Return:      On failure - Exits calling tst_exit(). Non '0' TEST_RETURNurn code.   */
-/*	      On success - Exits calling tst_exit(). With '0' TEST_RETURNurn code.  */
+/* Return:      On failure - Exits calling tst_exit(). Non '0' return code.   */
+/*	      On success - Exits calling tst_exit(). With '0' return code.  */
 /*									    */
 /******************************************************************************/
 extern void cleanup() {
@@ -140,7 +140,7 @@ extern void cleanup() {
 /* Output:      None.							 */
 /*									    */
 /* Return:      On failure - Exits by calling cleanup().		      */
-/*	      On success - TEST_RETURNurns 0.				       */
+/*	      On success - returns 0.				       */
 /*									    */
 /******************************************************************************/
 void setup() {
@@ -154,7 +154,7 @@ int main(int ac, char **av) {
 	pid_t pid1;
 	int lc;			/* loop counter */
 	int rval;
-	char *msg;		/* message TEST_RETURNurned from parse_opts */
+	char *msg;		/* message returned from parse_opts */
 
 	/* parse standard options */
 	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
@@ -166,20 +166,20 @@ int main(int ac, char **av) {
 		Tst_count = 0;
 		for (testno = 0; testno < TST_TOTAL; ++testno) {
 
-			TEST(pid1 = fork());    //call to fork()
-			if (TEST_RETURN == -1) {
-				tst_brkm(TFAIL|TTERRNO, cleanup, "fork failed");
-			} else if (TEST_RETURN == 0) {
-				TEST(unshare(CLONE_FILES));
-				if (TEST_RETURN == 0) {
+			pid1 = fork();    //call to fork()
+			if (pid1 == -1) {
+				tst_brkm(TFAIL|TERRNO, cleanup, "fork failed");
+			} else if (pid1 == 0) {
+				switch (unshare(CLONE_FILES)) {
+				case 0:
 					printf("unshare with CLONE_FILES call "
 					    "succeeded\n");
 					rval = 0;
-				} else if (TEST_RETURN == -1) {
-					if (TEST_ERRNO == ENOSYS) {
+					break;
+				case -1:
+					if (errno == ENOSYS)
 						rval = 1;
-					} else {
-						errno = TEST_ERRNO;
+					else {
 						perror("unshare failed");
 						rval = 2;
 					}
@@ -200,36 +200,34 @@ int main(int ac, char **av) {
 					default:
 						tst_brkm(TFAIL, cleanup,
 						    "unshare failed");
-						break;
 					}
 				}
 			}
 
 			pid1 = fork();
-			if (TEST_RETURN == -1) {
+			if (pid1 == -1) {
 				tst_brkm(TFAIL|TERRNO, cleanup,
 				    "fork failed");
 			} else if (pid1 == 0) {
-				TEST(unshare(CLONE_FS));
-				if (TEST_RETURN == 0) {
+				switch (unshare(CLONE_FS)) {
+				case 0:
 					printf("unshare with CLONE_FS call "
 					    "succeeded\n");
 					rval = 0;
-				} else if (TEST_RETURN == -1) {
-					if (TEST_ERRNO == ENOSYS) {
+					break;
+				case -1:
+					if (errno == ENOSYS)
 						rval = 1;
-					} else {
-						errno = TEST_ERRNO;
+					else {
 						perror("unshare failed");
 						rval = 2;
 					}
 				}
 				exit(rval);
 			} else {
-				if (wait(&rval) == -1) {
+				if (wait(&rval) == -1)
 					tst_brkm(TBROK|TERRNO, cleanup,
 					    "wait failed");
-				}
 				if (rval != 0 && WIFEXITED(rval)) {
 					switch (WEXITSTATUS(rval)) {
 					case 1:
@@ -249,17 +247,17 @@ int main(int ac, char **av) {
 			if (pid1 == -1) {
 				tst_brkm(TFAIL|TERRNO, cleanup,
 				    "fork() failed.");
-			} else if (TEST_RETURN == 0) {
-				TEST(unshare(CLONE_NEWNS));
-				if (TEST_RETURN == 0) {
+			} else if (pid1 == 0) {
+				switch (unshare(CLONE_NEWNS)) {
+				case 0:
 					printf("unshare call with CLONE_NEWNS "
 					    "succeeded\n");
 					rval = 0;
-				} else if (TEST_RETURN == -1) {
-					if (TEST_ERRNO == ENOSYS) {
+					break;
+				case -1:
+					if (errno == ENOSYS)
 						rval = 1;
-					} else {
-						errno = TEST_ERRNO;
+					else {
 						perror("unshare failed");
 						rval = 2;
 					}
@@ -299,4 +297,4 @@ int main(void)
 	tst_resm(TCONF, "unshare is undefined.");
 	tst_exit();
 }
-#endif
\ No newline at end of file
+#endif

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#5 lore raw

Hi Garrett,

Garrett Cooper said the following on 2011-2-15 22:29:

Quoted 2 lines

How about this?

The patch is OK, thanks.
but "break;" in block "default:" can be deleted:)

Quoted 2 lines

Thanks,
-Garrett

Signature · 14 lines
Best Regards,
Peng Haitao


------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#6 lore raw
Quoted 8 lines · Peng Haitao

Hi Garrett,

Garrett Cooper said the following on 2011-2-15 22:29:

Quoted 2 lines

How about this?

 The patch is OK, thanks.
but "break;" in block "default:" can be deleted:)

Sure -- thanks!
-Garrett

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list