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