diff -r 000000000000 -r bde4ae8d615e os/ossrv/genericopenlibs/cstdlib/TSTLIB/TWPIPE.C --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os/ossrv/genericopenlibs/cstdlib/TSTLIB/TWPIPE.C Fri Jun 15 03:10:57 2012 +0200 @@ -0,0 +1,312 @@ +/* +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Test code for pipes, using dubious WINS extension for multiple processes... +* +* +*/ + + + +#include +#include +#include +#include /* for MAXPATHLEN */ +#include +#include + +#include "CTEST.H" + +int fids[3]; + +/** +@SYMTestCaseID SYSLIB-STDLIB-CT-1092 +@SYMTestCaseDesc Tests for operations on pipes +@SYMTestPriority High +@SYMTestActions Tests for command line arguments,directory operations,environment variables. +@SYMTestExpectedResults Test must not fail +@SYMREQ REQ0000 +*/ +int do_main(int argc, wchar_t* argv[]) + { + test_Data; + int i; + wchar_t* var; + wchar_t* varname; + wchar_t cwd[MAXPATHLEN]; + char buf[200]; + char buf1[200]; + + test_Title("PIPE"); + + test_Next("Command line arguments"); + test(argc>0); + test(argv!=0); + printf(" argc=%d\r\n", argc); + for (i=0; i0) + { + char buf[5]; + printf("Child calls read of fid=0\n"); + nbytes=read(0,buf,sizeof(buf)); + printf("Child got %d bytes\n", nbytes); + if (nbytes>0) + { + if (firstread) + { + /* We hope that there is still stuff to read */ + printf("Child calls E32IOSELECT(WRITE) on STDIN\n"); + mask=E32SELECT_WRITE; + err=ioctl(0,E32IOSELECT,(void*)&mask); + test(err==0); + test(mask==0); + printf("Child calls E32IOSELECT(READ) on STDIN\n"); + mask=E32SELECT_READ+E32SELECT_WRITE; + err=ioctl(0,E32IOSELECT,(void*)&mask); + test(err==0); + test(mask==E32SELECT_READ); + firstread=0; + } + printf(" %02d >%.*s<\n", nbytes, nbytes, buf); + } + else + if (nbytes<0) + printf(" %d (errno=%d)\n", nbytes, errno); + } + + printf("Child calls E32IOSELECT on STDOUT"); + mask=E32SELECT_READ+E32SELECT_WRITE; + err=ioctl(1,E32IOSELECT,(void*)&mask); + test(err==0); + test(mask==E32SELECT_WRITE); + + fflush(stdout); + + do_main(2, argv); + fclose(stdout); + } + +/** +@SYMTestCaseID SYSLIB-STDLIB-CT-1094 +@SYMTestCaseDesc Tests for pipe file descriptors +@SYMTestPriority High +@SYMTestActions Tests for writing to the pipe file descriptors +@SYMTestExpectedResults Test must not fail +@SYMREQ REQ0000 +*/ +void do_piping() + { + test_Data; + char* s; + char buf[180]; + + test_Title("PIPE"); + + test_Next("Pipe file descriptors"); + printf(" fids= %d, %d, %d\n", fids[0], fids[1], fids[2]); + + if (fids[0]>=0) + { + int nbytes; + int remainder; + int mask, err; + const char* buf="test data 18 bytes"; + + test_Next("E32IOSELECT(READ) on Child STDIN"); + mask=E32SELECT_READ; + err=ioctl(fids[0],E32IOSELECT,(void*)&mask); + test(err==0); + test(mask==0); + test_Next("E32IOSELECT(WRITE) on Child STDIN"); + mask=E32SELECT_READ+E32SELECT_WRITE; + err=ioctl(fids[0],E32IOSELECT,(void*)&mask); + test(err==0); + test(mask==E32SELECT_WRITE); + + test_Next("Child STDIN"); + remainder=strlen(buf); + while (remainder>0) + { + int length=(remainder<7)?remainder:7; + nbytes=write(fids[0],buf,length); + printf(" >%.*s<",nbytes,buf); + buf+=nbytes; + remainder-=nbytes; + test(nbytes>0); + test(nbytes<=length); + } + printf("\n"); + close(fids[0]); + sleep(5); + } + if (fids[1]>=0) + { + FILE* cout; + int mask, err; + int firstread=1; + + test_Next("Child STDOUT"); + cout=wfdopen(fids[1],(wchar_t*)L"r"); + test(cout!=0); + + do + { + s=fgets(buf,sizeof(buf),cout); + if (s!=0) + { + printf(" >%s", s); + if (firstread) + { + test_Next("\nE32IOSELECT(WRITE) on Child STDOUT"); + mask=E32SELECT_WRITE; + err=ioctl(fids[1],E32IOSELECT,(void*)&mask); + test(err==0); + test(mask==0); + test_Next("E32IOSELECT(READ) on Child STDOUT"); + mask=E32SELECT_READ+E32SELECT_WRITE; + err=ioctl(fids[1],E32IOSELECT,(void*)&mask); + test(err==0); + test(mask==E32SELECT_READ); + firstread=0; + } + } + } + while (s!=0); + fclose(cout); + } + + test_Close(); + } + +/* Linked with mcrt0.o, so that the exe starts the CPosixServer automatically as per the + * plan all along. + */ + +int wmain(int argc, wchar_t* argv[]) + { + void* proc2; + + start_redirection_server(); + + if (argc==1) + { + do_mainA(); + + proc2 = create_process(do_mainB, "B", "rw", fids); + if (proc2) + start_process(proc2); + else + perror("Failed to start processB: "); + + if (proc2) + { + int exit; + do_piping(); + exit=wait_for_process(proc2); + printf("wait_for_process returned %d\r\n", exit); + } + } + else + { + do_mainB(); + } + + return 0; + }