1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is the Netscape Portable Runtime (NSPR).
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2000
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
42 * This test runs in conjunction with the pipeping2 test.
43 * The pipeping2 test creates two pipes and passes two
44 * pipe fd's to this test. Then the pipeping2 test writes
45 * "ping" to this test and this test writes "pong" back.
46 * To run this pair of tests, just invoke pipeping2.
48 * Tested areas: process creation, pipes, file descriptor
59 #define NUM_ITERATIONS 10
61 int main(int argc, char **argv)
63 PRFileDesc *pipe_read, *pipe_write;
69 pipe_read = PR_GetInheritedFD("PIPE_READ");
70 if (pipe_read == NULL) {
71 fprintf(stderr, "PR_GetInheritedFD failed\n");
74 status = PR_SetFDInheritable(pipe_read, PR_FALSE);
75 if (status == PR_FAILURE) {
76 fprintf(stderr, "PR_SetFDInheritable failed\n");
79 pipe_write = PR_GetInheritedFD("PIPE_WRITE");
80 if (pipe_write == NULL) {
81 fprintf(stderr, "PR_GetInheritedFD failed\n");
84 status = PR_SetFDInheritable(pipe_write, PR_FALSE);
85 if (status == PR_FAILURE) {
86 fprintf(stderr, "PR_SetFDInheritable failed\n");
90 for (idx = 0; idx < NUM_ITERATIONS; idx++) {
91 memset(buf, 0, sizeof(buf));
92 nBytes = PR_Read(pipe_read, buf, sizeof(buf));
94 fprintf(stderr, "PR_Read failed: (%d, %d)\n",
95 PR_GetError(), PR_GetOSError());
98 printf("pong process: received \"%s\"\n", buf);
100 fprintf(stderr, "pong process: expected 5 bytes but got %d bytes\n",
104 if (strcmp(buf, "ping") != 0) {
105 fprintf(stderr, "pong process: expected \"ping\" but got \"%s\"\n",
111 printf("pong process: sending \"%s\"\n", buf);
112 nBytes = PR_Write(pipe_write, buf, 5);
114 fprintf(stderr, "PR_Write failed\n");
119 status = PR_Close(pipe_read);
120 if (status == PR_FAILURE) {
121 fprintf(stderr, "PR_Close failed\n");
124 status = PR_Close(pipe_write);
125 if (status == PR_FAILURE) {
126 fprintf(stderr, "PR_Close failed\n");