|
1 // Copyright (c) 1996-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 the License "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 // e32test\bench\t_proc1.cpp |
|
15 // One half of the process relative type test stuff |
|
16 // Overview: |
|
17 // Tests the RProcess class, including tests on the heap, process naming, |
|
18 // process resumption, process creation and shared chunks. |
|
19 // API Information: |
|
20 // RProcess |
|
21 // Details: |
|
22 // - Open a nonexistent process by a process Id and checks for the failure |
|
23 // of finding this process. |
|
24 // - Open a process with invalid name and verify failure results are as expected. |
|
25 // - Test the closing of processes by calling Kill, Terminate, and Panic methods. |
|
26 // Verify results are as expected. |
|
27 // - Create a process and verify the full path name of the loaded executable on |
|
28 // which this process is based. |
|
29 // - Open a process by name, rename the process in a variety of ways and verify |
|
30 // the results are as expected. |
|
31 // - Open a process, assign high, low, and bad priorities, verify the results |
|
32 // are as expected. |
|
33 // - Open a process, kill it and verify the results are as expected. |
|
34 // - Open a process by name based on the file name, verify the results are as |
|
35 // expected. |
|
36 // - Retrieve the process Id and open a handle on it. Create a duplicate process. |
|
37 // Verify the results are as expected. |
|
38 // - Find a process using TFindProcess() and open a handle on it. Verify the |
|
39 // results are as expected. |
|
40 // - Check chunk sharing between threads and verify results are as expected. |
|
41 // - Perform a "speed" test where a new thread is created and the thread increments |
|
42 // a count until stopped. Calculate and display counts per second. Verify results |
|
43 // are as expected. |
|
44 // - Verify the ExitReason, ExitType and ExitCatagory when the thread dies. |
|
45 // - Verify that stopping the process completes existing pending requests with |
|
46 // KErrServerTerminated. |
|
47 // - Verify that the heap was not corrupted by the tests. |
|
48 // Platforms/Drives/Compatibility: |
|
49 // All. |
|
50 // Assumptions/Requirement/Pre-requisites: |
|
51 // Failures and causes: |
|
52 // Base Port information: |
|
53 // |
|
54 // |
|
55 |
|
56 #include <e32test.h> |
|
57 #include "../mmu/mmudetect.h" |
|
58 #include "t_proc.h" |
|
59 |
|
60 LOCAL_D RTest test(_L("T_PROC1")); |
|
61 |
|
62 const TBufC<67> tooLong=_L("This should return KErrBadName and not crash.......0123456789ABCDEF"); |
|
63 const TBufC<66> notQuiteTooLong=_L("This should return KErrNone and be completely OK..0123456789ABCDEF"); |
|
64 const TBufC<26> bond=_L("Bond, James Bond[00000000]"); |
|
65 const TBufC<16> jamesBond=_L("Bond, James Bond"); |
|
66 |
|
67 RProcess proc; |
|
68 RProcess proc2; |
|
69 RProcess proc3; |
|
70 RProcess proc4; |
|
71 |
|
72 TName command; |
|
73 TRequestStatus stat,notStat; |
|
74 |
|
75 const TInt KKillReason=2563453; |
|
76 const TInt KTerminateReason=8034255; |
|
77 const TInt KPanicReason=39365235; |
|
78 |
|
79 LOCAL_D RSemaphore client; |
|
80 LOCAL_D TInt speedCount; |
|
81 |
|
82 class RDisplay : public RSessionBase |
|
83 { |
|
84 public: |
|
85 TInt Open(); |
|
86 TInt Display(const TDesC& aMessage); |
|
87 TInt Read(); |
|
88 TInt Write(); |
|
89 TInt Stop(); |
|
90 TInt Test(); |
|
91 TVersion Version(); |
|
92 }; |
|
93 |
|
94 TInt RDisplay::Open() |
|
95 // |
|
96 // Open the server. |
|
97 // |
|
98 { |
|
99 |
|
100 return(CreateSession(_L("Display"),Version(),1)); |
|
101 } |
|
102 |
|
103 TInt RDisplay::Display(const TDesC& aMessage) |
|
104 // |
|
105 // Display a message. |
|
106 // |
|
107 { |
|
108 |
|
109 TBuf<0x10> b(aMessage); |
|
110 return(SendReceive(CMyServer::EDisplay,TIpcArgs(&b))); |
|
111 } |
|
112 |
|
113 TInt RDisplay::Read() |
|
114 // |
|
115 // Get session to test CSession2::ReadL. |
|
116 // |
|
117 { |
|
118 |
|
119 TBuf<0x10> b(_L("Testing read")); |
|
120 return(SendReceive(CMyServer::ERead,TIpcArgs(&b))); |
|
121 } |
|
122 |
|
123 TInt RDisplay::Write() |
|
124 // |
|
125 // Get session to test CSession2::WriteL. |
|
126 // |
|
127 { |
|
128 |
|
129 TBuf<0x10> b; |
|
130 TBufC<0x10> c; // Bad descriptor - read only |
|
131 TInt r=SendReceive(CMyServer::EWrite,TIpcArgs(&b,&c)); |
|
132 if (r==KErrNone && b!=_L("It worked!")) |
|
133 r=KErrGeneral; |
|
134 return r; |
|
135 } |
|
136 |
|
137 TInt RDisplay::Test() |
|
138 // |
|
139 // Send a message and wait for completion. |
|
140 // |
|
141 { |
|
142 |
|
143 TInt i[4]; |
|
144 return(SendReceive(CMyServer::ETest,TIpcArgs(&i[0]))); |
|
145 } |
|
146 |
|
147 TInt RDisplay::Stop() |
|
148 // |
|
149 // Stop the server. |
|
150 // |
|
151 { |
|
152 |
|
153 TInt i[4]; |
|
154 return(SendReceive(CMyServer::EStop,TIpcArgs(&i[0]))); |
|
155 } |
|
156 |
|
157 TVersion RDisplay::Version() |
|
158 // |
|
159 // Return the current version. |
|
160 // |
|
161 { |
|
162 |
|
163 TVersion v(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); |
|
164 return(v); |
|
165 } |
|
166 |
|
167 LOCAL_C TInt RunPanicThread(RThread& aThread) |
|
168 { |
|
169 TRequestStatus s; |
|
170 aThread.Logon(s); |
|
171 TBool jit = User::JustInTime(); |
|
172 User::SetJustInTime(EFalse); |
|
173 aThread.Resume(); |
|
174 User::WaitForRequest(s); |
|
175 User::SetJustInTime(jit); |
|
176 return s.Int(); |
|
177 } |
|
178 |
|
179 TInt KillProtectedEntry(TAny*) |
|
180 { |
|
181 proc.Kill(KErrGeneral); |
|
182 return KErrGeneral; |
|
183 } |
|
184 |
|
185 TInt createProc2(RProcess& aProcess) |
|
186 { |
|
187 TFileName filename(RProcess().FileName()); |
|
188 TInt pos=filename.LocateReverse(TChar('\\')); |
|
189 filename.SetLength(pos+1); |
|
190 filename+=_L("T_PROC2.EXE"); |
|
191 TInt r=aProcess.Create(filename, command); |
|
192 if (r==KErrNone) |
|
193 { |
|
194 TFullName fn(aProcess.FullName()); |
|
195 test.Printf(_L("Created %S\n"),&fn); |
|
196 } |
|
197 return r; |
|
198 } |
|
199 |
|
200 void simpleTests1() |
|
201 { |
|
202 test.Next(_L("Open by name")); |
|
203 RProcess me; |
|
204 TInt r=proc2.Open(me.Name()); |
|
205 test(r==KErrNone); |
|
206 test.Next(_L("Rename")); |
|
207 TName initName(me.Name()); |
|
208 r=User::RenameProcess(jamesBond); |
|
209 test(r==KErrNone); |
|
210 test(me.Name().Left(26)==bond); |
|
211 test(proc2.Name().Left(26)==bond); |
|
212 r=User::RenameProcess(tooLong); |
|
213 test(r==KErrBadName); |
|
214 test(me.Name().Left(26)==bond); |
|
215 test(proc2.Name().Left(26)==bond); |
|
216 TName* work=new TName(notQuiteTooLong); |
|
217 r=User::RenameProcess(*work); |
|
218 test(r==KErrNone); |
|
219 work->Append(_L("[00000000]")); |
|
220 test(me.Name().Length()==KMaxKernelName); |
|
221 test(me.Name().Left(KMaxKernelName-4)==*work); |
|
222 test(proc2.Name().Length()==KMaxKernelName); |
|
223 test(proc2.Name().Left(KMaxKernelName-4)==*work); |
|
224 delete work; |
|
225 r=User::RenameProcess(_L("T_PROC1")); |
|
226 test(r==KErrNone); |
|
227 TFullName fn(_L("T_PROC1[")); |
|
228 TUidType uidType(me.Type()); |
|
229 TUint32 uid3 = uidType[2].iUid; |
|
230 fn.AppendNumFixedWidth(uid3,EHex,8); |
|
231 fn.Append(']'); |
|
232 test(proc2.Name().Left(17)==fn); |
|
233 test(me.Name().Left(17)==fn); |
|
234 TInt l = initName.Locate('['); |
|
235 r=User::RenameProcess(initName.Left(l)); |
|
236 test(r==KErrNone); |
|
237 test(proc2.Name()==initName); |
|
238 proc2.Close(); |
|
239 } |
|
240 |
|
241 TInt BadPriority(TAny* proc2) |
|
242 { |
|
243 ((RProcess*)proc2)->SetPriority(EPriorityWindowServer); |
|
244 return KErrNone; |
|
245 } |
|
246 |
|
247 void simpleTests2() |
|
248 { |
|
249 TInt r=proc2.Open(proc.Name()); |
|
250 test.Next(_L("Mess with Priority")); |
|
251 proc.SetPriority(EPriorityHigh); |
|
252 test.Printf(_L("%d %d\n"),proc.Priority(),proc2.Priority()); |
|
253 test(proc.Priority()==EPriorityHigh); |
|
254 test(proc2.Priority()==EPriorityHigh); |
|
255 proc2.SetPriority(EPriorityLow); |
|
256 test(proc.Priority()==EPriorityLow); |
|
257 test(proc2.Priority()==EPriorityLow); |
|
258 |
|
259 RThread thread; |
|
260 r=thread.Create(_L("Bad Priority"),BadPriority,KDefaultStackSize,NULL,&proc2); |
|
261 test(r==KErrNone); |
|
262 r=RunPanicThread(thread); |
|
263 test(r==EBadPriority); |
|
264 test(thread.ExitType()==EExitPanic); |
|
265 test(thread.ExitReason()==EBadPriority); |
|
266 test(thread.ExitCategory()==_L("KERN-EXEC")); |
|
267 CLOSE_AND_WAIT(thread); |
|
268 test(proc.Priority()==EPriorityLow); |
|
269 test(proc2.Priority()==EPriorityLow); |
|
270 proc2.Close(); |
|
271 } |
|
272 |
|
273 void procTests1() |
|
274 { |
|
275 test.Next(_L("Test functions")); |
|
276 TFileName fileName(proc.FileName()); |
|
277 test.Printf(fileName); |
|
278 #ifndef __WINS__ |
|
279 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)) |
|
280 test(fileName.Mid(1).CompareF(_L(":\\Sys\\Bin\\T_PROC2.EXE"))==0); |
|
281 else |
|
282 test(fileName.Mid(1).CompareF(_L(":\\System\\Bin\\T_PROC2.EXE"))==0); |
|
283 #else |
|
284 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin)) |
|
285 test(fileName.CompareF(_L("Z:\\Sys\\Bin\\T_PROC2.EXE"))==0); |
|
286 else |
|
287 test(fileName.CompareF(_L("Z:\\System\\Bin\\T_PROC2.EXE"))==0); |
|
288 #endif |
|
289 test(proc.Name().Left(21).CompareF(_L("T_PROC2.EXE[00000000]"))==0); |
|
290 test(proc.Priority()==EPriorityForeground); |
|
291 test(proc.ExitType()==EExitPending); |
|
292 test(proc.ExitReason()==0); |
|
293 test(proc.ExitCategory()==KNullDesC); |
|
294 } |
|
295 |
|
296 void procTests2() |
|
297 { |
|
298 test.Next(_L("Kill and recreate")); |
|
299 RProcess proc2; |
|
300 TInt r=proc2.Open(proc.Id()); |
|
301 test(r==KErrNone); |
|
302 test(proc2.Handle()!=0); |
|
303 proc.Logon(stat); |
|
304 proc.Logon(notStat); |
|
305 r=proc.LogonCancel(notStat); |
|
306 test(r==KErrNone); |
|
307 test(notStat==KErrNone); |
|
308 proc.Kill(KKillReason); |
|
309 User::WaitForRequest(stat); |
|
310 test(stat==KKillReason); |
|
311 test(proc.ExitType()==EExitKill); |
|
312 test(proc.ExitReason()==KKillReason); |
|
313 test(proc.ExitCategory()==_L("Kill")); |
|
314 proc.Close(); |
|
315 test(proc.Handle()==0); |
|
316 test(proc2.ExitType()==EExitKill); |
|
317 test(proc2.ExitReason()==KKillReason); |
|
318 test(proc2.ExitCategory()==_L("Kill")); |
|
319 CLOSE_AND_WAIT(proc2); |
|
320 test(proc2.Handle()==0); |
|
321 } |
|
322 |
|
323 void procTests3() |
|
324 { |
|
325 TFileName filename(RProcess().FileName()); |
|
326 TInt pos=filename.LocateReverse(TChar('\\')); |
|
327 filename.SetLength(pos+1); |
|
328 filename+=_L("T_PROC2.EXE"); |
|
329 TInt r=proc.Create(filename, command); |
|
330 test(r==KErrNone); |
|
331 TFullName fn(proc.FullName()); |
|
332 test.Printf(_L("Created %S\n"),&fn); |
|
333 test(proc.FileName().CompareF(filename)==0); |
|
334 test(proc.Name().Left(21).CompareF(_L("T_PROC2.EXE[00000000]"))==0); |
|
335 test(proc.Priority()==EPriorityForeground); |
|
336 test(proc.ExitType()==EExitPending); |
|
337 test(proc.ExitReason()==0); |
|
338 test(proc.ExitCategory()==KNullDesC); |
|
339 } |
|
340 |
|
341 void procTests4() |
|
342 { |
|
343 test.Next(_L("Get and open by Id")); |
|
344 TProcessId id=proc.Id(); |
|
345 TProcessId id2=proc.Id(); |
|
346 test(id==id2); |
|
347 TInt r=proc2.Open(proc.Name()); |
|
348 test(r==KErrNone); |
|
349 id2=proc2.Id(); |
|
350 test(id==id2); |
|
351 r=proc3.Open(id); |
|
352 test(r==KErrNone); |
|
353 id2=proc3.Id(); |
|
354 test(id==id2); |
|
355 proc3.Close(); |
|
356 if (HaveVirtMem()) |
|
357 { |
|
358 test.Next(_L("Create duplicate")); |
|
359 r=createProc2(proc3); |
|
360 test(r==KErrNone); |
|
361 id2=proc3.Id(); |
|
362 test(id!=id2); |
|
363 test(*(TUint*)&id<*(TUint*)&id2); |
|
364 } |
|
365 } |
|
366 |
|
367 void procTests5() |
|
368 { |
|
369 test.Next(_L("Try to find processes")); |
|
370 TFindProcess* findProc=new TFindProcess(_L("T_PROC2*")); |
|
371 test(findProc!=NULL); |
|
372 TFullName* result=new TFullName; |
|
373 test(result!=NULL); |
|
374 TInt r=findProc->Next(*result); |
|
375 test(r==KErrNone); |
|
376 TFullName temp = proc.FullName(); |
|
377 test(result->CompareF(temp)==0); |
|
378 r=findProc->Next(*result); |
|
379 test(r==KErrNone); |
|
380 test(result->CompareF(proc3.FullName())==0); |
|
381 r=findProc->Next(*result); |
|
382 test(r==KErrNotFound); |
|
383 findProc->Find(_L("T?PROC2*]*")); |
|
384 r=findProc->Next(*result); |
|
385 test(r==KErrNone); |
|
386 test(result->CompareF(temp)==0); |
|
387 r=findProc->Next(*result); |
|
388 test(r==KErrNone); |
|
389 test(result->CompareF(proc3.FullName())==0); |
|
390 delete result; |
|
391 test.Next(_L("Open by find handle")); |
|
392 r=proc4.Open(*findProc); |
|
393 test(r==KErrNone); |
|
394 TProcessId id=proc3.Id(); |
|
395 TProcessId id2=proc4.Id(); |
|
396 test(id==id2); |
|
397 delete findProc; |
|
398 } |
|
399 |
|
400 void procTests6() |
|
401 { |
|
402 test.Next(_L("Kill duplicate")); |
|
403 proc3.Logon(stat); |
|
404 test(stat==KRequestPending); |
|
405 proc4.Kill(12345); |
|
406 User::WaitForRequest(stat); |
|
407 test(stat==12345); |
|
408 } |
|
409 |
|
410 void createProcess() |
|
411 // |
|
412 // Create T_PROC2 and, on the way, do lots of basic tests |
|
413 // |
|
414 { |
|
415 test.Start(_L("Create")); |
|
416 TInt r=globSem1.CreateGlobal(_L("GlobSem1"), 0); |
|
417 test(r==KErrNone); |
|
418 r=globSem2.CreateGlobal(_L("GlobSem2"), 0); |
|
419 test(r==KErrNone); |
|
420 |
|
421 r=createProc2(proc); |
|
422 test(r==KErrNone); |
|
423 |
|
424 procTests1(); |
|
425 |
|
426 simpleTests1(); |
|
427 simpleTests2(); |
|
428 |
|
429 procTests2(); |
|
430 procTests3(); |
|
431 procTests4(); |
|
432 if (HaveVirtMem()) |
|
433 { |
|
434 procTests5(); |
|
435 procTests6(); |
|
436 } |
|
437 |
|
438 proc2.Close(); |
|
439 proc3.Close(); |
|
440 if (proc4.Handle()) |
|
441 CLOSE_AND_WAIT(proc4); |
|
442 |
|
443 test.Next(_L("Resume")); |
|
444 proc.Logon(stat); // logon to process |
|
445 proc.Logon(notStat); |
|
446 r=proc.LogonCancel(notStat); |
|
447 test(r==KErrNone); |
|
448 test(notStat==KErrNone); |
|
449 test(proc.ExitType()==EExitPending); |
|
450 proc.Resume(); |
|
451 globSem1.Wait(); // wait for T_PROC2 to get started |
|
452 test.End(); |
|
453 } |
|
454 |
|
455 void murderProcess() |
|
456 { |
|
457 test.Start(_L("Kill")); |
|
458 RProcess process; |
|
459 TInt r=createProc2(process); |
|
460 test(r==KErrNone); |
|
461 TProcessId id=process.Id(); |
|
462 TProcessId id2=process.Id(); |
|
463 test(id==id2); |
|
464 TRequestStatus stat; |
|
465 process.Logon(stat); |
|
466 test(process.ExitType()==EExitPending); |
|
467 process.Kill(KKillReason); |
|
468 User::WaitForRequest(stat); |
|
469 test(stat==KKillReason); |
|
470 test(process.ExitType()==EExitKill); |
|
471 test(process.ExitReason()==KKillReason); |
|
472 test(process.ExitCategory()==_L("Kill")); |
|
473 CLOSE_AND_WAIT(process); |
|
474 |
|
475 test.Next(_L("Terminate")); |
|
476 r=createProc2(process); |
|
477 test(r==KErrNone); |
|
478 id2=process.Id(); |
|
479 test(*(TUint*)&id+2==*(TUint*)&id2); // use 2 ID's each time, one for process, one for thread |
|
480 process.Logon(stat); |
|
481 test(process.ExitType()==EExitPending); |
|
482 process.Terminate(KTerminateReason); |
|
483 User::WaitForRequest(stat); |
|
484 test(stat==KTerminateReason); |
|
485 test(process.ExitType()==EExitTerminate); |
|
486 test(process.ExitReason()==KTerminateReason); |
|
487 test(process.ExitCategory()==_L("Terminate")); |
|
488 CLOSE_AND_WAIT(process); |
|
489 |
|
490 test.Next(_L("Panic")); |
|
491 r=createProc2(process); |
|
492 test(r==KErrNone); |
|
493 id2=process.Id(); |
|
494 test(*(TUint*)&id+4==*(TUint*)&id2); |
|
495 test(process.ExitType()==EExitPending); |
|
496 process.Logon(stat); |
|
497 process.SetJustInTime(EFalse); // prevent the process panic from starting the debugger |
|
498 process.Panic(_L("BOO!"),KPanicReason); |
|
499 User::WaitForRequest(stat); |
|
500 test(stat==KPanicReason); |
|
501 test(process.ExitType()==EExitPanic); |
|
502 test(process.ExitReason()==KPanicReason); |
|
503 test(process.ExitCategory()==_L("BOO!")); |
|
504 CLOSE_AND_WAIT(process); |
|
505 test.End(); |
|
506 } |
|
507 |
|
508 void sharedChunks() |
|
509 { |
|
510 test.Start(_L("Test chunk sharing between threads")); |
|
511 |
|
512 test.Next(_L("Create chunk Marmalade")); |
|
513 TInt r=0; |
|
514 RChunk chunk; |
|
515 TInt size=0x1000; |
|
516 TInt maxSize=0x5000; |
|
517 r=chunk.CreateGlobal(_L("Marmalade"),size,maxSize); |
|
518 test(r==KErrNone); |
|
519 test.Next(_L("Write 0-9 to it")); |
|
520 TUint8* base=chunk.Base(); |
|
521 for (TInt8 j=0;j<10;j++) |
|
522 *base++=j; // write 0 - 9 to the chunk |
|
523 globSem2.Signal(); // T_PROC2 can check the chunk now |
|
524 globSem1.Wait(); |
|
525 chunk.Close(); // now it's ok to kill the chunk |
|
526 |
|
527 test.End(); |
|
528 } |
|
529 |
|
530 TInt sharedChunks2(TAny* /*aDummy*/) |
|
531 { |
|
532 RTest test(_L("Shared Chunks 2")); |
|
533 |
|
534 test.Title(); |
|
535 test.Start(_L("Test chunk sharing between threads")); |
|
536 |
|
537 test.Next(_L("Create chunk Marmalade")); |
|
538 TInt r=0; |
|
539 RChunk chunk; |
|
540 TInt size=0x1000; |
|
541 TInt maxSize=0x5000; |
|
542 r=chunk.CreateGlobal(_L("Marmalade"),size,maxSize); |
|
543 test(r==KErrNone); |
|
544 test.Next(_L("Write 0-9 to it")); |
|
545 TUint8* base=chunk.Base(); |
|
546 for (TInt8 j=0;j<10;j++) |
|
547 *base++=j; // write 0 - 9 to the chunk |
|
548 globSem2.Signal(); // T_PROC2 can check the chunk now |
|
549 globSem1.Wait(); |
|
550 chunk.Close(); // now it's ok to kill the chunk |
|
551 |
|
552 test.End(); |
|
553 return(KErrNone); |
|
554 } |
|
555 |
|
556 TInt speedyThreadEntryPoint(TAny*) |
|
557 // |
|
558 // The entry point for the speed test thread. |
|
559 // |
|
560 { |
|
561 RDisplay t; |
|
562 TInt r=t.Open(); |
|
563 test(r==KErrNone); |
|
564 speedCount=0; |
|
565 client.Signal(); |
|
566 while ((r=t.Test())==KErrNone) |
|
567 speedCount++; |
|
568 t.Close(); |
|
569 return r; |
|
570 } |
|
571 |
|
572 TInt BadName(TAny*) |
|
573 { |
|
574 proc.Open(_L("*")); |
|
575 return KErrNone; |
|
576 } |
|
577 |
|
578 TInt sharedHeap(TAny*) |
|
579 { |
|
580 RTest test2(_L("sharedHeap")); |
|
581 test2.Title(); |
|
582 test2.Start(_L("Shared heap tests")); |
|
583 |
|
584 RAllocator* allocator = &User::Allocator(); |
|
585 test2.Printf(_L("sharedHeap's heap is at %08x\n"), allocator); |
|
586 |
|
587 TInt size; |
|
588 allocator->AllocSize(size); |
|
589 test2.Printf(_L("sharedHeap's heap allocsize is %08x\n"),size); |
|
590 |
|
591 // Press a key only if running the test in manual mode. We will be |
|
592 // able to ascertain this when RTest has been enhanced. |
|
593 // test.Next(_L("Press a key to continue")); |
|
594 // test2.Getch(); |
|
595 |
|
596 test2.End(); |
|
597 return(KErrNone); |
|
598 } |
|
599 |
|
600 _LIT(KTestProcessNewName,"T_PROC1_NEW.EXE"); |
|
601 |
|
602 TInt DupRenameProcTest(TInt aCall) |
|
603 { |
|
604 test.Printf(_L("DupRenameProcTest: call %d\n"),aCall); |
|
605 |
|
606 TInt r; |
|
607 |
|
608 switch(aCall) |
|
609 { |
|
610 case 1: |
|
611 { |
|
612 r = User::RenameProcess(KTestProcessNewName); |
|
613 test(r==KErrNone); |
|
614 TFullName fn(RProcess().FullName()); |
|
615 test.Printf(_L("Renamed to %S\n"),&fn); |
|
616 TInt li = fn.Locate('['); |
|
617 TInt ri = fn.Locate(']'); |
|
618 test(fn.Left(li)==KTestProcessNewName); |
|
619 test(fn.Mid(ri+1)==_L("0001")); |
|
620 } |
|
621 |
|
622 case 0: |
|
623 { |
|
624 TFileName filename(RProcess().FileName()); |
|
625 TInt pos=filename.LocateReverse(TChar('\\')); |
|
626 filename.SetLength(pos+1); |
|
627 filename+=_L("T_PROC1.EXE"); |
|
628 RProcess pr; |
|
629 TBuf16<10> call; |
|
630 call.Num(aCall+1); |
|
631 r = pr.Create(filename, call); |
|
632 TFullName fn(pr.FullName()); |
|
633 test.Printf(_L("Created %S\n"),&fn); |
|
634 TRequestStatus st; |
|
635 pr.Logon(st); |
|
636 pr.Resume(); |
|
637 User::WaitForRequest(st); |
|
638 CLOSE_AND_WAIT(pr); |
|
639 } |
|
640 return KErrNone; |
|
641 |
|
642 case 2: |
|
643 { |
|
644 r = User::RenameProcess(KTestProcessNewName); |
|
645 test(r==KErrNone); |
|
646 TFullName fn(RProcess().FullName()); |
|
647 test.Printf(_L("Renamed to %S\n"),&fn); |
|
648 TInt li = fn.Locate('['); |
|
649 TInt ri = fn.Locate(']'); |
|
650 test(fn.Left(li)==KTestProcessNewName); |
|
651 test(fn.Mid(ri+1)==_L("0002")); |
|
652 } |
|
653 return KErrNone; |
|
654 |
|
655 default: |
|
656 return KErrArgument; |
|
657 } |
|
658 } |
|
659 |
|
660 _LIT(KTestProcessName,"TestName"); |
|
661 |
|
662 void TestProcessRename() |
|
663 { |
|
664 // Rename the current process with test name |
|
665 TInt r = User::RenameProcess(KTestProcessName); |
|
666 test(r==KErrNone); |
|
667 TName name1 = RProcess().Name(); |
|
668 |
|
669 // Check new name is correct |
|
670 TName name2 = name1; |
|
671 name2.SetLength(KTestProcessName().Length()); |
|
672 test(name2.CompareF(KTestProcessName)==0); |
|
673 |
|
674 // Rename the process with same test name |
|
675 r = User::RenameProcess(KTestProcessName); |
|
676 test(r==KErrNone); |
|
677 name2 = RProcess().Name(); |
|
678 test(name1.Compare(name2)==0); // name should be unchanged |
|
679 } |
|
680 |
|
681 TInt E32Main() |
|
682 { |
|
683 __KHEAP_MARK; |
|
684 |
|
685 // Turn off lazy dll unloading |
|
686 RLoader l; |
|
687 test(l.Connect()==KErrNone); |
|
688 test(l.CancelLazyDllUnload()==KErrNone); |
|
689 l.Close(); |
|
690 |
|
691 TBuf16<512> cmd; |
|
692 User::CommandLine(cmd); |
|
693 if(cmd.Length() && TChar(cmd[0]).IsDigit()) |
|
694 { |
|
695 TInt r = DupRenameProcTest(TUint(TChar(cmd[0])) - '0'); |
|
696 test(r==KErrNone); |
|
697 return 0; |
|
698 } |
|
699 |
|
700 test.Title(); |
|
701 |
|
702 test.Start(_L("Testing process stuff 1")); |
|
703 TInt r; |
|
704 TRequestStatus s; |
|
705 test.Next(_L("Creating semaphore")); |
|
706 r=client.CreateLocal(0); |
|
707 test(r==KErrNone); |
|
708 |
|
709 test.Next(_L("Try to open nonexistant process by ID")); |
|
710 r=proc.Open(*(TProcessId*)&KMaxTUint); |
|
711 test(r==KErrNotFound); |
|
712 |
|
713 test.Next(_L("Try to open process with invalid name")); |
|
714 RThread thread; |
|
715 r=thread.Create(_L("Bad Name"),BadName,KDefaultStackSize,NULL,NULL); |
|
716 test(r==KErrNone); |
|
717 TRequestStatus threadStat; |
|
718 thread.Logon(threadStat); |
|
719 TBool justInTime=User::JustInTime(); |
|
720 User::SetJustInTime(EFalse); |
|
721 thread.Resume(); |
|
722 User::WaitForRequest(threadStat); |
|
723 User::SetJustInTime(justInTime); |
|
724 test(threadStat==EBadName); |
|
725 test(thread.ExitType()==EExitPanic); |
|
726 test(thread.ExitReason()==EBadName); |
|
727 test(thread.ExitCategory()==_L("KERN-EXEC")); |
|
728 CLOSE_AND_WAIT(thread); |
|
729 |
|
730 test.Next(_L("Murder processes in different ways")); |
|
731 murderProcess(); |
|
732 |
|
733 test.Next(_L("Create second process")); |
|
734 createProcess(); |
|
735 |
|
736 test.Next(_L("Shared Chunks from main thread")); |
|
737 sharedChunks(); |
|
738 |
|
739 test.Next(_L("Shared chunks from secondary thread")); |
|
740 RThread t; |
|
741 r=t.Create(_L("Shared chunks 2"),sharedChunks2,KDefaultStackSize,KHeapSize,KHeapSize,NULL); |
|
742 test(r==KErrNone); |
|
743 t.Logon(s); |
|
744 t.Resume(); |
|
745 User::WaitForRequest(s); |
|
746 test(s==KErrNone); |
|
747 CLOSE_AND_WAIT(t); |
|
748 |
|
749 test.Next(_L("Starting speedy client")); |
|
750 RThread speedy; |
|
751 r=speedy.Create(_L("Speedy"),speedyThreadEntryPoint,KDefaultStackSize,KHeapSize,KHeapSize,NULL); |
|
752 test(r==KErrNone); |
|
753 |
|
754 RThread().SetPriority(EPriorityMuchMore); |
|
755 speedy.SetPriority(EPriorityNormal); |
|
756 TRequestStatus speedyStatus; |
|
757 speedy.Logon(speedyStatus); |
|
758 speedy.Resume(); |
|
759 |
|
760 test.Next(_L("Wait for speedy to start")); |
|
761 client.Wait(); |
|
762 |
|
763 globSem1.Wait(); // wait for proc2 to be nice & quiet |
|
764 test.Printf(_L("Starting speed test...\n")); |
|
765 User::After(300000); |
|
766 TInt b=speedCount; |
|
767 User::After(3000000); |
|
768 TInt n=speedCount; |
|
769 test.Printf(_L("Count = %d in 1 second\n"),(n-b)/3); |
|
770 |
|
771 test.Next(_L("Tell second process speed tests are done")); |
|
772 globSem2.Signal(); |
|
773 |
|
774 test.Next(_L("Process Logon")); |
|
775 User::WaitForRequest(stat); |
|
776 const TDesC& cat=proc.ExitCategory(); |
|
777 test.Printf(_L("Exit category = %S\n"),&cat); |
|
778 test.Printf(_L("Exit reason = %x\n"),proc.ExitReason()); |
|
779 test.Printf(_L("Exit type = %x\n"),proc.ExitType()); |
|
780 |
|
781 test(stat==KErrNone); |
|
782 test(proc.ExitCategory()==_L("Kill")); |
|
783 test(proc.ExitReason()==KErrNone); |
|
784 test(proc.ExitType()==EExitKill); |
|
785 test(notStat==KErrNone); |
|
786 test.Next(_L("Test LogonCancel to dead process is ok")); |
|
787 r=proc.LogonCancel(stat); |
|
788 test(r==KErrGeneral); |
|
789 globSem1.Close(); |
|
790 globSem2.Close(); |
|
791 client.Close(); |
|
792 |
|
793 User::WaitForRequest(speedyStatus); |
|
794 test(speedyStatus==KErrServerTerminated); |
|
795 test(speedy.ExitReason()==KErrServerTerminated); |
|
796 test(speedy.ExitType()==EExitKill); |
|
797 CLOSE_AND_WAIT(speedy); |
|
798 CLOSE_AND_WAIT(proc); |
|
799 |
|
800 User::After(5000000); // wait for MMC session to disappear |
|
801 |
|
802 test.Next(_L("Test rename of the processes with duplicate names")); |
|
803 r = DupRenameProcTest(0); |
|
804 test(r==KErrNone); |
|
805 |
|
806 TestProcessRename(); |
|
807 |
|
808 test.Next(_L("Check for kernel alloc heaven")); |
|
809 __KHEAP_MARKEND; |
|
810 |
|
811 test.End(); |
|
812 |
|
813 return(KErrNone); |
|
814 } |
|
815 |
|
816 |