31
|
1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// Name : tmisc.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
|
|
19 |
#include "tmisc.h"
|
|
20 |
#include <stdio.h>
|
|
21 |
#include <stdlib.h>
|
|
22 |
#include <time.h>
|
|
23 |
#include <unistd.h>
|
|
24 |
#include <errno.h>
|
|
25 |
#include <dirent.h>
|
|
26 |
#include <string.h>
|
|
27 |
#include <wchar.h>
|
|
28 |
#include <sys/stat.h>
|
|
29 |
#include <fcntl.h>
|
|
30 |
#include <spawn.h>
|
|
31 |
#include <sched.h>
|
|
32 |
#include <sys/wait.h>
|
|
33 |
#include <sys/syslimits.h>
|
|
34 |
#include <time.h>
|
|
35 |
|
|
36 |
#define MAXVAL 3
|
|
37 |
int counter;
|
|
38 |
|
|
39 |
void* thread1(void* arg);
|
|
40 |
void* thread2(void* arg);
|
|
41 |
void* thread3(void* arg);
|
|
42 |
|
|
43 |
CTestMisc::~CTestMisc()
|
|
44 |
{
|
|
45 |
}
|
|
46 |
|
|
47 |
CTestMisc::CTestMisc(const TDesC& aStepName)
|
|
48 |
{
|
|
49 |
// MANDATORY Call to base class method to set up the human readable name for logging.
|
|
50 |
SetTestStepName(aStepName);
|
|
51 |
}
|
|
52 |
|
|
53 |
TVerdict CTestMisc::doTestStepL()
|
|
54 |
{
|
|
55 |
__UHEAP_MARK;
|
|
56 |
int err;
|
|
57 |
TVerdict err1;
|
|
58 |
if(TestStepName() == Ktest_random)
|
|
59 |
{
|
|
60 |
INFO_PRINTF1(_L("TestRandom():"));
|
|
61 |
err = TestRandom();
|
|
62 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
63 |
}
|
|
64 |
else if(TestStepName() == Ktest_nanosleep)
|
|
65 |
{
|
|
66 |
INFO_PRINTF1(_L("TestNanoSleep():"));
|
|
67 |
err = TestNanoSleep();
|
|
68 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
69 |
}
|
|
70 |
else if(TestStepName() == Ktest_fileoper)
|
|
71 |
{
|
|
72 |
|
|
73 |
INFO_PRINTF1(_L("TestFileOper():"));
|
|
74 |
err = TestFileOper();
|
|
75 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
76 |
}
|
|
77 |
else if(TestStepName() == Ktest_stdio)
|
|
78 |
{
|
|
79 |
INFO_PRINTF1(_L("TestStdio():"));
|
|
80 |
err = TestStdio();
|
|
81 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
82 |
}
|
|
83 |
else if(TestStepName() == Ktest_realloc)
|
|
84 |
{
|
|
85 |
INFO_PRINTF1(_L("TestRealloc():"));
|
|
86 |
err = TestRealloc();
|
|
87 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
88 |
}
|
|
89 |
else if(TestStepName() == KTestSysConf)
|
|
90 |
{
|
|
91 |
INFO_PRINTF1(_L("TestSysConf():"));
|
|
92 |
err = TestSysConf();
|
|
93 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
94 |
}
|
|
95 |
else if(TestStepName() == KTestScandir)
|
|
96 |
{
|
|
97 |
INFO_PRINTF1(_L("TestScandir():"));
|
|
98 |
err = TestScandir();
|
|
99 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
100 |
}
|
|
101 |
else if(TestStepName() == KTestReaddir)
|
|
102 |
{
|
|
103 |
INFO_PRINTF1(_L("TestReaddir():"));
|
|
104 |
err = TestReaddir();
|
|
105 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
106 |
}
|
|
107 |
else if(TestStepName() == KTestDiropr)
|
|
108 |
{
|
|
109 |
INFO_PRINTF1(_L("TestDiropr():"));
|
|
110 |
err = TestDiropr();
|
|
111 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
112 |
}
|
|
113 |
else if(TestStepName() == KTestWOpendir)
|
|
114 |
{
|
|
115 |
INFO_PRINTF1(_L("TestWOpendir():"));
|
|
116 |
err = TestWOpendir();
|
|
117 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
118 |
}
|
|
119 |
else if(TestStepName() == KTestWDiropr)
|
|
120 |
{
|
|
121 |
INFO_PRINTF1(_L("TestWDiropr():"));
|
|
122 |
err = TestWDiropr();
|
|
123 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
124 |
}
|
|
125 |
else if(TestStepName() == KTestFMScalls)
|
|
126 |
{
|
|
127 |
INFO_PRINTF1(_L("TestFMScalls():"));
|
|
128 |
err = TestFMScalls();
|
|
129 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
130 |
}
|
|
131 |
else if(TestStepName() == KTestGetDirEntries)
|
|
132 |
{
|
|
133 |
INFO_PRINTF1(_L("TestGetDirEntries():"));
|
|
134 |
err = TestGetDirEntries();
|
|
135 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
136 |
}
|
|
137 |
else if(TestStepName() == KTestAlphasort)
|
|
138 |
{
|
|
139 |
INFO_PRINTF1(_L("TestAlphasort():"));
|
|
140 |
err = TestAlphasort();
|
|
141 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
142 |
}
|
|
143 |
else if(TestStepName() == KTestPosixSpawn)
|
|
144 |
{
|
|
145 |
INFO_PRINTF1(_L("TestPosixSpawn():"));
|
|
146 |
err = TestPosixSpawn();
|
|
147 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
148 |
}
|
|
149 |
else if(TestStepName() == KTestPosixSpawn1)
|
|
150 |
{
|
|
151 |
INFO_PRINTF1(_L("TestPosixSpawn1():"));
|
|
152 |
err = TestPosixSpawn1();
|
|
153 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
154 |
}
|
|
155 |
|
|
156 |
else if(TestStepName() == KTestSystem0)
|
|
157 |
{
|
|
158 |
INFO_PRINTF1(_L("TestSystem0():"));
|
|
159 |
err = TestSystem0();
|
|
160 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
161 |
}
|
|
162 |
else if(TestStepName() == KTestSystem1)
|
|
163 |
{
|
|
164 |
INFO_PRINTF1(_L("TestSystem1():"));
|
|
165 |
err = TestSystem1();
|
|
166 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
167 |
}
|
|
168 |
else if(TestStepName() == KTestSystem2)
|
|
169 |
{
|
|
170 |
INFO_PRINTF1(_L("TestSystem2():"));
|
|
171 |
err = TestSystem2();
|
|
172 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
173 |
}
|
|
174 |
else if(TestStepName() == KTestAbort1)
|
|
175 |
{
|
|
176 |
INFO_PRINTF1(_L("TestAbort1():"));
|
|
177 |
err = TestAbort1();
|
|
178 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
179 |
}
|
|
180 |
else if(TestStepName() == KTestExit1)
|
|
181 |
{
|
|
182 |
INFO_PRINTF1(_L("TestExit1():"));
|
|
183 |
err = TestExit1();
|
|
184 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
185 |
}
|
|
186 |
else if(TestStepName() == KTestExit2)
|
|
187 |
{
|
|
188 |
INFO_PRINTF1(_L("TestExit2():"));
|
|
189 |
err = TestExit2();
|
|
190 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
191 |
}
|
|
192 |
else if(TestStepName() == KTestExitE1)
|
|
193 |
{
|
|
194 |
INFO_PRINTF1(_L("TestExitE1():"));
|
|
195 |
err = TestExitE1();
|
|
196 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
197 |
}
|
|
198 |
else if(TestStepName() == KTestExit3)
|
|
199 |
{
|
|
200 |
INFO_PRINTF1(_L("TestExit3():"));
|
|
201 |
err = TestExit3();
|
|
202 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
203 |
}
|
|
204 |
else if(TestStepName() == KTestExit4)
|
|
205 |
{
|
|
206 |
INFO_PRINTF1(_L("TestExit4():"));
|
|
207 |
err = TestExit4();
|
|
208 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
209 |
}
|
|
210 |
else if(TestStepName() == KTestExit5)
|
|
211 |
{
|
|
212 |
INFO_PRINTF1(_L("TestExit5():"));
|
|
213 |
err = TestExit5();
|
|
214 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
215 |
}
|
|
216 |
else if(TestStepName() == KTestExit6)
|
|
217 |
{
|
|
218 |
INFO_PRINTF1(_L("TestExit6():"));
|
|
219 |
err = TestExit6();
|
|
220 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
221 |
}
|
|
222 |
else if(TestStepName() == KTestWaitpid1)
|
|
223 |
{
|
|
224 |
INFO_PRINTF1(_L("TestWaitpid1():"));
|
|
225 |
err = TestWaitpid1();
|
|
226 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
227 |
}
|
|
228 |
else if(TestStepName() == KTestWaitpid2)
|
|
229 |
{
|
|
230 |
INFO_PRINTF1(_L("TestWaitpid2():"));
|
|
231 |
err = TestWaitpid2();
|
|
232 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
233 |
}
|
|
234 |
else if(TestStepName() == KTestWaitpid3)
|
|
235 |
{
|
|
236 |
INFO_PRINTF1(_L("TestWaitpid3():"));
|
|
237 |
err = TestWaitpid3();
|
|
238 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
239 |
}
|
|
240 |
else if(TestStepName() == Ksemoptest16 )
|
|
241 |
{
|
|
242 |
INFO_PRINTF1(_L("semoptest16():"));
|
|
243 |
err = semoptest16();
|
|
244 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
245 |
}
|
|
246 |
else if(TestStepName() == Ksemoptest17 )
|
|
247 |
{
|
|
248 |
INFO_PRINTF1(_L("semoptest17():"));
|
|
249 |
err = semoptest17();
|
|
250 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
251 |
}
|
|
252 |
else if(TestStepName() == Ksemoptest18 )
|
|
253 |
{
|
|
254 |
INFO_PRINTF1(_L("semoptest18():"));
|
|
255 |
err = semoptest18();
|
|
256 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
257 |
}
|
|
258 |
else if(TestStepName() == Ksemoptest19 )
|
|
259 |
{
|
|
260 |
INFO_PRINTF1(_L("semoptest19():"));
|
|
261 |
err = semoptest19();
|
|
262 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
263 |
}
|
|
264 |
else if(TestStepName() == Ksemoptest20 )
|
|
265 |
{
|
|
266 |
INFO_PRINTF1(_L("semoptest20():"));
|
|
267 |
err = semoptest20();
|
|
268 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
269 |
}
|
|
270 |
else if(TestStepName() == KTestMaxFopen)
|
|
271 |
{
|
|
272 |
INFO_PRINTF1(_L("TestMaxFopen():"));
|
|
273 |
err = TestMaxFopen();
|
|
274 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
275 |
}
|
|
276 |
else if(TestStepName() == KTestPopen3FdTransfer)
|
|
277 |
{
|
|
278 |
INFO_PRINTF1(_L("TestPopen3FdTransfer():"));
|
|
279 |
err = TestPopen3FdTransfer();
|
|
280 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
281 |
}
|
|
282 |
else if(TestStepName() == KTestPopenFdTransfer)
|
|
283 |
{
|
|
284 |
INFO_PRINTF1(_L("TestPopenFdTransfer():"));
|
|
285 |
err = TestPopenFdTransfer();
|
|
286 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
287 |
}
|
|
288 |
else if(TestStepName() == KTestSystemFdTransfer)
|
|
289 |
{
|
|
290 |
INFO_PRINTF1(_L("TestSystemFdTransfer():"));
|
|
291 |
err = TestSystemFdTransfer();
|
|
292 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
293 |
}
|
|
294 |
else if(TestStepName() == KTestPosixSpawnFdTransfer)
|
|
295 |
{
|
|
296 |
INFO_PRINTF1(_L("TestPosixSpawnFdTransfer():"));
|
|
297 |
err = TestPosixSpawnFdTransfer();
|
|
298 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
299 |
}
|
|
300 |
|
|
301 |
else if(TestStepName() == KTestPopen3PipeReadTransfer)
|
|
302 |
{
|
|
303 |
INFO_PRINTF1(_L("TestPopen3PipeReadTransfer():"));
|
|
304 |
err = TestPopen3PipeReadTransfer();
|
|
305 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
306 |
}
|
|
307 |
|
|
308 |
else if(TestStepName() == KTestPopen3PipeWriteTransfer)
|
|
309 |
{
|
|
310 |
INFO_PRINTF1(_L("TestPopen3PipeWriteTransfer():"));
|
|
311 |
err = TestPopen3PipeWriteTransfer();
|
|
312 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
313 |
}
|
|
314 |
|
|
315 |
else if(TestStepName() == KTestPopenPipeReadTransfer)
|
|
316 |
{
|
|
317 |
INFO_PRINTF1(_L("TestPopenPipeReadTransfer():"));
|
|
318 |
err = TestPopenPipeReadTransfer();
|
|
319 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
320 |
}
|
|
321 |
|
|
322 |
else if(TestStepName() == KTestPopenPipeWriteTransfer)
|
|
323 |
{
|
|
324 |
INFO_PRINTF1(_L("TestPopenPipeWriteTransfer():"));
|
|
325 |
err = TestPopenPipeWriteTransfer();
|
|
326 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
327 |
}
|
|
328 |
else if(TestStepName() == KTestFileReadWrite)
|
|
329 |
{
|
|
330 |
INFO_PRINTF1(_L("TestFileReadWrite():"));
|
|
331 |
err = TestFileReadWrite();
|
|
332 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
333 |
}
|
|
334 |
else if(TestStepName() == KTestPipeReadWrite)
|
|
335 |
{
|
|
336 |
INFO_PRINTF1(_L("TestPipeReadWrite():"));
|
|
337 |
err = TestPipeReadWrite();
|
|
338 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
339 |
}
|
|
340 |
else if(TestStepName() == KTestTzname)
|
|
341 |
{
|
|
342 |
INFO_PRINTF1(_L("TestTzname():"));
|
|
343 |
err = TestTzname();
|
|
344 |
SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
|
|
345 |
}
|
|
346 |
else if(TestStepName() == KTestOpenWithExclusiveLock)
|
|
347 |
{
|
|
348 |
INFO_PRINTF1(_L("TestOpenWithExclusiveLock():"));
|
|
349 |
err1 = TestOpenWithExclusiveLock();
|
|
350 |
return err1;
|
|
351 |
}
|
|
352 |
__UHEAP_MARKEND;
|
|
353 |
return TestStepResult();
|
|
354 |
}
|
|
355 |
|
|
356 |
// -----------------------------------------------------------------------------
|
|
357 |
// Tests to improve coverage
|
|
358 |
// -----------------------------------------------------------------------------
|
|
359 |
//
|
|
360 |
TVerdict CTestMisc::TestRandom()
|
|
361 |
{
|
|
362 |
SetTestStepResult(EPass);
|
|
363 |
|
|
364 |
unsigned seed=1;
|
|
365 |
char state_array[64];
|
|
366 |
size_t size=64;
|
|
367 |
|
|
368 |
char* init_state=initstate(seed, &state_array[0], size);
|
|
369 |
if(init_state==NULL)
|
|
370 |
{
|
|
371 |
INFO_PRINTF1(_L("Error in initstate()..."));
|
|
372 |
SetTestStepResult(EFail);
|
|
373 |
}
|
|
374 |
else
|
|
375 |
{
|
|
376 |
random();
|
|
377 |
unsigned change_seed=2;
|
|
378 |
srandom(change_seed);
|
|
379 |
char* set_state=setstate(&state_array[0]);
|
|
380 |
if(set_state==NULL)
|
|
381 |
{
|
|
382 |
INFO_PRINTF1(_L("Error in setstate()..."));
|
|
383 |
SetTestStepResult(EFail);
|
|
384 |
return TestStepResult();
|
|
385 |
}
|
|
386 |
char state[4];
|
|
387 |
char* init_state=initstate(seed, &state[0], 4);
|
|
388 |
if(init_state!=NULL)
|
|
389 |
{
|
|
390 |
INFO_PRINTF1(_L("Error in initstate()..."));
|
|
391 |
SetTestStepResult(EFail);
|
|
392 |
}
|
|
393 |
}
|
|
394 |
|
|
395 |
return TestStepResult();
|
|
396 |
}
|
|
397 |
|
|
398 |
|
|
399 |
|
|
400 |
TVerdict CTestMisc::TestNanoSleep()
|
|
401 |
{
|
|
402 |
SetTestStepResult(EPass);
|
|
403 |
|
|
404 |
struct timespec rqtp;
|
|
405 |
struct timespec rmtp;
|
|
406 |
rqtp.tv_sec=1;
|
|
407 |
rqtp.tv_nsec=10;
|
|
408 |
|
|
409 |
|
|
410 |
int ret=nanosleep(&rqtp, &rmtp);
|
|
411 |
if(ret!=0)
|
|
412 |
{
|
|
413 |
INFO_PRINTF1(_L("Error in nanosleep()..."));
|
|
414 |
SetTestStepResult(EFail);
|
|
415 |
}
|
|
416 |
|
|
417 |
return TestStepResult();
|
|
418 |
}
|
|
419 |
|
|
420 |
int getFirstMissingDrive(char& aChar)
|
|
421 |
{
|
|
422 |
RFs fs;
|
|
423 |
fs.Connect();
|
|
424 |
|
|
425 |
//obtain list of available drives
|
|
426 |
char ch = 'A';
|
|
427 |
TDriveList driveList8;
|
|
428 |
fs.DriveList(driveList8);
|
|
429 |
fs.Close();
|
|
430 |
|
|
431 |
for (TInt i = 0; i < KMaxDrives; ++i)
|
|
432 |
{
|
|
433 |
if (driveList8[i]==0)
|
|
434 |
{
|
|
435 |
aChar=ch;
|
|
436 |
return 0;
|
|
437 |
}
|
|
438 |
++ch;
|
|
439 |
}
|
|
440 |
return -1;
|
|
441 |
}
|
|
442 |
|
|
443 |
TVerdict CTestMisc::TestFileOper()
|
|
444 |
{
|
|
445 |
SetTestStepResult(EPass);
|
|
446 |
int index=0;
|
|
447 |
FILE* fptr=NULL;
|
|
448 |
|
|
449 |
char file[12+1]; //rqd max is 12
|
|
450 |
char drive;
|
|
451 |
if(getFirstMissingDrive(drive)==0)
|
|
452 |
{
|
|
453 |
sprintf(file, "%c:\\file.txt", drive);
|
|
454 |
fptr=fopen(file, "a");
|
|
455 |
if(fptr!=NULL || errno!=ENOENT)
|
|
456 |
{
|
|
457 |
INFO_PRINTF2(_L("fopen() error- Error no. %d..."), errno);
|
|
458 |
SetTestStepResult(EFail);
|
|
459 |
return TestStepResult();
|
|
460 |
}
|
|
461 |
}
|
|
462 |
|
|
463 |
fptr=fopen("c:\\file.txt", "a");
|
|
464 |
if(fptr==NULL)
|
|
465 |
{
|
|
466 |
INFO_PRINTF1(_L("Error in fopen()..."));
|
|
467 |
SetTestStepResult(EFail);
|
|
468 |
return TestStepResult();
|
|
469 |
}
|
|
470 |
|
|
471 |
while(index<5)
|
|
472 |
{
|
|
473 |
fputs("Testing stdio\n",fptr);
|
|
474 |
putc(65, fptr);
|
|
475 |
index++;
|
|
476 |
}
|
|
477 |
|
|
478 |
char setbuf[15];
|
|
479 |
setbuffer(fptr, setbuf, 15);
|
|
480 |
fputs("writing into \n", fptr);
|
|
481 |
|
|
482 |
while(!feof(fptr) && !ferror(fptr))
|
|
483 |
{
|
|
484 |
getc(fptr);
|
|
485 |
}
|
|
486 |
|
|
487 |
if( !(fileno(fptr)>0))
|
|
488 |
{
|
|
489 |
INFO_PRINTF1(_L("Error in fileno()..."));
|
|
490 |
SetTestStepResult(EFail);
|
|
491 |
}
|
|
492 |
|
|
493 |
int fid=open("CON:", O_RDWR);
|
|
494 |
if(fid==-1)
|
|
495 |
{
|
|
496 |
INFO_PRINTF1(_L("Error in open()..."));
|
|
497 |
SetTestStepResult(EFail);
|
|
498 |
fclose(fptr);
|
|
499 |
return TestStepResult();
|
|
500 |
}
|
|
501 |
|
|
502 |
char bufCon[] = "Writing to console\n" ;
|
|
503 |
int written=write(fid, bufCon, 10);
|
|
504 |
if(written!=10)
|
|
505 |
{
|
|
506 |
INFO_PRINTF1(_L(" write failed()..."));
|
|
507 |
SetTestStepResult(EFail);
|
|
508 |
}
|
|
509 |
|
|
510 |
int fidcom=open("COM1:", O_WRONLY );
|
|
511 |
if(fidcom==-1)
|
|
512 |
{
|
|
513 |
INFO_PRINTF1(_L("Error in open()..."));
|
|
514 |
SetTestStepResult(EFail);
|
|
515 |
close(fid);
|
|
516 |
fclose(fptr);
|
|
517 |
return TestStepResult();
|
|
518 |
}
|
|
519 |
|
|
520 |
char bufCom[] = "Writing to com1\n" ;
|
|
521 |
written=write(fid, bufCom, 10);
|
|
522 |
if(written!=10)
|
|
523 |
{
|
|
524 |
INFO_PRINTF1(_L(" write failed()..."));
|
|
525 |
SetTestStepResult(EFail);
|
|
526 |
close(fidcom);
|
|
527 |
close(fid);
|
|
528 |
fclose(fptr);
|
|
529 |
return TestStepResult();
|
|
530 |
}
|
|
531 |
|
|
532 |
close(fidcom);
|
|
533 |
close(fid);
|
|
534 |
fclose(fptr);
|
|
535 |
return TestStepResult();
|
|
536 |
}
|
|
537 |
|
|
538 |
|
|
539 |
TVerdict CTestMisc::TestRealloc()
|
|
540 |
{
|
|
541 |
SetTestStepResult(EPass);
|
|
542 |
|
|
543 |
int* iptr=(int*)malloc(5*sizeof(int));
|
|
544 |
if(iptr==NULL)
|
|
545 |
{
|
|
546 |
INFO_PRINTF1(_L("Error in malloc()..."));
|
|
547 |
SetTestStepResult(EFail);
|
|
548 |
return TestStepResult();
|
|
549 |
}
|
|
550 |
|
|
551 |
iptr=(int*)reallocf(iptr, 10*sizeof(int));
|
|
552 |
if(iptr==NULL)
|
|
553 |
{
|
|
554 |
INFO_PRINTF1(_L("Error in reallocf()..."));
|
|
555 |
SetTestStepResult(EFail);
|
|
556 |
}
|
|
557 |
free(iptr);
|
|
558 |
return TestStepResult();
|
|
559 |
}
|
|
560 |
|
|
561 |
|
|
562 |
TVerdict CTestMisc::TestSockAtMark()
|
|
563 |
{
|
|
564 |
SetTestStepResult(EPass);
|
|
565 |
|
|
566 |
return TestStepResult();
|
|
567 |
}
|
|
568 |
|
|
569 |
TVerdict CTestMisc::TestSysConf()
|
|
570 |
{
|
|
571 |
long result;
|
|
572 |
|
|
573 |
INFO_PRINTF1(_L("Examining OPEN_MAX limit"));
|
|
574 |
|
|
575 |
result = sysconf(_SC_OPEN_MAX);
|
|
576 |
if (result == -1)
|
|
577 |
{
|
|
578 |
if (errno == 0)
|
|
579 |
{
|
|
580 |
INFO_PRINTF1(_L("OPEN_MAX is not supported."));
|
|
581 |
}
|
|
582 |
else
|
|
583 |
{
|
|
584 |
INFO_PRINTF1(_L("sysconf() error"));
|
|
585 |
}
|
|
586 |
SetTestStepResult(EFail);
|
|
587 |
}
|
|
588 |
else
|
|
589 |
{
|
|
590 |
INFO_PRINTF2(_L("OPEN_MAX is %ld\n"), result);
|
|
591 |
SetTestStepResult(EPass);
|
|
592 |
}
|
|
593 |
return TestStepResult();
|
|
594 |
}
|
|
595 |
|
|
596 |
TVerdict CTestMisc::TestScandir()
|
|
597 |
{
|
|
598 |
struct dirent **namelist;
|
|
599 |
int n;
|
|
600 |
n = mkdir("c:\\private\\1028308C\\", S_IWUSR);
|
|
601 |
if (n < 0)
|
|
602 |
{
|
|
603 |
INFO_PRINTF1(_L("Error in mkdir()"));
|
|
604 |
SetTestStepResult(EFail);
|
|
605 |
}
|
|
606 |
n = mkdir("c:\\private\\1028308C\\test\\", S_IWUSR);
|
|
607 |
if (n < 0)
|
|
608 |
{
|
|
609 |
INFO_PRINTF1(_L("Error in mkdir()"));
|
|
610 |
SetTestStepResult(EFail);
|
|
611 |
}
|
|
612 |
FILE *fp = fopen("c:\\private\\1028308C\\test\\tmp.txt","w");
|
|
613 |
if (fp == NULL)
|
|
614 |
{
|
|
615 |
INFO_PRINTF1(_L("Error in fopen()"));
|
|
616 |
SetTestStepResult(EFail);
|
|
617 |
}
|
|
618 |
n = scandir("c:\\private\\1028308C\\test", &namelist, 0, NULL);
|
|
619 |
if (n < 0)
|
|
620 |
{
|
|
621 |
INFO_PRINTF1(_L("Error in scandir()"));
|
|
622 |
SetTestStepResult(EFail);
|
|
623 |
}
|
|
624 |
else
|
|
625 |
{
|
|
626 |
INFO_PRINTF1(_L("Directory list"));
|
|
627 |
while(n--)
|
|
628 |
{
|
|
629 |
TBuf<MAX_LEN> buf;
|
|
630 |
TInt len = strlen(namelist[n]->d_name);
|
|
631 |
for (TInt i = 0 ; i<len ; i++)
|
|
632 |
{
|
|
633 |
buf.Append(namelist[n]->d_name[i]);
|
|
634 |
}
|
|
635 |
INFO_PRINTF2(_L("%S"), &buf);
|
|
636 |
free(namelist[n]);
|
|
637 |
}
|
|
638 |
free(namelist);
|
|
639 |
SetTestStepResult(EPass);
|
|
640 |
}
|
|
641 |
fclose(fp);
|
|
642 |
n = unlink("c:\\private\\1028308C\\test\\tmp.txt");
|
|
643 |
if (n < 0)
|
|
644 |
{
|
|
645 |
INFO_PRINTF1(_L("Error in unlink()"));
|
|
646 |
SetTestStepResult(EFail);
|
|
647 |
}
|
|
648 |
n = rmdir("c:\\private\\1028308C\\test");
|
|
649 |
if (n < 0)
|
|
650 |
{
|
|
651 |
INFO_PRINTF1(_L("Error in rmdir()"));
|
|
652 |
SetTestStepResult(EFail);
|
|
653 |
}
|
|
654 |
return TestStepResult();
|
|
655 |
}
|
|
656 |
|
|
657 |
TVerdict CTestMisc::TestDiropr()
|
|
658 |
{
|
|
659 |
char* directory = "c:\\";
|
|
660 |
struct dirent *dp;
|
|
661 |
|
|
662 |
DIR* ret = opendir(directory);
|
|
663 |
if (ret == NULL)
|
|
664 |
{
|
|
665 |
INFO_PRINTF1(_L("Can't open directory"));
|
|
666 |
SetTestStepResult(EFail);
|
|
667 |
return TestStepResult();
|
|
668 |
}
|
|
669 |
while((dp = readdir(ret))!= NULL)
|
|
670 |
{
|
|
671 |
TBuf<MAX_LEN> buf;
|
|
672 |
TInt len = strlen(dp->d_name);
|
|
673 |
for (TInt i = 0 ; i<len ; i++)
|
|
674 |
{
|
|
675 |
buf.Append(dp->d_name[i]);
|
|
676 |
}
|
|
677 |
INFO_PRINTF2(_L("%S"), &buf);
|
|
678 |
}
|
|
679 |
closedir(ret);
|
|
680 |
ret = opendir(directory);
|
|
681 |
long int pos = 2 , rdpos;
|
|
682 |
//set the position of the directory stream
|
|
683 |
seekdir(ret , pos);
|
|
684 |
rdpos = telldir(ret);
|
|
685 |
if (pos == rdpos)
|
|
686 |
{
|
|
687 |
INFO_PRINTF1(_L("seekdir() and telldir() success"));
|
|
688 |
}
|
|
689 |
INFO_PRINTF2(_L("Dir or file at position %d"),pos+1);
|
|
690 |
dp = readdir(ret);
|
|
691 |
TBuf<MAX_LEN> buf;
|
|
692 |
TInt len = strlen(dp->d_name);
|
|
693 |
for (TInt i = 0 ; i<len ; i++)
|
|
694 |
{
|
|
695 |
buf.Append(dp->d_name[i]);
|
|
696 |
}
|
|
697 |
INFO_PRINTF2(_L("%S"), &buf);
|
|
698 |
//set position to beginning of directory stream
|
|
699 |
rewinddir(ret);
|
|
700 |
pos = telldir(ret);
|
|
701 |
if (pos == 0)
|
|
702 |
{
|
|
703 |
INFO_PRINTF1(_L("rewinddir() success!"));
|
|
704 |
}
|
|
705 |
else
|
|
706 |
{
|
|
707 |
INFO_PRINTF1(_L("rewinddir() error!"));
|
|
708 |
}
|
|
709 |
closedir(ret);
|
|
710 |
return TestStepResult();
|
|
711 |
}
|
|
712 |
|
|
713 |
TVerdict CTestMisc::TestReaddir()
|
|
714 |
{
|
|
715 |
char* directory = "c:\\";
|
|
716 |
struct dirent *dp;
|
|
717 |
|
|
718 |
DIR* ret = opendir(directory);
|
|
719 |
if (ret == NULL)
|
|
720 |
{
|
|
721 |
INFO_PRINTF1(_L("Can't open directory"));
|
|
722 |
SetTestStepResult(EFail);
|
|
723 |
return TestStepResult();
|
|
724 |
}
|
|
725 |
else
|
|
726 |
{
|
|
727 |
while((dp = readdir(ret))!= NULL)
|
|
728 |
{
|
|
729 |
TBuf<MAX_LEN> buf;
|
|
730 |
TInt len = strlen(dp->d_name);
|
|
731 |
for (TInt i = 0 ; i<len ; i++)
|
|
732 |
{
|
|
733 |
buf.Append(dp->d_name[i]);
|
|
734 |
}
|
|
735 |
INFO_PRINTF2(_L("%S"), &buf);
|
|
736 |
}
|
|
737 |
if (dp == NULL)
|
|
738 |
{
|
|
739 |
if (errno == 0)
|
|
740 |
{
|
|
741 |
INFO_PRINTF1(_L("End of directory"));
|
|
742 |
closedir(ret);
|
|
743 |
SetTestStepResult(EPass);
|
|
744 |
}
|
|
745 |
else
|
|
746 |
{
|
|
747 |
INFO_PRINTF1(_L("readdir() error!"));
|
|
748 |
SetTestStepResult(EFail);
|
|
749 |
}
|
|
750 |
}
|
|
751 |
|
|
752 |
}
|
|
753 |
return TestStepResult();
|
|
754 |
}
|
|
755 |
|
|
756 |
TVerdict CTestMisc::TestWOpendir()
|
|
757 |
{
|
|
758 |
wchar_t* directory = L"c:\\";
|
|
759 |
struct wdirent *dp;
|
|
760 |
|
|
761 |
WDIR* wret = wopendir(directory);
|
|
762 |
if (wret == NULL)
|
|
763 |
{
|
|
764 |
INFO_PRINTF1(_L("Can't open directory"));
|
|
765 |
SetTestStepResult(EFail);
|
|
766 |
return TestStepResult();
|
|
767 |
}
|
|
768 |
INFO_PRINTF1(_L("wopendir success!"));
|
|
769 |
//Now read directory and get first entry
|
|
770 |
dp = wreaddir(wret);
|
|
771 |
if (dp == NULL)
|
|
772 |
{
|
|
773 |
if (errno == 0)
|
|
774 |
{
|
|
775 |
INFO_PRINTF1(_L("End of directory"));
|
|
776 |
wclosedir(wret);
|
|
777 |
SetTestStepResult(EPass);
|
|
778 |
}
|
|
779 |
else
|
|
780 |
{
|
|
781 |
INFO_PRINTF1(_L("wreaddir() error!"));
|
|
782 |
SetTestStepResult(EFail);
|
|
783 |
}
|
|
784 |
}
|
|
785 |
wclosedir(wret);
|
|
786 |
return TestStepResult();
|
|
787 |
}
|
|
788 |
|
|
789 |
TVerdict CTestMisc::TestWDiropr()
|
|
790 |
{
|
|
791 |
wchar_t* directory = L"c:\\";
|
|
792 |
|
|
793 |
WDIR* wret = wopendir(directory);
|
|
794 |
if (wret == NULL)
|
|
795 |
{
|
|
796 |
INFO_PRINTF1(_L("Can't open directory"));
|
|
797 |
SetTestStepResult(EFail);
|
|
798 |
return TestStepResult();
|
|
799 |
}
|
|
800 |
long int pos = 2 , rdpos;
|
|
801 |
//set the position of the directory stream
|
|
802 |
wseekdir(wret , pos);
|
|
803 |
rdpos = wtelldir(wret);
|
|
804 |
if (pos == rdpos)
|
|
805 |
{
|
|
806 |
INFO_PRINTF1(_L("wseekdir() and wtelldir() success"));
|
|
807 |
}
|
|
808 |
|
|
809 |
//set position to beginning of directory stream
|
|
810 |
wrewinddir(wret);
|
|
811 |
pos = wtelldir(wret);
|
|
812 |
if (pos == 0)
|
|
813 |
{
|
|
814 |
INFO_PRINTF1(_L("wrewinddir() success!"));
|
|
815 |
}
|
|
816 |
else
|
|
817 |
{
|
|
818 |
INFO_PRINTF1(_L("wrewinddir() error!"));
|
|
819 |
}
|
|
820 |
wclosedir(wret);
|
|
821 |
return TestStepResult();
|
|
822 |
}
|
|
823 |
|
|
824 |
TVerdict CTestMisc::TestFMScalls()
|
|
825 |
{
|
|
826 |
SetTestStepResult(EPass);
|
|
827 |
|
|
828 |
wrmdir(L"c:\\wfmstest1");
|
|
829 |
wrmdir(L"c:\\wfmstest2");
|
|
830 |
|
|
831 |
wchar_t *dir1=L"c:\\wfmstest1";
|
|
832 |
TInt ret=wmkdir(dir1, S_IWUSR);
|
|
833 |
if (ret!=0)
|
|
834 |
{
|
|
835 |
INFO_PRINTF1(_L("wmkdir() failed..."));
|
|
836 |
INFO_PRINTF2(_L("The errno value is %d\n"),errno);
|
|
837 |
SetTestStepResult(EFail);
|
|
838 |
return TestStepResult();
|
|
839 |
}
|
|
840 |
|
|
841 |
wchar_t *dir2=L"c:\\wfmstest2";
|
|
842 |
ret=wmkdir(dir2, S_IWUSR);
|
|
843 |
if (ret!=0)
|
|
844 |
{
|
|
845 |
INFO_PRINTF1(_L("wmkdir() failed..."));
|
|
846 |
INFO_PRINTF2(_L("The errno value is %d\n"),errno);
|
|
847 |
SetTestStepResult(EFail);
|
|
848 |
wrmdir(L"c:\\wfmstest1");
|
|
849 |
return TestStepResult();
|
|
850 |
}
|
|
851 |
|
|
852 |
ret=wchdir(dir1);
|
|
853 |
if (ret!=0)
|
|
854 |
{
|
|
855 |
INFO_PRINTF1(_L("wchdir() failed..."));
|
|
856 |
INFO_PRINTF2(_L("The errno value is %d\n"),errno);
|
|
857 |
SetTestStepResult(EFail);
|
|
858 |
wrmdir(L"c:\\wfmstest1");
|
|
859 |
wrmdir(L"c:\\wfmstest2");
|
|
860 |
return TestStepResult();
|
|
861 |
}
|
|
862 |
|
|
863 |
wchar_t path[50];
|
|
864 |
if(wgetcwd(path, 50)==NULL)
|
|
865 |
{
|
|
866 |
INFO_PRINTF1(_L("wrealpath() failed..."));
|
|
867 |
INFO_PRINTF2(_L("The errno value is %d\n"),errno);
|
|
868 |
SetTestStepResult(EFail);
|
|
869 |
wrmdir(L"c:\\wfmstest1");
|
|
870 |
wrmdir(L"c:\\wfmstest2");
|
|
871 |
return TestStepResult();
|
|
872 |
}
|
|
873 |
|
|
874 |
wchar_t *file1=L"c:\\wfmstest1\\temp.txt";
|
|
875 |
ret=wopen(file1,O_CREAT, S_IWUSR);
|
|
876 |
if (ret==-1)
|
|
877 |
{
|
|
878 |
INFO_PRINTF1(_L("wopen() failed..."));
|
|
879 |
INFO_PRINTF2(_L("The errno value is %d\n"),errno);
|
|
880 |
SetTestStepResult(EFail);
|
|
881 |
wrmdir(L"c:\\wfmstest1");
|
|
882 |
wrmdir(L"c:\\wfmstest2");
|
|
883 |
return TestStepResult();
|
|
884 |
}
|
|
885 |
|
|
886 |
close(ret);
|
|
887 |
|
|
888 |
wchar_t *file=L"c:\\wfmstest1\\temp1.txt";
|
|
889 |
ret=wrename(file1, file);
|
|
890 |
if (ret!=0)
|
|
891 |
{
|
|
892 |
INFO_PRINTF1(_L("wrename() failed..."));
|
|
893 |
SetTestStepResult(EFail);
|
|
894 |
return TestStepResult();
|
|
895 |
}
|
|
896 |
|
|
897 |
ret=wchmod(file,S_IRUSR);
|
|
898 |
if (ret!=0)
|
|
899 |
{
|
|
900 |
INFO_PRINTF1(_L("wchmod() failed..."));
|
|
901 |
SetTestStepResult(EFail);
|
|
902 |
return TestStepResult();
|
|
903 |
}
|
|
904 |
|
|
905 |
struct stat statbuf ;
|
|
906 |
ret = wstat(file , &statbuf) ;
|
|
907 |
if (ret!=0)
|
|
908 |
{
|
|
909 |
INFO_PRINTF1(_L("wstat() failed..."));
|
|
910 |
SetTestStepResult(EFail);
|
|
911 |
return TestStepResult();
|
|
912 |
}
|
|
913 |
|
|
914 |
wchar_t realpath[50+1];
|
|
915 |
if(wrealpath(L"\\wfmstest1\\temp1.txt", realpath) ==NULL)
|
|
916 |
{
|
|
917 |
INFO_PRINTF1(_L("wrealpath() failed..."));
|
|
918 |
SetTestStepResult(EFail);
|
|
919 |
return TestStepResult();
|
|
920 |
}
|
|
921 |
|
|
922 |
ret=wunlink(file);
|
|
923 |
if (ret!=0)
|
|
924 |
{
|
|
925 |
INFO_PRINTF1(_L("wunlink() failed..."));
|
|
926 |
SetTestStepResult(EFail);
|
|
927 |
return TestStepResult();
|
|
928 |
}
|
|
929 |
|
|
930 |
ret=wrmdir(dir1);
|
|
931 |
if (ret!=0)
|
|
932 |
{
|
|
933 |
INFO_PRINTF1(_L("wrmdir() failed..."));
|
|
934 |
SetTestStepResult(EFail);
|
|
935 |
return TestStepResult();
|
|
936 |
}
|
|
937 |
|
|
938 |
ret=wrmdir(dir2);
|
|
939 |
if (ret!=0)
|
|
940 |
{
|
|
941 |
INFO_PRINTF1(_L("wrmdir() failed..."));
|
|
942 |
SetTestStepResult(EFail);
|
|
943 |
return TestStepResult();
|
|
944 |
}
|
|
945 |
|
|
946 |
if (!wsystem(NULL) || (wsystem(L"z:\\sys\\bin\\TPopenWriteChildPopen.exe") == -1))
|
|
947 |
{
|
|
948 |
INFO_PRINTF1(_L("wsystem() failed..."));
|
|
949 |
SetTestStepResult(EFail);
|
|
950 |
return TestStepResult();
|
|
951 |
}
|
|
952 |
|
|
953 |
return TestStepResult();
|
|
954 |
}
|
|
955 |
|
|
956 |
TVerdict CTestMisc::TestGetDirEntries()
|
|
957 |
{
|
|
958 |
int fd;
|
|
959 |
char buf[1024];
|
|
960 |
long basep;
|
|
961 |
|
|
962 |
fd = open("c:\\", O_RDONLY);
|
|
963 |
if (fd == -1)
|
|
964 |
{
|
|
965 |
INFO_PRINTF1(_L("open failed..."));
|
|
966 |
SetTestStepResult(EFail);
|
|
967 |
return TestStepResult();
|
|
968 |
}
|
|
969 |
|
|
970 |
int ret = getdirentries(fd, buf, 1024, &basep);
|
|
971 |
if (ret == -1)
|
|
972 |
{
|
|
973 |
INFO_PRINTF2(_L("getdirentries() error- Error no. %d..."), errno);
|
|
974 |
SetTestStepResult(EFail);
|
|
975 |
return TestStepResult();
|
|
976 |
}
|
|
977 |
else if (ret == 0)
|
|
978 |
{
|
|
979 |
INFO_PRINTF1(_L("End of directory reached!"));
|
|
980 |
SetTestStepResult(EPass);
|
|
981 |
return TestStepResult();
|
|
982 |
}
|
|
983 |
else
|
|
984 |
{
|
|
985 |
INFO_PRINTF2(_L("getdirentries() read %d bytes"), ret);
|
|
986 |
SetTestStepResult(EPass);
|
|
987 |
return TestStepResult();
|
|
988 |
}
|
|
989 |
}
|
|
990 |
|
|
991 |
TVerdict CTestMisc::TestAlphasort()
|
|
992 |
{
|
|
993 |
SetTestStepResult(EPass);
|
|
994 |
char* directory = "c:\\";
|
|
995 |
struct dirent *dp1, *dp2;
|
|
996 |
DIR* ret = opendir(directory);
|
|
997 |
if (ret == NULL)
|
|
998 |
{
|
|
999 |
INFO_PRINTF1(_L("Can't open directory"));
|
|
1000 |
SetTestStepResult(EFail);
|
|
1001 |
return TestStepResult();
|
|
1002 |
}
|
|
1003 |
INFO_PRINTF1(_L("Read first entry"));
|
|
1004 |
dp1 = readdir(ret);
|
|
1005 |
TBuf<MAX_LEN> buf;
|
|
1006 |
TInt len = strlen(dp1->d_name);
|
|
1007 |
for (TInt i = 0 ; i<len ; i++)
|
|
1008 |
{
|
|
1009 |
buf.Append(dp1->d_name[i]);
|
|
1010 |
}
|
|
1011 |
INFO_PRINTF2(_L("First File Entry:%S"), &buf);
|
|
1012 |
|
|
1013 |
INFO_PRINTF1(_L("Read second entry"));
|
|
1014 |
char* directory1 = "c:\\logs";
|
|
1015 |
closedir(ret);
|
|
1016 |
ret = opendir(directory1);
|
|
1017 |
if (ret == NULL)
|
|
1018 |
{
|
|
1019 |
INFO_PRINTF1(_L("Can't open directory"));
|
|
1020 |
SetTestStepResult(EFail);
|
|
1021 |
return TestStepResult();
|
|
1022 |
}
|
|
1023 |
dp2 = readdir(ret);
|
|
1024 |
TBuf<MAX_LEN> buf1;
|
|
1025 |
len = strlen(dp2->d_name);
|
|
1026 |
for (TInt i = 0 ; i<len ; i++)
|
|
1027 |
{
|
|
1028 |
buf1.Append(dp2->d_name[i]);
|
|
1029 |
}
|
|
1030 |
INFO_PRINTF2(_L("Second File Entry:%S"), &buf1);
|
|
1031 |
|
|
1032 |
int n = alphasort(&dp1, &dp2);
|
|
1033 |
if (n < 0)
|
|
1034 |
{
|
|
1035 |
INFO_PRINTF1(_L("first entry less than second"));
|
|
1036 |
}
|
|
1037 |
else if(n == 0)
|
|
1038 |
{
|
|
1039 |
INFO_PRINTF1(_L("Both entries are same"));
|
|
1040 |
}
|
|
1041 |
else if(n > 0)
|
|
1042 |
{
|
|
1043 |
INFO_PRINTF1(_L("first entry greater than second enttry"));
|
|
1044 |
}
|
|
1045 |
closedir(ret);
|
|
1046 |
|
|
1047 |
|
|
1048 |
return TestStepResult();
|
|
1049 |
}
|
|
1050 |
|
|
1051 |
|
|
1052 |
TVerdict CTestMisc::TestStdio()
|
|
1053 |
{
|
|
1054 |
SetTestStepResult(EPass);
|
|
1055 |
|
|
1056 |
int ret;
|
|
1057 |
char read_buf[10];
|
|
1058 |
|
|
1059 |
wprintf(L"Using wprintf\n");
|
|
1060 |
putwchar(L'Y');
|
|
1061 |
|
|
1062 |
wprintf(L"Read integer\n");
|
|
1063 |
wscanf(L"%d",&ret);
|
|
1064 |
if(ret!=5)
|
|
1065 |
{
|
|
1066 |
INFO_PRINTF1(_L("wscanf failed"));
|
|
1067 |
SetTestStepResult(EFail);
|
|
1068 |
}
|
|
1069 |
|
|
1070 |
getwchar();
|
|
1071 |
gets(&read_buf[0]);
|
|
1072 |
read_buf[5]='\0';
|
|
1073 |
|
|
1074 |
if(strcmp("stdio", read_buf))
|
|
1075 |
{
|
|
1076 |
INFO_PRINTF1(_L("gets failed"));
|
|
1077 |
SetTestStepResult(EFail);
|
|
1078 |
}
|
|
1079 |
if(puts(read_buf)<0)
|
|
1080 |
{
|
|
1081 |
INFO_PRINTF1(_L("puts failed"));
|
|
1082 |
SetTestStepResult(EFail);
|
|
1083 |
}
|
|
1084 |
|
|
1085 |
int character;
|
|
1086 |
if( (character=getchar())!=65)
|
|
1087 |
{
|
|
1088 |
INFO_PRINTF1(_L("getchar failed"));
|
|
1089 |
SetTestStepResult(EFail);
|
|
1090 |
}
|
|
1091 |
if( !(putchar(character)>0) )
|
|
1092 |
{
|
|
1093 |
INFO_PRINTF1(_L("putchar failed"));
|
|
1094 |
SetTestStepResult(EFail);
|
|
1095 |
}
|
|
1096 |
|
|
1097 |
printf("Read integer again\n");
|
|
1098 |
scanf("%d",&ret);
|
|
1099 |
if(ret!=5)
|
|
1100 |
{
|
|
1101 |
INFO_PRINTF1(_L("scanf failed"));
|
|
1102 |
SetTestStepResult(EFail);
|
|
1103 |
}
|
|
1104 |
|
|
1105 |
return TestStepResult();
|
|
1106 |
}
|
|
1107 |
|
|
1108 |
|
|
1109 |
TVerdict CTestMisc::testposix()
|
|
1110 |
{
|
|
1111 |
SetTestStepResult(EFail);
|
|
1112 |
|
|
1113 |
short flag;
|
|
1114 |
pid_t pgroup;
|
|
1115 |
int policy;
|
|
1116 |
sigset_t sigmaskset;
|
|
1117 |
sigset_t sigdefaultset;
|
|
1118 |
sigset_t sigmaskget;
|
|
1119 |
sigset_t sigdefaultget;
|
|
1120 |
struct sched_param schedset;
|
|
1121 |
struct sched_param schedget;
|
|
1122 |
|
|
1123 |
|
|
1124 |
//init
|
|
1125 |
posix_spawnattr_t attrp;
|
|
1126 |
|
|
1127 |
int err=posix_spawnattr_init(&attrp);
|
|
1128 |
if(err!=0)
|
|
1129 |
{
|
|
1130 |
INFO_PRINTF1(_L("posix_spawnattr_init failed..."));
|
|
1131 |
return TestStepResult();
|
|
1132 |
}
|
|
1133 |
|
|
1134 |
|
|
1135 |
//set
|
|
1136 |
err=posix_spawnattr_setflags(&attrp, (POSIX_SPAWN_SETSIGMASK|POSIX_SPAWN_SETPGROUP|POSIX_SPAWN_SETSCHEDPARAM|
|
|
1137 |
POSIX_SPAWN_SETSCHEDULER|POSIX_SPAWN_SETSIGDEF|POSIX_SPAWN_SETSIGMASK) );
|
|
1138 |
|
|
1139 |
if(err!=0)
|
|
1140 |
{
|
|
1141 |
INFO_PRINTF1(_L("posix_spawnattr_init failed..."));
|
|
1142 |
return TestStepResult();
|
|
1143 |
}
|
|
1144 |
|
|
1145 |
err=posix_spawnattr_setsigmask(&attrp, &sigmaskset);
|
|
1146 |
if(err!=0)
|
|
1147 |
{
|
|
1148 |
INFO_PRINTF1(_L("posix_spawnattr_init failed..."));
|
|
1149 |
return TestStepResult();
|
|
1150 |
}
|
|
1151 |
|
|
1152 |
if(posix_spawnattr_getsigmask(&attrp, &sigmaskget) )//|| (*sigmaskget!=1))
|
|
1153 |
{
|
|
1154 |
INFO_PRINTF1(_L("posix_spawnattr_getsigdefault failed..."));
|
|
1155 |
return TestStepResult();
|
|
1156 |
}
|
|
1157 |
if(posix_spawnattr_getflags(&attrp, &flag) || (flag!=(POSIX_SPAWN_SETSIGMASK|POSIX_SPAWN_SETPGROUP|POSIX_SPAWN_SETSCHEDPARAM|
|
|
1158 |
POSIX_SPAWN_SETSCHEDULER|POSIX_SPAWN_SETSIGDEF|POSIX_SPAWN_SETSIGMASK)))
|
|
1159 |
{
|
|
1160 |
INFO_PRINTF1(_L("posix_spawnattr_getflags failed..."));
|
|
1161 |
return TestStepResult();
|
|
1162 |
}
|
|
1163 |
|
|
1164 |
err=posix_spawnattr_setschedpolicy(&attrp, 1);
|
|
1165 |
if(err!=0)
|
|
1166 |
{
|
|
1167 |
INFO_PRINTF1(_L("posix_spawnattr_setschedpolicy failed..."));
|
|
1168 |
return TestStepResult();
|
|
1169 |
}
|
|
1170 |
|
|
1171 |
if(posix_spawnattr_getschedpolicy(&attrp, &policy) || (policy!=1))
|
|
1172 |
{
|
|
1173 |
INFO_PRINTF1(_L("posix_spawnattr_getschedpolicy failed..."));
|
|
1174 |
return TestStepResult();
|
|
1175 |
}
|
|
1176 |
|
|
1177 |
err=posix_spawnattr_setsigdefault(&attrp, &sigdefaultset);
|
|
1178 |
if(err!=0)
|
|
1179 |
{
|
|
1180 |
INFO_PRINTF1(_L("posix_spawnattr_setsigdefault failed..."));
|
|
1181 |
return TestStepResult();
|
|
1182 |
}
|
|
1183 |
|
|
1184 |
if(posix_spawnattr_getsigdefault(&attrp, &sigdefaultget))// || (*sigdefaultget!=2))
|
|
1185 |
{
|
|
1186 |
INFO_PRINTF1(_L("posix_spawnattr_getsigdefault failed..."));
|
|
1187 |
return TestStepResult();
|
|
1188 |
}
|
|
1189 |
|
|
1190 |
err=posix_spawnattr_setpgroup(&attrp, (pid_t)2);
|
|
1191 |
if(err!=0)
|
|
1192 |
{
|
|
1193 |
INFO_PRINTF1(_L("posix_spawnattr_setpgroup failed..."));
|
|
1194 |
return TestStepResult();
|
|
1195 |
}
|
|
1196 |
|
|
1197 |
if(posix_spawnattr_getpgroup(&attrp, &pgroup) || (pgroup!=(pid_t)2))
|
|
1198 |
{
|
|
1199 |
INFO_PRINTF1(_L("posix_spawnattr_getpgroup failed..."));
|
|
1200 |
return TestStepResult();
|
|
1201 |
}
|
|
1202 |
|
|
1203 |
err=posix_spawnattr_setschedparam(&attrp, &schedset);
|
|
1204 |
if(err!=0)
|
|
1205 |
{
|
|
1206 |
INFO_PRINTF1(_L("posix_spawnattr_setschedpolicy failed..."));
|
|
1207 |
return TestStepResult();
|
|
1208 |
}
|
|
1209 |
|
|
1210 |
if(posix_spawnattr_getschedparam(&attrp, &schedget ))
|
|
1211 |
{
|
|
1212 |
INFO_PRINTF1(_L("posix_spawnattr_getschedpolicy failed..."));
|
|
1213 |
return TestStepResult();
|
|
1214 |
}
|
|
1215 |
|
|
1216 |
posix_spawn_file_actions_t file_actions;
|
|
1217 |
|
|
1218 |
err=posix_spawn_file_actions_init(&file_actions);
|
|
1219 |
|
|
1220 |
|
|
1221 |
if(err!=0)
|
|
1222 |
{
|
|
1223 |
INFO_PRINTF1(_L("posix_spawn_file_actions_init failed..."));
|
|
1224 |
return TestStepResult();
|
|
1225 |
}
|
|
1226 |
|
|
1227 |
|
|
1228 |
mkdir("C:\\testposix", S_IWUSR);
|
|
1229 |
int fd1= open("c:\\testposix\\posixspawnfile1.txt", O_RDONLY|O_CREAT);
|
|
1230 |
int fd2= open("c:\\testposix\\posixspawnfile2.txt", O_RDWR|O_CREAT);
|
|
1231 |
FILE* fp = NULL ;
|
|
1232 |
pid_t pid;
|
|
1233 |
char **argv=(char**)malloc(3*sizeof(char*));
|
|
1234 |
err=posix_spawn_file_actions_addopen(&file_actions,3, "c:\\testposix\\posixspawnfile3.txt", O_RDWR|O_CREAT, 0666);
|
|
1235 |
if(err!=0)
|
|
1236 |
{
|
|
1237 |
INFO_PRINTF1(_L("posix_spawn_file_actions_addopen failed..."));
|
|
1238 |
goto exit;
|
|
1239 |
}
|
|
1240 |
|
|
1241 |
err=posix_spawn_file_actions_adddup2(&file_actions, fd2, 1);
|
|
1242 |
if(err!=0)
|
|
1243 |
{
|
|
1244 |
INFO_PRINTF1(_L("posix_spawn_file_actions_adddup2 failed..."));
|
|
1245 |
goto exit;
|
|
1246 |
}
|
|
1247 |
|
|
1248 |
|
|
1249 |
|
|
1250 |
|
|
1251 |
|
|
1252 |
argv[0]=(char*)malloc(34*sizeof(char));
|
|
1253 |
argv[1]=(char*)malloc(4*sizeof(char));
|
|
1254 |
argv[2]= 0;
|
|
1255 |
|
|
1256 |
strcpy(argv[0], "z:\\sys\\bin\\posix_spawn.exe");
|
|
1257 |
sprintf(argv[1], "%d", fd1);
|
|
1258 |
|
|
1259 |
|
|
1260 |
if(posix_spawn(&pid, "z:\\sys\\bin\\posix_spawn.exe", &file_actions, &attrp, argv, (char**)NULL))
|
|
1261 |
{
|
|
1262 |
INFO_PRINTF1(_L("posix_spawn failed..."));
|
|
1263 |
goto exit;
|
|
1264 |
}
|
|
1265 |
|
|
1266 |
int status;
|
|
1267 |
if (waitpid(pid, &status, WUNTRACED)!=pid)
|
|
1268 |
{
|
|
1269 |
INFO_PRINTF1(_L("waitpid failed..."));
|
|
1270 |
goto exit;
|
|
1271 |
}
|
|
1272 |
//Get FILE pointer from open file pointer fd2 and read the string which is written by child process.
|
|
1273 |
fp = fdopen(fd2, "r");
|
|
1274 |
if (fp == NULL)
|
|
1275 |
{
|
|
1276 |
ERR_PRINTF1(_L("fdopen after child return failed."));
|
|
1277 |
goto exit;
|
|
1278 |
}
|
|
1279 |
rewind(fp);
|
|
1280 |
char str[5];
|
|
1281 |
if(fgets(str,5,fp) == NULL || strcmp(str,"pass") != 0)
|
|
1282 |
{
|
|
1283 |
ERR_PRINTF1(_L("Failed write to a file descriptor passed to the child process."));
|
|
1284 |
}
|
|
1285 |
else
|
|
1286 |
{
|
|
1287 |
SetTestStepResult(EPass);
|
|
1288 |
}
|
|
1289 |
|
|
1290 |
exit:
|
|
1291 |
close(fd2);
|
|
1292 |
close(fd1);
|
|
1293 |
unlink("c:\\testposix\\posixspawnfile3.txt");
|
|
1294 |
unlink("c:\\testposix\\posixspawnfile2.txt");
|
|
1295 |
unlink("c:\\testposix\\posixspawnfile1.txt");
|
|
1296 |
rmdir("C:\\testposix");
|
|
1297 |
free((void*)argv[0]);
|
|
1298 |
free((void*)argv[1]);
|
|
1299 |
free((void*)argv);
|
|
1300 |
posix_spawn_file_actions_destroy(&file_actions);
|
|
1301 |
return TestStepResult();
|
|
1302 |
}
|
|
1303 |
|
|
1304 |
|
|
1305 |
TVerdict CTestMisc::TestPosixSpawn()
|
|
1306 |
{
|
|
1307 |
SetTestStepResult(EPass);
|
|
1308 |
CActiveScheduler *pActiveScheduler=new CActiveScheduler();
|
|
1309 |
CActiveScheduler::Install(pActiveScheduler);
|
|
1310 |
|
|
1311 |
if(testposix()==EFail)
|
|
1312 |
{
|
|
1313 |
INFO_PRINTF1(_L("posix_spawn test failed"));
|
|
1314 |
delete pActiveScheduler;
|
|
1315 |
SetTestStepResult(EFail);
|
|
1316 |
}
|
|
1317 |
|
|
1318 |
CActiveScheduler::Install(NULL);
|
|
1319 |
delete pActiveScheduler;
|
|
1320 |
|
|
1321 |
return TestStepResult();
|
|
1322 |
}
|
|
1323 |
|
|
1324 |
TInt CTestMisc::TestPosixSpawn1()
|
|
1325 |
{
|
|
1326 |
|
|
1327 |
int RetVal = 0;
|
|
1328 |
int ret = 0;
|
|
1329 |
pid_t Processpid;
|
|
1330 |
|
|
1331 |
RetVal= posix_spawn(&Processpid,NULL,NULL,NULL,NULL,NULL);
|
|
1332 |
if(RetVal == 0)
|
|
1333 |
{
|
|
1334 |
|
|
1335 |
(void)waitpid(Processpid,NULL,0);
|
|
1336 |
}
|
|
1337 |
|
|
1338 |
if(ECHILD == RetVal)
|
|
1339 |
{
|
|
1340 |
ret = KErrNone;
|
|
1341 |
}
|
|
1342 |
else
|
|
1343 |
{
|
|
1344 |
ret = KErrGeneral;
|
|
1345 |
}
|
|
1346 |
return ret;
|
|
1347 |
}
|
|
1348 |
|
|
1349 |
TVerdict CTestMisc::TestSystem0()
|
|
1350 |
{
|
|
1351 |
SetTestStepResult(EPass);
|
|
1352 |
|
|
1353 |
char *command = "z:\\sys\\bin\\tstdlib_helloworld.exe";
|
|
1354 |
int i = system(command);
|
|
1355 |
|
|
1356 |
if(i!=1)
|
|
1357 |
{
|
|
1358 |
SetTestStepResult(EFail);
|
|
1359 |
}
|
|
1360 |
|
|
1361 |
return TestStepResult();
|
|
1362 |
}
|
|
1363 |
|
|
1364 |
TVerdict CTestMisc::TestSystem1()
|
|
1365 |
{
|
|
1366 |
SetTestStepResult(EPass);
|
|
1367 |
|
|
1368 |
char *command = "z:\\sys\\bin\\tstdlib_helloworld.exe";
|
|
1369 |
char comname[64] = " ";
|
|
1370 |
|
|
1371 |
strcat(comname,command);
|
|
1372 |
int i = system(comname);
|
|
1373 |
|
|
1374 |
if(i!=1)
|
|
1375 |
{
|
|
1376 |
SetTestStepResult(EFail);
|
|
1377 |
}
|
|
1378 |
|
|
1379 |
return TestStepResult();
|
|
1380 |
}
|
|
1381 |
|
|
1382 |
TVerdict CTestMisc::TestSystem2()
|
|
1383 |
{
|
|
1384 |
SetTestStepResult(EPass);
|
|
1385 |
|
|
1386 |
int i = system("z:\\sys\\bin\\tstdlib_testsystem.exe a b c");
|
|
1387 |
|
|
1388 |
if(i!=4)
|
|
1389 |
{
|
|
1390 |
SetTestStepResult(EFail);
|
|
1391 |
}
|
|
1392 |
|
|
1393 |
return TestStepResult();
|
|
1394 |
}
|
|
1395 |
|
|
1396 |
TVerdict CTestMisc::TestAbort1()
|
|
1397 |
{
|
|
1398 |
SetTestStepResult(EPass);
|
|
1399 |
|
|
1400 |
int i = system("z:\\sys\\bin\\tstdlib_testabort.exe");
|
|
1401 |
|
|
1402 |
if(i!=1)
|
|
1403 |
{
|
|
1404 |
SetTestStepResult(EFail);
|
|
1405 |
}
|
|
1406 |
|
|
1407 |
return TestStepResult();
|
|
1408 |
}
|
|
1409 |
|
|
1410 |
TVerdict CTestMisc::TestExit1()
|
|
1411 |
{
|
|
1412 |
SetTestStepResult(EPass);
|
|
1413 |
|
|
1414 |
#if defined(__WINSCW__) || defined(__WINS__)
|
|
1415 |
INFO_PRINTF1(_L("atexit() not supported on the emulator!"));
|
|
1416 |
|
|
1417 |
#else
|
|
1418 |
int i = system("z:\\sys\\bin\\tstdlib_testexit.exe");
|
|
1419 |
|
|
1420 |
char buf1[64];
|
|
1421 |
char buf2[64];
|
|
1422 |
|
|
1423 |
FILE *fp = fopen("c:\\some.txt", "r");
|
|
1424 |
if(fp)
|
|
1425 |
{
|
|
1426 |
fscanf(fp, "%s", buf1);
|
|
1427 |
fgetc(fp); //skip the space
|
|
1428 |
fscanf(fp, "%s", buf2);
|
|
1429 |
}
|
|
1430 |
|
|
1431 |
TBuf8<50> tempString1((TUint8 *)&buf1);
|
|
1432 |
TBuf8<50> tempString2((TUint8 *)&buf2);
|
|
1433 |
TBuf<50> displayString1;
|
|
1434 |
TBuf<50> displayString2;
|
|
1435 |
|
|
1436 |
displayString1.Copy(tempString1);
|
|
1437 |
displayString2.Copy(tempString2);
|
|
1438 |
INFO_PRINTF3(_L("Executing exitfunc3.: %S %S\n"), &displayString1,&displayString2);
|
|
1439 |
|
|
1440 |
strcat(buf1, " ");
|
|
1441 |
strcat(buf1, buf2);
|
|
1442 |
if(strcmp(buf1, "Executing exitfunc3.") != 0)
|
|
1443 |
{
|
|
1444 |
SetTestStepResult(EFail);
|
|
1445 |
}
|
|
1446 |
|
|
1447 |
if(fp)
|
|
1448 |
{
|
|
1449 |
fgetc(fp); //skip the newline
|
|
1450 |
|
|
1451 |
fscanf(fp, "%s", buf1);
|
|
1452 |
fgetc(fp); //skip the space
|
|
1453 |
fscanf(fp, "%s", buf2);
|
|
1454 |
}
|
|
1455 |
|
|
1456 |
tempString1 = (TUint8 *)buf1;
|
|
1457 |
tempString2 = (TUint8 *)buf2;
|
|
1458 |
displayString1.Copy(tempString1);
|
|
1459 |
displayString2.Copy(tempString2);
|
|
1460 |
INFO_PRINTF3(_L("Executing exitfunc2.: %S %S\n"), &displayString1,&displayString2);
|
|
1461 |
|
|
1462 |
strcat(buf1, " ");
|
|
1463 |
strcat(buf1, buf2);
|
|
1464 |
if(strcmp(buf1, "Executing exitfunc2.") != 0)
|
|
1465 |
SetTestStepResult(EFail);
|
|
1466 |
|
|
1467 |
if(fp)
|
|
1468 |
{
|
|
1469 |
fgetc(fp); //skip the newline
|
|
1470 |
|
|
1471 |
fscanf(fp, "%s", buf1);
|
|
1472 |
fgetc(fp); //skip the space
|
|
1473 |
fscanf(fp, "%s", buf2);
|
|
1474 |
}
|
|
1475 |
|
|
1476 |
tempString1 = (TUint8 *)buf1;
|
|
1477 |
tempString2 = (TUint8 *)buf2;
|
|
1478 |
displayString1.Copy(tempString1);
|
|
1479 |
displayString2.Copy(tempString2);
|
|
1480 |
INFO_PRINTF3(_L("Executing exitfunc1.: %S %S\n"), &displayString1,&displayString2);
|
|
1481 |
|
|
1482 |
strcat(buf1, " ");
|
|
1483 |
strcat(buf1, buf2);
|
|
1484 |
if(strcmp(buf1, "Executing exitfunc1.") != 0)
|
|
1485 |
{
|
|
1486 |
SetTestStepResult(EFail);
|
|
1487 |
}
|
|
1488 |
|
|
1489 |
if(fp)
|
|
1490 |
{
|
|
1491 |
fclose(fp);
|
|
1492 |
}
|
|
1493 |
|
|
1494 |
if (i != 1)
|
|
1495 |
{
|
|
1496 |
INFO_PRINTF1(_L("The system() call has failed\n"));
|
|
1497 |
SetTestStepResult(EFail);
|
|
1498 |
}
|
|
1499 |
|
|
1500 |
#endif
|
|
1501 |
|
|
1502 |
return TestStepResult();
|
|
1503 |
}
|
|
1504 |
|
|
1505 |
TVerdict CTestMisc::TestExit2()
|
|
1506 |
{
|
|
1507 |
SetTestStepResult(EPass);
|
|
1508 |
|
|
1509 |
int i = system("z:\\sys\\bin\\tstdlib_testexitec.exe");
|
|
1510 |
|
|
1511 |
if(i!=3)
|
|
1512 |
{
|
|
1513 |
SetTestStepResult(EFail);
|
|
1514 |
}
|
|
1515 |
|
|
1516 |
return TestStepResult();
|
|
1517 |
}
|
|
1518 |
|
|
1519 |
TVerdict CTestMisc::TestExitE1()
|
|
1520 |
{
|
|
1521 |
SetTestStepResult(EPass);
|
|
1522 |
|
|
1523 |
int i = system("z:\\sys\\bin\\tstdlib_test_exitE.exe");
|
|
1524 |
|
|
1525 |
if(i!=5)
|
|
1526 |
{
|
|
1527 |
SetTestStepResult(EFail);
|
|
1528 |
}
|
|
1529 |
|
|
1530 |
return TestStepResult();
|
|
1531 |
}
|
|
1532 |
|
|
1533 |
TVerdict CTestMisc::TestExit3()
|
|
1534 |
{
|
|
1535 |
SetTestStepResult(EPass);
|
|
1536 |
|
|
1537 |
int i = system("z:\\sys\\bin\\tstdlib_test_exit.exe");
|
|
1538 |
|
|
1539 |
if(i!=6)
|
|
1540 |
{
|
|
1541 |
SetTestStepResult(EFail);
|
|
1542 |
}
|
|
1543 |
|
|
1544 |
return TestStepResult();
|
|
1545 |
}
|
|
1546 |
|
|
1547 |
TVerdict CTestMisc::TestExit4()
|
|
1548 |
{
|
|
1549 |
SetTestStepResult(EPass);
|
|
1550 |
|
|
1551 |
system("z:\\sys\\bin\\tstdlib_test_exit4.exe");
|
|
1552 |
system("z:\\sys\\bin\\tstdlib_test_exit4.exe");
|
|
1553 |
|
|
1554 |
return TestStepResult();
|
|
1555 |
}
|
|
1556 |
|
|
1557 |
TVerdict CTestMisc::TestExit5()
|
|
1558 |
{
|
|
1559 |
SetTestStepResult(EPass);
|
|
1560 |
|
|
1561 |
system("z:\\sys\\bin\\tstdlib_test_exit5.exe");
|
|
1562 |
|
|
1563 |
return TestStepResult();
|
|
1564 |
}
|
|
1565 |
|
|
1566 |
TVerdict CTestMisc::TestExit6()
|
|
1567 |
{
|
|
1568 |
SetTestStepResult(EPass);
|
|
1569 |
|
|
1570 |
if(system("z:\\sys\\bin\\tstdlib_test_exit6.exe") == -1)
|
|
1571 |
SetTestStepResult(EFail);
|
|
1572 |
|
|
1573 |
return TestStepResult();
|
|
1574 |
}
|
|
1575 |
|
|
1576 |
/* ********************************** */
|
|
1577 |
/* Waitpid() test to check for status */
|
|
1578 |
/* normal termination of the child */
|
|
1579 |
/* ********************************** */
|
|
1580 |
|
|
1581 |
TVerdict CTestMisc::TestWaitpid1()
|
|
1582 |
{
|
|
1583 |
SetTestStepResult(EPass);
|
|
1584 |
int status,ret1, ret;
|
|
1585 |
int fd[3];
|
|
1586 |
ret = popen3("z:\\sys\\bin\\helloworld_waitpid.exe", NULL, NULL, fd);
|
|
1587 |
INFO_PRINTF2(_L("popen3() returns %d\n"), ret);
|
|
1588 |
ret1 = waitpid(ret, &status, 0);
|
|
1589 |
INFO_PRINTF2(_L("waitpid() returns %d\n"), ret1);
|
|
1590 |
INFO_PRINTF2(_L("status %d\n"), status);
|
|
1591 |
if (WIFEXITED(status))
|
|
1592 |
{
|
|
1593 |
INFO_PRINTF2(_L("exit status is %d\n"), WEXITSTATUS(status));
|
|
1594 |
if (WEXITSTATUS(status) == 4)
|
|
1595 |
{
|
|
1596 |
SetTestStepResult(EPass);
|
|
1597 |
}
|
|
1598 |
else
|
|
1599 |
{
|
|
1600 |
SetTestStepResult(EFail);
|
|
1601 |
}
|
|
1602 |
}
|
|
1603 |
else
|
|
1604 |
{
|
|
1605 |
SetTestStepResult(EFail);
|
|
1606 |
}
|
|
1607 |
return TestStepResult();
|
|
1608 |
}
|
|
1609 |
|
|
1610 |
/* ************************************* */
|
|
1611 |
/* Waitpid() test to check for status */
|
|
1612 |
/* when the child was killed */
|
|
1613 |
/* ************************************* */
|
|
1614 |
|
|
1615 |
TVerdict CTestMisc::TestWaitpid2()
|
|
1616 |
{
|
|
1617 |
SetTestStepResult(EPass);
|
|
1618 |
int status,ret1, ret;
|
|
1619 |
int fd[3];
|
|
1620 |
RProcess pro;
|
|
1621 |
ret = popen3("z:\\sys\\bin\\helloworld_waitpid.exe", NULL, NULL, fd);
|
|
1622 |
INFO_PRINTF2(_L("popen3() returns %d\n"), ret);
|
|
1623 |
pro.Open(ret);
|
|
1624 |
pro.Kill(0);//exit reason is 0
|
|
1625 |
ret1 = waitpid(ret, &status, WNOHANG);
|
|
1626 |
INFO_PRINTF2(_L("waitpid() returns %d\n"), ret1);
|
|
1627 |
INFO_PRINTF2(_L("status %d\n"), status);
|
|
1628 |
if (WIFEXITED(status))
|
|
1629 |
{
|
|
1630 |
INFO_PRINTF2(_L("exit status is %d\n"), WEXITSTATUS(status));
|
|
1631 |
if (WEXITSTATUS(status) == 0)
|
|
1632 |
{
|
|
1633 |
SetTestStepResult(EPass);
|
|
1634 |
}
|
|
1635 |
else
|
|
1636 |
{
|
|
1637 |
SetTestStepResult(EFail);
|
|
1638 |
}
|
|
1639 |
}
|
|
1640 |
else
|
|
1641 |
{
|
|
1642 |
SetTestStepResult(EFail);
|
|
1643 |
}
|
|
1644 |
return TestStepResult();
|
|
1645 |
}
|
|
1646 |
|
|
1647 |
/* ************************************* */
|
|
1648 |
/* Waitpid() test to check for status */
|
|
1649 |
/* when the child panics */
|
|
1650 |
/* ************************************* */
|
|
1651 |
|
|
1652 |
TVerdict CTestMisc::TestWaitpid3()
|
|
1653 |
{
|
|
1654 |
SetTestStepResult(EPass);
|
|
1655 |
int status,ret1, ret;
|
|
1656 |
int fd[3];
|
|
1657 |
RProcess pro;
|
|
1658 |
ret = popen3("z:\\sys\\bin\\helloworld_waitpid.exe", NULL, NULL, fd);
|
|
1659 |
INFO_PRINTF2(_L("popen3() returns %d\n"), ret);
|
|
1660 |
pro.Open(ret);
|
|
1661 |
pro.Panic(_L("Rprocess Panics here"), 3);//exit reason is 3
|
|
1662 |
ret1 = waitpid(ret, &status, WNOHANG);
|
|
1663 |
INFO_PRINTF2(_L("waitpid() returns %d\n"), ret1);
|
|
1664 |
INFO_PRINTF2(_L("status %d\n"), status);
|
|
1665 |
if (!WIFEXITED(status))
|
|
1666 |
{
|
|
1667 |
INFO_PRINTF2(_L("exit status is %d\n"), WEXITSTATUS(status));
|
|
1668 |
if (WEXITSTATUS(status) == 3)
|
|
1669 |
{
|
|
1670 |
SetTestStepResult(EPass);
|
|
1671 |
}
|
|
1672 |
else
|
|
1673 |
{
|
|
1674 |
SetTestStepResult(EFail);
|
|
1675 |
}
|
|
1676 |
}
|
|
1677 |
else
|
|
1678 |
{
|
|
1679 |
SetTestStepResult(EFail);
|
|
1680 |
}
|
|
1681 |
return TestStepResult();
|
|
1682 |
}
|
|
1683 |
|
|
1684 |
|
|
1685 |
// SEM_UNDO
|
|
1686 |
|
|
1687 |
//If sem_op is a positive integer and the calling process has alter permission, the value of sem_op shall be added to semval and, if (sem_flg &SEM_UNDO) is non-zero, the value of sem_op shall be subtracted from the calling process' semadj value for the specified semaphore.
|
|
1688 |
|
|
1689 |
TInt CTestMisc::semoptest16()
|
|
1690 |
{
|
|
1691 |
int msq_id,ret=KErrNone;
|
|
1692 |
int ret1,i,x,semkey,get;
|
|
1693 |
union semun tmpo,arg;
|
|
1694 |
unsigned short tmpi[2];
|
|
1695 |
int fds[3];
|
|
1696 |
char *path;
|
|
1697 |
|
|
1698 |
#if defined (__EPOC32__)
|
|
1699 |
path = "z:\\tstdapis\\tmisc.ini";
|
|
1700 |
#else
|
|
1701 |
path = "c:\\tstdapis\\tmisc.ini";
|
|
1702 |
#endif
|
|
1703 |
|
|
1704 |
if ((semkey = ftok(path, 'r')) == (key_t) -1)
|
|
1705 |
{
|
|
1706 |
_LIT(KFunc, "ftok failed with errno %d\n");
|
|
1707 |
INFO_PRINTF2(KFunc, errno);
|
|
1708 |
return KErrGeneral;
|
|
1709 |
}
|
|
1710 |
|
|
1711 |
if ((msq_id = semget(semkey,2, IPC_W | IPC_R|IPC_CREAT | IPC_EXCL | 0666)) == -1)
|
|
1712 |
{
|
|
1713 |
_LIT(KFunc, "semaphore create failed with errno %d\n");
|
|
1714 |
INFO_PRINTF2(KFunc, errno);
|
|
1715 |
return KErrGeneral;
|
|
1716 |
}
|
|
1717 |
|
|
1718 |
arg.val = 3;
|
|
1719 |
|
|
1720 |
get = semctl(msq_id, 1, SETVAL,arg);
|
|
1721 |
if (get == -1)
|
|
1722 |
{
|
|
1723 |
_LIT(KFunc, "semaphore SETVAL failed with errno %d\n");
|
|
1724 |
INFO_PRINTF2(KFunc, errno);
|
|
1725 |
ret = KErrGeneral;
|
|
1726 |
}
|
|
1727 |
|
|
1728 |
x = popen3("z:\\sys\\bin\\Tsemundo1.exe",NULL,NULL,fds);
|
|
1729 |
if(x==-1)
|
|
1730 |
{
|
|
1731 |
_LIT(KFunc, "popen3 failed with errno %d\n");
|
|
1732 |
INFO_PRINTF2(KFunc, errno);
|
|
1733 |
ret = KErrGeneral;
|
|
1734 |
}
|
|
1735 |
sleep(5);
|
|
1736 |
|
|
1737 |
_LIT(KStmt,"After Semop operations ");
|
|
1738 |
INFO_PRINTF1(KStmt);
|
|
1739 |
tmpo.array = &tmpi[0];
|
|
1740 |
ret1 = semctl(msq_id, 1,GETALL,tmpo);
|
|
1741 |
if(ret1 == -1)
|
|
1742 |
{
|
|
1743 |
_LIT(KFunc, "semaphore GETALL failed with errno %d\n");
|
|
1744 |
INFO_PRINTF2(KFunc, errno);
|
|
1745 |
ret = KErrGeneral;
|
|
1746 |
}
|
|
1747 |
|
|
1748 |
for(i=0;i<2;i++)
|
|
1749 |
{
|
|
1750 |
_LIT(KFunc, "semaphore GETVAL for the %d semaphore is %d \n");
|
|
1751 |
INFO_PRINTF3(KFunc, i,tmpi[i]);
|
|
1752 |
}
|
|
1753 |
|
|
1754 |
if( tmpi[0] != 0 && tmpi[1] != 2)
|
|
1755 |
{
|
|
1756 |
_LIT(KFunc, "semaphore semop failed and didnt modified the semval\n");
|
|
1757 |
INFO_PRINTF1(KFunc);
|
|
1758 |
ret = KErrGeneral;
|
|
1759 |
}
|
|
1760 |
if (semctl(msq_id, 1, IPC_RMID) == -1)
|
|
1761 |
{
|
|
1762 |
_LIT(KFunc, "semaphore delete failed with errno %d\n");
|
|
1763 |
INFO_PRINTF2(KFunc, errno);
|
|
1764 |
ret = KErrGeneral;
|
|
1765 |
}
|
|
1766 |
|
|
1767 |
return ret;
|
|
1768 |
}
|
|
1769 |
|
|
1770 |
|
|
1771 |
TInt CTestMisc::semoptest17()
|
|
1772 |
{
|
|
1773 |
int msq_id,ret=KErrNone;
|
|
1774 |
int ret1,i,x,semkey,get;
|
|
1775 |
union semun tmpo,arg,arg1;
|
|
1776 |
unsigned short tmpi[2];
|
|
1777 |
int fds[3];
|
|
1778 |
char *path;
|
|
1779 |
|
|
1780 |
#if defined (__EPOC32__)
|
|
1781 |
path = "z:\\tstdapis\\tmisc.ini";
|
|
1782 |
#else
|
|
1783 |
path = "c:\\tstdapis\\tmisc.ini";
|
|
1784 |
#endif
|
|
1785 |
|
|
1786 |
if ((semkey = ftok(path, 'r')) == (key_t) -1)
|
|
1787 |
{
|
|
1788 |
_LIT(KFunc, "ftok failed with errno %d\n");
|
|
1789 |
INFO_PRINTF2(KFunc, errno);
|
|
1790 |
return KErrGeneral;
|
|
1791 |
}
|
|
1792 |
|
|
1793 |
if ((msq_id = semget(semkey,2, IPC_W | IPC_R|IPC_CREAT | IPC_EXCL | 0666)) == -1)
|
|
1794 |
{
|
|
1795 |
_LIT(KFunc, "semaphore create failed with errno %d\n");
|
|
1796 |
INFO_PRINTF2(KFunc, errno);
|
|
1797 |
return KErrGeneral;
|
|
1798 |
}
|
|
1799 |
|
|
1800 |
arg.val = 5;
|
|
1801 |
|
|
1802 |
get = semctl(msq_id, 0, SETVAL,arg);
|
|
1803 |
if (get == -1)
|
|
1804 |
{
|
|
1805 |
_LIT(KFunc, "semaphore SETVAL failed with errno %d\n");
|
|
1806 |
INFO_PRINTF2(KFunc, errno);
|
|
1807 |
ret = KErrGeneral;
|
|
1808 |
}
|
|
1809 |
|
|
1810 |
arg1.val = 10;
|
|
1811 |
|
|
1812 |
get = semctl(msq_id, 1, SETVAL,arg1);
|
|
1813 |
if (get == -1)
|
|
1814 |
{
|
|
1815 |
_LIT(KFunc, "semaphore SETVAL failed with errno %d\n");
|
|
1816 |
INFO_PRINTF2(KFunc, errno);
|
|
1817 |
ret = KErrGeneral;
|
|
1818 |
}
|
|
1819 |
|
|
1820 |
x = popen3("z:\\sys\\bin\\Tsemundo2.exe",NULL,NULL,fds);
|
|
1821 |
if(x==-1)
|
|
1822 |
{
|
|
1823 |
_LIT(KFunc, "popen3 failed with errno %d\n");
|
|
1824 |
INFO_PRINTF2(KFunc, errno);
|
|
1825 |
ret = KErrGeneral;
|
|
1826 |
}
|
|
1827 |
sleep(5);
|
|
1828 |
|
|
1829 |
_LIT(KStmt,"After Semop operations ");
|
|
1830 |
INFO_PRINTF1(KStmt);
|
|
1831 |
tmpo.array = &tmpi[0];
|
|
1832 |
ret1 = semctl(msq_id, 1,GETALL,tmpo);
|
|
1833 |
if(ret1 == -1)
|
|
1834 |
{
|
|
1835 |
_LIT(KFunc, "semaphore GETALL failed with errno %d\n");
|
|
1836 |
INFO_PRINTF2(KFunc, errno);
|
|
1837 |
ret = KErrGeneral;
|
|
1838 |
}
|
|
1839 |
|
|
1840 |
for(i=0;i<2;i++)
|
|
1841 |
{
|
|
1842 |
_LIT(KFunc, "semaphore GETVAL for the %d semaphore is %d \n");
|
|
1843 |
INFO_PRINTF3(KFunc, i,tmpi[i]);
|
|
1844 |
}
|
|
1845 |
|
|
1846 |
if( tmpi[0] != 20 && tmpi[1] != 30)
|
|
1847 |
{
|
|
1848 |
_LIT(KFunc, "semaphore semop failed and didnt modified the semval\n");
|
|
1849 |
INFO_PRINTF1(KFunc);
|
|
1850 |
ret = KErrGeneral;
|
|
1851 |
}
|
|
1852 |
if (semctl(msq_id, 1, IPC_RMID) == -1)
|
|
1853 |
{
|
|
1854 |
_LIT(KFunc, "semaphore delete failed with errno %d\n");
|
|
1855 |
INFO_PRINTF2(KFunc, errno);
|
|
1856 |
ret = KErrGeneral;
|
|
1857 |
}
|
|
1858 |
|
|
1859 |
return ret;
|
|
1860 |
}
|
|
1861 |
|
|
1862 |
|
|
1863 |
TInt CTestMisc::semoptest18()
|
|
1864 |
{
|
|
1865 |
int msq_id,ret=KErrNone;
|
|
1866 |
int ret1,i,x,semkey,get;
|
|
1867 |
union semun tmpo,arg1;
|
|
1868 |
unsigned short tmpi[2];
|
|
1869 |
int fds[3];
|
|
1870 |
char *path;
|
|
1871 |
|
|
1872 |
#if defined (__EPOC32__)
|
|
1873 |
path = "z:\\tstdapis\\tmisc.ini";
|
|
1874 |
#else
|
|
1875 |
path = "c:\\tstdapis\\tmisc.ini";
|
|
1876 |
#endif
|
|
1877 |
|
|
1878 |
if ((semkey = ftok(path, 'r')) == (key_t) -1)
|
|
1879 |
{
|
|
1880 |
_LIT(KFunc, "ftok failed with errno %d\n");
|
|
1881 |
INFO_PRINTF2(KFunc, errno);
|
|
1882 |
return KErrGeneral;
|
|
1883 |
}
|
|
1884 |
|
|
1885 |
if ((msq_id = semget(semkey,2, IPC_W | IPC_R|IPC_CREAT | IPC_EXCL | 0666)) == -1)
|
|
1886 |
{
|
|
1887 |
_LIT(KFunc, "semaphore create failed with errno %d\n");
|
|
1888 |
INFO_PRINTF2(KFunc, errno);
|
|
1889 |
return KErrGeneral;
|
|
1890 |
}
|
|
1891 |
|
|
1892 |
x = popen3("z:\\sys\\bin\\Tsemundo3.exe",NULL,NULL,fds);
|
|
1893 |
if(x==-1)
|
|
1894 |
{
|
|
1895 |
_LIT(KFunc, "popen3 failed with errno %d\n");
|
|
1896 |
INFO_PRINTF2(KFunc, errno);
|
|
1897 |
ret = KErrGeneral;
|
|
1898 |
}
|
|
1899 |
|
|
1900 |
arg1.val = 4;
|
|
1901 |
|
|
1902 |
get = semctl(msq_id, 1, SETVAL,arg1);
|
|
1903 |
if (get == -1)
|
|
1904 |
{
|
|
1905 |
_LIT(KFunc, "semaphore SETVAL failed with errno %d\n");
|
|
1906 |
INFO_PRINTF2(KFunc, errno);
|
|
1907 |
ret = KErrGeneral;
|
|
1908 |
}
|
|
1909 |
|
|
1910 |
sleep(5);
|
|
1911 |
|
|
1912 |
_LIT(KStmt,"After Semop operations ");
|
|
1913 |
INFO_PRINTF1(KStmt);
|
|
1914 |
tmpo.array = &tmpi[0];
|
|
1915 |
ret1 = semctl(msq_id, 1,GETALL,tmpo);
|
|
1916 |
if(ret1 == -1)
|
|
1917 |
{
|
|
1918 |
_LIT(KFunc, "semaphore GETALL failed with errno %d\n");
|
|
1919 |
INFO_PRINTF2(KFunc, errno);
|
|
1920 |
ret = KErrGeneral;
|
|
1921 |
}
|
|
1922 |
|
|
1923 |
for(i=0;i<2;i++)
|
|
1924 |
{
|
|
1925 |
_LIT(KFunc, "semaphore GETVAL for the %d semaphore is %d \n");
|
|
1926 |
INFO_PRINTF3(KFunc, i,tmpi[i]);
|
|
1927 |
}
|
|
1928 |
|
|
1929 |
if( tmpi[0] != 1 && tmpi[1] != 1)
|
|
1930 |
{
|
|
1931 |
_LIT(KFunc, "semaphore semop failed and didnt modified the semval\n");
|
|
1932 |
INFO_PRINTF1(KFunc);
|
|
1933 |
ret = KErrGeneral;
|
|
1934 |
}
|
|
1935 |
if (semctl(msq_id, 1, IPC_RMID) == -1)
|
|
1936 |
{
|
|
1937 |
_LIT(KFunc, "semaphore delete failed with errno %d\n");
|
|
1938 |
INFO_PRINTF2(KFunc, errno);
|
|
1939 |
ret = KErrGeneral;
|
|
1940 |
}
|
|
1941 |
|
|
1942 |
return ret;
|
|
1943 |
}
|
|
1944 |
|
|
1945 |
// THREADS & PROCESSES
|
|
1946 |
|
|
1947 |
// *** Thread1 ***
|
|
1948 |
|
|
1949 |
void* StartFn1(void* arg)
|
|
1950 |
{
|
|
1951 |
int semnops=3,x;
|
|
1952 |
int msgq_id = (int)arg;
|
|
1953 |
struct sembuf lSemBuf[3];
|
|
1954 |
union semun arg1,arg2,arg3;
|
|
1955 |
|
|
1956 |
// wait for -5,-10,-15
|
|
1957 |
|
|
1958 |
lSemBuf[0].sem_num = 0;
|
|
1959 |
lSemBuf[0].sem_op = -5;
|
|
1960 |
lSemBuf[0].sem_flg = 0;
|
|
1961 |
|
|
1962 |
lSemBuf[1].sem_num = 1;
|
|
1963 |
lSemBuf[1].sem_op = -10;
|
|
1964 |
lSemBuf[1].sem_flg = 0;
|
|
1965 |
|
|
1966 |
lSemBuf[2].sem_num = 2;
|
|
1967 |
lSemBuf[2].sem_op = -15;
|
|
1968 |
lSemBuf[2].sem_flg = 0;
|
|
1969 |
|
|
1970 |
x = semop(msgq_id,&lSemBuf[0],semnops);
|
|
1971 |
if(x==-1)
|
|
1972 |
{
|
|
1973 |
exit(0);
|
|
1974 |
}
|
|
1975 |
|
|
1976 |
// wait
|
|
1977 |
sleep(5);
|
|
1978 |
|
|
1979 |
// setval 6,11,16
|
|
1980 |
arg1.val = 6;
|
|
1981 |
int get = semctl(msgq_id, 0, SETVAL,arg1);
|
|
1982 |
|
|
1983 |
arg2.val = 11;
|
|
1984 |
get = semctl(msgq_id, 1, SETVAL,arg2);
|
|
1985 |
|
|
1986 |
arg3.val = 16;
|
|
1987 |
get = semctl(msgq_id, 2, SETVAL,arg3);
|
|
1988 |
|
|
1989 |
|
|
1990 |
// exit
|
|
1991 |
return NULL;
|
|
1992 |
}
|
|
1993 |
|
|
1994 |
|
|
1995 |
// *** Thread2 ***
|
|
1996 |
|
|
1997 |
void* StartFn2(void* arg)
|
|
1998 |
{
|
|
1999 |
int semnops=3,x;
|
|
2000 |
int msgq_id = (int)arg;
|
|
2001 |
struct sembuf lSemBuf[3];
|
|
2002 |
union semun arg1,arg2,arg3;
|
|
2003 |
|
|
2004 |
// wait for wait for 6,11,16
|
|
2005 |
|
|
2006 |
lSemBuf[0].sem_num = 0;
|
|
2007 |
lSemBuf[0].sem_op = -6;
|
|
2008 |
lSemBuf[0].sem_flg = 0;
|
|
2009 |
|
|
2010 |
lSemBuf[1].sem_num = 1;
|
|
2011 |
lSemBuf[1].sem_op = -11;
|
|
2012 |
lSemBuf[1].sem_flg = 0;
|
|
2013 |
|
|
2014 |
lSemBuf[2].sem_num = 2;
|
|
2015 |
lSemBuf[2].sem_op = -16;
|
|
2016 |
lSemBuf[2].sem_flg = 0;
|
|
2017 |
|
|
2018 |
x = semop(msgq_id,&lSemBuf[0],semnops);
|
|
2019 |
if(x==-1)
|
|
2020 |
{
|
|
2021 |
exit(0);
|
|
2022 |
}
|
|
2023 |
|
|
2024 |
// wait
|
|
2025 |
sleep(5);
|
|
2026 |
|
|
2027 |
// setval 7,12,17
|
|
2028 |
arg1.val = 7;
|
|
2029 |
int get = semctl(msgq_id, 0, SETVAL,arg1);
|
|
2030 |
|
|
2031 |
arg2.val = 12;
|
|
2032 |
get = semctl(msgq_id, 1, SETVAL,arg2);
|
|
2033 |
|
|
2034 |
arg3.val = 17;
|
|
2035 |
get = semctl(msgq_id, 2, SETVAL,arg3);
|
|
2036 |
|
|
2037 |
// exit
|
|
2038 |
return NULL;
|
|
2039 |
}
|
|
2040 |
|
|
2041 |
TInt CTestMisc::semoptest19()
|
|
2042 |
{
|
|
2043 |
int msq_id,ret=KErrNone,semnops=2;
|
|
2044 |
int x,semkey;
|
|
2045 |
union semun arg1,arg2,arg3;
|
|
2046 |
int fds[3];
|
|
2047 |
struct sembuf lSemBuf[3];
|
|
2048 |
pthread_t testThread1;
|
|
2049 |
pthread_t testThread2;
|
|
2050 |
|
|
2051 |
char *path;
|
|
2052 |
|
|
2053 |
#if defined (__EPOC32__)
|
|
2054 |
path = "z:\\tstdapis\\tmisc.ini";
|
|
2055 |
#else
|
|
2056 |
path = "c:\\tstdapis\\tmisc.ini";
|
|
2057 |
#endif
|
|
2058 |
|
|
2059 |
if ((semkey = ftok(path, 'r')) == (key_t) -1)
|
|
2060 |
{
|
|
2061 |
_LIT(KFunc, "ftok failed with errno %d\n");
|
|
2062 |
INFO_PRINTF2(KFunc, errno);
|
|
2063 |
return KErrGeneral;
|
|
2064 |
}
|
|
2065 |
|
|
2066 |
if ((msq_id = semget(semkey,3, IPC_W | IPC_R|IPC_CREAT | IPC_EXCL | 0666)) == -1)
|
|
2067 |
{
|
|
2068 |
_LIT(KFunc, "semaphore create failed with errno %d\n");
|
|
2069 |
INFO_PRINTF2(KFunc, errno);
|
|
2070 |
return KErrGeneral;
|
|
2071 |
}
|
|
2072 |
|
|
2073 |
// setval to 5,10,15
|
|
2074 |
|
|
2075 |
arg1.val = 5;
|
|
2076 |
int get = semctl(msq_id, 0, SETVAL,arg1);
|
|
2077 |
|
|
2078 |
arg2.val = 10;
|
|
2079 |
get = semctl(msq_id, 1, SETVAL,arg2);
|
|
2080 |
|
|
2081 |
arg3.val = 15;
|
|
2082 |
get = semctl(msq_id, 2, SETVAL,arg3);
|
|
2083 |
|
|
2084 |
|
|
2085 |
|
|
2086 |
// create two threads
|
|
2087 |
|
|
2088 |
pthread_create(&testThread1,NULL,StartFn1,(TAny*)msq_id);
|
|
2089 |
pthread_create(&testThread2,NULL,StartFn2,(TAny*)msq_id);
|
|
2090 |
|
|
2091 |
// create a process
|
|
2092 |
|
|
2093 |
x = popen3("z:\\sys\\bin\\Tsemundo4.exe",NULL,NULL,fds);
|
|
2094 |
if(x==-1)
|
|
2095 |
{
|
|
2096 |
_LIT(KFunc, "popen3 failed with errno %d\n");
|
|
2097 |
INFO_PRINTF2(KFunc, errno);
|
|
2098 |
ret = KErrGeneral;
|
|
2099 |
}
|
|
2100 |
|
|
2101 |
|
|
2102 |
// wait for -10,-15,-20
|
|
2103 |
lSemBuf[0].sem_num = 0;
|
|
2104 |
lSemBuf[0].sem_op = -10;
|
|
2105 |
lSemBuf[0].sem_flg = 0;
|
|
2106 |
|
|
2107 |
lSemBuf[1].sem_num = 1;
|
|
2108 |
lSemBuf[1].sem_op = -15;
|
|
2109 |
lSemBuf[1].sem_flg = 0;
|
|
2110 |
|
|
2111 |
lSemBuf[2].sem_num = 2;
|
|
2112 |
lSemBuf[2].sem_op = -20;
|
|
2113 |
lSemBuf[2].sem_flg = 0;
|
|
2114 |
x = semop(msq_id,&lSemBuf[0],semnops);
|
|
2115 |
if(x==-1)
|
|
2116 |
{
|
|
2117 |
_LIT(KFunc, "semop failed with errno %d\n");
|
|
2118 |
INFO_PRINTF2(KFunc, errno);
|
|
2119 |
ret = KErrGeneral;
|
|
2120 |
}
|
|
2121 |
|
|
2122 |
// exit
|
|
2123 |
if (semctl(msq_id, 2, IPC_RMID) == -1)
|
|
2124 |
{
|
|
2125 |
_LIT(KFunc, "semaphore delete failed with errno %d\n");
|
|
2126 |
INFO_PRINTF2(KFunc, errno);
|
|
2127 |
ret = KErrGeneral;
|
|
2128 |
}
|
|
2129 |
return ret;
|
|
2130 |
}
|
|
2131 |
|
|
2132 |
void* thread1(void* arg)
|
|
2133 |
{
|
|
2134 |
int semid = *(int*)(arg);
|
|
2135 |
int ret=0;
|
|
2136 |
|
|
2137 |
struct sembuf LockSem[2];
|
|
2138 |
struct sembuf UnLockSem[2];
|
|
2139 |
|
|
2140 |
LockSem[0].sem_num = 0;
|
|
2141 |
LockSem[0].sem_op = 0;
|
|
2142 |
LockSem[0].sem_flg = SEM_UNDO;
|
|
2143 |
|
|
2144 |
LockSem[1].sem_num = 1;
|
|
2145 |
LockSem[1].sem_op = -1;
|
|
2146 |
LockSem[1].sem_flg = SEM_UNDO;
|
|
2147 |
|
|
2148 |
|
|
2149 |
UnLockSem[0].sem_num = 0;
|
|
2150 |
UnLockSem[0].sem_op = 3;
|
|
2151 |
UnLockSem[0].sem_flg = SEM_UNDO;
|
|
2152 |
|
|
2153 |
UnLockSem[1].sem_num = 1;
|
|
2154 |
UnLockSem[1].sem_op = 2;
|
|
2155 |
UnLockSem[1].sem_flg = SEM_UNDO;
|
|
2156 |
|
|
2157 |
printf("Calling the semop from thread1\n");
|
|
2158 |
|
|
2159 |
while(1)
|
|
2160 |
{
|
|
2161 |
if(counter == MAXVAL)
|
|
2162 |
break;
|
|
2163 |
ret = semop(semid, &LockSem[0], 2);
|
|
2164 |
if(ret == -1 || counter == MAXVAL)
|
|
2165 |
{
|
|
2166 |
printf("Semop failed with errno %d\n",errno);
|
|
2167 |
break;
|
|
2168 |
}
|
|
2169 |
counter++;
|
|
2170 |
ret = semop(semid, &UnLockSem[0], 2);
|
|
2171 |
if(ret == -1)
|
|
2172 |
{
|
|
2173 |
printf("Semop failed with errno %d\n",errno);
|
|
2174 |
break;
|
|
2175 |
}
|
|
2176 |
|
|
2177 |
}
|
|
2178 |
return 0;
|
|
2179 |
}
|
|
2180 |
|
|
2181 |
void* thread2(void* arg)
|
|
2182 |
{
|
|
2183 |
int semid = *(int*)(arg);
|
|
2184 |
int ret=0;
|
|
2185 |
|
|
2186 |
struct sembuf LockSem[2];
|
|
2187 |
struct sembuf UnLockSem[2];
|
|
2188 |
|
|
2189 |
LockSem[0].sem_num = 0;
|
|
2190 |
LockSem[0].sem_op = 0;
|
|
2191 |
LockSem[0].sem_flg = SEM_UNDO;
|
|
2192 |
|
|
2193 |
LockSem[1].sem_num = 1;
|
|
2194 |
LockSem[1].sem_op = -2;
|
|
2195 |
LockSem[1].sem_flg = SEM_UNDO;
|
|
2196 |
|
|
2197 |
|
|
2198 |
UnLockSem[0].sem_num = 0;
|
|
2199 |
UnLockSem[0].sem_op = 3;
|
|
2200 |
UnLockSem[0].sem_flg = SEM_UNDO;
|
|
2201 |
|
|
2202 |
UnLockSem[1].sem_num = 1;
|
|
2203 |
UnLockSem[1].sem_op = 1;
|
|
2204 |
UnLockSem[1].sem_flg = SEM_UNDO;
|
|
2205 |
|
|
2206 |
|
|
2207 |
printf("Calling the semop from thread2\n");
|
|
2208 |
|
|
2209 |
while(1)
|
|
2210 |
{
|
|
2211 |
if(counter == MAXVAL)
|
|
2212 |
break;
|
|
2213 |
ret = semop(semid, &LockSem[0], 2);
|
|
2214 |
if(ret == -1 || counter == MAXVAL)
|
|
2215 |
{
|
|
2216 |
printf("Semop failed with errno %d\n",errno);
|
|
2217 |
break;
|
|
2218 |
}
|
|
2219 |
counter++;
|
|
2220 |
ret = semop(semid, &UnLockSem[0], 2);
|
|
2221 |
if(ret == -1)
|
|
2222 |
{
|
|
2223 |
printf("Semop failed with errno %d\n",errno);
|
|
2224 |
break;
|
|
2225 |
}
|
|
2226 |
|
|
2227 |
}
|
|
2228 |
return 0;
|
|
2229 |
}
|
|
2230 |
|
|
2231 |
|
|
2232 |
|
|
2233 |
void* thread3(void* arg)
|
|
2234 |
{
|
|
2235 |
int semid = *(int*)(arg);
|
|
2236 |
int ret=0;
|
|
2237 |
|
|
2238 |
struct sembuf LockSem[2];
|
|
2239 |
struct sembuf UnLockSem[2];
|
|
2240 |
struct sembuf SemBuf[2];
|
|
2241 |
|
|
2242 |
LockSem[0].sem_num = 0;
|
|
2243 |
LockSem[0].sem_op = -2;
|
|
2244 |
LockSem[0].sem_flg = SEM_UNDO;
|
|
2245 |
|
|
2246 |
UnLockSem[0].sem_num = 0;
|
|
2247 |
UnLockSem[0].sem_op = -1;
|
|
2248 |
UnLockSem[0].sem_flg = 0;
|
|
2249 |
|
|
2250 |
SemBuf[0].sem_num = 0;
|
|
2251 |
SemBuf[0].sem_op = 5;
|
|
2252 |
SemBuf[0].sem_flg = SEM_UNDO;
|
|
2253 |
|
|
2254 |
|
|
2255 |
printf("Calling the semop from thread2\n");
|
|
2256 |
|
|
2257 |
while(1)
|
|
2258 |
{
|
|
2259 |
ret = semop(semid, &LockSem[0], 1);
|
|
2260 |
if(ret == -1)
|
|
2261 |
{
|
|
2262 |
printf("Semop failed with errno %d\n",errno);
|
|
2263 |
break;
|
|
2264 |
}
|
|
2265 |
printf("The value is %d\n",counter);
|
|
2266 |
|
|
2267 |
if(counter == MAXVAL) //you check this by adding and comparing the total
|
|
2268 |
{
|
|
2269 |
semop(semid, &SemBuf[0], 1);
|
|
2270 |
break;
|
|
2271 |
}
|
|
2272 |
|
|
2273 |
ret = semop(semid, &UnLockSem[0], 1);
|
|
2274 |
if(ret == -1)
|
|
2275 |
{
|
|
2276 |
printf("Semop failed with errno %d\n",errno);
|
|
2277 |
break;
|
|
2278 |
}
|
|
2279 |
}
|
|
2280 |
return 0;
|
|
2281 |
}
|
|
2282 |
|
|
2283 |
TInt CTestMisc::semoptest20()
|
|
2284 |
{
|
|
2285 |
int semid,ret=KErrNone,ret1=0;
|
|
2286 |
struct sembuf sb[2];
|
|
2287 |
struct sembuf sb1[1];
|
|
2288 |
union semun setval;
|
|
2289 |
unsigned short int tmp[]={0,0};
|
|
2290 |
int result;
|
|
2291 |
|
|
2292 |
pthread_t tid1;
|
|
2293 |
pthread_t tid2;
|
|
2294 |
pthread_t tid3;
|
|
2295 |
|
|
2296 |
setval.array = &tmp[0];
|
|
2297 |
|
|
2298 |
sb[0].sem_num = 1;
|
|
2299 |
sb[0].sem_op = 1;
|
|
2300 |
sb[0].sem_flg = SEM_UNDO;
|
|
2301 |
|
|
2302 |
sb1[0].sem_num = 0;
|
|
2303 |
sb1[0].sem_op = -5;
|
|
2304 |
sb1[0].sem_flg = 0;
|
|
2305 |
|
|
2306 |
|
|
2307 |
if ((semid = semget(IPC_PRIVATE,2,IPC_CREAT | IPC_EXCL | IPC_R | IPC_W)) == -1)
|
|
2308 |
{
|
|
2309 |
_LIT(KFunc, "semaphore create failed with errno %d\n");
|
|
2310 |
INFO_PRINTF2(KFunc, errno);
|
|
2311 |
return KErrGeneral;
|
|
2312 |
}
|
|
2313 |
|
|
2314 |
semctl(semid,2,SETALL,setval);
|
|
2315 |
if(ret1 == -1)
|
|
2316 |
{
|
|
2317 |
_LIT(KFunc, "semaphore SETALL failed with errno %d\n");
|
|
2318 |
INFO_PRINTF2(KFunc, errno);
|
|
2319 |
ret = KErrGeneral;
|
|
2320 |
}
|
|
2321 |
|
|
2322 |
|
|
2323 |
pthread_create(&tid1, NULL, thread1, &semid);
|
|
2324 |
pthread_create(&tid2, NULL, thread2, &semid);
|
|
2325 |
pthread_create(&tid3, NULL, thread3, &semid);
|
|
2326 |
|
|
2327 |
|
|
2328 |
result = semop(semid, &sb[0], 1);
|
|
2329 |
if(result == -1)
|
|
2330 |
{
|
|
2331 |
_LIT(KFunc, "semaphore semop failed with errno %d\n");
|
|
2332 |
INFO_PRINTF2(KFunc, errno);
|
|
2333 |
ret = KErrGeneral;
|
|
2334 |
}
|
|
2335 |
|
|
2336 |
result = semop(semid, &sb1[0], 1);
|
|
2337 |
if(result == -1)
|
|
2338 |
{
|
|
2339 |
_LIT(KFunc, "semaphore semop failed with errno %d\n");
|
|
2340 |
INFO_PRINTF2(KFunc, errno);
|
|
2341 |
ret = KErrGeneral;
|
|
2342 |
}
|
|
2343 |
|
|
2344 |
tmp[0] = 0;
|
|
2345 |
tmp[1] = 5;
|
|
2346 |
|
|
2347 |
if(semctl(semid,2,SETALL,setval))
|
|
2348 |
{
|
|
2349 |
_LIT(KFunc, "semaphore setall failed with errno %d\n");
|
|
2350 |
INFO_PRINTF2(KFunc, errno);
|
|
2351 |
ret = KErrGeneral;
|
|
2352 |
}
|
|
2353 |
|
|
2354 |
if (semctl(semid, 1, IPC_RMID) == -1)
|
|
2355 |
{
|
|
2356 |
_LIT(KFunc, "semaphore delete failed with errno %d\n");
|
|
2357 |
INFO_PRINTF2(KFunc, errno);
|
|
2358 |
ret = KErrGeneral;
|
|
2359 |
}
|
|
2360 |
pthread_join(tid1,NULL);
|
|
2361 |
pthread_join(tid2,NULL);
|
|
2362 |
pthread_join(tid3,NULL);
|
|
2363 |
return ret;
|
|
2364 |
}
|
|
2365 |
|
|
2366 |
|
|
2367 |
TVerdict CTestMisc::TestMaxFopen()
|
|
2368 |
{
|
|
2369 |
SetTestStepResult(EPass);
|
|
2370 |
|
|
2371 |
FILE *fp[1220];
|
|
2372 |
char name[1220] =
|
|
2373 |
{
|
|
2374 |
0
|
|
2375 |
};
|
|
2376 |
int i=0;
|
|
2377 |
mkdir("c:\\Test0", 700);
|
|
2378 |
mkdir("c:\\Test1", 700);
|
|
2379 |
mkdir("c:\\Test2",700);
|
|
2380 |
mkdir("c:\\Test3",700);
|
|
2381 |
mkdir("c:\\Test4",700);
|
|
2382 |
|
|
2383 |
for(i = 0; i < OPEN_MAX; i++)
|
|
2384 |
{
|
|
2385 |
if(i <= 50)
|
|
2386 |
sprintf(name, "%s%d%s", "c://Test0//Hello",i,".txt");
|
|
2387 |
else if (i <= 100)
|
|
2388 |
sprintf(name, "%s%d%s", "c://Test1//Hello",i,".txt");
|
|
2389 |
else if (i <= 150)
|
|
2390 |
sprintf(name, "%s%d%s", "c://Test2//Hello",i,".txt");
|
|
2391 |
else if (i <= 240)
|
|
2392 |
sprintf(name, "%s%d%s", "c://Test3//Hello",i,".txt");
|
|
2393 |
else
|
|
2394 |
sprintf(name, "%s%d%s", "c://Test4//Hello",i,".txt");
|
|
2395 |
errno = 0;
|
|
2396 |
|
|
2397 |
|
|
2398 |
if ((fp [i] = fopen (name, "a")) == NULL)
|
|
2399 |
{
|
|
2400 |
INFO_PRINTF2(_L("Failed to open file number : %d"), i);
|
|
2401 |
INFO_PRINTF2(_L("Error number : %d"), errno);
|
|
2402 |
|
|
2403 |
if(i != (OPEN_MAX-3))
|
|
2404 |
{
|
|
2405 |
SetTestStepResult(EFail);
|
|
2406 |
}
|
|
2407 |
|
|
2408 |
break;
|
|
2409 |
}
|
|
2410 |
|
|
2411 |
}
|
|
2412 |
for(--i; i >=0 ; i--)
|
|
2413 |
{
|
|
2414 |
fclose(fp[i]);
|
|
2415 |
if(i <= 50)
|
|
2416 |
sprintf(name, "%s%d%s", "c://Test0//Hello",i,".txt");
|
|
2417 |
else if (i <= 100)
|
|
2418 |
sprintf(name, "%s%d%s", "c://Test1//Hello",i,".txt");
|
|
2419 |
else if (i <= 150)
|
|
2420 |
sprintf(name, "%s%d%s", "c://Test2//Hello",i,".txt");
|
|
2421 |
else if (i <= 240)
|
|
2422 |
sprintf(name, "%s%d%s", "c://Test3//Hello",i,".txt");
|
|
2423 |
else
|
|
2424 |
sprintf(name, "%s%d%s", "c://Test4//Hello",i,".txt");
|
|
2425 |
unlink(name);
|
|
2426 |
|
|
2427 |
}
|
|
2428 |
rmdir("c:\\Test1");
|
|
2429 |
rmdir("c:\\Test2");
|
|
2430 |
rmdir("c:\\Test3");
|
|
2431 |
rmdir("c:\\Test4");
|
|
2432 |
return TestStepResult();
|
|
2433 |
}
|
|
2434 |
|
|
2435 |
TInt CTestMisc::TestPopen3FdTransfer()
|
|
2436 |
{
|
|
2437 |
int fds[3];
|
|
2438 |
int fd1 = open("C:\\SharedFile.txt",O_CREAT|O_RDWR);
|
|
2439 |
|
|
2440 |
if(fd1 <= 0)
|
|
2441 |
{
|
|
2442 |
INFO_PRINTF1(_L("Error opening SharedFile.txt file"));
|
|
2443 |
return errno;
|
|
2444 |
}
|
|
2445 |
int fd2 = open("C:\\popentest.txt",O_CREAT|O_RDWR);
|
|
2446 |
if(fd2 <= 0)
|
|
2447 |
{
|
|
2448 |
INFO_PRINTF1(_L("Error creating file popentest.txt"));
|
|
2449 |
close(fd1);
|
|
2450 |
return errno;
|
|
2451 |
}
|
|
2452 |
|
|
2453 |
char buf[10];
|
|
2454 |
sprintf(buf,"%d",fd2);
|
|
2455 |
if(write(fd1,buf,strlen(buf)+1) == -1)
|
|
2456 |
{
|
|
2457 |
INFO_PRINTF1(_L("Error writing to SharedFile.txt"));
|
|
2458 |
close(fd1);
|
|
2459 |
close(fd2);
|
|
2460 |
return errno;
|
|
2461 |
}
|
|
2462 |
close(fd1);
|
|
2463 |
int pid,status;
|
|
2464 |
if ((pid=popen3("z:\\sys\\bin\\TPopen3FdTransfer.exe",NULL,environ,fds)) == -1)
|
|
2465 |
{
|
|
2466 |
INFO_PRINTF1(_L("Cant create the process using popen3"));
|
|
2467 |
close(fd2);
|
|
2468 |
return errno;
|
|
2469 |
}
|
|
2470 |
|
|
2471 |
int ret = waitpid(pid, &status, 0);
|
|
2472 |
|
|
2473 |
close(fd2);
|
|
2474 |
INFO_PRINTF2(_L("waitpid return result = %d"), status);
|
|
2475 |
return status;
|
|
2476 |
|
|
2477 |
}
|
|
2478 |
|
|
2479 |
TInt CTestMisc::TestPopenFdTransfer()
|
|
2480 |
{
|
|
2481 |
FILE *fp;
|
|
2482 |
char filename[15];
|
|
2483 |
int tempfd[10];
|
|
2484 |
int fd1 = open("C:\\SharedFile.txt",O_CREAT|O_RDWR);
|
|
2485 |
|
|
2486 |
if(fd1 <= 0)
|
|
2487 |
{
|
|
2488 |
INFO_PRINTF1(_L("Error opening SharedFile.txt file"));
|
|
2489 |
return errno;
|
|
2490 |
}
|
|
2491 |
//open temporary files to check the fd transfer for more than 8 files
|
|
2492 |
for(int i = 1; i<= 10; i++)
|
|
2493 |
{
|
|
2494 |
sprintf(filename,"C:\\temp%d",i);
|
|
2495 |
if((tempfd[i-1] = open(filename,O_CREAT|O_RDWR)) < 0)
|
|
2496 |
{
|
|
2497 |
INFO_PRINTF2(_L("Error opening %s file"),filename);
|
|
2498 |
break;
|
|
2499 |
}
|
|
2500 |
|
|
2501 |
}
|
|
2502 |
|
|
2503 |
int fd2 = open("C:\\popentest.txt",O_CREAT|O_RDWR);
|
|
2504 |
if(fd2 <= 0)
|
|
2505 |
{
|
|
2506 |
INFO_PRINTF1(_L("Error creating file popentest.txt"));
|
|
2507 |
close(fd1);
|
|
2508 |
return errno;
|
|
2509 |
}
|
|
2510 |
|
|
2511 |
char buf[10];
|
|
2512 |
sprintf(buf,"%d",fd2);
|
|
2513 |
if(write(fd1,buf,strlen(buf)+1) == -1)
|
|
2514 |
{
|
|
2515 |
INFO_PRINTF1(_L("Error writing to SharedFile.txt"));
|
|
2516 |
close(fd1);
|
|
2517 |
close(fd2);
|
|
2518 |
return errno;
|
|
2519 |
}
|
|
2520 |
close(fd1);
|
|
2521 |
char mode='r';
|
|
2522 |
if((fp = popen("z:\\sys\\bin\\TPopen3FdTransfer.exe", &mode)) == NULL)
|
|
2523 |
{
|
|
2524 |
INFO_PRINTF1(_L("Cant create the process using popen"));
|
|
2525 |
close(fd2);
|
|
2526 |
return errno;
|
|
2527 |
}
|
|
2528 |
|
|
2529 |
int ret = pclose(fp);
|
|
2530 |
INFO_PRINTF2(_L("pclose return result = %d"), ret);
|
|
2531 |
close(fd2);
|
|
2532 |
|
|
2533 |
for(int i = 1; i<= 10; i++)
|
|
2534 |
{
|
|
2535 |
close(tempfd[i-1]);
|
|
2536 |
}
|
|
2537 |
return ret;
|
|
2538 |
|
|
2539 |
}
|
|
2540 |
|
|
2541 |
TInt CTestMisc::TestSystemFdTransfer()
|
|
2542 |
{
|
|
2543 |
int fd1 = open("C:\\SharedFile.txt",O_CREAT|O_RDWR);
|
|
2544 |
|
|
2545 |
if(fd1 <= 0)
|
|
2546 |
{
|
|
2547 |
INFO_PRINTF1(_L("Error opening SharedFile.txt file"));
|
|
2548 |
return errno;
|
|
2549 |
}
|
|
2550 |
int fd2 = open("C:\\popentest.txt",O_CREAT|O_RDWR);
|
|
2551 |
if(fd2 <= 0)
|
|
2552 |
{
|
|
2553 |
INFO_PRINTF1(_L("Error creating file popentest.txt"));
|
|
2554 |
close(fd1);
|
|
2555 |
return errno;
|
|
2556 |
}
|
|
2557 |
|
|
2558 |
char buf[10];
|
|
2559 |
sprintf(buf,"%d",fd2);
|
|
2560 |
if(write(fd1,buf,strlen(buf)+1) == -1)
|
|
2561 |
{
|
|
2562 |
INFO_PRINTF1(_L("Error writing to SharedFile.txt"));
|
|
2563 |
close(fd1);
|
|
2564 |
close(fd2);
|
|
2565 |
return errno;
|
|
2566 |
}
|
|
2567 |
close(fd1);
|
|
2568 |
int ret;
|
|
2569 |
ret = system("z:\\sys\\bin\\TPopen3FdTransfer.exe");
|
|
2570 |
close(fd2);
|
|
2571 |
INFO_PRINTF2(_L("system return result = %d"), ret);
|
|
2572 |
return ret;
|
|
2573 |
|
|
2574 |
}
|
|
2575 |
|
|
2576 |
TInt CTestMisc::TestPosixSpawnFdTransfer()
|
|
2577 |
{
|
|
2578 |
int fd1 = open("C:\\SharedFile.txt",O_CREAT|O_RDWR);
|
|
2579 |
|
|
2580 |
if(fd1 <= 0)
|
|
2581 |
{
|
|
2582 |
INFO_PRINTF1(_L("Error opening SharedFile.txt file"));
|
|
2583 |
return errno;
|
|
2584 |
}
|
|
2585 |
int fd2 = open("C:\\popentest.txt",O_CREAT|O_RDWR);
|
|
2586 |
if(fd2 <= 0)
|
|
2587 |
{
|
|
2588 |
INFO_PRINTF1(_L("Error creating file popentest.txt"));
|
|
2589 |
close(fd1);
|
|
2590 |
return errno;
|
|
2591 |
}
|
|
2592 |
|
|
2593 |
char buf[10];
|
|
2594 |
sprintf(buf,"%d",fd2);
|
|
2595 |
if(write(fd1,buf,strlen(buf)+1) == -1)
|
|
2596 |
{
|
|
2597 |
INFO_PRINTF1(_L("Error writing to SharedFile.txt"));
|
|
2598 |
close(fd1);
|
|
2599 |
close(fd2);
|
|
2600 |
return errno;
|
|
2601 |
}
|
|
2602 |
close(fd1);
|
|
2603 |
|
|
2604 |
|
|
2605 |
char **argv=(char**)malloc(2*sizeof(char*));
|
|
2606 |
argv[0]=(char*)malloc(40*sizeof(char));
|
|
2607 |
argv[1]= 0;
|
|
2608 |
|
|
2609 |
strcpy(argv[0], "z:\\sys\\bin\\TPopen3FdTransfer.exe");
|
|
2610 |
|
|
2611 |
pid_t pid;
|
|
2612 |
if(posix_spawn(&pid, "z:\\sys\\bin\\TPopen3FdTransfer.exe", NULL, NULL, argv, (char**)NULL))
|
|
2613 |
{
|
|
2614 |
INFO_PRINTF1(_L("Cant create posix_spawn"));
|
|
2615 |
free((void*)argv);
|
|
2616 |
free((void*)argv[0]);
|
|
2617 |
close(fd2);
|
|
2618 |
return -1;
|
|
2619 |
}
|
|
2620 |
TInt status;
|
|
2621 |
waitpid(pid, &status, 0);
|
|
2622 |
|
|
2623 |
close(fd2);
|
|
2624 |
free((void*)argv[0]);
|
|
2625 |
free((void*)argv);
|
|
2626 |
INFO_PRINTF2(_L("waitpid return result = %d"), status);
|
|
2627 |
return status;
|
|
2628 |
|
|
2629 |
}
|
|
2630 |
|
|
2631 |
TInt CTestMisc::TestPopen3PipeReadTransfer()
|
|
2632 |
{
|
|
2633 |
int fds[3];
|
|
2634 |
int fd1 = open("C:\\SharedFile.txt",O_CREAT|O_RDWR);
|
|
2635 |
|
|
2636 |
if(fd1 <= 0)
|
|
2637 |
{
|
|
2638 |
INFO_PRINTF1(_L("Error opening SharedFile.txt file"));
|
|
2639 |
return errno;
|
|
2640 |
}
|
|
2641 |
|
|
2642 |
char filename[15];
|
|
2643 |
int tempfd[10];
|
|
2644 |
|
|
2645 |
for(int i = 1; i<= 10; i++)
|
|
2646 |
{
|
|
2647 |
sprintf(filename,"C:\\temp%d",i);
|
|
2648 |
if((tempfd[i-1] = open(filename,O_CREAT|O_RDWR)) < 0)
|
|
2649 |
{
|
|
2650 |
INFO_PRINTF2(_L("Error opening %s file"),filename);
|
|
2651 |
break;
|
|
2652 |
}
|
|
2653 |
|
|
2654 |
}
|
|
2655 |
int fd[2];
|
|
2656 |
if(pipe(fd) == -1)
|
|
2657 |
{
|
|
2658 |
INFO_PRINTF1(_L("Error creating pipes"));
|
|
2659 |
close(fd1);
|
|
2660 |
return errno;
|
|
2661 |
}
|
|
2662 |
|
|
2663 |
char buf[10];
|
|
2664 |
sprintf(buf,"%d",fd[0]);
|
|
2665 |
if(write(fd1,buf,strlen(buf)+1) == -1)
|
|
2666 |
{
|
|
2667 |
INFO_PRINTF1(_L("Error writing to SharedFile.txt"));
|
|
2668 |
close(fd1);
|
|
2669 |
close(fd[0]),close(fd[1]);
|
|
2670 |
return errno;
|
|
2671 |
}
|
|
2672 |
close(fd1);
|
|
2673 |
int pid,status;
|
|
2674 |
if ((pid=popen3("z:\\sys\\bin\\PipeReadTransfer.exe",NULL,environ,fds)) == -1)
|
|
2675 |
{
|
|
2676 |
INFO_PRINTF1(_L("Cant create the process popen3"));
|
|
2677 |
close(fd[0]),close(fd[1]);
|
|
2678 |
return errno;
|
|
2679 |
}
|
|
2680 |
|
|
2681 |
if(write(fd[1],"testing pipe",12) == -1)
|
|
2682 |
{
|
|
2683 |
INFO_PRINTF1(_L("Error writing to pipe"));
|
|
2684 |
close(fd[0]),close(fd[1]);
|
|
2685 |
return errno;
|
|
2686 |
}
|
|
2687 |
|
|
2688 |
int ret = waitpid(pid, &status, 0);
|
|
2689 |
|
|
2690 |
close(fd[0]),close(fd[1]);
|
|
2691 |
INFO_PRINTF2(_L("waitpid return result = %d"), status);
|
|
2692 |
|
|
2693 |
for(int i = 1; i<= 10; i++)
|
|
2694 |
{
|
|
2695 |
close(tempfd[i-1]);
|
|
2696 |
}
|
|
2697 |
|
|
2698 |
return status;
|
|
2699 |
|
|
2700 |
}
|
|
2701 |
|
|
2702 |
TInt CTestMisc::TestPopenPipeReadTransfer()
|
|
2703 |
{
|
|
2704 |
FILE *fp;
|
|
2705 |
int fd1 = open("C:\\SharedFile.txt",O_CREAT|O_RDWR);
|
|
2706 |
|
|
2707 |
if(fd1 <= 0)
|
|
2708 |
{
|
|
2709 |
INFO_PRINTF1(_L("Error opening SharedFile.txt file"));
|
|
2710 |
return errno;
|
|
2711 |
}
|
|
2712 |
|
|
2713 |
int fd[2];
|
|
2714 |
if(pipe(fd) == -1)
|
|
2715 |
{
|
|
2716 |
INFO_PRINTF1(_L("Error creating pipes"));
|
|
2717 |
close(fd1);
|
|
2718 |
return errno;
|
|
2719 |
}
|
|
2720 |
|
|
2721 |
char buf[10];
|
|
2722 |
sprintf(buf,"%d",fd[0]);
|
|
2723 |
if(write(fd1,buf,strlen(buf)+1) == -1)
|
|
2724 |
{
|
|
2725 |
INFO_PRINTF1(_L("Error writing to SharedFile.txt"));
|
|
2726 |
close(fd1);
|
|
2727 |
close(fd[0]),close(fd[1]);
|
|
2728 |
return errno;
|
|
2729 |
}
|
|
2730 |
close(fd1);
|
|
2731 |
char mode='r';
|
|
2732 |
if((fp = popen("z:\\sys\\bin\\PipeReadTransfer.exe", &mode)) == NULL)
|
|
2733 |
{
|
|
2734 |
INFO_PRINTF1(_L("Cant create process using popen"));
|
|
2735 |
close(fd[0]),close(fd[1]);
|
|
2736 |
return errno;
|
|
2737 |
}
|
|
2738 |
if(write(fd[1],"testing pipe",12) == -1)
|
|
2739 |
{
|
|
2740 |
INFO_PRINTF1(_L("Error writing to pipe"));
|
|
2741 |
close(fd[0]),close(fd[1]);
|
|
2742 |
return errno;
|
|
2743 |
}
|
|
2744 |
|
|
2745 |
int ret = pclose(fp);
|
|
2746 |
INFO_PRINTF2(_L("pclose return result = %d"), ret);
|
|
2747 |
close(fd[0]),close(fd[1]);
|
|
2748 |
return ret;
|
|
2749 |
|
|
2750 |
}
|
|
2751 |
|
|
2752 |
TInt CTestMisc::TestPopen3PipeWriteTransfer()
|
|
2753 |
{
|
|
2754 |
int fds[3];
|
|
2755 |
int fd1 = open("C:\\SharedFile.txt",O_CREAT|O_RDWR);
|
|
2756 |
|
|
2757 |
if(fd1 <= 0)
|
|
2758 |
{
|
|
2759 |
INFO_PRINTF1(_L("Error opening SharedFile.txt file"));
|
|
2760 |
return errno;
|
|
2761 |
}
|
|
2762 |
|
|
2763 |
int fd[2];
|
|
2764 |
if(pipe(fd) == -1)
|
|
2765 |
{
|
|
2766 |
INFO_PRINTF1(_L("Error creating pipes"));
|
|
2767 |
close(fd1);
|
|
2768 |
return errno;
|
|
2769 |
}
|
|
2770 |
|
|
2771 |
char buf[10];
|
|
2772 |
sprintf(buf,"%d",fd[1]);
|
|
2773 |
if(write(fd1,buf,strlen(buf)+1) == -1)
|
|
2774 |
{
|
|
2775 |
INFO_PRINTF1(_L("Error writing to SharedFile.txt"));
|
|
2776 |
close(fd1);
|
|
2777 |
close(fd[0]),close(fd[1]);
|
|
2778 |
return errno;
|
|
2779 |
}
|
|
2780 |
close(fd1);
|
|
2781 |
int pid,status;
|
|
2782 |
if ((pid=popen3("z:\\sys\\bin\\PipeWriteTransfer.exe",NULL,environ,fds)) == -1)
|
|
2783 |
{
|
|
2784 |
INFO_PRINTF1(_L("Can't create process using popen3"));
|
|
2785 |
close(fd[0]),close(fd[1]);
|
|
2786 |
return errno;
|
|
2787 |
}
|
|
2788 |
|
|
2789 |
if(read(fd[0],buf,5) == -1)
|
|
2790 |
{
|
|
2791 |
INFO_PRINTF1(_L("Error reading from pipe"));
|
|
2792 |
close(fd[0]),close(fd[1]);
|
|
2793 |
return errno;
|
|
2794 |
}
|
|
2795 |
|
|
2796 |
int ret = waitpid(pid, &status, 0);
|
|
2797 |
|
|
2798 |
close(fd[0]),close(fd[1]);
|
|
2799 |
INFO_PRINTF2(_L("waitpid return result = %d"), status);
|
|
2800 |
return status;
|
|
2801 |
|
|
2802 |
}
|
|
2803 |
|
|
2804 |
TInt CTestMisc::TestPopenPipeWriteTransfer()
|
|
2805 |
{
|
|
2806 |
FILE *fp;
|
|
2807 |
int fd1 = open("C:\\SharedFile.txt",O_CREAT|O_RDWR);
|
|
2808 |
|
|
2809 |
if(fd1 <= 0)
|
|
2810 |
{
|
|
2811 |
INFO_PRINTF1(_L("Error opening SharedFile.txt file"));
|
|
2812 |
return errno;
|
|
2813 |
}
|
|
2814 |
|
|
2815 |
int fd[2];
|
|
2816 |
if(pipe(fd) == -1)
|
|
2817 |
{
|
|
2818 |
INFO_PRINTF1(_L("Error creating pipes"));
|
|
2819 |
close(fd1);
|
|
2820 |
return errno;
|
|
2821 |
}
|
|
2822 |
|
|
2823 |
char buf[10];
|
|
2824 |
sprintf(buf,"%d",fd[1]);
|
|
2825 |
if(write(fd1,buf,strlen(buf)+1) == -1)
|
|
2826 |
{
|
|
2827 |
INFO_PRINTF1(_L("Error writing to SharedFile.txt"));
|
|
2828 |
close(fd1);
|
|
2829 |
close(fd[0]),close(fd[1]);
|
|
2830 |
return errno;
|
|
2831 |
}
|
|
2832 |
close(fd1);
|
|
2833 |
char mode='r';
|
|
2834 |
if((fp = popen("z:\\sys\\bin\\PipeWriteTransfer.exe", &mode)) == NULL)
|
|
2835 |
{
|
|
2836 |
INFO_PRINTF1(_L("Cant create process using popen"));
|
|
2837 |
close(fd[0]),close(fd[1]);
|
|
2838 |
return errno;
|
|
2839 |
}
|
|
2840 |
|
|
2841 |
if(read(fd[0],buf,5) == -1)
|
|
2842 |
{
|
|
2843 |
INFO_PRINTF1(_L("Error reading from pipe"));
|
|
2844 |
close(fd[0]),close(fd[1]);
|
|
2845 |
return errno;
|
|
2846 |
}
|
|
2847 |
|
|
2848 |
int ret = pclose(fp);
|
|
2849 |
INFO_PRINTF2(_L("pclose return result = %d"), ret);
|
|
2850 |
close(fd[0]),close(fd[1]);
|
|
2851 |
return ret;
|
|
2852 |
|
|
2853 |
}
|
|
2854 |
|
|
2855 |
TVerdict CTestMisc::TestPipeReadWrite()
|
|
2856 |
{
|
|
2857 |
SetTestStepResult(EPass);
|
|
2858 |
int err, fd[2];
|
|
2859 |
const char *bufW = "somesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesome";
|
|
2860 |
char bufR[720];
|
|
2861 |
err = pipe (fd);
|
|
2862 |
if (err < 0)
|
|
2863 |
{
|
|
2864 |
INFO_PRINTF1 (_L("error in creating the pipe\n"));
|
|
2865 |
}
|
|
2866 |
fcntl(fd[1],F_SETFL, O_NONBLOCK);
|
|
2867 |
err = write (fd[1], bufW, strlen (bufW));
|
|
2868 |
if (err < 0)
|
|
2869 |
{
|
|
2870 |
INFO_PRINTF2(_L("error in writing the pipe\n"), err);
|
|
2871 |
}
|
|
2872 |
else
|
|
2873 |
{
|
|
2874 |
INFO_PRINTF1(_L("success in writing\n"));
|
|
2875 |
INFO_PRINTF2 (_L("the returned value is %d\n"), err);
|
|
2876 |
}
|
|
2877 |
|
|
2878 |
fcntl(fd[0],F_SETFL, O_NONBLOCK);
|
|
2879 |
err = read (fd[0], bufR, err);
|
|
2880 |
if (err < 0)
|
|
2881 |
{
|
|
2882 |
INFO_PRINTF2(_L("error in writing the pipe\n"), err);
|
|
2883 |
}
|
|
2884 |
else
|
|
2885 |
{
|
|
2886 |
INFO_PRINTF1(_L("success in reading\n"));
|
|
2887 |
INFO_PRINTF2 (_L("the returned value is %d\n"), err);
|
|
2888 |
}
|
|
2889 |
return TestStepResult();
|
|
2890 |
}
|
|
2891 |
|
|
2892 |
TVerdict CTestMisc::TestFileReadWrite()
|
|
2893 |
{
|
|
2894 |
SetTestStepResult(EPass);
|
|
2895 |
int fd,ret,ret1,fd1;
|
|
2896 |
char *buf = (char*)malloc(688);
|
|
2897 |
char *buf1 = "somesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesomesome";
|
|
2898 |
unlink("c:\\readwrite.txt");
|
|
2899 |
fd = open("c:\\readwrite.txt",O_RDWR|O_CREAT,0666);
|
|
2900 |
fcntl(fd,F_SETFL, O_NONBLOCK);
|
|
2901 |
|
|
2902 |
if (fd > 0)
|
|
2903 |
{
|
|
2904 |
INFO_PRINTF1(_L("success in opening the file\n"));
|
|
2905 |
ret = write(fd,buf1,strlen(buf1)); //works fine in both mode.(acc. to the spec)
|
|
2906 |
if (ret == -1)
|
|
2907 |
{
|
|
2908 |
INFO_PRINTF1(_L("error in writing\n"));
|
|
2909 |
}
|
|
2910 |
else
|
|
2911 |
{
|
|
2912 |
INFO_PRINTF1(_L("success in writing\n"));
|
|
2913 |
INFO_PRINTF2(_L("value returned is %d"),ret);
|
|
2914 |
}
|
|
2915 |
close(fd);
|
|
2916 |
}
|
|
2917 |
fd1 = open("c:\\readwrite.txt",O_RDWR);
|
|
2918 |
if (fd1 >0 )
|
|
2919 |
{
|
|
2920 |
INFO_PRINTF1(_L("success in opening the file for the second time\n"));
|
|
2921 |
ret1 = read(fd1,buf,ret);
|
|
2922 |
if(ret1 == -1)
|
|
2923 |
{
|
|
2924 |
INFO_PRINTF1(_L("error in reading\n"));
|
|
2925 |
}
|
|
2926 |
else
|
|
2927 |
{
|
|
2928 |
INFO_PRINTF1(_L("success in reading\n"));
|
|
2929 |
INFO_PRINTF2(_L("value returned is %d"),ret1);
|
|
2930 |
}
|
|
2931 |
close(fd1);
|
|
2932 |
free(buf);
|
|
2933 |
}
|
|
2934 |
else
|
|
2935 |
{
|
|
2936 |
INFO_PRINTF1(_L("error in opening the file \n"));
|
|
2937 |
}
|
|
2938 |
return TestStepResult();
|
|
2939 |
}
|
|
2940 |
|
|
2941 |
TVerdict CTestMisc::TestTzname()
|
|
2942 |
{
|
|
2943 |
SetTestStepResult(EPass);
|
|
2944 |
int i = -1;
|
|
2945 |
tzname[0] = "symbian";
|
|
2946 |
char * temp = "symbian";
|
|
2947 |
|
|
2948 |
i = strcmp(temp,tzname[0]);
|
|
2949 |
if(i == 0)
|
|
2950 |
SetTestStepResult(EPass);
|
|
2951 |
else
|
|
2952 |
SetTestStepResult(EFail);
|
|
2953 |
|
|
2954 |
return TestStepResult();
|
|
2955 |
}
|
|
2956 |
|
|
2957 |
|
|
2958 |
TVerdict CTestMisc::TestOpenWithExclusiveLock()
|
|
2959 |
{
|
|
2960 |
SetTestStepResult(EPass);
|
|
2961 |
//creating the file for the first time
|
|
2962 |
int fd1 = open("C:\\openexclusivelockfile.txt",O_CREAT|O_RDWR, 0666);
|
|
2963 |
if(fd1 <= 0)
|
|
2964 |
{
|
|
2965 |
INFO_PRINTF1(_L("Error opening openexclusivelockfile.txt file"));
|
|
2966 |
SetTestStepResult(EFail);
|
|
2967 |
}
|
|
2968 |
//writing something into the file
|
|
2969 |
int writeval = write(fd1, "elephant on land", 18);
|
|
2970 |
if(writeval <= 0)
|
|
2971 |
{
|
|
2972 |
INFO_PRINTF1(_L("Error writing into openexclusivelockfile.txt file"));
|
|
2973 |
SetTestStepResult(EFail);
|
|
2974 |
}
|
|
2975 |
//closing the file descriptor
|
|
2976 |
close(fd1);
|
|
2977 |
//re-opening file with O_EXLOCK flag
|
|
2978 |
int fd2 = open("C:\\openexclusivelockfile.txt",O_EXLOCK, 0666);
|
|
2979 |
if(fd2 <= 0)
|
|
2980 |
{
|
|
2981 |
INFO_PRINTF1(_L("Error opening file openexclusivelockfile.txt"));
|
|
2982 |
SetTestStepResult(EFail);
|
|
2983 |
}
|
|
2984 |
//we will spawn an exe which will try to write to the child exe
|
|
2985 |
//and will fail if it tries to write to the locked region
|
|
2986 |
char **argv=(char**)malloc(2*sizeof(char*));
|
|
2987 |
argv[0]=(char*)malloc(50*sizeof(char));
|
|
2988 |
argv[1]= 0;
|
|
2989 |
|
|
2990 |
strcpy(argv[0], "z:\\sys\\bin\\childopenexclusivelock.exe");
|
|
2991 |
|
|
2992 |
pid_t pid;
|
|
2993 |
if(posix_spawn(&pid, "z:\\sys\\bin\\childopenexclusivelock.exe", NULL, NULL, argv, (char**)NULL))
|
|
2994 |
{
|
|
2995 |
INFO_PRINTF1(_L("Cant create posix_spawn"));
|
|
2996 |
free((void*)argv);
|
|
2997 |
free((void*)argv[0]);
|
|
2998 |
close(fd2);
|
|
2999 |
SetTestStepResult(EFail);
|
|
3000 |
}
|
|
3001 |
TInt status;
|
|
3002 |
waitpid(pid, &status, 0);
|
|
3003 |
INFO_PRINTF2(_L("waitpid returns = %d"), WEXITSTATUS(status));
|
|
3004 |
if (WEXITSTATUS(status) == 0)
|
|
3005 |
{
|
|
3006 |
INFO_PRINTF1(_L("child process failed to write into the locked region as expected"));
|
|
3007 |
INFO_PRINTF1(_L("test case passed"));
|
|
3008 |
SetTestStepResult(EPass);
|
|
3009 |
}
|
|
3010 |
else
|
|
3011 |
{
|
|
3012 |
INFO_PRINTF1(_L("test case failed"));
|
|
3013 |
SetTestStepResult(EFail);
|
|
3014 |
}
|
|
3015 |
close(fd2);
|
|
3016 |
free((void*)argv[0]);
|
|
3017 |
free((void*)argv);
|
|
3018 |
unlink("C:\\openexclusivelockfile.txt");
|
|
3019 |
return TestStepResult();
|
|
3020 |
}
|