michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * File: pipepong.c michael@0: * michael@0: * Description: michael@0: * This test runs in conjunction with the pipeping test. michael@0: * The pipeping test creates two pipes and redirects the michael@0: * stdin and stdout of this test to the pipes. Then the michael@0: * pipeping test writes "ping" to this test and this test michael@0: * writes "pong" back. Note that this test does not depend michael@0: * on NSPR at all. To run this pair of tests, just invoke michael@0: * pipeping. michael@0: * michael@0: * Tested areas: process creation, pipes, file descriptor michael@0: * inheritance, standard I/O redirection. michael@0: */ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #define NUM_ITERATIONS 10 michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: char buf[1024]; michael@0: size_t nBytes; michael@0: int idx; michael@0: michael@0: for (idx = 0; idx < NUM_ITERATIONS; idx++) { michael@0: memset(buf, 0, sizeof(buf)); michael@0: nBytes = fread(buf, 1, 5, stdin); michael@0: fprintf(stderr, "pong process: received \"%s\"\n", buf); michael@0: if (nBytes != 5) { michael@0: fprintf(stderr, "pong process: expected 5 bytes but got %d bytes\n", michael@0: nBytes); michael@0: exit(1); michael@0: } michael@0: if (strcmp(buf, "ping") != 0) { michael@0: fprintf(stderr, "pong process: expected \"ping\" but got \"%s\"\n", michael@0: buf); michael@0: exit(1); michael@0: } michael@0: michael@0: strcpy(buf, "pong"); michael@0: fprintf(stderr, "pong process: sending \"%s\"\n", buf); michael@0: nBytes = fwrite(buf, 1, 5, stdout); michael@0: if (nBytes != 5) { michael@0: fprintf(stderr, "pong process: fwrite failed\n"); michael@0: exit(1); michael@0: } michael@0: fflush(stdout); michael@0: } michael@0: michael@0: return 0; michael@0: }