author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 02:35:35 +0300 | |
changeset 281 | 13fbfa31d2ba |
parent 0 | a41df078684a |
child 293 | 0659d0e1a03c |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1995-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_svr5.cpp |
|
15 |
// Overview: |
|
16 |
// Test client server shareable sessions and benchmark their performance. |
|
17 |
// API information: |
|
18 |
// CSession2, CServer2, RSessionBase, RMessage2, DServer, DSession |
|
19 |
// Details: |
|
20 |
// - Start the test server |
|
21 |
// - Open a connection with the server specifying 0 message slots should be |
|
22 |
// available for the session and verify the server returns KErrServerBusy |
|
23 |
// when it tries to pass a message to it. |
|
24 |
// - Open a connection using a fixed pool of messages and test that the server |
|
25 |
// handles the messages correctly. |
|
26 |
// - Open a connection using the kernel's global pool of messages and test the |
|
27 |
// servers handles the messages correctly. |
|
28 |
// - Open a shareable session with the server and verify that: |
|
29 |
// - all arguments are passed to the server and back correctly |
|
30 |
// - server can read and write to/from the client and return the appropriate |
|
31 |
// errors when bad descriptors are passed in. |
|
32 |
// - another thread can share the session to send messages to the server. |
|
33 |
// - a message sent by one thread can be saved and completed later in |
|
34 |
// response to a message sent by a different thread. |
|
35 |
// - another thread can close the session. |
|
36 |
// - a different thread can attach to a session by handle. |
|
37 |
// - Establish a global shareable session to the server and test it fails, as |
|
38 |
// the server doesn't support global shareable sessions. |
|
39 |
// - Open an unshareable session with the server and verify that: |
|
40 |
// - all arguments are passed to the server and back correctly. |
|
41 |
// - server can reads and write to/from the client and return the |
|
42 |
// appropriate errors when bad descriptors are passed in. |
|
43 |
// - the session handle is local (thread owned) |
|
44 |
// - Open an automatically shared session using ShareAuto and test it can be |
|
45 |
// shared by threads in the same process. |
|
46 |
// - Send dummy messages that the server completes immediately and display how |
|
47 |
// many are completed per second. |
|
48 |
// - Verify that stopping the server completes existing pending requests with |
|
49 |
// KErrServerTerminated. |
|
50 |
// - Verify that the kernel does not crash by completing a message with an invalid |
|
51 |
// handle and verify the client is panicked with EBadMessageHandle. |
|
52 |
// Platforms/Drives/Compatibility: |
|
53 |
// All. |
|
54 |
// Assumptions/Requirement/Pre-requisites: |
|
55 |
// Failures and causes: |
|
56 |
// Base Port information: |
|
57 |
// This test does not help to validate an EKA2 port. |
|
58 |
// |
|
59 |
// |
|
60 |
||
61 |
#include <e32base.h> |
|
62 |
#include <e32base_private.h> |
|
63 |
#define __E32TEST_EXTENSION__ |
|
64 |
#include <e32test.h> |
|
65 |
#include <e32svr.h> |
|
66 |
||
67 |
#include "../mmu/mmudetect.h" |
|
68 |
||
69 |
const TInt KHeapSize=0x2000; |
|
70 |
const TInt KMajorVersionNumber=1; |
|
71 |
const TInt KMinorVersionNumber=0; |
|
72 |
const TInt KBuildVersionNumber=1; |
|
73 |
||
74 |
_LIT(KServerName,"Display"); |
|
75 |
||
76 |
TInt SessionCreateLResult=0; |
|
77 |
TInt SessionCostructCount=0; |
|
78 |
TInt SessionDestructCount=0; |
|
79 |
||
80 |
class CMySession : public CSession2 |
|
81 |
{ |
|
82 |
public: |
|
83 |
CMySession(); |
|
84 |
~CMySession(); |
|
85 |
void DisplayName(const RMessage2& aM); |
|
86 |
virtual void ServiceL(const RMessage2& aMessage); |
|
87 |
virtual void CreateL(); |
|
88 |
TInt Hold(const RMessage2& aM); |
|
89 |
TInt Release(const RMessage2& aM); |
|
90 |
public: |
|
91 |
RPointerArray<TInt> iAsyncMsgArray; // 'pointers' are actually message handles |
|
92 |
TInt iCompleteIndex; |
|
93 |
}; |
|
94 |
||
95 |
TInt AsyncMsgOrder(const TInt& aL, const TInt& aR) |
|
96 |
{ |
|
97 |
TInt lh = (TInt)&aL; |
|
98 |
TInt rh = (TInt)&aR; |
|
99 |
RMessage2 l(*(const RMessagePtr2*)&lh); |
|
100 |
RMessage2 r(*(const RMessagePtr2*)&rh); |
|
101 |
return l.Int0() - r.Int0(); |
|
102 |
} |
|
103 |
||
104 |
TInt GetClientName(const RMessagePtr2& aM, TFullName& aN) |
|
105 |
{ |
|
106 |
RThread t; |
|
107 |
TInt r = aM.Client(t); |
|
108 |
if (r==KErrNone) |
|
109 |
{ |
|
110 |
aN = t.FullName(); |
|
111 |
t.Close(); |
|
112 |
} |
|
113 |
return r; |
|
114 |
} |
|
115 |
||
116 |
class CMyServer : public CServer2 |
|
117 |
{ |
|
118 |
public: |
|
119 |
enum {EDisplay,ERead,EWrite,ETest,EStop,EHold,ERelease,EGetCompleteIndex}; |
|
120 |
public: |
|
121 |
CMyServer(TInt aPriority); |
|
122 |
static CMyServer* New(TInt aPriority); |
|
123 |
virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const; |
|
124 |
}; |
|
125 |
||
126 |
class CMyActiveScheduler : public CActiveScheduler |
|
127 |
{ |
|
128 |
public: |
|
129 |
virtual void Error(TInt anError) const; //Overloading pure virtual function |
|
130 |
}; |
|
131 |
||
132 |
class RDisplay : public RSessionBase |
|
133 |
{ |
|
134 |
public: |
|
135 |
TInt Open(); |
|
136 |
TInt OpenNoAsync(); |
|
137 |
TInt OpenDynamic(); |
|
138 |
TInt OpenUS(); |
|
139 |
TInt OpenS(); |
|
140 |
TInt OpenGS(); |
|
141 |
TInt Display(const TDesC& aMessage); |
|
142 |
TInt Read(); |
|
143 |
TInt Write(); |
|
144 |
TInt Stop(); |
|
145 |
TInt Test(); |
|
146 |
TInt Echo(TInt aWhat, TInt a0, TInt a1, TInt a2, TInt a3); |
|
147 |
TVersion Version(); |
|
148 |
TInt Hold(TInt aOrder=0, TInt aArg=0); |
|
149 |
void Hold(TRequestStatus& aStatus, TInt aOrder=0, TInt aArg=0); |
|
150 |
TInt Release(TInt aCount=KMaxTInt); |
|
151 |
TInt CompleteIndex(); |
|
152 |
}; |
|
153 |
||
154 |
LOCAL_D RTest test(_L("T_SVR")); |
|
155 |
LOCAL_D RTest testSvr(_L("T_SVR Server")); |
|
156 |
LOCAL_D RTest testSpeedy(_L("T_SVR Speedy")); |
|
157 |
LOCAL_D RSemaphore client; |
|
158 |
LOCAL_D TInt speedCount; |
|
159 |
||
160 |
CMySession::CMySession() |
|
161 |
// |
|
162 |
// Constructor |
|
163 |
// |
|
164 |
{ |
|
165 |
++SessionCostructCount; |
|
166 |
} |
|
167 |
||
168 |
CMySession::~CMySession() |
|
169 |
{ |
|
170 |
iAsyncMsgArray.Close(); |
|
171 |
++SessionDestructCount; |
|
172 |
} |
|
173 |
||
174 |
void CMySession::CreateL() |
|
175 |
{ |
|
176 |
User::LeaveIfError(SessionCreateLResult); |
|
177 |
} |
|
178 |
||
179 |
void CMySession::DisplayName(const RMessage2& aM) |
|
180 |
// |
|
181 |
// Display the client's name. |
|
182 |
// |
|
183 |
{ |
|
184 |
||
185 |
TFullName fn; |
|
186 |
TInt r = GetClientName(aM, fn); |
|
187 |
testSvr(r==KErrNone); |
|
188 |
TBuf<256> text; |
|
189 |
r=aM.Read(0,text); |
|
190 |
testSvr(r==KErrNone); |
|
191 |
testSvr.Printf(_L("Session %08x %S\n%S\n"), this, &fn, &text); |
|
192 |
} |
|
193 |
||
194 |
CMyServer* CMyServer::New(TInt aPriority) |
|
195 |
// |
|
196 |
// Create a new CMyServer. |
|
197 |
// |
|
198 |
{ |
|
199 |
||
200 |
return new CMyServer(aPriority); |
|
201 |
} |
|
202 |
||
203 |
CMyServer::CMyServer(TInt aPriority) |
|
204 |
// |
|
205 |
// Constructor. |
|
206 |
// |
|
207 |
: CServer2(aPriority, ESharableSessions) |
|
208 |
{} |
|
209 |
||
210 |
CSession2* CMyServer::NewSessionL(const TVersion& aVersion, const RMessage2&) const |
|
211 |
// |
|
212 |
// Create a new client for this server. |
|
213 |
// |
|
214 |
{ |
|
215 |
||
216 |
TVersion v(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); |
|
217 |
if (!User::QueryVersionSupported(v,aVersion)) |
|
218 |
User::Leave(KErrNotSupported); |
|
219 |
return new(ELeave) CMySession; |
|
220 |
} |
|
221 |
||
222 |
void CMySession::ServiceL(const RMessage2& aMessage) |
|
223 |
// |
|
224 |
// Handle messages for this server. |
|
225 |
// |
|
226 |
{ |
|
227 |
||
228 |
TInt f = aMessage.Function(); |
|
229 |
if (f & 0x40000000) |
|
230 |
{ |
|
231 |
TInt what = f & 0x3fffffff; |
|
232 |
TInt a0 = aMessage.Int0(); |
|
233 |
TInt a1 = aMessage.Int1(); |
|
234 |
TInt a2 = aMessage.Int2(); |
|
235 |
TInt a3 = aMessage.Int3(); |
|
236 |
switch (what) |
|
237 |
{ |
|
238 |
case 0: |
|
239 |
aMessage.Complete(a0); |
|
240 |
return; |
|
241 |
case 1: |
|
242 |
aMessage.Complete(a1); |
|
243 |
return; |
|
244 |
case 2: |
|
245 |
aMessage.Complete(a2); |
|
246 |
return; |
|
247 |
case 3: |
|
248 |
aMessage.Complete(a3); |
|
249 |
return; |
|
250 |
case 4: |
|
251 |
aMessage.Complete(a0+a1+a2+a3); |
|
252 |
return; |
|
253 |
case 5: |
|
254 |
aMessage.Complete(a0*a0+a1*a1+a2*a2+a3*a3); |
|
255 |
return; |
|
256 |
default: |
|
257 |
break; |
|
258 |
} |
|
259 |
} |
|
260 |
||
261 |
TInt r=KErrNone; |
|
262 |
TBuf<0x100> b; |
|
263 |
switch (f) |
|
264 |
{ |
|
265 |
case CMyServer::EDisplay: |
|
266 |
DisplayName(aMessage); |
|
267 |
break; |
|
268 |
case CMyServer::ERead: |
|
269 |
testSvr.Printf(_L("read message received\n")); |
|
270 |
r=aMessage.Read(0,b); |
|
271 |
if (r==KErrNone && b!=_L("Testing read")) |
|
272 |
r=KErrGeneral; |
|
273 |
if (r==KErrNone) |
|
274 |
{ |
|
275 |
r=aMessage.Read(0,b,-1); |
|
276 |
if (r==KErrNone) |
|
277 |
r=KErrGeneral; |
|
278 |
if (r==KErrArgument) |
|
279 |
r=KErrNone; |
|
280 |
} |
|
281 |
if (r==KErrNone && HaveVirtMem()) |
|
282 |
{ |
|
283 |
r=aMessage.Read(1,b); |
|
284 |
if (r==KErrNone) |
|
285 |
r=KErrGeneral; |
|
286 |
if (r==KErrBadDescriptor) |
|
287 |
r=KErrNone; |
|
288 |
} |
|
289 |
break; |
|
290 |
case CMyServer::EWrite: |
|
291 |
testSvr.Printf(_L("write message received\n")); |
|
292 |
r=aMessage.Write(0,_L("It worked!")); |
|
293 |
RDebug::Print(_L("Write returns %d"),r); |
|
294 |
if (r==KErrNone) |
|
295 |
{ |
|
296 |
r=aMessage.Write(0,b,-1); |
|
297 |
if (r==KErrNone) |
|
298 |
r=KErrGeneral; |
|
299 |
if (r==KErrArgument) |
|
300 |
r=KErrNone; |
|
301 |
} |
|
302 |
if (r==KErrNone) |
|
303 |
{ |
|
304 |
r=aMessage.Write(1,b); |
|
305 |
if (r==KErrNone) |
|
306 |
r=KErrGeneral; |
|
307 |
if (r==KErrBadDescriptor) |
|
308 |
r=KErrNone; |
|
309 |
} |
|
310 |
if (r==KErrNone && HaveVirtMem()) |
|
311 |
{ |
|
312 |
r=aMessage.Write(2,b); |
|
313 |
if (r==KErrNone) |
|
314 |
r=KErrGeneral; |
|
315 |
if (r==KErrBadDescriptor) |
|
316 |
r=KErrNone; |
|
317 |
} |
|
318 |
break; |
|
319 |
case CMyServer::ETest: |
|
320 |
break; |
|
321 |
case CMyServer::EStop: |
|
322 |
testSvr.Printf(_L("stop message received\n")); |
|
323 |
CActiveScheduler::Stop(); |
|
324 |
break; |
|
325 |
case CMyServer::EHold: |
|
326 |
{ |
|
327 |
r = Hold(aMessage); |
|
328 |
if (r==KErrNone) |
|
329 |
return; |
|
330 |
break; |
|
331 |
} |
|
332 |
case CMyServer::ERelease: |
|
333 |
{ |
|
334 |
r = Release(aMessage); |
|
335 |
break; |
|
336 |
} |
|
337 |
case CMyServer::EGetCompleteIndex: |
|
338 |
{ |
|
339 |
r = iCompleteIndex; |
|
340 |
break; |
|
341 |
} |
|
342 |
default: |
|
343 |
r=KErrNotSupported; |
|
344 |
} |
|
345 |
aMessage.Complete(r); |
|
346 |
} |
|
347 |
||
348 |
TInt CMySession::Hold(const RMessage2& a) |
|
349 |
{ |
|
350 |
TInt ord = a.Int0(); |
|
351 |
TInt arg = a.Int1(); |
|
352 |
TFullName fn; |
|
353 |
TInt r = GetClientName(a, fn); |
|
354 |
testSvr(r==KErrNone); |
|
355 |
testSvr.Printf(_L("Hold message from %S ord %08x arg %08x\n"), &fn, ord, arg); |
|
356 |
r = iAsyncMsgArray.InsertInOrder((const TInt*)a.Handle(), &AsyncMsgOrder); |
|
357 |
return r; |
|
358 |
} |
|
359 |
||
360 |
TInt CMySession::Release(const RMessage2& a) |
|
361 |
{ |
|
362 |
TInt req_count = a.Int0(); |
|
363 |
TInt avail = iAsyncMsgArray.Count(); |
|
364 |
TInt count = Min(req_count, avail); |
|
365 |
TFullName fn; |
|
366 |
TInt r = GetClientName(a, fn); |
|
367 |
testSvr(r==KErrNone); |
|
368 |
testSvr.Printf(_L("Release message from %S req_count=%d count=%d\n"), &fn, req_count, count); |
|
369 |
while (count--) |
|
370 |
{ |
|
371 |
TInt mp = (TInt)iAsyncMsgArray[0]; |
|
372 |
iAsyncMsgArray.Remove(0); |
|
373 |
RMessage2 m(*(const RMessagePtr2*)&mp); |
|
374 |
TInt arg = m.Int1(); |
|
375 |
TInt code = arg ? arg ^ iCompleteIndex : 0; |
|
376 |
r = GetClientName(m, fn); |
|
377 |
testSvr(r==KErrNone); |
|
378 |
testSvr.Printf(_L("Releasing %S arg=%08x index=%08x code=%08x\n"), &fn, arg, iCompleteIndex, code); |
|
379 |
++iCompleteIndex; |
|
380 |
m.Complete(code); |
|
381 |
} |
|
382 |
return KErrNone; |
|
383 |
} |
|
384 |
||
385 |
void CMyActiveScheduler::Error(TInt anError) const |
|
386 |
// |
|
387 |
// Called if any Run() method leaves. |
|
388 |
// |
|
389 |
{ |
|
390 |
||
391 |
testSvr.Panic(anError,_L("CMyActiveScheduler::Error")); |
|
392 |
} |
|
393 |
||
394 |
TInt RDisplay::Open() |
|
395 |
{ |
|
396 |
TInt r=CreateSession(KServerName,Version(),8); // use fixed pool of 8 slots |
|
397 |
if (r==KErrNone) |
|
398 |
r=ShareAuto(); |
|
399 |
return r; |
|
400 |
} |
|
401 |
||
402 |
TInt RDisplay::OpenUS() |
|
403 |
{ |
|
404 |
return CreateSession(KServerName,Version(),8,EIpcSession_Unsharable); // use fixed pool of 8 slots |
|
405 |
} |
|
406 |
||
407 |
TInt RDisplay::OpenS() |
|
408 |
{ |
|
409 |
return CreateSession(KServerName,Version(),8,EIpcSession_Sharable); // use fixed pool of 8 slots |
|
410 |
} |
|
411 |
||
412 |
TInt RDisplay::OpenGS() |
|
413 |
{ |
|
414 |
return CreateSession(KServerName,Version(),8,EIpcSession_GlobalSharable); // use fixed pool of 8 slots |
|
415 |
} |
|
416 |
||
417 |
TInt RDisplay::OpenNoAsync() |
|
418 |
{ |
|
419 |
||
420 |
TInt r=CreateSession(KServerName,Version(),0); // no asynchronous messages allowed |
|
421 |
if (r==KErrNone) |
|
422 |
r=ShareAuto(); |
|
423 |
return r; |
|
424 |
} |
|
425 |
||
426 |
TInt RDisplay::OpenDynamic() |
|
427 |
{ |
|
428 |
TInt r=CreateSession(KServerName,Version(),-1); // use global dynamic message pool |
|
429 |
if (r==KErrNone) |
|
430 |
r=ShareAuto(); |
|
431 |
return r; |
|
432 |
} |
|
433 |
||
434 |
TInt RDisplay::Display(const TDesC& aMessage) |
|
435 |
// |
|
436 |
// Display a message. |
|
437 |
// |
|
438 |
{ |
|
439 |
||
440 |
TBuf<0x100> b(aMessage); |
|
441 |
return SendReceive(CMyServer::EDisplay, TIpcArgs(&b)); |
|
442 |
} |
|
443 |
||
444 |
TInt RDisplay::Read() |
|
445 |
// |
|
446 |
// Get session to test CSession2::ReadL. |
|
447 |
// |
|
448 |
{ |
|
449 |
||
450 |
TBuf<0x10> b(_L("Testing read")); |
|
451 |
TBuf<0x10>* bad = (TBuf<0x10> *)(0x30000000); |
|
452 |
||
453 |
return SendReceive(CMyServer::ERead, TIpcArgs(&b, bad)); |
|
454 |
} |
|
455 |
||
456 |
TInt RDisplay::Write() |
|
457 |
// |
|
458 |
// Get session to test CSession2::WriteL. |
|
459 |
// |
|
460 |
{ |
|
461 |
||
462 |
TBuf<0x10> b; |
|
463 |
TBufC<0x10> c; // Bad descriptor - read only |
|
464 |
TBuf<0x10>* bad = (TBuf<0x10> *)(0x30000000); |
|
465 |
TInt r=SendReceive(CMyServer::EWrite, TIpcArgs(&b, &c, bad)); |
|
466 |
if (r==KErrNone && b!=_L("It worked!")) |
|
467 |
r=KErrGeneral; |
|
468 |
return r; |
|
469 |
} |
|
470 |
||
471 |
TInt RDisplay::Test() |
|
472 |
// |
|
473 |
// Send a message and wait for completion. |
|
474 |
// |
|
475 |
{ |
|
476 |
||
477 |
return SendReceive(CMyServer::ETest, TIpcArgs()); |
|
478 |
} |
|
479 |
||
480 |
TInt RDisplay::Stop() |
|
481 |
// |
|
482 |
// Stop the server. |
|
483 |
// |
|
484 |
{ |
|
485 |
||
486 |
return SendReceive(CMyServer::EStop, TIpcArgs()); |
|
487 |
} |
|
488 |
||
489 |
TVersion RDisplay::Version() |
|
490 |
// |
|
491 |
// Return the current version. |
|
492 |
// |
|
493 |
{ |
|
494 |
||
495 |
TVersion v(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); |
|
496 |
return v; |
|
497 |
} |
|
498 |
||
499 |
TInt RDisplay::Echo(TInt aWhat, TInt a0, TInt a1, TInt a2, TInt a3) |
|
500 |
{ |
|
501 |
return SendReceive(0x40000000|aWhat, TIpcArgs(a0,a1,a2,a3)); |
|
502 |
} |
|
503 |
||
504 |
TInt RDisplay::Hold(TInt aOrder, TInt aArg) |
|
505 |
{ |
|
506 |
||
507 |
return Send(CMyServer::EHold, TIpcArgs(aOrder, aArg)); |
|
508 |
} |
|
509 |
||
510 |
void RDisplay::Hold(TRequestStatus& aStatus, TInt aOrder, TInt aArg) |
|
511 |
{ |
|
512 |
||
513 |
SendReceive(CMyServer::EHold, TIpcArgs(aOrder, aArg), aStatus); |
|
514 |
} |
|
515 |
||
516 |
TInt RDisplay::Release(TInt aCount) |
|
517 |
{ |
|
518 |
||
519 |
return SendReceive(CMyServer::ERelease, TIpcArgs(aCount)); |
|
520 |
} |
|
521 |
||
522 |
TInt RDisplay::CompleteIndex() |
|
523 |
{ |
|
524 |
return SendReceive(CMyServer::EGetCompleteIndex, TIpcArgs()); |
|
525 |
} |
|
526 |
||
527 |
TInt serverThreadEntryPoint(TAny*) |
|
528 |
// |
|
529 |
// The entry point for the producer thread. |
|
530 |
// |
|
531 |
{ |
|
532 |
||
533 |
testSvr.Title(); |
|
534 |
testSvr.Start(_L("Create CActiveScheduler")); |
|
535 |
CMyActiveScheduler* pR=new CMyActiveScheduler; |
|
536 |
testSvr(pR!=NULL); |
|
537 |
CActiveScheduler::Install(pR); |
|
538 |
// |
|
539 |
testSvr.Next(_L("Create CMyServer")); |
|
540 |
CMyServer* pS=CMyServer::New(0); |
|
541 |
testSvr(pS!=NULL); |
|
542 |
// |
|
543 |
testSvr.Next(_L("Start CMyServer")); |
|
544 |
TInt r=pS->Start(KServerName); |
|
545 |
testSvr(r==KErrNone); |
|
546 |
// |
|
547 |
testSvr.Next(_L("Signal to client that we have started")); |
|
548 |
client.Signal(); |
|
549 |
// |
|
550 |
testSvr.Next(_L("Start CActiveScheduler")); |
|
551 |
CActiveScheduler::Start(); |
|
552 |
// |
|
553 |
testSvr.Next(_L("Exit server")); |
|
554 |
delete pS; |
|
555 |
testSvr.Close(); |
|
556 |
return(KErrNone); |
|
557 |
} |
|
558 |
||
559 |
TInt speedyThreadEntryPoint(TAny* aDisplay) |
|
560 |
// |
|
561 |
// The entry point for the speed test thread. |
|
562 |
// |
|
563 |
{ |
|
564 |
||
565 |
RDisplay& t=*(RDisplay*)aDisplay; |
|
566 |
TInt r=t.Test(); |
|
567 |
testSpeedy(r==KErrNone); |
|
568 |
speedCount=0; |
|
569 |
client.Signal(); |
|
570 |
while ((r=t.Test())==KErrNone) |
|
571 |
speedCount++; |
|
572 |
testSpeedy(r==KErrServerTerminated); |
|
573 |
return(KErrNone); |
|
574 |
} |
|
575 |
||
576 |
TInt RunPanicThread(RThread& aThread) |
|
577 |
{ |
|
578 |
TRequestStatus s; |
|
579 |
aThread.Logon(s); |
|
580 |
TBool jit = User::JustInTime(); |
|
581 |
User::SetJustInTime(EFalse); |
|
582 |
aThread.Resume(); |
|
583 |
User::WaitForRequest(s); |
|
584 |
User::SetJustInTime(jit); |
|
585 |
return s.Int(); |
|
586 |
} |
|
587 |
||
588 |
TInt RogueThread1(TAny*) |
|
589 |
{ |
|
590 |
// try to kill the kernel |
|
591 |
RMutex mutex; |
|
592 |
TPtrC* p=(TPtrC*)0x30000000; |
|
593 |
mutex.CreateGlobal(*p,EOwnerProcess); // this should panic the thread |
|
594 |
return KErrNone; |
|
595 |
} |
|
596 |
||
597 |
class RMessageT : public RMessage2 |
|
598 |
{ |
|
599 |
public: |
|
600 |
RMessageT(TLinAddr anAddr) { iFunction=0; iHandle=(TInt)anAddr; } |
|
601 |
}; |
|
602 |
||
603 |
TInt RogueThread2(TAny*) |
|
604 |
{ |
|
605 |
// try to kill the kernel |
|
606 |
RMessageT m(0x30000000); |
|
607 |
m.Complete(KErrNone); // this should panic the thread |
|
608 |
return KErrNone; |
|
609 |
} |
|
610 |
||
611 |
TInt RogueThread3(TAny*) |
|
612 |
{ |
|
613 |
// try to kill the kernel |
|
614 |
RMessageT m(0x80000000); |
|
615 |
m.Complete(KErrNone); // this should panic the thread |
|
616 |
return KErrNone; |
|
617 |
} |
|
618 |
||
619 |
TInt RogueThread4(TAny*) |
|
620 |
{ |
|
621 |
// try to kill the kernel |
|
622 |
RMessageT m(0x800fff00); // this should be off the end of the kernel heap |
|
623 |
m.Complete(KErrNone); // this should panic the thread |
|
624 |
return KErrNone; |
|
625 |
} |
|
626 |
||
281
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
627 |
TInt RogueThread5(TAny*) |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
628 |
{ |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
629 |
// try to masquerade as the WindowServer |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
630 |
UserSvr::WsRegisterThread(); // this should panic the thread |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
631 |
return KErrNone; |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
632 |
} |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
633 |
|
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
634 |
TInt RogueThread6(TAny*) |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
635 |
{ |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
636 |
// try to masquerade as the FileServer |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
637 |
UserSvr::FsRegisterThread(); // this should panic the thread |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
638 |
return KErrNone; |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
639 |
} |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
640 |
|
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
641 |
TInt RogueThread7(TAny*) |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
642 |
{ |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
643 |
// try to masquerade as the FileServer |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
644 |
RChunk myChunk; |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
645 |
TInt err = myChunk.CreateLocal(4096, 8192); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
646 |
if (err == KErrNone) |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
647 |
UserSvr::RegisterTrustedChunk(myChunk.Handle()); // this should panic the thread |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
648 |
return err; |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
649 |
} |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
650 |
|
0 | 651 |
void DisplayThreadExitInfo(const RThread& aThread) |
652 |
{ |
|
653 |
TFullName fn=aThread.FullName(); |
|
654 |
TExitType exitType=aThread.ExitType(); |
|
655 |
TInt exitReason=aThread.ExitReason(); |
|
656 |
TBuf<32> exitCat=aThread.ExitCategory(); |
|
657 |
test.Printf(_L("Thread %S exited %d,%d,%S\n"),&fn,exitType,exitReason,&exitCat); |
|
658 |
} |
|
659 |
||
660 |
void RogueThreadTest() |
|
661 |
{ |
|
662 |
RThread thread; |
|
663 |
TInt r; |
|
664 |
if (HaveVirtMem()) |
|
665 |
{ |
|
666 |
test.Next(_L("Rogue thread test 1")); |
|
667 |
r=thread.Create(_L("Rogue1"),RogueThread1,KDefaultStackSize,KHeapSize,KHeapSize,NULL); |
|
668 |
test_KErrNone(r); |
|
669 |
RunPanicThread(thread); // wait for rogue thread to die |
|
670 |
DisplayThreadExitInfo(thread); |
|
671 |
test(thread.ExitType()==EExitPanic); |
|
672 |
test(thread.ExitReason()==ECausedException); |
|
673 |
thread.Close(); |
|
674 |
} |
|
675 |
||
676 |
test.Next(_L("Rogue thread test 2")); |
|
677 |
r=thread.Create(_L("Rogue2"),RogueThread2,KDefaultStackSize,KHeapSize,KHeapSize,NULL); |
|
678 |
test_KErrNone(r); |
|
679 |
RunPanicThread(thread); // wait for rogue thread to die |
|
680 |
DisplayThreadExitInfo(thread); |
|
681 |
test(thread.ExitType()==EExitPanic); |
|
682 |
test(thread.ExitReason()==EBadMessageHandle); |
|
683 |
thread.Close(); |
|
684 |
||
685 |
test.Next(_L("Rogue thread test 3")); |
|
686 |
r=thread.Create(_L("Rogue3"),RogueThread3,KDefaultStackSize,KHeapSize,KHeapSize,NULL); |
|
687 |
test_KErrNone(r); |
|
688 |
RunPanicThread(thread); // wait for rogue thread to die |
|
689 |
DisplayThreadExitInfo(thread); |
|
690 |
test(thread.ExitType()==EExitPanic); |
|
691 |
test(thread.ExitReason()==EBadMessageHandle); |
|
692 |
thread.Close(); |
|
693 |
||
694 |
test.Next(_L("Rogue thread test 4")); |
|
695 |
r=thread.Create(_L("Rogue4"),RogueThread4,KDefaultStackSize,KHeapSize,KHeapSize,NULL); |
|
696 |
test_KErrNone(r); |
|
697 |
RunPanicThread(thread); // wait for rogue thread to die |
|
698 |
DisplayThreadExitInfo(thread); |
|
699 |
test(thread.ExitType()==EExitPanic); |
|
700 |
test(thread.ExitReason()==EBadMessageHandle); |
|
701 |
thread.Close(); |
|
281
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
702 |
|
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
703 |
test.Next(_L("Rogue thread test 5")); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
704 |
r=thread.Create(_L("Rogue5"),RogueThread5,KDefaultStackSize,KHeapSize,KHeapSize,NULL); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
705 |
test_KErrNone(r); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
706 |
RunPanicThread(thread); // wait for rogue thread to die |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
707 |
DisplayThreadExitInfo(thread); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
708 |
test(thread.ExitType()==EExitPanic); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
709 |
test(thread.ExitReason()==EAccessDenied); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
710 |
thread.Close(); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
711 |
|
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
712 |
test.Next(_L("Rogue thread test 6")); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
713 |
r=thread.Create(_L("Rogue6"),RogueThread6,KDefaultStackSize,KHeapSize,KHeapSize,NULL); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
714 |
test_KErrNone(r); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
715 |
RunPanicThread(thread); // wait for rogue thread to die |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
716 |
DisplayThreadExitInfo(thread); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
717 |
test(thread.ExitType()==EExitPanic); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
718 |
test(thread.ExitReason()==EAccessDenied); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
719 |
thread.Close(); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
720 |
|
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
721 |
test.Next(_L("Rogue thread test 7")); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
722 |
r=thread.Create(_L("Rogue7"),RogueThread7,KDefaultStackSize,KHeapSize,KHeapSize,NULL); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
723 |
test_KErrNone(r); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
724 |
RunPanicThread(thread); // wait for rogue thread to die |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
725 |
DisplayThreadExitInfo(thread); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
726 |
test(thread.ExitType()==EExitPanic); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
727 |
test(thread.ExitReason()==EAccessDenied); |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
728 |
thread.Close(); |
0 | 729 |
} |
730 |
||
731 |
TInt SecondClient(TAny* aSession) |
|
732 |
{ |
|
733 |
RDisplay d; |
|
734 |
d.SetHandle(TInt(aSession)); |
|
735 |
TInt r=d.Display(_L("Second client")); |
|
736 |
if (r!=KErrNone) |
|
737 |
return r; |
|
738 |
r = d.Echo(0,19,31,83,487); |
|
739 |
if (r!=19) |
|
740 |
return -999990; |
|
741 |
r = d.Echo(1,19,31,83,487); |
|
742 |
if (r!=31) |
|
743 |
return -999991; |
|
744 |
r = d.Echo(2,19,31,83,487); |
|
745 |
if (r!=83) |
|
746 |
return -999992; |
|
747 |
r = d.Echo(3,19,31,83,487); |
|
748 |
if (r!=487) |
|
749 |
return -999993; |
|
750 |
r = d.Echo(4,19,31,83,487); |
|
751 |
if (r!=620) |
|
752 |
return -999994; |
|
753 |
r = d.Echo(5,19,31,83,487); |
|
754 |
if (r!=245380) |
|
755 |
return -999995; |
|
756 |
r=d.Read(); |
|
757 |
if (r!=KErrNone) |
|
758 |
return r; |
|
759 |
r=d.Write(); |
|
760 |
if (r!=KErrNone) |
|
761 |
return r; |
|
762 |
d.Release(); |
|
763 |
return KErrNone; |
|
764 |
} |
|
765 |
||
766 |
TInt ThirdClient(TAny* aSession) |
|
767 |
{ |
|
768 |
RDisplay d; |
|
769 |
d.SetHandle(TInt(aSession)); |
|
770 |
TInt r=d.Display(_L("Third client")); |
|
771 |
if (r!=KErrNone) |
|
772 |
return r; |
|
773 |
r=d.Hold(); |
|
774 |
if (r!=KErrNone) |
|
775 |
return r; |
|
776 |
r=d.Read(); |
|
777 |
if (r!=KErrNone) |
|
778 |
return r; |
|
779 |
r=d.Write(); |
|
780 |
if (r!=KErrNone) |
|
781 |
return r; |
|
782 |
return KErrNone; |
|
783 |
} |
|
784 |
||
785 |
void TestSecondClient(RSessionBase& aSession) |
|
786 |
{ |
|
787 |
RThread t; |
|
788 |
TInt r=t.Create(_L("SecondClient"),SecondClient,0x1000,NULL,(TAny*)aSession.Handle()); |
|
789 |
test_KErrNone(r); |
|
790 |
TRequestStatus s; |
|
791 |
t.Logon(s); |
|
792 |
t.Resume(); |
|
793 |
User::WaitForRequest(s); |
|
794 |
test_KErrNone(s.Int()); |
|
795 |
t.Close(); |
|
796 |
} |
|
797 |
||
798 |
void TestThirdClient(RSessionBase& aSession) |
|
799 |
{ |
|
800 |
RThread t; |
|
801 |
TInt r=t.Create(_L("ThirdClient"),ThirdClient,0x1000,NULL,(TAny*)aSession.Handle()); |
|
802 |
test_KErrNone(r); |
|
803 |
TRequestStatus s; |
|
804 |
t.Logon(s); |
|
805 |
t.Resume(); |
|
806 |
User::WaitForRequest(s); |
|
807 |
test_KErrNone(s.Int()); |
|
808 |
t.Close(); |
|
809 |
} |
|
810 |
||
811 |
TInt FourthClient(TAny* aSession) |
|
812 |
{ |
|
813 |
RDisplay d; |
|
814 |
d.SetHandle(TInt(aSession)); |
|
815 |
TInt r=d.Display(_L("Fourth client")); |
|
816 |
if (r!=KErrNone) |
|
817 |
return r; |
|
818 |
d.Close(); |
|
819 |
return KErrNone; |
|
820 |
} |
|
821 |
||
822 |
void TestSessionClose() |
|
823 |
{ |
|
824 |
RDisplay d; |
|
825 |
TInt r=d.Open(); |
|
826 |
test_KErrNone(r); |
|
827 |
TRequestStatus msgStat; |
|
828 |
d.Hold(msgStat); |
|
829 |
test(msgStat==KRequestPending); |
|
830 |
RThread t; |
|
831 |
r=t.Create(_L("FourthClient"),FourthClient,0x1000,NULL,(TAny*)d.Handle()); |
|
832 |
test_KErrNone(r); |
|
833 |
TRequestStatus s; |
|
834 |
t.Logon(s); |
|
835 |
t.Resume(); |
|
836 |
User::WaitForRequest(s); |
|
837 |
test_KErrNone(s.Int()); |
|
838 |
t.Close(); |
|
839 |
User::After(1000000); |
|
840 |
test(msgStat==KRequestPending); |
|
841 |
} |
|
842 |
||
843 |
TInt FifthClient(TAny* aDisplay) |
|
844 |
{ |
|
845 |
RDisplay& d=*(RDisplay*)aDisplay; |
|
846 |
TInt r=d.Open(); |
|
847 |
if (r!=KErrNone) |
|
848 |
return r; |
|
849 |
r=d.Display(_L("Fifth client")); |
|
850 |
if (r!=KErrNone) |
|
851 |
return r; |
|
852 |
return KErrNone; |
|
853 |
} |
|
854 |
||
855 |
void TestZeroShares() |
|
856 |
{ |
|
857 |
RDisplay d; |
|
858 |
d.SetHandle(0); |
|
859 |
RThread t; |
|
860 |
TInt r=t.Create(_L("FifthClient"),FifthClient,0x1000,NULL,&d); |
|
861 |
test_KErrNone(r); |
|
862 |
TRequestStatus s; |
|
863 |
t.Logon(s); |
|
864 |
t.Resume(); |
|
865 |
User::WaitForRequest(s); |
|
866 |
test_KErrNone(s.Int()); |
|
867 |
test(d.Handle()!=0); |
|
868 |
t.Close(); |
|
869 |
r=d.Display(_L("Access after last share closed")); |
|
870 |
test_KErrNone(r); |
|
871 |
d.Close(); |
|
872 |
} |
|
873 |
||
874 |
TInt AttachClient1(TAny* aSession) |
|
875 |
{ |
|
876 |
RDisplay d; |
|
877 |
d.SetHandle(TInt(aSession)); |
|
878 |
__KHEAP_MARK; |
|
879 |
TInt r=d.Display(_L("Attach client 1")); |
|
880 |
__KHEAP_MARKEND; // shouldn't need to allocate memory |
|
881 |
return r; |
|
882 |
} |
|
883 |
||
884 |
TInt AttachClient2(TAny* aSession) |
|
885 |
{ |
|
886 |
RDisplay d; |
|
887 |
d.SetHandle(TInt(aSession)); |
|
888 |
TInt r=d.Display(_L("Attach client 2")); |
|
889 |
if (r!=KErrNone) |
|
890 |
return r; |
|
891 |
__KHEAP_MARK; |
|
892 |
r=d.Display(_L("Attach client 2")); |
|
893 |
__KHEAP_MARKEND; // check no memory was allocated by message send |
|
894 |
return r; |
|
895 |
} |
|
896 |
||
897 |
void TestAttach(RSessionBase& aSession) |
|
898 |
{ |
|
899 |
test.Next(_L("Test Attach")); |
|
900 |
RThread t; |
|
901 |
TInt r=t.Create(_L("AttachClient1"),AttachClient1,0x1000,NULL,(TAny*)aSession.Handle()); |
|
902 |
test_KErrNone(r); |
|
903 |
r=RunPanicThread(t); // wait for thread to die |
|
904 |
test_KErrNone(r); |
|
905 |
test(t.ExitType()==EExitKill); |
|
906 |
test_KErrNone(t.ExitReason()); |
|
907 |
t.Close(); |
|
908 |
||
909 |
r=t.Create(_L("AttachClient2"),AttachClient2,0x1000,NULL,(TAny*)aSession.Handle()); |
|
910 |
test_KErrNone(r); |
|
911 |
TRequestStatus s; |
|
912 |
t.Logon(s); |
|
913 |
t.Resume(); |
|
914 |
User::WaitForRequest(s); |
|
915 |
test_KErrNone(s.Int()); |
|
916 |
test(t.ExitType()==EExitKill); |
|
917 |
test_KErrNone(t.ExitReason()); |
|
918 |
t.Close(); |
|
919 |
} |
|
920 |
||
921 |
TInt SixthClient(TAny* aDisplay) |
|
922 |
{ |
|
923 |
RDisplay& d=*(RDisplay*)aDisplay; |
|
924 |
TInt r=d.Display(_L("Sixth client")); |
|
925 |
if (r!=KErrNone) |
|
926 |
return r; |
|
927 |
TRequestStatus s; |
|
928 |
User::WaitForRequest(s); |
|
929 |
return KErrNone; |
|
930 |
} |
|
931 |
||
932 |
TInt SeventhClient(TAny* aDisplay) |
|
933 |
{ |
|
934 |
RDisplay& d=*(RDisplay*)aDisplay; |
|
935 |
TInt r=d.Display(_L("Seventh client")); |
|
936 |
if (r!=KErrNone) |
|
937 |
return r; |
|
938 |
TRequestStatus s; |
|
939 |
User::WaitForRequest(s); |
|
940 |
return KErrNone; |
|
941 |
} |
|
942 |
||
943 |
TInt EighthClient(TAny* aDisplay) |
|
944 |
{ |
|
945 |
RDisplay& d=*(RDisplay*)aDisplay; |
|
946 |
TInt r=d.Display(_L("Eighth client")); |
|
947 |
if (r!=KErrNone) |
|
948 |
return r; |
|
949 |
TRequestStatus s; |
|
950 |
User::WaitForRequest(s); |
|
951 |
return KErrNone; |
|
952 |
} |
|
953 |
||
954 |
TInt NinthClient(TAny* aDisplay) |
|
955 |
{ |
|
956 |
RDisplay& d=*(RDisplay*)aDisplay; |
|
957 |
TInt r=d.Display(_L("Ninth client")); |
|
958 |
if (r!=KErrNone) |
|
959 |
return r; |
|
960 |
TRequestStatus s; |
|
961 |
User::WaitForRequest(s); |
|
962 |
return KErrNone; |
|
963 |
} |
|
964 |
||
965 |
void TestAsync(RDisplay& aD) |
|
966 |
{ |
|
967 |
TInt ci = aD.CompleteIndex(); |
|
968 |
TRequestStatus s[128]; |
|
969 |
TInt i; |
|
970 |
TInt r; |
|
971 |
for (i=0; i<128; ++i) |
|
972 |
{ |
|
973 |
TInt ord = i ^ 0x55; |
|
974 |
TInt arg = i + 1; |
|
975 |
aD.Hold(s[i], ord, arg); |
|
976 |
if (s[i]==KErrServerBusy) |
|
977 |
{ |
|
978 |
User::WaitForRequest(s[i]); |
|
979 |
break; |
|
980 |
} |
|
981 |
test(s[i]==KRequestPending); |
|
982 |
} |
|
983 |
r = aD.Release(); |
|
984 |
test_KErrNone(r); |
|
985 |
TInt j; |
|
986 |
for (j=0; j<128; ++j) |
|
987 |
{ |
|
988 |
if ( (j^0x55) >= i ) |
|
989 |
continue; |
|
990 |
TInt code = s[j^0x55].Int(); |
|
991 |
TInt expected = ci ^ ((j^0x55)+1); |
|
992 |
if (code != expected) |
|
993 |
{ |
|
994 |
test.Printf(_L("j=%02x i=%02x expected=%08x got=%08x\n"),j,j^0x55,expected,code); |
|
995 |
test(0); |
|
996 |
} |
|
997 |
User::WaitForRequest(s[j^0x55]); |
|
998 |
++ci; |
|
999 |
} |
|
1000 |
} |
|
1001 |
||
1002 |
void TestSession(RDisplay& aSess) |
|
1003 |
{ |
|
1004 |
// |
|
1005 |
TInt r; |
|
1006 |
test.Next(_L("Test all args passed")); |
|
1007 |
test(aSess.Echo(0,3,5,7,11)==3); |
|
1008 |
test(aSess.Echo(1,3,5,7,11)==5); |
|
1009 |
test(aSess.Echo(2,3,5,7,11)==7); |
|
1010 |
test(aSess.Echo(3,3,5,7,11)==11); |
|
1011 |
test(aSess.Echo(4,3,5,7,11)==26); |
|
1012 |
test(aSess.Echo(5,3,5,7,11)==204); |
|
1013 |
// |
|
1014 |
test.Next(_L("Send to server")); |
|
1015 |
r=aSess.Display(_L("First message")); |
|
1016 |
test_KErrNone(r); |
|
1017 |
// |
|
1018 |
test.Next(_L("Read")); |
|
1019 |
r=aSess.Read(); |
|
1020 |
test_KErrNone(r); |
|
1021 |
// |
|
1022 |
test.Next(_L("Write")); |
|
1023 |
r=aSess.Write(); |
|
1024 |
test_KErrNone(r); |
|
1025 |
// |
|
1026 |
TestThirdClient(aSess); |
|
1027 |
User::After(1000000); |
|
1028 |
TestSecondClient(aSess); |
|
1029 |
User::After(1000000); |
|
1030 |
TestSessionClose(); |
|
1031 |
User::After(1000000); |
|
1032 |
TestZeroShares(); |
|
1033 |
User::After(1000000); |
|
1034 |
TestAttach(aSess); |
|
1035 |
User::After(1000000); |
|
1036 |
} |
|
1037 |
||
1038 |
void TestUnsharableSession(RDisplay& aSess) |
|
1039 |
{ |
|
1040 |
// |
|
1041 |
TInt r; |
|
1042 |
test.Next(_L("Test all args passed")); |
|
1043 |
test(aSess.Echo(0,3,5,7,11)==3); |
|
1044 |
test(aSess.Echo(1,3,5,7,11)==5); |
|
1045 |
test(aSess.Echo(2,3,5,7,11)==7); |
|
1046 |
test(aSess.Echo(3,3,5,7,11)==11); |
|
1047 |
test(aSess.Echo(4,3,5,7,11)==26); |
|
1048 |
test(aSess.Echo(5,3,5,7,11)==204); |
|
1049 |
// |
|
1050 |
test.Next(_L("Send to server")); |
|
1051 |
r=aSess.Display(_L("First message")); |
|
1052 |
test_KErrNone(r); |
|
1053 |
// |
|
1054 |
test.Next(_L("Read")); |
|
1055 |
r=aSess.Read(); |
|
1056 |
test_KErrNone(r); |
|
1057 |
// |
|
1058 |
test.Next(_L("Write")); |
|
1059 |
r=aSess.Write(); |
|
1060 |
test_KErrNone(r); |
|
1061 |
// |
|
1062 |
TInt h = aSess.Handle(); |
|
1063 |
test.Printf(_L("HANDLE %08x\n"), h); |
|
1064 |
test((h & KHandleFlagLocal)!=0); |
|
1065 |
} |
|
1066 |
||
1067 |
void TestSessionCreateLLeaving() |
|
1068 |
{ |
|
1069 |
SessionCreateLResult=KErrGeneral; |
|
1070 |
||
1071 |
TInt c=SessionCostructCount; |
|
1072 |
TInt d=SessionDestructCount; |
|
1073 |
||
1074 |
RDisplay t; |
|
1075 |
TInt r = t.Open(); |
|
1076 |
test(r==SessionCreateLResult); |
|
1077 |
||
1078 |
test(SessionCostructCount==c+1); |
|
1079 |
test(SessionDestructCount==d+1); |
|
1080 |
||
1081 |
SessionCreateLResult=KErrNone; |
|
1082 |
} |
|
1083 |
||
1084 |
GLDEF_C TInt E32Main() |
|
1085 |
// |
|
1086 |
// Test timers. |
|
1087 |
// |
|
1088 |
{ |
|
1089 |
||
1090 |
test.Title(); |
|
1091 |
test.Start(_L("Creating client semaphore")); |
|
1092 |
TInt r=client.CreateLocal(0); |
|
1093 |
test_KErrNone(r); |
|
1094 |
// |
|
1095 |
test.Next(_L("Creating server thread")); |
|
1096 |
RThread server; |
|
1097 |
r=server.Create(_L("Server"),serverThreadEntryPoint,KDefaultStackSize,KHeapSize,KHeapSize,NULL); |
|
1098 |
test_KErrNone(r); |
|
1099 |
server.SetPriority(EPriorityMore); |
|
1100 |
// |
|
1101 |
test.Next(_L("Resume server thread")); |
|
1102 |
server.Resume(); |
|
1103 |
test(ETrue); |
|
1104 |
// |
|
1105 |
test.Next(_L("Wait for server to start")); |
|
1106 |
client.Wait(); |
|
1107 |
// |
|
1108 |
test.Next(_L("Connect to server")); |
|
1109 |
RDisplay t; |
|
1110 |
r = t.OpenNoAsync(); |
|
1111 |
test_KErrNone(r); |
|
1112 |
test.Next(_L("Send to server")); |
|
1113 |
r=t.Display(_L("AsyncMsg")); |
|
1114 |
test_KErrNone(r); |
|
1115 |
TRequestStatus s0; |
|
1116 |
t.Hold(s0); |
|
1117 |
test(s0==KErrServerBusy); |
|
1118 |
t.Close(); |
|
1119 |
// |
|
1120 |
test.Next(_L("Test Session::CreateL leaving")); |
|
1121 |
TestSessionCreateLLeaving(); |
|
1122 |
// |
|
1123 |
test.Next(_L("Async fixed pool")); |
|
1124 |
r = t.Open(); |
|
1125 |
test_KErrNone(r); |
|
1126 |
TestAsync(t); |
|
1127 |
TestAsync(t); |
|
1128 |
t.Close(); |
|
1129 |
test.Next(_L("Async global pool")); |
|
1130 |
r = t.OpenDynamic(); |
|
1131 |
test_KErrNone(r); |
|
1132 |
TestAsync(t); |
|
1133 |
TestAsync(t); |
|
1134 |
t.Close(); |
|
1135 |
// |
|
1136 |
r=t.Open(); |
|
1137 |
test_KErrNone(r); |
|
1138 |
// |
|
1139 |
TestSession(t); |
|
1140 |
// |
|
1141 |
RDisplay tt; |
|
1142 |
r = tt.OpenS(); |
|
1143 |
test.Printf(_L("OpenS -> %d\n"),r); |
|
1144 |
test_KErrNone(r); |
|
1145 |
TestSession(tt); |
|
1146 |
tt.Close(); |
|
1147 |
// |
|
1148 |
r = tt.OpenGS(); |
|
1149 |
test.Printf(_L("OpenGS -> %d\n"),r); |
|
1150 |
test(r==KErrPermissionDenied); |
|
1151 |
tt.Close(); |
|
1152 |
// |
|
1153 |
r = tt.OpenUS(); |
|
1154 |
test.Printf(_L("OpenUS -> %d\n"),r); |
|
1155 |
test_KErrNone(r); |
|
1156 |
TestUnsharableSession(tt); |
|
1157 |
tt.Close(); |
|
1158 |
// |
|
1159 |
test.Next(_L("Starting speedy client")); |
|
1160 |
RThread speedy; |
|
1161 |
TRequestStatus speedyStat; |
|
1162 |
r=speedy.Create(_L("Speedy"),speedyThreadEntryPoint,KDefaultStackSize,KHeapSize,KHeapSize,&t); |
|
1163 |
test_KErrNone(r); |
|
1164 |
speedy.Logon(speedyStat); |
|
1165 |
RThread t1; |
|
1166 |
RThread t2; |
|
1167 |
RThread t3; |
|
1168 |
RThread t4; |
|
1169 |
TRequestStatus s1; |
|
1170 |
TRequestStatus s2; |
|
1171 |
TRequestStatus s3; |
|
1172 |
TRequestStatus s4; |
|
1173 |
r=t1.Create(_L("SixthClient"),SixthClient,0x1000,NULL,&t); |
|
1174 |
test_KErrNone(r); |
|
1175 |
t1.Logon(s1); |
|
1176 |
r=t2.Create(_L("SeventhClient"),SeventhClient,0x1000,NULL,&t); |
|
1177 |
test_KErrNone(r); |
|
1178 |
t2.Logon(s2); |
|
1179 |
r=t3.Create(_L("EighthClient"),EighthClient,0x1000,NULL,&t); |
|
1180 |
test_KErrNone(r); |
|
1181 |
t3.Logon(s3); |
|
1182 |
r=t4.Create(_L("NinthClient"),NinthClient,0x1000,NULL,&t); |
|
1183 |
test_KErrNone(r); |
|
1184 |
t4.Logon(s4); |
|
1185 |
t1.Resume(); |
|
1186 |
t2.Resume(); |
|
1187 |
t3.Resume(); |
|
1188 |
t4.Resume(); |
|
1189 |
User::After(1000000); |
|
1190 |
// |
|
1191 |
test.Next(_L("Wait for speedy to start")); |
|
1192 |
speedy.SetPriority(EPriorityNormal); |
|
1193 |
RThread().SetPriority(EPriorityMuchMore); |
|
1194 |
speedy.Resume(); |
|
1195 |
client.Wait(); |
|
1196 |
// |
|
1197 |
test.Printf(_L("Starting speed test...\n")); |
|
1198 |
User::After(300000); |
|
1199 |
TInt b=speedCount; |
|
1200 |
User::After(3000000); |
|
1201 |
TInt n=speedCount; |
|
1202 |
test.Printf(_L("Count = %d in 1 second\n"),(n-b)/3); |
|
1203 |
// |
|
1204 |
test.Next(_L("Stop server")); |
|
1205 |
r=t.Stop(); |
|
1206 |
test_KErrNone(r); |
|
1207 |
User::After(0); // Allow the speed client to die |
|
1208 |
// |
|
1209 |
test.Next(_L("Close extra threads")); |
|
1210 |
t1.Kill(0); |
|
1211 |
User::WaitForRequest(s1); |
|
1212 |
test(t1.ExitType()==EExitKill && s1==KErrNone); |
|
1213 |
t2.Kill(0); |
|
1214 |
User::WaitForRequest(s2); |
|
1215 |
test(t2.ExitType()==EExitKill && s2==KErrNone); |
|
1216 |
t3.Kill(0); |
|
1217 |
User::WaitForRequest(s3); |
|
1218 |
test(t3.ExitType()==EExitKill && s3==KErrNone); |
|
1219 |
t4.Kill(0); |
|
1220 |
User::WaitForRequest(s4); |
|
1221 |
test(t4.ExitType()==EExitKill && s4==KErrNone); |
|
1222 |
User::WaitForRequest(speedyStat); |
|
1223 |
test(speedy.ExitType()==EExitKill && speedyStat==KErrNone); |
|
1224 |
// |
|
1225 |
test.Next(_L("Close all")); |
|
1226 |
t1.Close(); |
|
1227 |
t2.Close(); |
|
1228 |
t3.Close(); |
|
1229 |
t4.Close(); |
|
1230 |
speedy.Close(); |
|
1231 |
server.Close(); |
|
1232 |
client.Close(); |
|
1233 |
// |
|
1234 |
test.Next(_L("Close connection")); |
|
1235 |
t.Close(); |
|
1236 |
// |
|
1237 |
RogueThreadTest(); |
|
1238 |
// |
|
1239 |
test.End(); |
|
1240 |
return(0); |
|
1241 |
} |
|
1242 |