[PATCH] Test 5: Read/write using dup() of pipe fds

Sukadev Bhattiprolu sukadev at linux.vnet.ibm.com
Sun Jun 22 23:33:24 PDT 2008


---
 tests/pipe.c |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/tests/pipe.c b/tests/pipe.c
index 5b04f46..47f5da6 100644
--- a/tests/pipe.c
+++ b/tests/pipe.c
@@ -16,12 +16,13 @@ char *test_descriptions[] = {
 	"Test continous reads/writes from pipe",
 	"Test non-consecutive pipe-fds",
 	"Test with read-fd > write-fd",
+	"Test with dup of pipe fds around"
 	"Test with read-fd/write-fd swapped",
 	"Test with all-fds in use",
 	"Test with all-fds in use for pipes",
 };
 
-static int last_num = 4;
+static int last_num = 5;
 usage(char *argv[])
 {
 	int i;
@@ -145,13 +146,13 @@ int read_write_pipe(int *testfdsp, int close_unused)
 		exit(1);
 	}
 
+	read_fd = tmpfds[0];
+	write_fd = tmpfds[1];
 	if (testfdsp) {
 		reset_pipe_fds(tmpfds, testfdsp, close_unused);
+		/* read from dup'd fds even if main ones are open */
 		read_fd = testfdsp[0];
 		write_fd = testfdsp[1];
-	} else {
-		read_fd = tmpfds[0];
-		write_fd = tmpfds[1];
 	}
 
 	printf("read_fd %d, write_fd %d\n", read_fd, write_fd);
@@ -193,7 +194,7 @@ int read_write_pipe(int *testfdsp, int close_unused)
 		}
 	}
 
-	if (strncmp(wbuf, rbuf, strlen(wbufp))) {
+	if (strncmp(wbuf, rbuf, strlen(wbuf))) {
 		printf("Wrote: %s\n", wbuf);
 		printf("Read : %s\n", rbuf);
 		printf("Test FAILED\n");
@@ -214,6 +215,13 @@ static void test4()
 	read_write_pipe(tmpfds, 1);
 }
 
+static void test5()
+{
+	int tmpfds[2] = { 172, 101 };
+
+	read_write_pipe(tmpfds, 0);
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -238,6 +246,7 @@ main(int argc, char *argv[])
 	case 2: test2(); break;
 	case 3: test3(); break;
 	case 4: test4(); break;
+	case 5: test5(); break;
 	default:
 		printf("Unsupported test case %d\n", tc_num);
 		usage(argv);
-- 
1.5.2.5



More information about the Containers mailing list