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