|
1 // Copyright (c) 1997-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\thread\t_killer.cpp |
|
15 // Derived from T_MESSGE, tests threads killing each other, not cleaning up etc. |
|
16 // |
|
17 // |
|
18 |
|
19 |
|
20 #include <e32std.h> |
|
21 #include <e32std_private.h> |
|
22 #include <e32math.h> |
|
23 #include <e32test.h> |
|
24 #include <e32panic.h> |
|
25 |
|
26 const TInt KHeapMinSize=0x1000; |
|
27 const TInt KHeapMaxSize=0x1000; |
|
28 |
|
29 class CTestServer : public CServer2 |
|
30 { |
|
31 public: |
|
32 IMPORT_C CTestServer(TInt aPriority); |
|
33 enum TPanicType{ |
|
34 EInt0Error=1, EInt1Error, EInt2Error, EInt3Error, |
|
35 EPtr0Error, EPtr1Error, EPtr2Error, EPtr3Error, |
|
36 ECreateNameError, ENewSessionError, |
|
37 EClientError, EWatcherError, EKilled |
|
38 }; |
|
39 static void Panic(TPanicType aReason); |
|
40 protected: |
|
41 //override the pure virtual functions: |
|
42 IMPORT_C virtual CSession2* NewSessionL(const TVersion& aVersion, const RMessage2 &) const; |
|
43 }; |
|
44 |
|
45 |
|
46 class CTestSession : public CSession2 |
|
47 { |
|
48 public: |
|
49 enum {EStop,ETestInt,ETestPtr,ETestClient,ETestComplete,ETestPtrComplete,ETestCompletePanic,ETestOtherSession,ETestCompleteAfter}; |
|
50 //Override pure virtual |
|
51 IMPORT_C virtual void ServiceL(const RMessage2& aMessage); |
|
52 private: |
|
53 void TestInt(const RMessage2& aMessage); |
|
54 void TestPtr(const RMessage2& aMessage); |
|
55 void TestClient(const RMessage2& aMessage); |
|
56 void TestComplete(const RMessage2& aMessage); |
|
57 void TestPtrComplete(const RMessage2& aMessage); |
|
58 void TestCompletePanic(); |
|
59 // |
|
60 TInt count1;//initially ==0 |
|
61 RMessage2 messages[5];//Used in TestComplete() |
|
62 // |
|
63 TInt count2;//initially ==0 |
|
64 RMessagePtr2 messagePtrs[5];//User in TestPtrComplete() |
|
65 }; |
|
66 |
|
67 |
|
68 class CMyActiveScheduler : public CActiveScheduler |
|
69 { |
|
70 public: |
|
71 virtual void Error(TInt anError) const; //override pure virtual error function |
|
72 }; |
|
73 |
|
74 |
|
75 class RSession : public RSessionBase |
|
76 { |
|
77 public: |
|
78 TInt PublicSendReceive(TInt aFunction, const TIpcArgs& aArgs) |
|
79 { |
|
80 return (SendReceive(aFunction, aArgs)); |
|
81 } |
|
82 void PublicSendReceive(TInt aFunction, const TIpcArgs& aArgs, TRequestStatus& aStatus) |
|
83 { |
|
84 SendReceive(aFunction, aArgs, aStatus); |
|
85 } |
|
86 TInt PublicCreateSession(const TDesC& aServer,TInt aMessageSlots) |
|
87 { |
|
88 return (CreateSession(aServer,User::Version(),aMessageSlots)); |
|
89 } |
|
90 }; |
|
91 |
|
92 //========================================================================= |
|
93 |
|
94 // CTestServer functions |
|
95 |
|
96 CTestServer::CTestServer(TInt aPriority) |
|
97 // |
|
98 // Constructor - sets name |
|
99 // |
|
100 : CServer2(aPriority) |
|
101 {} |
|
102 |
|
103 CSession2* CTestServer::NewSessionL(const TVersion& aVersion, const RMessage2 &) const |
|
104 // |
|
105 // Virtual fn - checks version supported and creates a CTestSession |
|
106 // |
|
107 { |
|
108 TVersion version(KE32MajorVersionNumber,KE32MinorVersionNumber,KE32BuildVersionNumber); |
|
109 if (User::QueryVersionSupported(version,aVersion)==EFalse) |
|
110 User::Leave(KErrNotSupported); |
|
111 |
|
112 CTestSession* newCTestSession = new CTestSession; |
|
113 if (newCTestSession==NULL) |
|
114 Panic(ENewSessionError); |
|
115 return(newCTestSession); |
|
116 } |
|
117 |
|
118 RThread clientThread, serverThread, killerThread; |
|
119 |
|
120 void CTestServer::Panic(TPanicType aReason) //static function |
|
121 { |
|
122 clientThread.Kill(KErrNone); |
|
123 User::Panic(_L("CTestServer"),aReason); |
|
124 } |
|
125 |
|
126 // CTestSession funtions |
|
127 |
|
128 RSession session, otherSession; |
|
129 RSemaphore sem; |
|
130 |
|
131 const TInt KTestInt[] = {-3866,30566,0,200}; |
|
132 const TIpcArgs KIpcArgInt(-3866,30566,0,200); |
|
133 |
|
134 void CTestSession::TestInt(const RMessage2& aMessage) |
|
135 // |
|
136 // Tests to see that the correct Int0/1/2/3 have been received |
|
137 // |
|
138 { |
|
139 if (aMessage.Int0()!=KTestInt[0]) |
|
140 CTestServer::Panic(CTestServer::EInt0Error); |
|
141 if (aMessage.Int1()!=KTestInt[1]) |
|
142 CTestServer::Panic(CTestServer::EInt1Error); |
|
143 if (aMessage.Int2()!=KTestInt[2]) |
|
144 CTestServer::Panic(CTestServer::EInt2Error); |
|
145 if (aMessage.Int3()!=KTestInt[3]) |
|
146 CTestServer::Panic(CTestServer::EInt3Error); |
|
147 } |
|
148 |
|
149 const TAny* KTestPtr[]={&clientThread, &serverThread, &session, &sem}; |
|
150 const TIpcArgs KIpcArgPtr(&clientThread, &serverThread, &session, &sem); |
|
151 |
|
152 void CTestSession::TestPtr(const RMessage2& aMessage) |
|
153 // |
|
154 // Tests to see that the correct Ptr0/1/2/3 have been received |
|
155 // |
|
156 { |
|
157 if (aMessage.Ptr0()!=KTestPtr[0]) |
|
158 CTestServer::Panic(CTestServer::EPtr0Error); |
|
159 if (aMessage.Ptr1()!=KTestPtr[1]) |
|
160 CTestServer::Panic(CTestServer::EPtr1Error); |
|
161 if (aMessage.Ptr2()!=KTestPtr[2]) |
|
162 CTestServer::Panic(CTestServer::EPtr2Error); |
|
163 if (aMessage.Ptr3()!=KTestPtr[3]) |
|
164 CTestServer::Panic(CTestServer::EPtr3Error); |
|
165 } |
|
166 |
|
167 TFullName clientName; |
|
168 TInt clientNumber; |
|
169 |
|
170 void CTestSession::TestClient(const RMessage2& aMessage) |
|
171 // |
|
172 // Tests Client() |
|
173 // |
|
174 { |
|
175 |
|
176 // Under WINS, thread names are not prefixed with the process name |
|
177 TFullName n=RProcess().Name(); |
|
178 n+=_L("::"); |
|
179 n+=clientName; |
|
180 |
|
181 RThread client; |
|
182 TInt r = aMessage.Client(client); |
|
183 if (r != KErrNone || client.FullName().CompareF(n)!=0) |
|
184 { |
|
185 client.Close(); |
|
186 clientThread.Kill(0); |
|
187 CTestServer::Panic(CTestServer::EClientError); |
|
188 } |
|
189 client.Close(); |
|
190 } |
|
191 |
|
192 void CTestSession::TestComplete(const RMessage2& aMessage) |
|
193 // |
|
194 // Stores messages up then Completes in reverse order |
|
195 // |
|
196 { |
|
197 messages[count1] = aMessage; |
|
198 if (++count1==5) |
|
199 for(count1=4; count1>=0; count1--) |
|
200 messages[count1].Complete(5-count1); //Complete with different 'error messages' |
|
201 } |
|
202 |
|
203 void CTestSession::TestPtrComplete(const RMessage2& aMessage) |
|
204 // |
|
205 // Stores messages up as RMessagePtrs then Completes in reverse order |
|
206 // Also tests RMessage2::MessagePtr() |
|
207 // |
|
208 { |
|
209 messagePtrs[count2] = aMessage; |
|
210 if (++count2==5) |
|
211 for(count2=4; count2>=0; count2--) |
|
212 messagePtrs[count2].Complete(10-count2*2); |
|
213 } |
|
214 |
|
215 void CTestSession::ServiceL(const RMessage2& aMessage) |
|
216 // |
|
217 // Virtual message-handler |
|
218 // |
|
219 { |
|
220 TInt r=KErrNone; |
|
221 switch (aMessage.Function()) |
|
222 { |
|
223 case EStop: |
|
224 CActiveScheduler::Stop(); |
|
225 break; |
|
226 case ETestInt: |
|
227 TestInt(aMessage); |
|
228 break; |
|
229 case ETestPtr: |
|
230 TestPtr(aMessage); |
|
231 break; |
|
232 case ETestClient: |
|
233 TestClient(aMessage); |
|
234 break; |
|
235 case ETestComplete: |
|
236 TestComplete(aMessage); |
|
237 return; |
|
238 case ETestPtrComplete: |
|
239 TestPtrComplete(aMessage); |
|
240 return; |
|
241 case ETestCompletePanic: |
|
242 aMessage.Complete(KErrNone); |
|
243 break; |
|
244 case ETestOtherSession: |
|
245 break; |
|
246 case ETestCompleteAfter: |
|
247 User::After(7000000); |
|
248 break; |
|
249 default: |
|
250 r=KErrNotSupported; |
|
251 |
|
252 } |
|
253 aMessage.Complete(r); |
|
254 |
|
255 } |
|
256 |
|
257 void CMyActiveScheduler::Error(TInt anError) const |
|
258 // |
|
259 // Virtual error handler |
|
260 // |
|
261 { |
|
262 User::Panic(_L("CMyActiveScheduer::Error"), anError); |
|
263 } |
|
264 |
|
265 LOCAL_D TInt64 TheSeed; |
|
266 GLDEF_C TInt Random(TInt aRange) |
|
267 { |
|
268 return (Math::Rand(TheSeed)>>11)%aRange; |
|
269 } |
|
270 |
|
271 TInt KillerThread(TAny*) |
|
272 // |
|
273 // Wait a random time and then kill the client thread |
|
274 // |
|
275 { |
|
276 RTest test(_L("T_KILLER...Killer")); |
|
277 TRequestStatus clientStatus; |
|
278 TInt delay=0; |
|
279 |
|
280 test.Title(); |
|
281 test.Start(_L("Logon to client")); |
|
282 clientThread.Logon(clientStatus); |
|
283 test.Next(_L("Delay....")); |
|
284 for (;;) |
|
285 { |
|
286 User::After(1000); |
|
287 delay++; |
|
288 if (clientStatus!=KRequestPending) |
|
289 return KErrNone; // client has already finished |
|
290 if (Random(1000)<1) |
|
291 break; // Time to die! |
|
292 } |
|
293 test.Printf(_L("Kill client after %d ms\n"), delay); |
|
294 clientThread.Kill(CTestServer::EKilled); |
|
295 |
|
296 test.Close(); // close console immediately |
|
297 // test.End(); // "Press ENTER to exit" |
|
298 return KErrNone; |
|
299 } |
|
300 |
|
301 TInt ClientThread(TAny* aPtr) |
|
302 // |
|
303 // Passed as the first client thread - signals the server to do several tests |
|
304 // |
|
305 { |
|
306 RTest test(_L("T_KILLER...client")); |
|
307 TInt repeat = (TInt)aPtr; |
|
308 |
|
309 test.Title(); |
|
310 test.Start(_L("Client thread")); |
|
311 |
|
312 do |
|
313 { |
|
314 test.Next(_L("Client loop")); |
|
315 test.Start(_L("Create Session")); |
|
316 TInt r=session.PublicCreateSession(_L("CTestServer"),5); |
|
317 if (r!=KErrNone) |
|
318 User::Panic(_L("CreateSessn failure"),r); |
|
319 |
|
320 test.Next(_L("Signal to test Int0/1/2/3()")); |
|
321 r=session.PublicSendReceive(CTestSession::ETestInt, KIpcArgInt); |
|
322 test(r==KErrNone); |
|
323 |
|
324 test.Next(_L("Signal to test Ptr0/1/2/3()")); |
|
325 r=session.PublicSendReceive(CTestSession::ETestPtr, KIpcArgPtr); |
|
326 test(r==KErrNone); |
|
327 |
|
328 test.Next(_L("Signal to test Client()")); |
|
329 r=session.PublicSendReceive(CTestSession::ETestClient, TIpcArgs()); |
|
330 test(r==KErrNone); |
|
331 |
|
332 test.Next(_L("Test RMessage2::Complete()")); |
|
333 TRequestStatus stat[7]; |
|
334 for (r=0;r<4;r++) |
|
335 { |
|
336 session.PublicSendReceive(CTestSession::ETestComplete, TIpcArgs(), stat[r]); |
|
337 test(stat[r]==KRequestPending); |
|
338 } |
|
339 session.PublicSendReceive(CTestSession::ETestComplete, TIpcArgs(), stat[4]); |
|
340 User::WaitForRequest(stat[0]); |
|
341 for (r=0;r<5;r++) |
|
342 test(stat[r]==5-r); //Test the 'error messages' set by Complete() |
|
343 test.Next(_L("Test RMessagePtr2::Complete()")); |
|
344 for (r=0;r<4;r++) |
|
345 { |
|
346 session.PublicSendReceive(CTestSession::ETestPtrComplete, TIpcArgs(), stat[r]); |
|
347 test(stat[r]==KRequestPending); |
|
348 } |
|
349 session.PublicSendReceive(CTestSession::ETestPtrComplete, TIpcArgs(), stat[4]); |
|
350 User::WaitForRequest(stat[0]); |
|
351 for (r=0;r<5;r++) |
|
352 test(stat[r]==10-r*2); |
|
353 |
|
354 test.Next(_L("Try another session")); |
|
355 r=otherSession.PublicCreateSession(_L("CTestServer"),5); |
|
356 test(r==KErrNone); |
|
357 |
|
358 r=otherSession.PublicSendReceive(CTestSession::ETestOtherSession, TIpcArgs()); |
|
359 test(r==KErrNone); |
|
360 |
|
361 // test.Next(_L("Try to disconnect")); |
|
362 // r=session.PublicSendReceive(RMessage2::EDisConnect,NULL);//Panics user |
|
363 // test(r==KErrNone); |
|
364 |
|
365 test.Next(_L("Saturate server")); |
|
366 for(r=0;r<7;r++) |
|
367 { |
|
368 test.Printf(_L("Send %d\r"),r); |
|
369 session.PublicSendReceive(CTestSession::ETestCompleteAfter,TIpcArgs(),stat[r]); |
|
370 if (r<5) |
|
371 test(stat[r]==KRequestPending); |
|
372 else |
|
373 test(stat[r]==KErrServerBusy); |
|
374 } |
|
375 test.Printf(_L("\n")); |
|
376 for(r=0;r<5;r++) |
|
377 { |
|
378 test.Printf(_L("Wait %d\r"),r); |
|
379 User::WaitForRequest(stat[r]); |
|
380 test(stat[r]==KErrNone); |
|
381 } |
|
382 test.Printf(_L("\n")); |
|
383 test.End(); |
|
384 } |
|
385 while (--repeat > 0); |
|
386 test.Start(_L("Signal to stop ActiveScheduler")); |
|
387 session.PublicSendReceive(CTestSession::EStop, TIpcArgs()); |
|
388 test.Close(); |
|
389 |
|
390 return (KErrNone); |
|
391 } |
|
392 |
|
393 TInt ServerThread(TAny*) |
|
394 // |
|
395 // Passed as the server thread in 2 tests - sets up and runs CTestServer |
|
396 // |
|
397 { |
|
398 RTest test(_L("T_KILLER...server")); |
|
399 |
|
400 test.Title(); |
|
401 test.Start(_L("Create and install ActiveScheduler")); |
|
402 CMyActiveScheduler* pScheduler = new CMyActiveScheduler; |
|
403 if (pScheduler==NULL) |
|
404 { |
|
405 clientThread.Kill(0); |
|
406 User::Panic(_L("CreateSched failure"),KErrNoMemory); |
|
407 } |
|
408 |
|
409 CActiveScheduler::Install(pScheduler); |
|
410 |
|
411 test.Next(_L("Creating and starting Server")); |
|
412 CTestServer* pServer = new CTestServer(0); |
|
413 if (pServer==NULL) |
|
414 { |
|
415 clientThread.Kill(0); |
|
416 User::Panic(_L("CreateServr failure"),KErrNoMemory); |
|
417 } |
|
418 |
|
419 TInt r=pServer->Start(_L("CTestServer"));//Starting a CServer2 also Adds it to the ActiveScheduler |
|
420 if (r!=KErrNone) |
|
421 { |
|
422 clientThread.Kill(0); |
|
423 User::Panic(_L("StartServr failure"),r); |
|
424 } |
|
425 |
|
426 |
|
427 test.Next(_L("Start ActiveScheduler and signal to client")); |
|
428 test.Printf(_L(" There might be something going on beneath this window")); |
|
429 sem.Signal(); |
|
430 CActiveScheduler::Start(); |
|
431 test.Next(_L("Destroy ActiveScheduler")); |
|
432 delete pScheduler; |
|
433 delete pServer; |
|
434 |
|
435 test.Close(); |
|
436 |
|
437 return (KErrNone); |
|
438 } |
|
439 |
|
440 const TInt KTestPanic = 14849; |
|
441 |
|
442 TInt PanicTestThread (TAny*) |
|
443 // |
|
444 // Passed as a thread entry - just calls RMessage2::Panic() |
|
445 // |
|
446 { |
|
447 RMessage2 message; |
|
448 message.Panic(_L("Testing Panic"),KTestPanic); |
|
449 return(KErrNone); |
|
450 } |
|
451 |
|
452 RTest test(_L("Main T_KILLER test")); |
|
453 |
|
454 TInt CompletePanicClientThread (TAny*) |
|
455 // |
|
456 // Passed as the second client thread entry - signals to server to call Complete() twice |
|
457 // |
|
458 { |
|
459 sem.Wait(); |
|
460 |
|
461 TInt r=session.PublicCreateSession(_L("CTestServer"),1); |
|
462 test(r==KErrNone); |
|
463 |
|
464 r=session.PublicSendReceive(CTestSession::ETestCompletePanic, TIpcArgs()); |
|
465 test(r==KErrNone); |
|
466 |
|
467 session.PublicSendReceive(CTestSession::EStop, TIpcArgs());//panic should occur before this is serviced |
|
468 return(KErrNone); |
|
469 } |
|
470 |
|
471 void SimpleRMessage() |
|
472 // |
|
473 // Simple RMessage2 Tests - constructors and assignment |
|
474 // |
|
475 { |
|
476 |
|
477 test.Start(_L("Default constructor")); |
|
478 RMessage2 message1; |
|
479 |
|
480 test.Next(_L("Copy constructor")); |
|
481 RMessage2 message2(message1); |
|
482 test(message1.Function()==message2.Function()); |
|
483 test(message1.Int0()==message2.Int0()); |
|
484 test(message1.Int1()==message2.Int1()); |
|
485 test(message1.Int2()==message2.Int2()); |
|
486 test(message1.Int3()==message2.Int3()); |
|
487 RThread client1; |
|
488 test(message1.Client(client1) == KErrNone); |
|
489 RThread client2; |
|
490 test(message2.Client(client2) == KErrNone); |
|
491 test(client1.Handle()==client2.Handle()); |
|
492 client2.Close(); |
|
493 |
|
494 test.Next(_L("Assignment operator")); |
|
495 RMessage2 message3(*(RMessage2*) SimpleRMessage);// Pass some rubbish so message3 is definitely != message1 |
|
496 message3=message1; |
|
497 test(message1.Function()==message3.Function()); |
|
498 test(message1.Int0()==message3.Int0()); |
|
499 test(message1.Int1()==message3.Int1()); |
|
500 test(message1.Int2()==message3.Int2()); |
|
501 test(message1.Int3()==message3.Int3()); |
|
502 RThread client3; |
|
503 test(message3.Client(client3) == KErrNone); |
|
504 test(client1.Handle()==client3.Handle()); |
|
505 client3.Close(); |
|
506 client1.Close(); |
|
507 test.End(); |
|
508 } |
|
509 |
|
510 GLDEF_C TInt E32Main() |
|
511 { |
|
512 TInt err; |
|
513 |
|
514 #ifdef __WINS__ |
|
515 User::SetDebugMask(0xa04); // KSERVER+KTHREAD+KLOGON |
|
516 #endif |
|
517 test.Title(); |
|
518 |
|
519 test.Next(_L("Sending messages between two threads")); |
|
520 TRequestStatus clientStat,killerStat,serverStat; |
|
521 TInt exitType; |
|
522 |
|
523 test.Start(_L("Create and start the server")); |
|
524 sem.CreateLocal(0); |
|
525 serverThread.Create(_L("Server Thread"),ServerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL); |
|
526 serverThread.Logon(serverStat); |
|
527 serverThread.Resume(); |
|
528 sem.Wait(); |
|
529 |
|
530 for (TInt i=0; serverStat==KRequestPending && i<100; i++) |
|
531 { |
|
532 test.Next(_L("Run and kill a client")); |
|
533 clientName.Format(_L("Client Thread %d"),++clientNumber); |
|
534 |
|
535 test.Start(_L("Create client and killer threads")); |
|
536 err=clientThread.Create(clientName,ClientThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,(TAny *)3); |
|
537 if (err) |
|
538 test.Panic(_L("!!clientThread .Create failed"), err); |
|
539 err=killerThread.Create(_L("Killer Thread"),KillerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL); |
|
540 if (err) |
|
541 test.Panic(_L("!!killerThread .Create failed"), err); |
|
542 |
|
543 test.Next(_L("Logon to the threads")); |
|
544 clientThread.Logon(clientStat); |
|
545 killerThread.Logon(killerStat); |
|
546 |
|
547 test.Next(_L("Start the threads")); |
|
548 clientThread.Resume(); |
|
549 killerThread.Resume(); |
|
550 |
|
551 test.Next(_L("Wait for the client to stop")); |
|
552 User::WaitForRequest(clientStat); |
|
553 test.Next(_L("Wait for the killer to stop")); |
|
554 User::WaitForRequest(killerStat); |
|
555 exitType=clientThread.ExitType(); |
|
556 switch (exitType) |
|
557 { |
|
558 case EExitKill: |
|
559 test.Printf(_L(" Client thread killed\n")); |
|
560 break; |
|
561 case EExitTerminate: |
|
562 test.Printf(_L("!!Client thread terminated:")); |
|
563 test.Panic(clientThread.ExitCategory(), clientThread.ExitReason()); |
|
564 case EExitPanic: |
|
565 test.Printf(_L("!!Client thread panicked:")); |
|
566 test.Panic(clientThread.ExitCategory(), clientThread.ExitReason()); |
|
567 default: |
|
568 test.Panic(_L("!!Client thread did something bizarre"), clientThread.ExitReason()); |
|
569 } |
|
570 exitType=killerThread.ExitType(); |
|
571 switch (exitType) |
|
572 { |
|
573 case EExitKill: |
|
574 test.Printf(_L(" Killer thread killed\n")); |
|
575 break; |
|
576 case EExitTerminate: |
|
577 test.Printf(_L("!!Killer thread terminated:")); |
|
578 test.Panic(killerThread.ExitCategory(), killerThread.ExitReason()); |
|
579 case EExitPanic: |
|
580 test.Printf(_L("!!Killer thread panicked:")); |
|
581 test.Panic(killerThread.ExitCategory(), killerThread.ExitReason()); |
|
582 // |
|
583 // To catch a panic put a breakpoint in User::Panic() (in UCDT\UC_UNC.CPP). |
|
584 // |
|
585 default: |
|
586 test.Panic(_L("!!Killer thread did something bizarre"), killerThread.ExitReason()); |
|
587 } |
|
588 test.Next(_L("Close the threads")); |
|
589 clientThread.Close(); |
|
590 killerThread.Close(); |
|
591 // test.Next(_L("Pause for 1 second")); |
|
592 // User::After(1000000); |
|
593 test.End(); |
|
594 } |
|
595 test.Next(_L("Close the server thread")); |
|
596 serverThread.Kill(0); // in case we got through the 100 iterations without killing it |
|
597 User::WaitForRequest(serverStat); |
|
598 exitType=serverThread.ExitType(); |
|
599 switch (exitType) |
|
600 { |
|
601 case EExitKill: |
|
602 test.Printf(_L(" Server thread killed\n")); |
|
603 break; |
|
604 case EExitTerminate: |
|
605 test.Printf(_L("!!Server thread terminated:")); |
|
606 test.Panic(serverThread.ExitCategory(), serverThread.ExitReason()); |
|
607 case EExitPanic: |
|
608 test.Printf(_L("!!Server thread panicked:")); |
|
609 test.Panic(serverThread.ExitCategory(), serverThread.ExitReason()); |
|
610 // |
|
611 // To catch a panic put a breakpoint in User::Panic() (in UCDT\UC_UNC.CPP). |
|
612 // |
|
613 default: |
|
614 test.Panic(_L("!!Server thread did something bizarre"), serverThread.ExitReason()); |
|
615 } |
|
616 serverThread.Close(); |
|
617 test.End(); |
|
618 |
|
619 test.Next(_L("The Panic() function")); |
|
620 RThread panicThread; |
|
621 panicThread.Create(_L("Panic Test Thread"),PanicTestThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL); |
|
622 TRequestStatus stat; |
|
623 panicThread.Logon(stat); |
|
624 // don't want just in time debugging as we trap panics |
|
625 TBool justInTime=User::JustInTime(); |
|
626 User::SetJustInTime(EFalse); |
|
627 panicThread.Resume(); |
|
628 User::WaitForRequest(stat); |
|
629 test(panicThread.ExitType()==EExitPanic); |
|
630 test(panicThread.ExitCategory().Compare(_L("Testing Panic"))==0); |
|
631 test(panicThread.ExitReason()==KTestPanic); |
|
632 panicThread.Close(); //If this Close() is missed out Wins build 48 throws a wobbler when we next connect a server |
|
633 |
|
634 |
|
635 test.Next(_L("Check it Panics if you try to Complete a message twice")); |
|
636 test.Start(_L("Create client and server threads")); |
|
637 clientThread.Create(_L("Client Thread"),CompletePanicClientThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL); |
|
638 serverThread.Create(_L("Server Thread"),ServerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize,NULL); |
|
639 |
|
640 test.Next(_L("Logon to the threads")); |
|
641 clientThread.Logon(clientStat); |
|
642 serverThread.Logon(serverStat); |
|
643 |
|
644 test.Next(_L("Start the threads")); |
|
645 sem.CreateLocal(0); |
|
646 clientThread.Resume(); |
|
647 serverThread.Resume(); |
|
648 |
|
649 test.Next(_L("Wait for the threads to stop")); |
|
650 User::WaitForRequest(clientStat); |
|
651 User::WaitForRequest(serverStat); |
|
652 test.Next(_L("Check the exit categories")); |
|
653 test(clientThread.ExitType()==EExitKill); |
|
654 test(clientThread.ExitCategory().Compare(_L("Kill"))==0); |
|
655 test(clientThread.ExitReason()==KErrNone); |
|
656 |
|
657 test(serverThread.ExitType()==EExitPanic); |
|
658 test(serverThread.ExitCategory().Compare(_L("USER"))==0); |
|
659 test(serverThread.ExitReason()==ETMesCompletion); |
|
660 |
|
661 User::SetJustInTime(justInTime); |
|
662 |
|
663 test.Next(_L("Close the threads")); |
|
664 clientThread.Close(); |
|
665 serverThread.Close(); |
|
666 test.End(); |
|
667 |
|
668 test.End(); |
|
669 |
|
670 return (KErrNone); |
|
671 } |
|
672 |