Update contrib.
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Test code for pipes, using dubious WINS extension for multiple processes...
25 #include <unistd.h> /* for MAXPATHLEN */
26 #include <sys/errno.h>
27 #include <sys/ioctl.h>
34 @SYMTestCaseID SYSLIB-STDLIB-CT-1074
35 @SYMTestCaseDesc Tests for operations on pipes
37 @SYMTestActions Tests for command line arguments,directory operations,environment variables.
38 @SYMTestExpectedResults Test must not fail
41 int do_main(int argc, char* argv[])
51 test_Next("Command line arguments");
54 printf(" argc=%d\r\n", argc);
55 for (i=0; i<argc; i++)
58 printf(" argv[%d]=\"%s\" length %d\r\n", i, argv[i], strlen(argv[i]));
62 test_Next("Current working directory");
63 var=getcwd(cwd,sizeof(cwd));
65 printf(" %s\r\n\n", cwd);
67 test_Next("Change directory");
70 var=getcwd(cwd,sizeof(cwd));
72 printf(" %s\r\n\n", cwd);
74 test_Next("Environment variables");
79 printf(" %s=%s\r\n", varname,var);
85 printf(" %s=%s\r\n", varname,var);
86 unsetenv("VARIABLE2");
92 printf(" %s=%s\r\n\n", varname,var);
101 Bodge up two pretend processes
103 @SYMTestCaseID SYSLIB-STDLIB-CT-1075
104 @SYMTestCaseDesc Tests for operations on pipes
105 @SYMTestPriority High
106 @SYMTestActions Excecute the basic test operations
107 @SYMTestExpectedResults Test must not fail
112 char* argv[] = { "tpipe.exe", "A" };
114 setenv("CLASSPATH",".;classes;?:/classes;?:/system/java/lib/classes.zip",0);
115 setenv("VARIABLE2","value2",0);
116 setenv("USER","Tumblin' Duke - Go fer yer guns!",0);
122 @SYMTestCaseID SYSLIB-STDLIB-CT-1076
123 @SYMTestCaseDesc Tests for operations on pipes
124 @SYMTestPriority High
125 @SYMTestActions Tests for ioctl functions
126 @SYMTestExpectedResults Test must not fail
132 char* argv[] = { "tpipe.exe", "B" };
137 /* Don't use test_* because it involves fflush and will cause deadlock */
138 printf("PIPE Child");
140 printf("Child reads from STDIN\n");
144 printf("Child calls read of fid=0\n");
145 nbytes=read(0,buf,sizeof(buf));
146 printf("Child got %d bytes\n", nbytes);
151 /* We hope that there is still stuff to read */
152 printf("Child calls E32IOSELECT(WRITE) on STDIN\n");
153 mask=E32SELECT_WRITE;
154 err=ioctl(0,E32IOSELECT,(void*)&mask);
157 printf("Child calls E32IOSELECT(READ) on STDIN\n");
158 mask=E32SELECT_READ+E32SELECT_WRITE;
159 err=ioctl(0,E32IOSELECT,(void*)&mask);
161 test(mask==E32SELECT_READ);
164 printf(" %02d >%.*s<\n", nbytes, nbytes, buf);
168 printf(" %d (errno=%d)\n", nbytes, errno);
171 printf("Child calls E32IOSELECT on STDOUT");
172 mask=E32SELECT_READ+E32SELECT_WRITE;
173 err=ioctl(1,E32IOSELECT,(void*)&mask);
175 test(mask==E32SELECT_WRITE);
184 @SYMTestCaseID SYSLIB-STDLIB-CT-1077
185 @SYMTestCaseDesc Tests for operations on pipes
186 @SYMTestPriority High
187 @SYMTestActions Tests for file descriptors
188 @SYMTestExpectedResults Test must not fail
199 test_Next("Pipe file descriptors");
200 printf(" fids= %d, %d, %d\n", fids[0], fids[1], fids[2]);
207 const char* buf="test data 18 bytes";
209 test_Next("E32IOSELECT(READ) on Child STDIN");
211 err=ioctl(fids[0],E32IOSELECT,(void*)&mask);
214 test_Next("E32IOSELECT(WRITE) on Child STDIN");
215 mask=E32SELECT_READ+E32SELECT_WRITE;
216 err=ioctl(fids[0],E32IOSELECT,(void*)&mask);
218 test(mask==E32SELECT_WRITE);
220 test_Next("Child STDIN");
221 remainder=strlen(buf);
224 int length=(remainder<7)?remainder:7;
225 nbytes=write(fids[0],buf,length);
226 printf(" >%.*s<",nbytes,buf);
230 test(nbytes<=length);
242 test_Next("Child STDOUT");
243 cout=fdopen(fids[1],"r");
248 s=fgets(buf,sizeof(buf),cout);
254 test_Next("\nE32IOSELECT(WRITE) on Child STDOUT");
255 mask=E32SELECT_WRITE;
256 err=ioctl(fids[1],E32IOSELECT,(void*)&mask);
259 test_Next("E32IOSELECT(READ) on Child STDOUT");
260 mask=E32SELECT_READ+E32SELECT_WRITE;
261 err=ioctl(fids[1],E32IOSELECT,(void*)&mask);
263 test(mask==E32SELECT_READ);
275 /* Linked with mcrt0.o, so that the exe starts the CPosixServer automatically as per the
279 int main(int argc, char* argv[])
283 start_redirection_server();
289 proc2 = create_process(do_mainB, "B", "rw", fids);
291 start_process(proc2);
293 perror("Failed to start processB: ");
299 exit=wait_for_process(proc2);
300 printf("wait_for_process returned %d\r\n", exit);