Skip to contentSkip to conversation

ltp setrlimit testcase patch for RLIMIT_FSIZE resource

PATCH In review Harsh Prateek Bora 3 participants 4 messages Aug 16, 2010 – Aug 24, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ltp setrlimit testcase patch for RLIMIT_FSIZE resource

Current testcase for setrlimit resource RLIMIT_FSIZE is using a global integer variable to communicate the number of bytes from child to parent which is incorrect. This has been corrected by introducing a pipe to transfer this information from child to parent process.

---
 testcases/kernel/syscalls/setrlimit/setrlimit01.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
testcases/kernel/syscalls/setrlimit/setrlimit01.c +15 -0
index 6952eb3..2bb1e9d 100644
@@ -156,7 +156,11 @@ void test2()
 	 * an wired value!  So, it is essential to fflush the parent's
 	 * write buffer HERE
 	 */
+	int pipefd[2];
 	fflush(stdout);
+	if (pipe(pipefd) == -1) {
+		tst_brkm(TBROK | TERRNO, NULL, "pipe creation failed");
+	}
 
 	/*
 	 * Spawn a child process, and reduce the filesize to
@@ -170,6 +174,7 @@ void test2()
 	}
 
 	if (pid == 0) {
+		close(pipefd[0]); /* close unused read end */
 		rlim.rlim_cur = 10;
 		rlim.rlim_max = 10;
 		if ((setrlimit(RLIMIT_FSIZE, &rlim)) == -1) {
@@ -181,6 +186,11 @@ void test2()
 		}
 
 		if ((bytes = write(fd, buf, 26)) != 10) {
+			if (write(pipefd[1], &bytes, sizeof(bytes))
+				< sizeof(bytes)) {
+				perror("child: write to pipe failed");
+			}
+			close(pipefd[1]); /* EOF */
 			exit(3);
 		}
 		exit(0);	/* success */
@@ -202,6 +212,11 @@ void test2()
 		tst_resm(TFAIL, "creating testfile failed");
 		break;
 	case 3:
+		close(pipefd[1]); /* close unused write end */
+		if (read(pipefd[0], &bytes, sizeof(bytes)) < sizeof(bytes)) {
+			tst_resm(TFAIL, "parent: reading pipe failed");
+		}
+		close(pipefd[0]);
 		tst_resm(TFAIL, "setrlimit failed, expected "
 			 "10 got %d", bytes);
 		break;
Signature · 13 lines
1.7.1.1


------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw
Quoted 36 lines · Harsh Prateek Bora

Current testcase for setrlimit resource RLIMIT_FSIZE is using a global integer variable to communicate the number of bytes from child to parent which is incorrect. This has been corrected by introducing a pipe to transfer this information from child to parent process.

---
 testcases/kernel/syscalls/setrlimit/setrlimit01.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
testcases/kernel/syscalls/setrlimit/setrlimit01.c +5 -0
index 6952eb3..2bb1e9d 100644
@@ -156,7 +156,11 @@ void test2()
 	 * an wired value!  So, it is essential to fflush the parent's
 	 * write buffer HERE
 	 */
+	int pipefd[2];
 	fflush(stdout);
+	if (pipe(pipefd) == -1) {
+		tst_brkm(TBROK | TERRNO, NULL, "pipe creation failed");
+	}
 
 	/*
 	 * Spawn a child process, and reduce the filesize to
@@ -170,6 +174,7 @@ void test2()
 	}
 
 	if (pid == 0) {
+		close(pipefd[0]); /* close unused read end */
 		rlim.rlim_cur = 10;
 		rlim.rlim_max = 10;
 		if ((setrlimit(RLIMIT_FSIZE, &rlim)) == -1) {

testcases/kernel/syscalls/setrlimit/setrlimit01.c void test2() · line 191

Quoted 6 lines
testcases/kernel/syscalls/setrlimit/setrlimit01.c +3 -0
@@ -181,6 +186,11 @@ void test2()
 		}
 
 		if ((bytes = write(fd, buf, 26)) != 10) {
+			if (write(pipefd[1], &bytes, sizeof(bytes))
+				< sizeof(bytes)) {
+				perror("child: write to pipe failed");

You still uses perror() here. Use tst_resm() instead.

Regards--
Subrata

Quoted 7 lines
testcases/kernel/syscalls/setrlimit/setrlimit01.c +2 -0
+			}
+			close(pipefd[1]); /* EOF */
 			exit(3);
 		}
 		exit(0);	/* success */
@@ -202,6 +212,11 @@ void test2()
 		tst_resm(TFAIL, "creating testfile failed");

testcases/kernel/syscalls/setrlimit/setrlimit01.c void test2() · line 222

Quoted 10 lines
testcases/kernel/syscalls/setrlimit/setrlimit01.c +5 -0
 		break;
 	case 3:
+		close(pipefd[1]); /* close unused write end */
+		if (read(pipefd[0], &bytes, sizeof(bytes)) < sizeof(bytes)) {
+			tst_resm(TFAIL, "parent: reading pipe failed");
+		}
+		close(pipefd[0]);
 		tst_resm(TFAIL, "setrlimit failed, expected "
 			 "10 got %d", bytes);
 		break;

------------------------------------------------------------------------------
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#2 lore raw
Quoted 39 lines · Subrata Modak
Quoted 38 lines · Harsh Prateek Bora

Current testcase for setrlimit resource RLIMIT_FSIZE is using a global integer variable to communicate the number of bytes from child to parent which is incorrect. This has been corrected by introducing a pipe to transfer this information from child to parent process.

---
 testcases/kernel/syscalls/setrlimit/setrlimit01.c |   15 +++++++++++++++

 1 files changed, 15 insertions(+), 0 deletions(-)
testcases/kernel/syscalls/setrlimit/setrlimit01.c +5 -0
index 6952eb3..2bb1e9d 100644
@@ -156,7 +156,11 @@ void test2()
        * an wired value!  So, it is essential to fflush the parent's
        * write buffer HERE
        */
+     int pipefd[2];
       fflush(stdout);
+     if (pipe(pipefd) == -1) {
+             tst_brkm(TBROK | TERRNO, NULL, "pipe creation failed");
+     }
 
       /*
        * Spawn a child process, and reduce the filesize to
@@ -170,6 +174,7 @@ void test2()
       }
 
       if (pid == 0) {
+             close(pipefd[0]); /* close unused read end */
               rlim.rlim_cur = 10;
               rlim.rlim_max = 10;
               if ((setrlimit(RLIMIT_FSIZE, &rlim)) == -1) {
@@ -181,6 +186,11 @@ void test2()
               }
 
Quoted 6 lines

testcases/kernel/syscalls/setrlimit/setrlimit01.c void test2() · line 191

Quoted 4 lines
testcases/kernel/syscalls/setrlimit/setrlimit01.c +3 -0
               if ((bytes = write(fd, buf, 26)) != 10) {
+                     if (write(pipefd[1], &bytes, sizeof(bytes))
+                             < sizeof(bytes)) {
+                             perror("child: write to pipe failed");

You still uses perror() here. Use tst_resm() instead.

This patch is actually ok. If you look at the test in context (as Harsh pointed out), the perror(3) call was within a forked process, and that's fine. It's the other areas that need to be tst_resm(3) calls because they're in the parent process and actually affect the final outcome of the test, and provide a uniform means of reporting.

Thanks,
-Garrett

------------------------------------------------------------------------------
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

#3 lore raw

Ok. Merged.

Regards--
Subrata

Quoted 48 lines · Garrett Cooper
Quoted 39 lines · Subrata Modak
Quoted 38 lines · Harsh Prateek Bora

Current testcase for setrlimit resource RLIMIT_FSIZE is using a global integer variable to communicate the number of bytes from child to parent which is incorrect. This has been corrected by introducing a pipe to transfer this information from child to parent process.

---
 testcases/kernel/syscalls/setrlimit/setrlimit01.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
testcases/kernel/syscalls/setrlimit/setrlimit01.c +5 -0
index 6952eb3..2bb1e9d 100644
@@ -156,7 +156,11 @@ void test2()
       * an wired value!  So, it is essential to fflush the parent's
       * write buffer HERE
       */
+     int pipefd[2];
      fflush(stdout);
+     if (pipe(pipefd) == -1) {
+             tst_brkm(TBROK | TERRNO, NULL, "pipe creation failed");
+     }
 
      /*
       * Spawn a child process, and reduce the filesize to
@@ -170,6 +174,7 @@ void test2()
      }
 
      if (pid == 0) {
+             close(pipefd[0]); /* close unused read end */
              rlim.rlim_cur = 10;
              rlim.rlim_max = 10;
              if ((setrlimit(RLIMIT_FSIZE, &rlim)) == -1) {
@@ -181,6 +186,11 @@ void test2()
              }
 
Quoted 6 lines

testcases/kernel/syscalls/setrlimit/setrlimit01.c void test2() · line 191

Quoted 4 lines
testcases/kernel/syscalls/setrlimit/setrlimit01.c +3 -0
              if ((bytes = write(fd, buf, 26)) != 10) {
+                     if (write(pipefd[1], &bytes, sizeof(bytes))
+                             < sizeof(bytes)) {
+                             perror("child: write to pipe failed");

You still uses perror() here. Use tst_resm() instead.

Quoted 8 lines

This patch is actually ok. If you look at the test in context (as Harsh pointed out), the perror(3) call was within a forked process, and that's fine. It's the other areas that need to be tst_resm(3) calls because they're in the parent process and actually affect the final outcome of the test, and provide a uniform means of reporting.

Thanks,
-Garrett

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program Be part of this innovative community and reach millions of netbook users worldwide. Take advantage of special opportunities to increase revenue and speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list