Skip to contentSkip to conversation

fs/9p: setrlimit testcase fix for RLIMIT_FSIZE

PATCH In review Harsh Prateek Bora 2 participants 2 messages Aug 12, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/9p: setrlimit testcase fix for RLIMIT_FSIZE

Current testcase for setrlimit for parameter RLIMIT_FSIZE does not convey the number of bytes actually written from child process to parent, as the child process writes to its own copy of global variable. This patch introduces a pipe to send the information from child to the parent process.

---
 testcases/kernel/syscalls/setrlimit/setrlimit01.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
testcases/kernel/syscalls/setrlimit/setrlimit01.c +16 -0
index 6952eb3..d9ff1de 100644
@@ -156,7 +156,12 @@ 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) {
+		perror("pipe");
+		exit(EXIT_FAILURE);
+	}
 
 	/*
 	 * Spawn a child process, and reduce the filesize to
@@ -170,6 +175,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 +187,11 @@ void test2()
 		}
 
 		if ((bytes = write(fd, buf, 26)) != 10) {
+			if (write(pipefd[1], &bytes, sizeof(bytes))
+				< sizeof(bytes)) {
+				perror("child: writing pipe failed\n");
+			}
+			close(pipefd[1]); /* EOF */
 			exit(3);
 		}
 		exit(0);	/* success */
@@ -202,6 +213,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)) {
+			perror("parent: reading pipe failed\n");
+		}
+		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 5 lines · Harsh Prateek Bora

Current testcase for setrlimit for parameter RLIMIT_FSIZE does not convey the number of bytes actually written from child process to parent, as the child process writes to its own copy of global variable. This patch introduces a pipe to send the information from child to the parent process.

Please use the tst_res(3) APIs instead of using raw perror(3) and exit(3), like so (ignoring indentation):

if (pipe(pipefd) == -1) {
    tst_brkm(TBROK | TERRNO, NULL, "pipe failed");
}

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