author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 07 Jan 2010 13:38:45 +0200 | |
changeset 33 | 0173bcd7697c |
parent 0 | a41df078684a |
child 109 | b3a1d9898418 |
child 249 | a179b74831c9 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2008-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\demandpaging\t_svrpinning.cpp |
|
15 |
// Overview: |
|
16 |
// Test the pinning of RMessage descriptor arguments. |
|
17 |
// API Information: |
|
18 |
// RMessage2, RMessagePtr2, RSessionBase, CSession2, CServer2 |
|
19 |
// Details: |
|
20 |
// Platforms/Drives/Compatibility: |
|
21 |
// All. |
|
22 |
// Assumptions/Requirement/Pre-requisites: |
|
23 |
// Failures and causes: |
|
24 |
// Base Port information: |
|
25 |
// |
|
26 |
// |
|
27 |
||
28 |
#define __E32TEST_EXTENSION__ |
|
29 |
||
30 |
#include <e32std.h> |
|
31 |
#include <e32std_private.h> |
|
32 |
#include <e32def.h> |
|
33 |
#include <e32def_private.h> |
|
34 |
#include <e32test.h> |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
35 |
#include <e32ver.h> |
0 | 36 |
#include <e32panic.h> |
37 |
#include <dptest.h> |
|
38 |
#include <u32hal.h> |
|
39 |
#include <hal.h> |
|
40 |
||
41 |
const TInt KHeapMinSize=0x1000; |
|
42 |
const TInt KHeapMaxSize=0x1000; |
|
43 |
||
44 |
const TUint KPageSize = 0x1000; |
|
45 |
TInt gPageSize; |
|
46 |
TUint gPageMask; |
|
47 |
TBool gDataPagingSupport = EFalse; |
|
48 |
TBool gProcessPaged; |
|
49 |
enum TServerPinning |
|
50 |
{ |
|
51 |
EServerDefault, |
|
52 |
EServerPinning, |
|
53 |
EServerNotPinning, |
|
54 |
EServerSetPinningTooLate, |
|
55 |
EServerPinningCount, |
|
56 |
}; |
|
57 |
TInt gServerPinningState; |
|
58 |
||
59 |
class CTestServer : public CServer2 |
|
60 |
{ |
|
61 |
public: |
|
62 |
CTestServer(TInt aPriority); |
|
63 |
protected: |
|
64 |
//override the pure virtual functions: |
|
65 |
virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const; |
|
66 |
}; |
|
67 |
||
68 |
||
69 |
class CTestSession : public CSession2 |
|
70 |
{ |
|
71 |
public: |
|
72 |
enum TTestMode |
|
73 |
{ |
|
74 |
EStop, |
|
75 |
ETestPinAll, |
|
76 |
ETestPinEven, |
|
77 |
ETestPinOdd, |
|
78 |
ETestPin3, |
|
79 |
ETestPin2, |
|
80 |
ETestPin1, |
|
81 |
ETestPin0, |
|
82 |
ETestPinWritable, |
|
83 |
ETestUnpinWritable, |
|
84 |
ETestPinOOM, |
|
85 |
ETestPinDefault, |
|
86 |
ETestDeadServer, |
|
87 |
}; |
|
88 |
//Override pure virtual |
|
89 |
IMPORT_C virtual void ServiceL(const RMessage2& aMessage); |
|
90 |
private: |
|
91 |
TInt CheckDesPresent(const RMessage2& aMessage, TUint aArgIndex, TBool aExpected, TBool aWrite); |
|
92 |
TInt CheckArgsPresent(const RMessage2& aMessage, TBool arg0Present, TBool arg1Present, TBool arg2Present, TBool arg3Present, TBool aWrite); |
|
93 |
TBool iClientDied; |
|
94 |
}; |
|
95 |
||
96 |
||
97 |
class CMyActiveScheduler : public CActiveScheduler |
|
98 |
{ |
|
99 |
public: |
|
100 |
virtual void Error(TInt anError) const; //override pure virtual error function |
|
101 |
}; |
|
102 |
||
103 |
||
104 |
class RSession : public RSessionBase |
|
105 |
{ |
|
106 |
public: |
|
107 |
TInt PublicSendReceive(TInt aFunction, const TIpcArgs &aPtr) |
|
108 |
{ |
|
109 |
return (SendReceive(aFunction, aPtr)); |
|
110 |
} |
|
111 |
TInt PublicCreateSession(const TDesC& aServer,TInt aMessageSlots) |
|
112 |
{ |
|
113 |
return (CreateSession(aServer,User::Version(),aMessageSlots)); |
|
114 |
} |
|
115 |
}; |
|
116 |
||
117 |
||
118 |
_LIT(KServerName,"CTestServer"); |
|
119 |
||
120 |
TBool UpdateExpected(TBool aExpected) |
|
121 |
{ |
|
122 |
if (!gDataPagingSupport // Data paging is not supported so memory should always be present |
|
123 |
|| gServerPinningState == EServerPinning // The server is a pinning server. |
|
124 |
/*|| (gServerPinningState == EServerDefault && !gProcessPaged)*/// The process isn't paged and default server policy |
|
125 |
) |
|
126 |
{ |
|
127 |
aExpected = ETrue; |
|
128 |
} |
|
129 |
return aExpected; |
|
130 |
} |
|
131 |
||
132 |
||
133 |
CTestServer::CTestServer(TInt aPriority) |
|
134 |
// |
|
135 |
// Constructor - sets name |
|
136 |
// |
|
137 |
: CServer2(aPriority) |
|
138 |
{} |
|
139 |
||
140 |
CSession2* CTestServer::NewSessionL(const TVersion& aVersion,const RMessage2& /*aMessage*/) const |
|
141 |
// |
|
142 |
// Virtual fn - checks version supported and creates a CTestSession |
|
143 |
// |
|
144 |
{ |
|
145 |
TVersion version(KE32MajorVersionNumber,KE32MinorVersionNumber,KE32BuildVersionNumber); |
|
146 |
if (User::QueryVersionSupported(version,aVersion)==EFalse) |
|
147 |
User::Leave(KErrNotSupported); |
|
148 |
CTestSession* newCTestSession = new CTestSession; |
|
149 |
if (newCTestSession==NULL) |
|
150 |
User::Panic(_L("NewSessionL failure"), KErrNoMemory); |
|
151 |
return(newCTestSession); |
|
152 |
} |
|
153 |
||
154 |
RSemaphore gSem; |
|
155 |
RSemaphore gSem1; |
|
156 |
||
157 |
TInt CTestSession::CheckDesPresent(const RMessage2& aMessage, TUint aArgIndex, TBool aExpected, TBool aWrite) |
|
158 |
{ |
|
159 |
if (aExpected) |
|
160 |
RDebug::Printf(" Checking message argument at %d is present", aArgIndex); |
|
161 |
else |
|
162 |
RDebug::Printf(" Checking message argument at %d is not present", aArgIndex); |
|
163 |
||
164 |
// Get the length of the descriptor and verify it is as expected. |
|
165 |
TInt length = aMessage.GetDesLength(aArgIndex); |
|
166 |
if (length < KErrNone) |
|
167 |
{ |
|
168 |
RDebug::Printf(" Error getting descriptor length %d", length); |
|
169 |
return length; |
|
170 |
} |
|
171 |
if (length < 3) |
|
172 |
{// The incorrect descriptor length. |
|
173 |
RDebug::Printf(" Error - Descriptor length too small %d", length); |
|
174 |
return KErrArgument; |
|
175 |
} |
|
176 |
if (!aWrite) |
|
177 |
{// Now read the descriptor and verify that it is present or not. |
|
178 |
TBuf8<5> des; |
|
179 |
TInt r = aMessage.Read(aArgIndex, des); |
|
180 |
TBool pass; |
|
181 |
if (iClientDied) |
|
182 |
pass = r == KErrDied || r == KErrBadDescriptor; |
|
183 |
else |
|
184 |
pass = r == (aExpected ? KErrNone : KErrBadDescriptor); |
|
185 |
if (!pass) |
|
186 |
{ |
|
187 |
RDebug::Printf(" Error reading descriptor data r %d", r); |
|
188 |
return KErrGeneral; |
|
189 |
} |
|
190 |
if (r==KErrNone && (des[0] != 'a' || des[1] != 'r' || des[2] != 'g')) |
|
191 |
{// The incorrect descriptor data has been passed. |
|
192 |
RDebug::Printf(" Error in descriptor data is corrupt r %d", r); |
|
193 |
return KErrArgument; |
|
194 |
} |
|
195 |
} |
|
196 |
else |
|
197 |
{// Now write to the maximum length of the descriptor. |
|
198 |
TInt max = aMessage.GetDesMaxLength(aArgIndex); |
|
199 |
if (max < 0) |
|
200 |
{ |
|
201 |
RDebug::Printf(" Error getting descriptor max. length %d", max); |
|
202 |
return length; |
|
203 |
} |
|
204 |
HBufC8* argTmp = HBufC8::New(max); |
|
205 |
TPtr8 argPtr = argTmp->Des(); |
|
206 |
argPtr.SetLength(max); |
|
207 |
for (TInt i = 0; i < max; i++) |
|
208 |
argPtr[i] = (TUint8)aArgIndex; |
|
209 |
TInt r = aMessage.Write(aArgIndex, argPtr); |
|
210 |
TBool pass; |
|
211 |
if (iClientDied) |
|
212 |
pass = r == KErrDied || r == KErrBadDescriptor; |
|
213 |
else |
|
214 |
pass = r == (aExpected ? KErrNone : KErrBadDescriptor); |
|
215 |
if (!pass) |
|
216 |
{ |
|
217 |
RDebug::Printf(" Error writing to the descriptor data r %d", r); |
|
218 |
return KErrGeneral; |
|
219 |
} |
|
220 |
} |
|
221 |
||
222 |
if (!aExpected) |
|
223 |
{// The client should have been killed as the data wasn't present. |
|
224 |
if(!iClientDied) |
|
225 |
User::After(500000); // allow time for client to die before next test |
|
226 |
iClientDied = ETrue; |
|
227 |
} |
|
228 |
return KErrNone; |
|
229 |
} |
|
230 |
||
231 |
TInt CTestSession::CheckArgsPresent(const RMessage2& aMessage, TBool arg0Present, TBool arg1Present, TBool arg2Present, TBool arg3Present, TBool aWrite=EFalse) |
|
232 |
{ |
|
233 |
// Adjust the pinning status expected based on the default policies. |
|
234 |
// (Must do this before anything else as UpdateExpected() accessed paged global data) |
|
235 |
arg0Present = UpdateExpected(arg0Present); |
|
236 |
arg1Present = UpdateExpected(arg1Present); |
|
237 |
arg2Present = UpdateExpected(arg2Present); |
|
238 |
arg3Present = UpdateExpected(arg3Present); |
|
239 |
||
240 |
// Flush the cache so on paged systems, unpinned paged memory will be discarded. |
|
241 |
DPTest::FlushCache(); |
|
242 |
||
243 |
TInt r = User::SetRealtimeState(User::ERealtimeStateOn); |
|
244 |
if (r != KErrNone) |
|
245 |
{ |
|
246 |
RDebug::Printf("Error setting realtime state r = %d", r); |
|
247 |
return r; |
|
248 |
} |
|
249 |
||
250 |
r = CheckDesPresent(aMessage, 0, arg0Present, aWrite); |
|
251 |
if (r == KErrNone) |
|
252 |
r = CheckDesPresent(aMessage, 1, arg1Present, aWrite); |
|
253 |
if (r == KErrNone) |
|
254 |
r = CheckDesPresent(aMessage, 2, arg2Present, aWrite); |
|
255 |
if (r == KErrNone) |
|
256 |
r = CheckDesPresent(aMessage, 3, arg3Present, aWrite); |
|
257 |
||
258 |
User::SetRealtimeState(User::ERealtimeStateOff); |
|
259 |
||
260 |
return r; |
|
261 |
} |
|
262 |
||
263 |
void CTestSession::ServiceL(const RMessage2& aMessage) |
|
264 |
// |
|
265 |
// Virtual message-handler |
|
266 |
// |
|
267 |
{ |
|
268 |
TInt r = KErrNone; |
|
269 |
iClientDied = EFalse; |
|
270 |
switch (aMessage.Function()) |
|
271 |
{ |
|
272 |
case EStop: |
|
273 |
CActiveScheduler::Stop(); |
|
274 |
break; |
|
275 |
case ETestPinAll: |
|
276 |
r = CheckArgsPresent(aMessage, ETrue, ETrue, ETrue, ETrue); |
|
277 |
break; |
|
278 |
case ETestPinOdd: |
|
279 |
r = CheckArgsPresent(aMessage, EFalse, ETrue, EFalse, ETrue); |
|
280 |
break; |
|
281 |
case ETestPinEven: |
|
282 |
r = CheckArgsPresent(aMessage, ETrue, EFalse, ETrue, EFalse); |
|
283 |
break; |
|
284 |
case ETestPin3: |
|
285 |
r = CheckArgsPresent(aMessage, ETrue, ETrue, ETrue, EFalse); |
|
286 |
break; |
|
287 |
case ETestPin2: |
|
288 |
r = CheckArgsPresent(aMessage, ETrue, ETrue, EFalse, EFalse); |
|
289 |
break; |
|
290 |
case ETestPin1: |
|
291 |
r = CheckArgsPresent(aMessage, ETrue, EFalse, EFalse, EFalse); |
|
292 |
break; |
|
293 |
case ETestPin0: |
|
294 |
case ETestPinDefault: |
|
295 |
r = CheckArgsPresent(aMessage, EFalse, EFalse, EFalse, EFalse); |
|
296 |
break; |
|
297 |
case ETestPinWritable: |
|
298 |
r = CheckArgsPresent(aMessage, ETrue, ETrue, ETrue, ETrue, ETrue); |
|
299 |
break; |
|
300 |
case ETestUnpinWritable: |
|
301 |
r = CheckArgsPresent(aMessage, EFalse, EFalse, EFalse, EFalse, ETrue); |
|
302 |
break; |
|
303 |
default: |
|
304 |
r = KErrNotSupported; |
|
305 |
||
306 |
} |
|
307 |
aMessage.Complete(r); |
|
308 |
||
309 |
// If descriptors aren't as expected then panic so the test will fail. |
|
310 |
if (r != KErrNone) |
|
311 |
User::Panic(_L("ServiceL failure"), r); |
|
312 |
} |
|
313 |
||
314 |
// CTestSession funtions |
|
315 |
||
316 |
void CMyActiveScheduler::Error(TInt anError) const |
|
317 |
// |
|
318 |
// Virtual error handler |
|
319 |
// |
|
320 |
{ |
|
321 |
User::Panic(_L("CMyActiveScheduer::Error"), anError); |
|
322 |
} |
|
323 |
||
324 |
TInt ServerThread(TAny* aPinningAttrib) |
|
325 |
// |
|
326 |
// Passed as the server thread in 2 tests - sets up and runs CTestServer |
|
327 |
// |
|
328 |
{ |
|
329 |
RTest test(_L("T_SVRPINNING...server")); |
|
330 |
CMyActiveScheduler* pScheduler = new CMyActiveScheduler; |
|
331 |
if (pScheduler == NULL) |
|
332 |
{ |
|
333 |
gSem.Signal(); |
|
334 |
test(0); |
|
335 |
} |
|
336 |
||
337 |
CActiveScheduler::Install(pScheduler); |
|
338 |
||
339 |
CTestServer* pServer = new CTestServer(0); |
|
340 |
if (pServer == NULL) |
|
341 |
{ |
|
342 |
gSem.Signal(); |
|
343 |
test(0); |
|
344 |
} |
|
345 |
||
346 |
// Set the pinning attributes of the server. |
|
347 |
TServerPinning pinningAttrib = (TServerPinning)(TInt)aPinningAttrib; |
|
348 |
switch (pinningAttrib) |
|
349 |
{ |
|
350 |
case EServerDefault : |
|
351 |
case EServerSetPinningTooLate : |
|
352 |
break; |
|
353 |
case EServerPinning : |
|
354 |
pServer->SetPinClientDescriptors(ETrue); |
|
355 |
break; |
|
356 |
case EServerNotPinning : |
|
357 |
pServer->SetPinClientDescriptors(EFalse); |
|
358 |
break; |
|
359 |
default : |
|
360 |
break; |
|
361 |
} |
|
362 |
||
363 |
//Starting a CServer2 also Adds it to the ActiveScheduler |
|
364 |
TInt r = pServer->Start(KServerName); |
|
365 |
if (r != KErrNone) |
|
366 |
{ |
|
367 |
gSem.Signal(); |
|
368 |
test(0); |
|
369 |
} |
|
370 |
||
371 |
if (pinningAttrib == EServerSetPinningTooLate) |
|
372 |
{ |
|
373 |
pServer->SetPinClientDescriptors(EFalse); |
|
374 |
} |
|
375 |
||
376 |
test.Next(_L("Start ActiveScheduler and signal to client")); |
|
377 |
test.Printf(_L(" There might be something going on beneath this window\n")); |
|
378 |
gSem.Signal(); |
|
379 |
CActiveScheduler::Start(); |
|
380 |
test.Next(_L("Destroy ActiveScheduler")); |
|
381 |
delete pScheduler; |
|
382 |
delete pServer; |
|
383 |
||
384 |
test.Close(); |
|
385 |
||
386 |
return (KErrNone); |
|
387 |
} |
|
388 |
||
389 |
||
390 |
||
391 |
#include <e32svr.h> |
|
392 |
||
393 |
void dummyFunction(TUint8* /*a0*/, TUint8* /*a1*/, TUint8* /*a2*/, TUint8* /*a3*/, TUint8* /*a4*/, TUint8* /*a5*/) |
|
394 |
{ |
|
395 |
} |
|
396 |
||
397 |
TInt ClientThread(TAny* aTestMode) |
|
398 |
// |
|
399 |
// Passed as the first client thread - signals the server to do several tests |
|
400 |
// |
|
401 |
{ |
|
402 |
// Create the message arguments to be pinned. Should be one of each type of |
|
403 |
// descriptor to test that the pinning code can correctly pin each type |
|
404 |
// descriptor data. Each descriptor's data should in a separate page in |
|
405 |
// thread's stack to ensure that access to each argument will cause a |
|
406 |
// separate page fault. |
|
407 |
||
408 |
TUint8 argBufs[KPageSize*(6+2)]; // enough for 6 whole pages |
|
409 |
TUint8* argBuf0 = (TUint8*)(TUintPtr(argBufs+gPageMask)&~gPageMask); |
|
410 |
TUint8* argBuf1 = argBuf0+KPageSize; |
|
411 |
TUint8* argBuf2 = argBuf1+KPageSize; |
|
412 |
TUint8* argBuf3 = argBuf2+KPageSize; |
|
413 |
TUint8* argBuf4 = argBuf3+KPageSize; |
|
414 |
TUint8* argBuf5 = argBuf4+KPageSize; |
|
415 |
||
416 |
argBuf0[0]='a'; argBuf0[1]='r'; argBuf0[2]='g'; argBuf0[3]='0'; argBuf0[4]='\0'; |
|
417 |
TPtr8 arg0(argBuf0, 5, 20); |
|
418 |
||
419 |
TBufC8<5>& arg1 = *(TBufC8<5>*)argBuf1; |
|
420 |
new (&arg1) TBufC8<5>((const TUint8*)"arg1"); |
|
421 |
||
422 |
argBuf2[0]='a'; argBuf2[1]='r'; argBuf2[2]='g'; argBuf2[3]='1'; argBuf2[4]='\0'; |
|
423 |
TPtrC8 arg2((const TUint8*)argBuf2); |
|
424 |
||
425 |
TBuf8<50>& arg3 = *(TBuf8<50>*)argBuf3; |
|
426 |
new (&arg3) TBuf8<50>((const TUint8*)"arg3"); |
|
427 |
||
428 |
// For some tests use this 5th and final type of descriptor. |
|
429 |
HBufC8* argTmp = HBufC8::New(7); |
|
430 |
*argTmp = (const TUint8*)"argTmp"; |
|
431 |
RBuf8 argTmpBuf(argTmp); |
|
432 |
||
433 |
// Need a couple of extra writable argments |
|
434 |
argBuf4[0]='a'; argBuf4[1]='r'; argBuf4[2]='g'; argBuf4[3]='4'; argBuf4[4]='\0'; |
|
435 |
TPtr8 arg4(argBuf4, 5, 20); |
|
436 |
argBuf5[0]='a'; argBuf5[1]='r'; argBuf5[2]='g'; argBuf5[3]='5'; argBuf5[4]='\0'; |
|
437 |
TPtr8 arg5(argBuf5, 5, 20); |
|
438 |
||
439 |
RTest test(_L("T_SVRPINNING...client")); |
|
440 |
RSession session; |
|
441 |
TInt r = session.PublicCreateSession(_L("CTestServer"),5); |
|
442 |
if (r != KErrNone) |
|
443 |
{ |
|
444 |
gSem.Signal(); |
|
445 |
test(0); |
|
446 |
} |
|
447 |
||
448 |
switch((TInt)aTestMode) |
|
449 |
{ |
|
450 |
case CTestSession::ETestPinAll: |
|
451 |
test.Printf(_L("Test pinning all args\n")); |
|
452 |
r = session.PublicSendReceive(CTestSession::ETestPinAll, TIpcArgs(&arg0, &arg1, &arg2, &arg3).PinArgs()); |
|
453 |
break; |
|
454 |
||
455 |
case CTestSession::ETestPinOdd: |
|
456 |
test.Printf(_L("Test pinning odd args\n")); |
|
457 |
r = session.PublicSendReceive(CTestSession::ETestPinOdd, TIpcArgs(&arg0, &argTmpBuf, &arg2, &arg3).PinArgs(EFalse, ETrue, EFalse, ETrue)); |
|
458 |
break; |
|
459 |
||
460 |
case CTestSession::ETestPinEven: |
|
461 |
test.Printf(_L("Test pinning even args\n")); |
|
462 |
r = session.PublicSendReceive(CTestSession::ETestPinEven, TIpcArgs(&arg0, &arg1, argTmp, &arg3).PinArgs(ETrue, EFalse, ETrue, EFalse)); |
|
463 |
break; |
|
464 |
||
465 |
case CTestSession::ETestPin3: |
|
466 |
test.Printf(_L("Test pinning 3 args\n")); |
|
467 |
r = session.PublicSendReceive(CTestSession::ETestPin3, TIpcArgs(&arg0, &arg1, &arg2, &arg3).PinArgs(ETrue, ETrue, ETrue, EFalse)); |
|
468 |
break; |
|
469 |
||
470 |
case CTestSession::ETestPin2: |
|
471 |
test.Printf(_L("Test pinning 2 args\n")); |
|
472 |
r = session.PublicSendReceive(CTestSession::ETestPin2, TIpcArgs(argTmp, &arg1, &arg2, &arg3).PinArgs(ETrue, ETrue, EFalse, EFalse)); |
|
473 |
break; |
|
474 |
||
475 |
case CTestSession::ETestPin1: |
|
476 |
test.Printf(_L("Test pinning 1 args\n")); |
|
477 |
r = session.PublicSendReceive(CTestSession::ETestPin1, TIpcArgs(&argTmpBuf, &arg1, &arg2, &arg3).PinArgs(ETrue, EFalse, EFalse, EFalse)); |
|
478 |
break; |
|
479 |
||
480 |
case CTestSession::ETestPin0: |
|
481 |
test.Printf(_L("Test pinning 0 args\n")); |
|
482 |
r = session.PublicSendReceive(CTestSession::ETestPin0, TIpcArgs(&arg0, &arg1, &arg2, &arg3).PinArgs(EFalse, EFalse, EFalse, EFalse)); |
|
483 |
break; |
|
484 |
||
485 |
case CTestSession::ETestPinDefault: |
|
486 |
test.Printf(_L("Test the default pinning policy of this server\n")); |
|
487 |
r = session.PublicSendReceive(CTestSession::ETestPinDefault, TIpcArgs(&arg0, &arg1, &arg2, argTmp)); |
|
488 |
break; |
|
489 |
||
490 |
case CTestSession::ETestPinWritable: |
|
491 |
test.Printf(_L("Test writing to pinned descriptors\n")); |
|
492 |
r = session.PublicSendReceive(CTestSession::ETestPinWritable, TIpcArgs(&arg0, &arg3, &arg4, &arg5).PinArgs(ETrue, ETrue, ETrue, ETrue)); |
|
493 |
// Verify the index of each argument has been written to each descriptor. |
|
494 |
{ |
|
495 |
TUint maxLength = arg0.MaxLength(); |
|
496 |
test_Equal(maxLength, arg0.Length()); |
|
497 |
TUint j = 0; |
|
498 |
for (; j < maxLength; j++) |
|
499 |
test_Equal(0, arg0[j]); |
|
500 |
maxLength = arg3.MaxLength(); |
|
501 |
test_Equal(maxLength, arg3.Length()); |
|
502 |
for (j = 0; j < maxLength; j++) |
|
503 |
test_Equal(1, arg3[j]); |
|
504 |
maxLength = arg4.MaxLength(); |
|
505 |
test_Equal(maxLength, arg4.Length()); |
|
506 |
for (j = 0; j < maxLength; j++) |
|
507 |
test_Equal(2, arg4[j]); |
|
508 |
maxLength = arg5.MaxLength(); |
|
509 |
test_Equal(maxLength, arg5.Length()); |
|
510 |
for (j = 0; j < maxLength; j++) |
|
511 |
test_Equal(3, arg5[j]); |
|
512 |
} |
|
513 |
break; |
|
514 |
||
515 |
case CTestSession::ETestUnpinWritable: |
|
516 |
test.Printf(_L("Test writing to unpinned descriptors\n")); |
|
517 |
r = session.PublicSendReceive(CTestSession::ETestUnpinWritable, TIpcArgs(&arg0, &arg3, &arg4, &arg5).PinArgs(EFalse, EFalse, EFalse, EFalse)); |
|
518 |
// Verify the index of each argument has been written to each descriptor. |
|
519 |
// Unless this is a pinnning server than the thread will be panicked before we reach there. |
|
520 |
{ |
|
521 |
TUint maxLength = arg0.MaxLength(); |
|
522 |
test_Equal(maxLength, arg0.Length()); |
|
523 |
TUint j = 0; |
|
524 |
for (j = 0; j < maxLength; j++) |
|
525 |
test_Equal(0, arg0[j]); |
|
526 |
maxLength = arg3.MaxLength(); |
|
527 |
test_Equal(maxLength, arg3.Length()); |
|
528 |
for (j = 0; j < maxLength; j++) |
|
529 |
test_Equal(1, arg3[j]); |
|
530 |
maxLength = arg4.MaxLength(); |
|
531 |
test_Equal(maxLength, arg4.Length()); |
|
532 |
for (j = 0; j < maxLength; j++) |
|
533 |
test_Equal(2, arg4[j]); |
|
534 |
maxLength = arg5.MaxLength(); |
|
535 |
test_Equal(maxLength, arg5.Length()); |
|
536 |
for (j = 0; j < maxLength; j++) |
|
537 |
test_Equal(3, arg5[j]); |
|
538 |
} |
|
539 |
break; |
|
540 |
||
541 |
case CTestSession::ETestDeadServer: |
|
542 |
test.Printf(_L("Test pinning to dead server\n")); |
|
543 |
gSem.Signal(); |
|
544 |
gSem1.Wait(); |
|
545 |
r = session.PublicSendReceive(CTestSession::ETestPinAll, TIpcArgs(&arg0, &arg1, &arg2, &arg3).PinArgs()); |
|
546 |
break; |
|
547 |
||
548 |
case CTestSession::ETestPinOOM: |
|
549 |
test.Printf(_L("Pinning OOM tests\n")); |
|
550 |
__KHEAP_MARK; |
|
551 |
const TUint KMaxKernelAllocations = 1024; |
|
552 |
TUint i; |
|
553 |
r = KErrNoMemory; |
|
554 |
for (i = 0; i < KMaxKernelAllocations && r == KErrNoMemory; i++) |
|
555 |
{ |
|
556 |
__KHEAP_FAILNEXT(i); |
|
557 |
r = session.PublicSendReceive(CTestSession::ETestPinAll, TIpcArgs(&arg0, &arg1, &arg2, &arg3).PinArgs()); |
|
558 |
__KHEAP_RESET; |
|
559 |
} |
|
560 |
test.Printf(_L("SendReceive took %d tries\n"),i); |
|
561 |
test_KErrNone(r); |
|
562 |
||
563 |
__KHEAP_MARKEND; |
|
564 |
break; |
|
565 |
} |
|
566 |
||
567 |
session.Close(); |
|
568 |
test.Close(); |
|
569 |
return r; |
|
570 |
} |
|
571 |
||
572 |
||
573 |
GLDEF_C TInt E32Main() |
|
574 |
{ |
|
575 |
RTest test(_L("T_SVRPINNING...main")); |
|
576 |
test.Title(); |
|
577 |
||
578 |
||
579 |
if (DPTest::Attributes() & DPTest::ERomPaging) |
|
580 |
test.Printf(_L("Rom paging supported\n")); |
|
581 |
if (DPTest::Attributes() & DPTest::ECodePaging) |
|
582 |
test.Printf(_L("Code paging supported\n")); |
|
583 |
if (DPTest::Attributes() & DPTest::EDataPaging) |
|
584 |
{ |
|
585 |
test.Printf(_L("Data paging supported\n")); |
|
586 |
gDataPagingSupport = ETrue; |
|
587 |
} |
|
588 |
||
589 |
// Determine the data paging attribute. |
|
590 |
RProcess process; // Default to point to current process. |
|
591 |
gProcessPaged = process.DefaultDataPaged(); |
|
592 |
test.Printf(_L("Process data paged %x\n"), gProcessPaged); |
|
593 |
||
594 |
test.Start(_L("Test IPC message arguments pinning")); |
|
595 |
test_KErrNone(HAL::Get(HAL::EMemoryPageSize, gPageSize)); |
|
596 |
gPageMask = gPageSize - 1; |
|
597 |
test_Equal(KPageSize, gPageSize); |
|
598 |
// Disable JIT as we are testing panics and don't want the emulator to hang. |
|
599 |
TBool justInTime = User::JustInTime(); |
|
600 |
User::SetJustInTime(EFalse); |
|
601 |
||
602 |
TBool exitFailure = EFalse; |
|
603 |
for ( gServerPinningState = EServerDefault; |
|
604 |
gServerPinningState < EServerSetPinningTooLate && !exitFailure; |
|
605 |
gServerPinningState++) |
|
606 |
{ |
|
607 |
// Create the server with the specified pinning mode. |
|
608 |
switch (gServerPinningState) |
|
609 |
{ |
|
610 |
case EServerDefault : |
|
611 |
test.Next(_L("Test server with default pinning policy")); |
|
612 |
break; |
|
613 |
case EServerPinning : |
|
614 |
test.Next(_L("Test server with pinning policy")); |
|
615 |
break; |
|
616 |
case EServerNotPinning : |
|
617 |
test.Next(_L("Test server with not pinning policy")); |
|
618 |
break; |
|
619 |
} |
|
620 |
test_KErrNone(gSem.CreateLocal(0)); |
|
621 |
test_KErrNone(gSem1.CreateLocal(0)); |
|
622 |
// Create the server thread it needs to have a unpaged stack and heap. |
|
623 |
TThreadCreateInfo serverInfo(_L("Server Thread"), ServerThread, KDefaultStackSize, (TAny*)gServerPinningState); |
|
624 |
serverInfo.SetPaging(TThreadCreateInfo::EUnpaged); |
|
625 |
serverInfo.SetCreateHeap(KHeapMinSize, KHeapMaxSize); |
|
626 |
RThread serverThread; |
|
627 |
test_KErrNone(serverThread.Create(serverInfo)); |
|
628 |
TRequestStatus serverStat; |
|
629 |
serverThread.Logon(serverStat); |
|
630 |
serverThread.Resume(); |
|
631 |
||
632 |
// Wait for the server to start and then create a session to it. |
|
633 |
gSem.Wait(); |
|
634 |
RSession session; |
|
635 |
test_KErrNone(session.PublicCreateSession(_L("CTestServer"),5)); |
|
636 |
||
637 |
for ( TUint clientTest = CTestSession::ETestPinAll; |
|
638 |
clientTest <= CTestSession::ETestPinDefault && !exitFailure; |
|
639 |
clientTest++) |
|
640 |
{ |
|
641 |
// Create the client thread it needs to have a paged stack and heap. |
|
642 |
TThreadCreateInfo clientInfo(_L("Client Thread"), ClientThread, 10 * gPageSize, (TAny*)clientTest); |
|
643 |
clientInfo.SetPaging(TThreadCreateInfo::EPaged); |
|
644 |
clientInfo.SetCreateHeap(KHeapMinSize, KHeapMaxSize); |
|
645 |
RThread clientThread; |
|
646 |
test_KErrNone(clientThread.Create(clientInfo)); |
|
647 |
||
648 |
TRequestStatus clientStat; |
|
649 |
clientThread.Logon(clientStat); |
|
650 |
clientThread.Resume(); |
|
651 |
||
652 |
// Wait for the client thread to end. |
|
653 |
User::WaitForRequest(clientStat); |
|
654 |
||
655 |
// If all the descriptor arguments were not pinned then the client |
|
656 |
// thread should have been panicked. |
|
657 |
TBool expectPanic = (clientTest == CTestSession::ETestPinAll || |
|
658 |
clientTest == CTestSession::ETestPinWritable || |
|
659 |
clientTest == CTestSession::ETestPinOOM )? 0 : 1; |
|
660 |
expectPanic = !UpdateExpected(!expectPanic); |
|
661 |
||
662 |
TInt exitReason = clientThread.ExitReason(); |
|
663 |
TInt exitType = clientThread.ExitType(); |
|
664 |
if (expectPanic) |
|
665 |
{ |
|
666 |
if (exitType != EExitPanic || |
|
667 |
exitReason != EIllegalFunctionForRealtimeThread || |
|
668 |
clientThread.ExitCategory() != _L("KERN-EXEC")) |
|
669 |
{// Thread didn't panic as expected. |
|
670 |
exitFailure = ETrue; |
|
671 |
} |
|
672 |
} |
|
673 |
else |
|
674 |
{ |
|
675 |
if (exitType != EExitKill || exitReason != KErrNone) |
|
676 |
{// Thread didn't exit gracefully as expected. |
|
677 |
exitFailure = ETrue; |
|
678 |
} |
|
679 |
} |
|
680 |
CLOSE_AND_WAIT(clientThread); |
|
681 |
} |
|
682 |
||
683 |
test.Next(_L("Test client sending message to closed server")); |
|
684 |
TThreadCreateInfo clientInfo(_L("Client Thread"), ClientThread, 10 * gPageSize, (TAny*)CTestSession::ETestDeadServer); |
|
685 |
clientInfo.SetPaging(TThreadCreateInfo::EPaged); |
|
686 |
clientInfo.SetCreateHeap(KHeapMinSize, KHeapMaxSize); |
|
687 |
RThread clientThread; |
|
688 |
test_KErrNone(clientThread.Create(clientInfo)); |
|
689 |
TRequestStatus clientStat; |
|
690 |
clientThread.Logon(clientStat); |
|
691 |
clientThread.Resume(); |
|
692 |
gSem.Wait(); |
|
693 |
||
694 |
// Signal to stop ActiveScheduler and wait for server to stop. |
|
695 |
session.PublicSendReceive(CTestSession::EStop, TIpcArgs()); |
|
696 |
session.Close(); |
|
697 |
User::WaitForRequest(serverStat); |
|
698 |
if (serverThread.ExitType() != EExitKill) |
|
699 |
{ |
|
700 |
test.Printf(_L("!!Server thread did something bizarre %d"), serverThread.ExitReason()); |
|
701 |
} |
|
702 |
||
703 |
gSem1.Signal(); |
|
704 |
User::WaitForRequest(clientStat); |
|
705 |
test_Equal(EExitKill, clientThread.ExitType()); |
|
706 |
test_Equal(KErrServerTerminated, clientThread.ExitReason()); |
|
707 |
||
708 |
CLOSE_AND_WAIT(clientThread); |
|
709 |
CLOSE_AND_WAIT(serverThread); |
|
710 |
CLOSE_AND_WAIT(gSem); |
|
711 |
CLOSE_AND_WAIT(gSem1); |
|
712 |
} |
|
713 |
test(!exitFailure); |
|
714 |
||
715 |
test.Next(_L("Test server setting pinning policy after server started")); |
|
716 |
RThread serverThread; |
|
717 |
test_KErrNone(serverThread.Create(_L("Server Thread"),ServerThread,KDefaultStackSize,KHeapMinSize,KHeapMaxSize, (TAny*)gServerPinningState)); |
|
718 |
TRequestStatus serverStat; |
|
719 |
serverThread.Logon(serverStat); |
|
720 |
serverThread.Resume(); |
|
721 |
// The server should have panicked with E32USER-CBase 106. |
|
722 |
User::WaitForRequest(serverStat); |
|
723 |
TInt exitReason = serverThread.ExitReason(); |
|
724 |
TInt exitType = serverThread.ExitType(); |
|
725 |
test_Equal(EExitPanic, exitType); |
|
726 |
test_Equal(ECServer2InvalidSetPin, exitReason); |
|
727 |
if (_L("E32USER-CBase") != serverThread.ExitCategory()) |
|
728 |
test(0); |
|
729 |
CLOSE_AND_WAIT(serverThread); |
|
730 |
||
731 |
test.End(); |
|
732 |
||
733 |
// Set JIT back to original state. |
|
734 |
User::SetJustInTime(justInTime); |
|
735 |
||
736 |
return (KErrNone); |
|
737 |
} |