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