sl@0
|
1 |
// Copyright (c) 2004-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\mmu\t_sharedchunk.cpp
|
sl@0
|
15 |
// Overview:
|
sl@0
|
16 |
// Test sharing an RChunk with a logical device
|
sl@0
|
17 |
// API Information:
|
sl@0
|
18 |
// RChunk
|
sl@0
|
19 |
// Details:
|
sl@0
|
20 |
// - Load and open the logical device driver ("D_SHAREDCHUNK"). Verify
|
sl@0
|
21 |
// results.
|
sl@0
|
22 |
// - Test and verify results of creating shared chunks under OOM conditions. Also verify
|
sl@0
|
23 |
// creating a chunk with a bad type, bad size and too large all fail as
|
sl@0
|
24 |
// expected.
|
sl@0
|
25 |
// - Test and verify opening and closing chunk user handles work as expected.
|
sl@0
|
26 |
// - Test and verify thread local and process local handles work as expected
|
sl@0
|
27 |
// - Test and verify setting restrictions on RChunk if created as shared chunk are as expected.
|
sl@0
|
28 |
// - Test and verify memory access for multiply and singly shared chunks,
|
sl@0
|
29 |
// is as expected. Including IPC, kernel, DFC and ISR reads & writes.
|
sl@0
|
30 |
// - Test and verify discontinuous memory commits for multiply and singly
|
sl@0
|
31 |
// shared chunks are as expected.
|
sl@0
|
32 |
// - Test and verify continuous memory commits for multiply and singly shared
|
sl@0
|
33 |
// chunks are as expected.
|
sl@0
|
34 |
// - Test and verify discontinuous and continuous physical memory commits for
|
sl@0
|
35 |
// multiply and singly shared chunks is as expected.
|
sl@0
|
36 |
// - Test Kern::OpenSharedChunk for multiply and singly shared chunks. Verify
|
sl@0
|
37 |
// results are as expected.
|
sl@0
|
38 |
// - Test that physical memory can be freed immediately after the chunk that mapped
|
sl@0
|
39 |
// it has been closed.
|
sl@0
|
40 |
// Platforms/Drives/Compatibility:
|
sl@0
|
41 |
// All.
|
sl@0
|
42 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
43 |
// Failures and causes:
|
sl@0
|
44 |
// Base Port information:
|
sl@0
|
45 |
//
|
sl@0
|
46 |
//
|
sl@0
|
47 |
|
sl@0
|
48 |
//! @file
|
sl@0
|
49 |
//! @SYMTestCaseID KBASE-T_SHAREDCHUNK
|
sl@0
|
50 |
//! @SYMREQ 3699
|
sl@0
|
51 |
//! @SYMTestPriority High
|
sl@0
|
52 |
//! @SYMTestActions Check creation, memory allocation and access to Shared Chunks
|
sl@0
|
53 |
//! @SYMTestExpectedResults Test runs until this message is emitted: RTEST: SUCCESS : T_SHAREDCHUNK test completed O.K.
|
sl@0
|
54 |
//! @SYMTestType UT
|
sl@0
|
55 |
#define __E32TEST_EXTENSION__
|
sl@0
|
56 |
|
sl@0
|
57 |
#include "d_sharedchunk.h"
|
sl@0
|
58 |
#include "d_gobble.h"
|
sl@0
|
59 |
#include <e32test.h>
|
sl@0
|
60 |
#include <e32hal.h>
|
sl@0
|
61 |
#include "u32std.h"
|
sl@0
|
62 |
#include <u32hal.h>
|
sl@0
|
63 |
#include <e32svr.h>
|
sl@0
|
64 |
#include <f32dbg.h>
|
sl@0
|
65 |
#include <e32def.h>
|
sl@0
|
66 |
#include <e32def_private.h>
|
sl@0
|
67 |
#include "freeram.h"
|
sl@0
|
68 |
|
sl@0
|
69 |
enum TSlaveCommand
|
sl@0
|
70 |
{
|
sl@0
|
71 |
ESlaveCheckChunk,
|
sl@0
|
72 |
ESlaveCreateChunk,
|
sl@0
|
73 |
};
|
sl@0
|
74 |
|
sl@0
|
75 |
//
|
sl@0
|
76 |
// Global data
|
sl@0
|
77 |
//
|
sl@0
|
78 |
|
sl@0
|
79 |
|
sl@0
|
80 |
RSharedChunkLdd Ldd;
|
sl@0
|
81 |
RChunk TheChunk;
|
sl@0
|
82 |
TInt PageSize;
|
sl@0
|
83 |
TUint32 MemModelAttributes;
|
sl@0
|
84 |
TBool PhysicalCommitSupported;
|
sl@0
|
85 |
TBool CachingAttributesSupported;
|
sl@0
|
86 |
TUint8 BssMem[100];
|
sl@0
|
87 |
|
sl@0
|
88 |
const TUint ChunkSize = 0x400000; // 4 meg reserved space for test chunk
|
sl@0
|
89 |
|
sl@0
|
90 |
_LIT(KSecondProcessName,"t_sharedchunk");
|
sl@0
|
91 |
#ifdef __T_SHAREDCHUNKF__
|
sl@0
|
92 |
_LIT(KOtherProcessName,"t_sharedchunk");
|
sl@0
|
93 |
LOCAL_D RTest test(_L("T_SHAREDCHUNKF"));
|
sl@0
|
94 |
#else
|
sl@0
|
95 |
_LIT(KOtherProcessName,"t_sharedchunkf");
|
sl@0
|
96 |
LOCAL_D RTest test(_L("T_SHAREDCHUNK"));
|
sl@0
|
97 |
#endif
|
sl@0
|
98 |
|
sl@0
|
99 |
_LIT8(KTestString, "lks4b7qeyfcea5fyaifyaefyi4flwdysuxanabxa");
|
sl@0
|
100 |
_LIT8(KTestString2,"jhfcalurnhfirlxszhrvcvduhrvndrucxnshxcsx");
|
sl@0
|
101 |
const TUint32 KTestValue = 0x12345678;
|
sl@0
|
102 |
const TUint32 KTestValue2 = KTestValue^0x0f0f0f0f;
|
sl@0
|
103 |
|
sl@0
|
104 |
//
|
sl@0
|
105 |
// Utilitiies for use by tests
|
sl@0
|
106 |
//
|
sl@0
|
107 |
|
sl@0
|
108 |
|
sl@0
|
109 |
_LIT(KLitKernExec, "KERN-EXEC");
|
sl@0
|
110 |
|
sl@0
|
111 |
void CheckFailMessage(const char* n,const char* c,const char* f,TInt r)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
TPtrC8 nn((const TUint8*)n);
|
sl@0
|
114 |
TPtrC8 cc((const TUint8*)c);
|
sl@0
|
115 |
TPtrC8 ff((const TUint8*)f);
|
sl@0
|
116 |
RBuf8 buf;
|
sl@0
|
117 |
buf.Create((nn.Size()+cc.Size()+ff.Size()+64)*2);
|
sl@0
|
118 |
buf.AppendFormat(_L8("\nCHECK failed: %S == 0x%x but was tested for %S%S\n"),&ff,r,&cc,&nn);
|
sl@0
|
119 |
test.Printf(buf.Expand());
|
sl@0
|
120 |
buf.Close();
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
#define CHECK(n,c,f) \
|
sl@0
|
124 |
{ \
|
sl@0
|
125 |
TInt _r=(TInt)(f); \
|
sl@0
|
126 |
if(!((TInt)(n)c(_r))) \
|
sl@0
|
127 |
{ \
|
sl@0
|
128 |
CheckFailMessage(#n,#c,#f,_r); \
|
sl@0
|
129 |
test(0); \
|
sl@0
|
130 |
} \
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
#define KCHECK_MEMORY(result,offset) \
|
sl@0
|
134 |
{ \
|
sl@0
|
135 |
/* test.Printf(_L("check offset 0x%08x\r"),offset); */ \
|
sl@0
|
136 |
CHECK(result,==,Ldd.CheckMemory(offset)); \
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
#define KWRITE_MEMORY(offset,value) \
|
sl@0
|
140 |
{ \
|
sl@0
|
141 |
CHECK(KErrNone,==,Ldd.WriteMemory(offset,value)); \
|
sl@0
|
142 |
}
|
sl@0
|
143 |
|
sl@0
|
144 |
#define UREAD_MEMORY(offset,value) \
|
sl@0
|
145 |
{ \
|
sl@0
|
146 |
CHECK(value,==,*(TUint*)(Base+offset)); \
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
inline TUint32 Tag(TUint32 offset)
|
sl@0
|
150 |
{ return (69069u*(offset*4+1)); }
|
sl@0
|
151 |
|
sl@0
|
152 |
TInt MemoryAccessThread(TAny* aAddress)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
TInt r = *(volatile TUint8*)aAddress; // read from aAddress
|
sl@0
|
155 |
(void)r;
|
sl@0
|
156 |
return 0;
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
TInt CheckUMemory(TAny* aAddress)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
RThread thread;
|
sl@0
|
162 |
thread.Create(KNullDesC,MemoryAccessThread,PageSize,&User::Heap(),aAddress);
|
sl@0
|
163 |
TRequestStatus status;
|
sl@0
|
164 |
thread.Logon(status);
|
sl@0
|
165 |
TBool jit = User::JustInTime();
|
sl@0
|
166 |
User::SetJustInTime(EFalse);
|
sl@0
|
167 |
thread.Resume();
|
sl@0
|
168 |
User::WaitForRequest(status);
|
sl@0
|
169 |
User::SetJustInTime(jit);
|
sl@0
|
170 |
TInt r;
|
sl@0
|
171 |
if(thread.ExitType()==EExitKill && thread.ExitReason()==0)
|
sl@0
|
172 |
r = 1; // Memory access pass
|
sl@0
|
173 |
else if(thread.ExitType()==EExitPanic && thread.ExitCategory()==KLitKernExec && thread.ExitReason()==3 )
|
sl@0
|
174 |
r = 0; // Memory access failed
|
sl@0
|
175 |
else
|
sl@0
|
176 |
r = -1; // Unexpected result
|
sl@0
|
177 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
178 |
return r;
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|
sl@0
|
181 |
#define UCHECK_MEMORY(result,offset) \
|
sl@0
|
182 |
{ \
|
sl@0
|
183 |
/* test.Printf(_L("ucheck offset 0x%08x\r"),offset); */ \
|
sl@0
|
184 |
CHECK(result,==,CheckUMemory(Base+offset)); \
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|
sl@0
|
187 |
TInt CheckPlatSecPanic(TThreadFunction aThreadFunction,TInt aThreadArgument)
|
sl@0
|
188 |
{
|
sl@0
|
189 |
RThread thread;
|
sl@0
|
190 |
thread.Create(KNullDesC,aThreadFunction,PageSize,&User::Heap(),(TAny*)aThreadArgument);
|
sl@0
|
191 |
TRequestStatus status;
|
sl@0
|
192 |
thread.Logon(status);
|
sl@0
|
193 |
TBool jit = User::JustInTime();
|
sl@0
|
194 |
User::SetJustInTime(EFalse);
|
sl@0
|
195 |
thread.Resume();
|
sl@0
|
196 |
User::WaitForRequest(status);
|
sl@0
|
197 |
User::SetJustInTime(jit);
|
sl@0
|
198 |
TInt r;
|
sl@0
|
199 |
if(thread.ExitType()==EExitPanic && thread.ExitCategory()==KLitKernExec && thread.ExitReason()==46 )
|
sl@0
|
200 |
r = 1; // PlatSec panic
|
sl@0
|
201 |
else if(thread.ExitType()==EExitKill && thread.ExitReason()==0)
|
sl@0
|
202 |
r = 0; // Exit without error
|
sl@0
|
203 |
else
|
sl@0
|
204 |
r = -1; // Unexpected result
|
sl@0
|
205 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
206 |
return r;
|
sl@0
|
207 |
}
|
sl@0
|
208 |
|
sl@0
|
209 |
//
|
sl@0
|
210 |
// The tests
|
sl@0
|
211 |
//
|
sl@0
|
212 |
|
sl@0
|
213 |
void CreateWithOomCheck(TInt aCreateFlags)
|
sl@0
|
214 |
{
|
sl@0
|
215 |
TInt failResult=KErrGeneral;
|
sl@0
|
216 |
for(TInt failCount=1; failCount<1000; failCount++)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
test.Printf(_L("alloc fail count = %d\n"),failCount);
|
sl@0
|
219 |
User::__DbgSetBurstAllocFail(ETrue,RAllocator::EFailNext,failCount,1000);
|
sl@0
|
220 |
__KHEAP_MARK;
|
sl@0
|
221 |
failResult = Ldd.CreateChunk(aCreateFlags);
|
sl@0
|
222 |
if(failResult==KErrNone)
|
sl@0
|
223 |
break;
|
sl@0
|
224 |
CHECK(KErrNoMemory,==,failResult);
|
sl@0
|
225 |
Ldd.IsDestroyed(); // This includes delay to let idle thread do cleanup
|
sl@0
|
226 |
__KHEAP_MARKEND;
|
sl@0
|
227 |
}
|
sl@0
|
228 |
User::__DbgSetAllocFail(ETrue,RAllocator::ENone,0);
|
sl@0
|
229 |
__KHEAP_RESET;
|
sl@0
|
230 |
CHECK(KErrNone,==,failResult);
|
sl@0
|
231 |
}
|
sl@0
|
232 |
|
sl@0
|
233 |
void TestCreate()
|
sl@0
|
234 |
{
|
sl@0
|
235 |
test.Start(_L("Creating chunk type Single,OwnsMemory"));
|
sl@0
|
236 |
CreateWithOomCheck(ChunkSize|ESingle|EOwnsMemory);
|
sl@0
|
237 |
CHECK(0,==,Ldd.IsDestroyed());
|
sl@0
|
238 |
|
sl@0
|
239 |
test.Next(_L("Close kernel handle"));
|
sl@0
|
240 |
CHECK(1,==,Ldd.CloseChunk()); // 1==DObject::EObjectDeleted
|
sl@0
|
241 |
CHECK(1,==,Ldd.IsDestroyed());
|
sl@0
|
242 |
|
sl@0
|
243 |
test.Next(_L("Creating chunk type Multiple,OwnsMemory"));
|
sl@0
|
244 |
CreateWithOomCheck(ChunkSize|EMultiple|EOwnsMemory);
|
sl@0
|
245 |
CHECK(0,==,Ldd.IsDestroyed());
|
sl@0
|
246 |
|
sl@0
|
247 |
test.Next(_L("Close kernel handle"));
|
sl@0
|
248 |
CHECK(1,==,Ldd.CloseChunk()); // 1==DObject::EObjectDeleted
|
sl@0
|
249 |
CHECK(1,==,Ldd.IsDestroyed());
|
sl@0
|
250 |
|
sl@0
|
251 |
if(PhysicalCommitSupported)
|
sl@0
|
252 |
{
|
sl@0
|
253 |
test.Next(_L("Creating chunk type Single,!OwnsMemory"));
|
sl@0
|
254 |
CreateWithOomCheck(ChunkSize|ESingle);
|
sl@0
|
255 |
CHECK(0,==,Ldd.IsDestroyed());
|
sl@0
|
256 |
|
sl@0
|
257 |
test.Next(_L("Close kernel handle"));
|
sl@0
|
258 |
CHECK(1,==,Ldd.CloseChunk()); // 1==DObject::EObjectDeleted
|
sl@0
|
259 |
CHECK(1,==,Ldd.IsDestroyed());
|
sl@0
|
260 |
|
sl@0
|
261 |
test.Next(_L("Creating chunk type Multiple,!OwnsMemory"));
|
sl@0
|
262 |
CreateWithOomCheck(ChunkSize|EMultiple);
|
sl@0
|
263 |
CHECK(0,==,Ldd.IsDestroyed());
|
sl@0
|
264 |
|
sl@0
|
265 |
test.Next(_L("Close kernel handle"));
|
sl@0
|
266 |
CHECK(1,==,Ldd.CloseChunk()); // 1==DObject::EObjectDeleted
|
sl@0
|
267 |
CHECK(1,==,Ldd.IsDestroyed());
|
sl@0
|
268 |
}
|
sl@0
|
269 |
else
|
sl@0
|
270 |
{
|
sl@0
|
271 |
test.Next(_L("Try creating unsupported chunk type Single,!OwnsMemory"));
|
sl@0
|
272 |
CHECK(KErrNotSupported,==,Ldd.CreateChunk(ChunkSize|ESingle));
|
sl@0
|
273 |
|
sl@0
|
274 |
test.Next(_L("Try creating unsupported chunk type Multiple,!OwnsMemory"));
|
sl@0
|
275 |
CHECK(KErrNotSupported,==,Ldd.CreateChunk(ChunkSize|EMultiple));
|
sl@0
|
276 |
}
|
sl@0
|
277 |
|
sl@0
|
278 |
test.Next(_L("__KHEAP_MARK"));
|
sl@0
|
279 |
__KHEAP_MARK;
|
sl@0
|
280 |
|
sl@0
|
281 |
test.Next(_L("Creating chunk (bad type)"));
|
sl@0
|
282 |
CHECK(KErrArgument,==,Ldd.CreateChunk(EBadType|EOwnsMemory|ChunkSize));
|
sl@0
|
283 |
|
sl@0
|
284 |
test.Next(_L("Creating chunk (bad size)"));
|
sl@0
|
285 |
CHECK(KErrArgument,==,Ldd.CreateChunk(ESingle|EOwnsMemory|0xffffff00));
|
sl@0
|
286 |
|
sl@0
|
287 |
test.Next(_L("Creating chunk (size too big)"));
|
sl@0
|
288 |
CHECK(KErrNoMemory,==,Ldd.CreateChunk(ESingle|EOwnsMemory|0x7fffff00));
|
sl@0
|
289 |
|
sl@0
|
290 |
test.Next(_L("__KHEAP_MARKEND"));
|
sl@0
|
291 |
__KHEAP_MARKEND;
|
sl@0
|
292 |
|
sl@0
|
293 |
test.End();
|
sl@0
|
294 |
}
|
sl@0
|
295 |
|
sl@0
|
296 |
|
sl@0
|
297 |
void OpenWithOomCheck(RChunk& aChunk)
|
sl@0
|
298 |
{
|
sl@0
|
299 |
TInt failResult=KErrGeneral;
|
sl@0
|
300 |
for(TInt failCount=1; failCount<1000; failCount++)
|
sl@0
|
301 |
{
|
sl@0
|
302 |
test.Printf(_L("alloc fail count = %d\n"),failCount);
|
sl@0
|
303 |
User::__DbgSetBurstAllocFail(ETrue,RAllocator::EFailNext,failCount,1000);
|
sl@0
|
304 |
__KHEAP_MARK;
|
sl@0
|
305 |
failResult = Ldd.GetChunkHandle(aChunk);
|
sl@0
|
306 |
if(failResult==KErrNone)
|
sl@0
|
307 |
break;
|
sl@0
|
308 |
CHECK(KErrNoMemory,==,failResult);
|
sl@0
|
309 |
Ldd.IsDestroyed(); // This includes delay to let idle thread do cleanup
|
sl@0
|
310 |
__KHEAP_MARKEND;
|
sl@0
|
311 |
}
|
sl@0
|
312 |
User::__DbgSetAllocFail(ETrue,RAllocator::ENone,0);
|
sl@0
|
313 |
__KHEAP_RESET;
|
sl@0
|
314 |
CHECK(KErrNone,==,failResult);
|
sl@0
|
315 |
}
|
sl@0
|
316 |
|
sl@0
|
317 |
void TestHandles()
|
sl@0
|
318 |
{
|
sl@0
|
319 |
TUint ChunkAttribs = ChunkSize|ESingle|EOwnsMemory;
|
sl@0
|
320 |
|
sl@0
|
321 |
test.Start(_L("Create chunk"));
|
sl@0
|
322 |
CHECK(KErrNone,==,Ldd.CreateChunk(ChunkAttribs));
|
sl@0
|
323 |
|
sl@0
|
324 |
test.Next(_L("Open user handle"));
|
sl@0
|
325 |
OpenWithOomCheck(TheChunk);
|
sl@0
|
326 |
|
sl@0
|
327 |
test.Next(_L("Close user handle"));
|
sl@0
|
328 |
TheChunk.Close();
|
sl@0
|
329 |
|
sl@0
|
330 |
test.Next(_L("Check chunk not destroyed"));
|
sl@0
|
331 |
CHECK(0,==,Ldd.IsDestroyed());
|
sl@0
|
332 |
|
sl@0
|
333 |
test.Next(_L("Close kernel handle"));
|
sl@0
|
334 |
CHECK(1,==,Ldd.CloseChunk()); // 1==DObject::EObjectDeleted
|
sl@0
|
335 |
|
sl@0
|
336 |
test.Next(_L("Check chunk destroyed"));
|
sl@0
|
337 |
CHECK(1,==,Ldd.IsDestroyed());
|
sl@0
|
338 |
|
sl@0
|
339 |
// Another chunk - closing handles in reverse order
|
sl@0
|
340 |
|
sl@0
|
341 |
test.Next(_L("Create chunk"));
|
sl@0
|
342 |
CHECK(KErrNone,==,Ldd.CreateChunk(ChunkAttribs));
|
sl@0
|
343 |
|
sl@0
|
344 |
test.Next(_L("Open user handle"));
|
sl@0
|
345 |
OpenWithOomCheck(TheChunk);
|
sl@0
|
346 |
|
sl@0
|
347 |
test.Next(_L("Close kernel handle"));
|
sl@0
|
348 |
CHECK(KErrNone,==,Ldd.CloseChunk());
|
sl@0
|
349 |
|
sl@0
|
350 |
test.Next(_L("Check chunk not destroyed"));
|
sl@0
|
351 |
CHECK(0,==,Ldd.IsDestroyed());
|
sl@0
|
352 |
|
sl@0
|
353 |
test.Next(_L("Using user handle to check chunk info"));
|
sl@0
|
354 |
if((MemModelAttributes&EMemModelTypeMask)!=EMemModelTypeDirect)
|
sl@0
|
355 |
{
|
sl@0
|
356 |
CHECK(0,==,TheChunk.Size());
|
sl@0
|
357 |
}
|
sl@0
|
358 |
CHECK(ChunkSize,==,TheChunk.MaxSize());
|
sl@0
|
359 |
|
sl@0
|
360 |
test.Next(_L("Close user handle"));
|
sl@0
|
361 |
TheChunk.Close();
|
sl@0
|
362 |
|
sl@0
|
363 |
test.Next(_L("Check chunk destroyed"));
|
sl@0
|
364 |
CHECK(1,==,Ldd.IsDestroyed());
|
sl@0
|
365 |
|
sl@0
|
366 |
test.End();
|
sl@0
|
367 |
}
|
sl@0
|
368 |
|
sl@0
|
369 |
TInt HandleOwnershipThread(TAny* aArg)
|
sl@0
|
370 |
{
|
sl@0
|
371 |
// Use existing handle and attempt to read from chunk
|
sl@0
|
372 |
TInt handle = (TInt) aArg;
|
sl@0
|
373 |
RChunk chunk;
|
sl@0
|
374 |
chunk.SetHandle(handle);
|
sl@0
|
375 |
TInt r = *(volatile TUint8*)chunk.Base();
|
sl@0
|
376 |
(void)r;
|
sl@0
|
377 |
CLOSE_AND_WAIT(chunk);
|
sl@0
|
378 |
return KErrNone;
|
sl@0
|
379 |
}
|
sl@0
|
380 |
|
sl@0
|
381 |
void TestHandleOwnership()
|
sl@0
|
382 |
{
|
sl@0
|
383 |
TUint ChunkAttribs = ChunkSize|ESingle|EOwnsMemory;
|
sl@0
|
384 |
RThread thread;
|
sl@0
|
385 |
TRequestStatus rs;
|
sl@0
|
386 |
|
sl@0
|
387 |
test.Start(_L("Create chunk"));
|
sl@0
|
388 |
CHECK(KErrNone,==,Ldd.CreateChunk(ChunkAttribs));
|
sl@0
|
389 |
|
sl@0
|
390 |
test.Next(_L("Commit page to chunk"));
|
sl@0
|
391 |
CHECK(KErrNone,==,Ldd.CommitMemory(EDiscontiguous,PageSize));
|
sl@0
|
392 |
|
sl@0
|
393 |
test.Next(_L("Check can access memory kernel side"));
|
sl@0
|
394 |
KCHECK_MEMORY(ETrue, 0);
|
sl@0
|
395 |
|
sl@0
|
396 |
// Handle is thread-owned
|
sl@0
|
397 |
test.Next(_L("Open user handle (thread-owned)"));
|
sl@0
|
398 |
CHECK(0,<=,Ldd.GetChunkHandle(TheChunk, ETrue));
|
sl@0
|
399 |
|
sl@0
|
400 |
test.Next(_L("Get memory size info"));
|
sl@0
|
401 |
if((MemModelAttributes&EMemModelTypeMask)!=EMemModelTypeDirect)
|
sl@0
|
402 |
{
|
sl@0
|
403 |
CHECK(PageSize,==,TheChunk.Size());
|
sl@0
|
404 |
}
|
sl@0
|
405 |
CHECK(ChunkSize,==,TheChunk.MaxSize());
|
sl@0
|
406 |
TUint8* Base = TheChunk.Base();
|
sl@0
|
407 |
CHECK(Base,!=,0);
|
sl@0
|
408 |
|
sl@0
|
409 |
test.Next(_L("Check can access memory user side"));
|
sl@0
|
410 |
UCHECK_MEMORY(ETrue, 0);
|
sl@0
|
411 |
|
sl@0
|
412 |
test.Next(_L("Use handle in a new thread"));
|
sl@0
|
413 |
CHECK(KErrNone,==,thread.Create(_L("thread1"), HandleOwnershipThread, KDefaultStackSize, KMinHeapSize, KMinHeapSize, (TAny*)TheChunk.Handle()));
|
sl@0
|
414 |
thread.Logon(rs);
|
sl@0
|
415 |
thread.Resume();
|
sl@0
|
416 |
User::WaitForRequest(rs);
|
sl@0
|
417 |
CHECK(EExitPanic,==,thread.ExitType());
|
sl@0
|
418 |
CHECK(0,==,thread.ExitReason()); // KERN-EXEC 0
|
sl@0
|
419 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
420 |
|
sl@0
|
421 |
test.Next(_L("Close user handle"));
|
sl@0
|
422 |
TheChunk.Close();
|
sl@0
|
423 |
|
sl@0
|
424 |
// Handle is process-owned
|
sl@0
|
425 |
test.Next(_L("Open user handle (process-owned"));
|
sl@0
|
426 |
CHECK(0,<=,Ldd.GetChunkHandle(TheChunk, EFalse));
|
sl@0
|
427 |
|
sl@0
|
428 |
test.Next(_L("Check can access memory user side"));
|
sl@0
|
429 |
UCHECK_MEMORY(ETrue, 0);
|
sl@0
|
430 |
|
sl@0
|
431 |
test.Next(_L("Close kernel handle"));
|
sl@0
|
432 |
CHECK(KErrNone,==,Ldd.CloseChunk());
|
sl@0
|
433 |
|
sl@0
|
434 |
test.Next(_L("Check chunk destroyed"));
|
sl@0
|
435 |
CHECK(0,==,Ldd.IsDestroyed());
|
sl@0
|
436 |
|
sl@0
|
437 |
test.Next(_L("Use handle in a new thread"));
|
sl@0
|
438 |
CHECK(KErrNone,==,thread.Create(_L("thread2"), HandleOwnershipThread, KDefaultStackSize, KMinHeapSize, KMinHeapSize, (TAny*)TheChunk.Handle()));
|
sl@0
|
439 |
thread.Logon(rs);
|
sl@0
|
440 |
thread.Resume();
|
sl@0
|
441 |
User::WaitForRequest(rs);
|
sl@0
|
442 |
CHECK(EExitKill,==,thread.ExitType());
|
sl@0
|
443 |
CHECK(KErrNone,==,thread.ExitReason());
|
sl@0
|
444 |
CLOSE_AND_WAIT(thread);
|
sl@0
|
445 |
|
sl@0
|
446 |
test.Next(_L("Check chunk destroyed"));
|
sl@0
|
447 |
CHECK(1,==,Ldd.IsDestroyed()); // Object was deleted
|
sl@0
|
448 |
|
sl@0
|
449 |
test.End();
|
sl@0
|
450 |
}
|
sl@0
|
451 |
|
sl@0
|
452 |
void SetCreateFlags(TUint& aCreateFlags,TCommitType aCommitType)
|
sl@0
|
453 |
{
|
sl@0
|
454 |
if(!((TInt)aCommitType&EPhysicalMask))
|
sl@0
|
455 |
aCreateFlags |= EOwnsMemory;
|
sl@0
|
456 |
else
|
sl@0
|
457 |
aCreateFlags &= ~EOwnsMemory;
|
sl@0
|
458 |
}
|
sl@0
|
459 |
|
sl@0
|
460 |
|
sl@0
|
461 |
void TestAccess(TUint aCreateFlags,TCommitType aCommitType)
|
sl@0
|
462 |
{
|
sl@0
|
463 |
const TUint32 offset = 0;
|
sl@0
|
464 |
const TUint32 size = PageSize;
|
sl@0
|
465 |
|
sl@0
|
466 |
SetCreateFlags(aCreateFlags,aCommitType);
|
sl@0
|
467 |
|
sl@0
|
468 |
test.Start(_L("Create chunk"));
|
sl@0
|
469 |
TUint8* kernelAddress;
|
sl@0
|
470 |
CHECK(KErrNone,==,Ldd.CreateChunk(aCreateFlags|ChunkSize,(TAny**)&kernelAddress));
|
sl@0
|
471 |
|
sl@0
|
472 |
if((MemModelAttributes&TUint32(EMemModelAttrNonExProt)) && (MemModelAttributes&EMemModelTypeMask)!=EMemModelTypeDirect)
|
sl@0
|
473 |
{
|
sl@0
|
474 |
test.Next(_L("Check can't access memory"));
|
sl@0
|
475 |
KCHECK_MEMORY(EFalse,offset);
|
sl@0
|
476 |
}
|
sl@0
|
477 |
|
sl@0
|
478 |
test.Next(_L("Commit page to chunk"));
|
sl@0
|
479 |
CHECK(KErrNone,==,Ldd.CommitMemory(aCommitType|offset,size));
|
sl@0
|
480 |
|
sl@0
|
481 |
test.Next(_L("Check can access memory kernel side"));
|
sl@0
|
482 |
KCHECK_MEMORY(ETrue, offset);
|
sl@0
|
483 |
|
sl@0
|
484 |
if((MemModelAttributes&EMemModelAttrKernProt) && (MemModelAttributes&EMemModelTypeMask)!=EMemModelTypeDirect)
|
sl@0
|
485 |
{
|
sl@0
|
486 |
test.Next(_L("Check user side can't access kernel memory"));
|
sl@0
|
487 |
TUint8* Base = kernelAddress;
|
sl@0
|
488 |
UCHECK_MEMORY(EFalse, offset);
|
sl@0
|
489 |
}
|
sl@0
|
490 |
|
sl@0
|
491 |
test.Next(_L("Open user handle"));
|
sl@0
|
492 |
CHECK(KErrNone,==,Ldd.GetChunkHandle(TheChunk));
|
sl@0
|
493 |
|
sl@0
|
494 |
test.Next(_L("Get memory size info"));
|
sl@0
|
495 |
if((MemModelAttributes&EMemModelTypeMask)!=EMemModelTypeDirect)
|
sl@0
|
496 |
{
|
sl@0
|
497 |
CHECK(PageSize,==,TheChunk.Size());
|
sl@0
|
498 |
}
|
sl@0
|
499 |
CHECK(ChunkSize,==,TheChunk.MaxSize());
|
sl@0
|
500 |
TUint8* Base = TheChunk.Base();
|
sl@0
|
501 |
CHECK(Base,!=,0);
|
sl@0
|
502 |
|
sl@0
|
503 |
test.Next(_L("Check can access memory user side"));
|
sl@0
|
504 |
UCHECK_MEMORY(ETrue, offset);
|
sl@0
|
505 |
|
sl@0
|
506 |
test.Next(_L("Check user and kernel access same memory"));
|
sl@0
|
507 |
KWRITE_MEMORY(offset,~Tag(offset));
|
sl@0
|
508 |
UREAD_MEMORY(offset,~Tag(offset));
|
sl@0
|
509 |
KWRITE_MEMORY(offset,Tag(offset));
|
sl@0
|
510 |
UREAD_MEMORY(offset,Tag(offset));
|
sl@0
|
511 |
|
sl@0
|
512 |
test.Next(_L("Close user handle"));
|
sl@0
|
513 |
CHECK(0,==,Ldd.CloseChunkHandle(TheChunk));
|
sl@0
|
514 |
CHECK(0,==,Ldd.IsDestroyed());
|
sl@0
|
515 |
|
sl@0
|
516 |
if((MemModelAttributes&EMemModelAttrKernProt) && (MemModelAttributes&EMemModelTypeMask)!=EMemModelTypeDirect)
|
sl@0
|
517 |
{
|
sl@0
|
518 |
test.Next(_L("Check can no-longer access memory user side"));
|
sl@0
|
519 |
UCHECK_MEMORY(EFalse,offset);
|
sl@0
|
520 |
}
|
sl@0
|
521 |
|
sl@0
|
522 |
test.Next(_L("Check can still access memory kernel side"));
|
sl@0
|
523 |
KCHECK_MEMORY(ETrue, offset);
|
sl@0
|
524 |
|
sl@0
|
525 |
test.Next(_L("Open user handle again"));
|
sl@0
|
526 |
CHECK(KErrNone,==,Ldd.GetChunkHandle(TheChunk));
|
sl@0
|
527 |
|
sl@0
|
528 |
test.Next(_L("Check can access chunk user side again"));
|
sl@0
|
529 |
CHECK(Base,==,TheChunk.Base());
|
sl@0
|
530 |
CHECK(ChunkSize,==,TheChunk.MaxSize());
|
sl@0
|
531 |
if((MemModelAttributes&EMemModelTypeMask)!=EMemModelTypeDirect)
|
sl@0
|
532 |
{
|
sl@0
|
533 |
CHECK(size,==,TheChunk.Size());
|
sl@0
|
534 |
}
|
sl@0
|
535 |
UREAD_MEMORY(offset,Tag(offset));
|
sl@0
|
536 |
|
sl@0
|
537 |
test.Next(_L("Close kernel handle"));
|
sl@0
|
538 |
CHECK(0,==,Ldd.CloseChunk());
|
sl@0
|
539 |
CHECK(0,==,Ldd.IsDestroyed());
|
sl@0
|
540 |
|
sl@0
|
541 |
test.Next(_L("Check can still access chunk user side"));
|
sl@0
|
542 |
CHECK(Base,==,TheChunk.Base());
|
sl@0
|
543 |
CHECK(ChunkSize,==,TheChunk.MaxSize());
|
sl@0
|
544 |
if((MemModelAttributes&EMemModelTypeMask)!=EMemModelTypeDirect)
|
sl@0
|
545 |
{
|
sl@0
|
546 |
CHECK(size,==,TheChunk.Size());
|
sl@0
|
547 |
}
|
sl@0
|
548 |
UREAD_MEMORY(offset,Tag(offset));
|
sl@0
|
549 |
|
sl@0
|
550 |
test.Next(_L("Close user handle"));
|
sl@0
|
551 |
TheChunk.Close();
|
sl@0
|
552 |
CHECK(1,==,Ldd.IsDestroyed());
|
sl@0
|
553 |
|
sl@0
|
554 |
test.Next(_L("Create chunk in another process"));
|
sl@0
|
555 |
|
sl@0
|
556 |
// Create test server
|
sl@0
|
557 |
RServer2 server;
|
sl@0
|
558 |
RMessage2 message;
|
sl@0
|
559 |
TRequestStatus status;
|
sl@0
|
560 |
CHECK(KErrNone,==,server.CreateGlobal(KSecondProcessName));
|
sl@0
|
561 |
server.Receive(message,status);
|
sl@0
|
562 |
|
sl@0
|
563 |
// Launch slave process
|
sl@0
|
564 |
RProcess process;
|
sl@0
|
565 |
CHECK(KErrNone,==,process.Create(KSecondProcessName,KNullDesC));
|
sl@0
|
566 |
CHECK(KErrNone,==,process.SetParameter(1,ESlaveCreateChunk));
|
sl@0
|
567 |
CHECK(KErrNone,==,process.SetParameter(2,(RBusLogicalChannel&)Ldd));
|
sl@0
|
568 |
CHECK(KErrNone,==,process.SetParameter(3,ChunkSize|aCreateFlags));
|
sl@0
|
569 |
CHECK(KErrNone,==,process.SetParameter(4,aCommitType));
|
sl@0
|
570 |
CHECK(KErrNone,==,process.SetParameter(5,PageSize));
|
sl@0
|
571 |
TRequestStatus logon;
|
sl@0
|
572 |
process.Logon(logon);
|
sl@0
|
573 |
process.Resume();
|
sl@0
|
574 |
|
sl@0
|
575 |
// Wait for slave to connect to test server
|
sl@0
|
576 |
User::WaitForRequest(logon,status);
|
sl@0
|
577 |
CHECK(KRequestPending,==,logon.Int())
|
sl@0
|
578 |
CHECK(KErrNone,==,status.Int());
|
sl@0
|
579 |
CHECK(RMessage2::EConnect,==,message.Function());
|
sl@0
|
580 |
message.Complete(KErrNone);
|
sl@0
|
581 |
server.Receive(message,status);
|
sl@0
|
582 |
|
sl@0
|
583 |
// Wait for message
|
sl@0
|
584 |
User::WaitForRequest(logon,status);
|
sl@0
|
585 |
CHECK(KRequestPending,==,logon.Int())
|
sl@0
|
586 |
CHECK(KErrNone,==,status.Int());
|
sl@0
|
587 |
CHECK(0,==,message.Function());
|
sl@0
|
588 |
|
sl@0
|
589 |
test.Next(_L("Check IPC read/write"));
|
sl@0
|
590 |
RBuf8 buf;
|
sl@0
|
591 |
buf.Create(KTestString().Size());
|
sl@0
|
592 |
CHECK(KErrNone,==,message.Read(0,buf));
|
sl@0
|
593 |
CHECK(ETrue,==,buf==KTestString());
|
sl@0
|
594 |
CHECK(KErrNone,==,message.Write(0,KTestString2));
|
sl@0
|
595 |
CHECK(KErrNone,==,message.Read(0,buf));
|
sl@0
|
596 |
CHECK(ETrue,==,buf==KTestString2());
|
sl@0
|
597 |
|
sl@0
|
598 |
test.Next(_L("Check Kernel read/write"));
|
sl@0
|
599 |
TInt n;
|
sl@0
|
600 |
TUint32 value;
|
sl@0
|
601 |
for(n=0; n<KTestString2().Size()-(TInt)sizeof(TInt)+1; n+=sizeof(TInt))
|
sl@0
|
602 |
{
|
sl@0
|
603 |
Ldd.ReadMemory(n,value);
|
sl@0
|
604 |
CHECK(*(TInt*)&KTestString2()[n],==,value);
|
sl@0
|
605 |
CHECK(KErrNone,==,Ldd.WriteMemory(n,*(TInt*)&KTestString()[n]));
|
sl@0
|
606 |
Ldd.ReadMemory(n,value);
|
sl@0
|
607 |
CHECK(*(TInt*)&KTestString()[n],==,value);
|
sl@0
|
608 |
}
|
sl@0
|
609 |
CHECK(KErrNone,==,message.Read(0,buf));
|
sl@0
|
610 |
CHECK(ETrue,==,buf==KTestString());
|
sl@0
|
611 |
buf.Close();
|
sl@0
|
612 |
|
sl@0
|
613 |
test.Next(_L("Check read/write from DFC"));
|
sl@0
|
614 |
CHECK(KErrNone,==,Ldd.WriteMemory(0,KTestValue));
|
sl@0
|
615 |
value = KTestValue2;
|
sl@0
|
616 |
CHECK(KErrNone,==,Ldd.DfcReadWrite(0,value));
|
sl@0
|
617 |
CHECK(KTestValue,==,value);
|
sl@0
|
618 |
CHECK(KErrNone,==,Ldd.ReadMemory(0,value));
|
sl@0
|
619 |
CHECK(KTestValue2,==,value);
|
sl@0
|
620 |
|
sl@0
|
621 |
test.Next(_L("Check read/write from ISR"));
|
sl@0
|
622 |
CHECK(KErrNone,==,Ldd.WriteMemory(0,KTestValue));
|
sl@0
|
623 |
value = KTestValue2;
|
sl@0
|
624 |
CHECK(KErrNone,==,Ldd.IsrReadWrite(0,value));
|
sl@0
|
625 |
CHECK(KTestValue,==,value);
|
sl@0
|
626 |
CHECK(KErrNone,==,Ldd.ReadMemory(0,value));
|
sl@0
|
627 |
CHECK(KTestValue2,==,value);
|
sl@0
|
628 |
|
sl@0
|
629 |
test.Next(_L("Cleanup resources"));
|
sl@0
|
630 |
server.Close();
|
sl@0
|
631 |
User::WaitForRequest(logon);
|
sl@0
|
632 |
CLOSE_AND_WAIT(process);
|
sl@0
|
633 |
|
sl@0
|
634 |
test.End();
|
sl@0
|
635 |
}
|
sl@0
|
636 |
|
sl@0
|
637 |
|
sl@0
|
638 |
RProcess OtherProcess;
|
sl@0
|
639 |
|
sl@0
|
640 |
TInt HandleShare(TAny* aHandle)
|
sl@0
|
641 |
{
|
sl@0
|
642 |
TInt r=OtherProcess.Create(KOtherProcessName,KNullDesC,EOwnerProcess);
|
sl@0
|
643 |
if(r==KErrNone)
|
sl@0
|
644 |
{
|
sl@0
|
645 |
r = OtherProcess.SetParameter(1,(RChunk&)aHandle);
|
sl@0
|
646 |
}
|
sl@0
|
647 |
return r;
|
sl@0
|
648 |
}
|
sl@0
|
649 |
|
sl@0
|
650 |
void TestRestrictions(TInt aAttrib)
|
sl@0
|
651 |
{
|
sl@0
|
652 |
TUint ChunkAttribs = ChunkSize|aAttrib|EOwnsMemory;
|
sl@0
|
653 |
|
sl@0
|
654 |
test.Start(_L("Create chunk"));
|
sl@0
|
655 |
CHECK(KErrNone,==,Ldd.CreateChunk(ChunkAttribs));
|
sl@0
|
656 |
|
sl@0
|
657 |
test.Next(_L("Open user handle"));
|
sl@0
|
658 |
CHECK(KErrNone,==,Ldd.GetChunkHandle(TheChunk));
|
sl@0
|
659 |
|
sl@0
|
660 |
test.Next(_L("Try changing restrictions"));
|
sl@0
|
661 |
CHECK(KErrAccessDenied,==,TheChunk.SetRestrictions(0));
|
sl@0
|
662 |
|
sl@0
|
663 |
test.Next(_L("Check allocation restrictions"));
|
sl@0
|
664 |
CHECK(KErrAccessDenied,==,TheChunk.Adjust(ChunkSize/2));
|
sl@0
|
665 |
CHECK(KErrAccessDenied,==,TheChunk.AdjustDoubleEnded(PageSize,ChunkSize));
|
sl@0
|
666 |
CHECK(KErrAccessDenied,==,TheChunk.Commit(PageSize,PageSize));
|
sl@0
|
667 |
CHECK(KErrAccessDenied,==,TheChunk.Allocate(PageSize));
|
sl@0
|
668 |
CHECK(KErrAccessDenied,==,TheChunk.Decommit(PageSize,PageSize));
|
sl@0
|
669 |
|
sl@0
|
670 |
test.Next(_L("Duplicate handle in same process"));
|
sl@0
|
671 |
RChunk chunk2;
|
sl@0
|
672 |
chunk2.SetHandle(TheChunk.Handle());
|
sl@0
|
673 |
CHECK(KErrNone,==,chunk2.Duplicate(RThread(),EOwnerProcess));
|
sl@0
|
674 |
|
sl@0
|
675 |
test.Next(_L("Try passing handle to other process"));
|
sl@0
|
676 |
if(aAttrib==EMultiple)
|
sl@0
|
677 |
{
|
sl@0
|
678 |
CHECK(0,==,CheckPlatSecPanic(HandleShare,*(TInt*)&chunk2));
|
sl@0
|
679 |
}
|
sl@0
|
680 |
else
|
sl@0
|
681 |
{
|
sl@0
|
682 |
CHECK(1,==,CheckPlatSecPanic(HandleShare,*(TInt*)&chunk2));
|
sl@0
|
683 |
}
|
sl@0
|
684 |
// Cleanup leftover process
|
sl@0
|
685 |
OtherProcess.Kill(0);
|
sl@0
|
686 |
OtherProcess.Close();
|
sl@0
|
687 |
|
sl@0
|
688 |
test.Next(_L("Close handles"));
|
sl@0
|
689 |
chunk2.Close();
|
sl@0
|
690 |
CHECK(0,==,Ldd.CloseChunk());
|
sl@0
|
691 |
TheChunk.Close();
|
sl@0
|
692 |
|
sl@0
|
693 |
test.End();
|
sl@0
|
694 |
}
|
sl@0
|
695 |
|
sl@0
|
696 |
|
sl@0
|
697 |
class TCommitRegion
|
sl@0
|
698 |
{
|
sl@0
|
699 |
public:
|
sl@0
|
700 |
TInt iOffset;
|
sl@0
|
701 |
TInt iSize;
|
sl@0
|
702 |
TInt iExpectedResult;
|
sl@0
|
703 |
};
|
sl@0
|
704 |
|
sl@0
|
705 |
void CheckRegion(TCommitRegion aRegion, TBool aCheckClear)
|
sl@0
|
706 |
{
|
sl@0
|
707 |
TUint8* Base = TheChunk.Base();
|
sl@0
|
708 |
TInt offset = aRegion.iOffset*PageSize;
|
sl@0
|
709 |
TInt limit = offset+aRegion.iSize*PageSize;
|
sl@0
|
710 |
while(offset<limit)
|
sl@0
|
711 |
{
|
sl@0
|
712 |
KCHECK_MEMORY(1,offset);
|
sl@0
|
713 |
UCHECK_MEMORY(1,offset);
|
sl@0
|
714 |
offset += PageSize;
|
sl@0
|
715 |
}
|
sl@0
|
716 |
if(!aCheckClear)
|
sl@0
|
717 |
return;
|
sl@0
|
718 |
|
sl@0
|
719 |
TUint32* ptr = (TUint32*)(Base+aRegion.iOffset*PageSize);
|
sl@0
|
720 |
TUint32* end = (TUint32*)((TInt)ptr+aRegion.iSize*PageSize);
|
sl@0
|
721 |
while(ptr<end)
|
sl@0
|
722 |
if(*ptr++!=0x03030303u)
|
sl@0
|
723 |
{
|
sl@0
|
724 |
CHECK(0x03030303u,==,*ptr);
|
sl@0
|
725 |
}
|
sl@0
|
726 |
};
|
sl@0
|
727 |
|
sl@0
|
728 |
void SetTags(TCommitRegion aRegion)
|
sl@0
|
729 |
{
|
sl@0
|
730 |
TUint8* Base = TheChunk.Base();
|
sl@0
|
731 |
TInt offset = aRegion.iOffset*PageSize;
|
sl@0
|
732 |
TInt limit = offset+aRegion.iSize*PageSize;
|
sl@0
|
733 |
while(offset<limit)
|
sl@0
|
734 |
{
|
sl@0
|
735 |
*(TUint*)(Base+offset) = Tag(offset);
|
sl@0
|
736 |
offset += sizeof(TUint);
|
sl@0
|
737 |
}
|
sl@0
|
738 |
};
|
sl@0
|
739 |
|
sl@0
|
740 |
void CheckTags(const TCommitRegion& aRegion)
|
sl@0
|
741 |
{
|
sl@0
|
742 |
TUint8* Base = TheChunk.Base();
|
sl@0
|
743 |
TInt offset = aRegion.iOffset*PageSize;
|
sl@0
|
744 |
TInt limit = offset+aRegion.iSize*PageSize;
|
sl@0
|
745 |
while(offset<limit)
|
sl@0
|
746 |
{
|
sl@0
|
747 |
KCHECK_MEMORY(1,offset); // Check page exists
|
sl@0
|
748 |
TInt limit2 = offset+PageSize;
|
sl@0
|
749 |
while(offset<limit2)
|
sl@0
|
750 |
{
|
sl@0
|
751 |
UREAD_MEMORY(offset,Tag(offset)); // Check contents match tags we set previousely
|
sl@0
|
752 |
offset += sizeof(TUint);
|
sl@0
|
753 |
}
|
sl@0
|
754 |
}
|
sl@0
|
755 |
};
|
sl@0
|
756 |
|
sl@0
|
757 |
void CheckOldTags(const TCommitRegion& aRegion, TInt aNewOffset)
|
sl@0
|
758 |
{
|
sl@0
|
759 |
TUint8* Base = TheChunk.Base();
|
sl@0
|
760 |
TInt oldOffset = aRegion.iOffset*PageSize;
|
sl@0
|
761 |
TInt offset = aNewOffset;
|
sl@0
|
762 |
TInt limit = offset+aRegion.iSize*PageSize;
|
sl@0
|
763 |
while(offset<limit)
|
sl@0
|
764 |
{
|
sl@0
|
765 |
KCHECK_MEMORY(1,offset); // Check page exists
|
sl@0
|
766 |
TInt limit2 = offset+PageSize;
|
sl@0
|
767 |
while(offset<limit2)
|
sl@0
|
768 |
{
|
sl@0
|
769 |
UREAD_MEMORY(offset,Tag(oldOffset)); // Check contents matched old tags
|
sl@0
|
770 |
offset += sizeof(TUint);
|
sl@0
|
771 |
oldOffset += sizeof(TUint);
|
sl@0
|
772 |
}
|
sl@0
|
773 |
}
|
sl@0
|
774 |
};
|
sl@0
|
775 |
|
sl@0
|
776 |
// Following assumes 4k pages...
|
sl@0
|
777 |
static const TCommitRegion CommitList[] =
|
sl@0
|
778 |
{
|
sl@0
|
779 |
{0,0}, // zero size commit
|
sl@0
|
780 |
{1,1}, // page 1
|
sl@0
|
781 |
|
sl@0
|
782 |
// Regions which overlap previous commit
|
sl@0
|
783 |
{1,1,KErrAlreadyExists},
|
sl@0
|
784 |
{0,2,KErrAlreadyExists},
|
sl@0
|
785 |
{1,2,KErrAlreadyExists},
|
sl@0
|
786 |
{0,3,KErrAlreadyExists},
|
sl@0
|
787 |
|
sl@0
|
788 |
{0,1}, // page 0
|
sl@0
|
789 |
{2,1}, // page 2
|
sl@0
|
790 |
|
sl@0
|
791 |
{250,6}, // pages at end of chunk boundary
|
sl@0
|
792 |
|
sl@0
|
793 |
{768,256}, // whole 1meg chunk
|
sl@0
|
794 |
|
sl@0
|
795 |
{400,512,KErrAlreadyExists}, // Monster commit which overlaps previous regions
|
sl@0
|
796 |
|
sl@0
|
797 |
{256,257}, // big commit which straddles more than one 1meg chunk
|
sl@0
|
798 |
|
sl@0
|
799 |
{-1,-1} // End marker
|
sl@0
|
800 |
};
|
sl@0
|
801 |
|
sl@0
|
802 |
void CheckCommitedContents(TInt aIndex)
|
sl@0
|
803 |
{
|
sl@0
|
804 |
while(--aIndex>=0)
|
sl@0
|
805 |
if(CommitList[aIndex].iExpectedResult==KErrNone)
|
sl@0
|
806 |
CheckTags(CommitList[aIndex]);
|
sl@0
|
807 |
};
|
sl@0
|
808 |
|
sl@0
|
809 |
void CheckCommitState(TInt aIndex)
|
sl@0
|
810 |
{
|
sl@0
|
811 |
TInt page=0;
|
sl@0
|
812 |
TInt lastPage=TheChunk.MaxSize()/PageSize;
|
sl@0
|
813 |
while(page<lastPage)
|
sl@0
|
814 |
{
|
sl@0
|
815 |
TInt i=aIndex;
|
sl@0
|
816 |
while(--i>=0)
|
sl@0
|
817 |
if(CommitList[i].iExpectedResult==KErrNone)
|
sl@0
|
818 |
if((TUint)(page-CommitList[i].iOffset) < (TUint)CommitList[i].iSize)
|
sl@0
|
819 |
break;
|
sl@0
|
820 |
TInt offset = page*PageSize;
|
sl@0
|
821 |
if(i>=0)
|
sl@0
|
822 |
{
|
sl@0
|
823 |
KCHECK_MEMORY(1,offset); // Check page exists
|
sl@0
|
824 |
}
|
sl@0
|
825 |
else
|
sl@0
|
826 |
{
|
sl@0
|
827 |
KCHECK_MEMORY(0,offset); // Check page doesn't exists
|
sl@0
|
828 |
}
|
sl@0
|
829 |
++page;
|
sl@0
|
830 |
}
|
sl@0
|
831 |
};
|
sl@0
|
832 |
|
sl@0
|
833 |
|
sl@0
|
834 |
void TestCommit(TUint aCreateFlags,TCommitType aCommitType)
|
sl@0
|
835 |
{
|
sl@0
|
836 |
SetCreateFlags(aCreateFlags,aCommitType);
|
sl@0
|
837 |
TUint ChunkAttribs = ChunkSize|aCreateFlags;
|
sl@0
|
838 |
|
sl@0
|
839 |
test.Start(_L("Create chunk"));
|
sl@0
|
840 |
CHECK(KErrNone,==,Ldd.CreateChunk(ChunkAttribs));
|
sl@0
|
841 |
|
sl@0
|
842 |
test.Next(_L("Check wrong commit type"));
|
sl@0
|
843 |
CHECK(KErrNotSupported,==,Ldd.CommitMemory((aCommitType^EPhysicalMask)|0,PageSize));
|
sl@0
|
844 |
CHECK(KErrNotSupported,==,Ldd.CommitMemory((aCommitType^EPhysicalMask^EContiguous)|0,PageSize));
|
sl@0
|
845 |
|
sl@0
|
846 |
if((TInt)aCommitType&EPhysicalMask)
|
sl@0
|
847 |
{
|
sl@0
|
848 |
test.Next(_L("Check commit with bad pysical address"));
|
sl@0
|
849 |
CHECK(KErrArgument,==,Ldd.CommitMemory((aCommitType|EBadPhysicalAddress)|0,PageSize));
|
sl@0
|
850 |
}
|
sl@0
|
851 |
|
sl@0
|
852 |
test.Next(_L("Open user handle"));
|
sl@0
|
853 |
CHECK(KErrNone,==,Ldd.GetChunkHandle(TheChunk));
|
sl@0
|
854 |
|
sl@0
|
855 |
const TCommitRegion* list = CommitList;
|
sl@0
|
856 |
for(;list->iOffset>=0; ++list)
|
sl@0
|
857 |
{
|
sl@0
|
858 |
TInt offset = list->iOffset*PageSize;
|
sl@0
|
859 |
TInt size = list->iSize*PageSize;
|
sl@0
|
860 |
TInt expectedResult = list->iExpectedResult;
|
sl@0
|
861 |
if((MemModelAttributes&EMemModelTypeMask)==EMemModelTypeDirect && expectedResult==KErrAlreadyExists)
|
sl@0
|
862 |
continue;
|
sl@0
|
863 |
TBuf<100> text;
|
sl@0
|
864 |
text.AppendFormat(_L("Commit pages: offset=%08x size=%08x expectedResult=%d"),offset,size,expectedResult);
|
sl@0
|
865 |
test.Next(text);
|
sl@0
|
866 |
|
sl@0
|
867 |
test.Start(_L("Do the Commit"));
|
sl@0
|
868 |
CHECK(expectedResult,==,Ldd.CommitMemory(aCommitType|offset,size));
|
sl@0
|
869 |
|
sl@0
|
870 |
if(expectedResult==KErrNone)
|
sl@0
|
871 |
{
|
sl@0
|
872 |
test.Next(_L("Check new memory has been comitted"));
|
sl@0
|
873 |
CheckRegion(*list,!(aCommitType&EPhysicalMask));
|
sl@0
|
874 |
}
|
sl@0
|
875 |
|
sl@0
|
876 |
if((MemModelAttributes&EMemModelTypeMask)!=EMemModelTypeDirect)
|
sl@0
|
877 |
{
|
sl@0
|
878 |
test.Next(_L("Check commit state of all pages in chunk"));
|
sl@0
|
879 |
CheckCommitState(list-CommitList+1);
|
sl@0
|
880 |
}
|
sl@0
|
881 |
|
sl@0
|
882 |
test.Next(_L("Check contents of previous commited regions are unchanged"));
|
sl@0
|
883 |
CheckCommitedContents(list-CommitList);
|
sl@0
|
884 |
|
sl@0
|
885 |
if(expectedResult==KErrNone)
|
sl@0
|
886 |
{
|
sl@0
|
887 |
test.Next(_L("Mark new memory"));
|
sl@0
|
888 |
SetTags(*list);
|
sl@0
|
889 |
}
|
sl@0
|
890 |
test.End();
|
sl@0
|
891 |
}
|
sl@0
|
892 |
|
sl@0
|
893 |
if((aCreateFlags&EMultiple) && (MemModelAttributes&EMemModelTypeMask)!=EMemModelTypeDirect)
|
sl@0
|
894 |
{
|
sl@0
|
895 |
test.Next(_L("Check another process sees same chunk state"));
|
sl@0
|
896 |
TInt regionCount = list-CommitList;
|
sl@0
|
897 |
|
sl@0
|
898 |
// create another process
|
sl@0
|
899 |
RProcess process;
|
sl@0
|
900 |
CHECK(KErrNone,==,process.Create(KOtherProcessName,KNullDesC));
|
sl@0
|
901 |
CHECK(KErrNone,==,process.SetParameter(1,ESlaveCheckChunk));
|
sl@0
|
902 |
CHECK(KErrNone,==,process.SetParameter(2,(RBusLogicalChannel&)Ldd));
|
sl@0
|
903 |
CHECK(KErrNone,==,process.SetParameter(3,(RChunk&)TheChunk));
|
sl@0
|
904 |
CHECK(KErrNone,==,process.SetParameter(4,regionCount));
|
sl@0
|
905 |
TRequestStatus status;
|
sl@0
|
906 |
process.Logon(status);
|
sl@0
|
907 |
process.Resume();
|
sl@0
|
908 |
|
sl@0
|
909 |
// Check chunk again in this process, concurrently with other process
|
sl@0
|
910 |
CheckCommitedContents(regionCount);
|
sl@0
|
911 |
CheckCommitState(regionCount);
|
sl@0
|
912 |
|
sl@0
|
913 |
// wait for other process to finish
|
sl@0
|
914 |
User::WaitForRequest(status);
|
sl@0
|
915 |
CHECK(EExitKill,==,process.ExitType());
|
sl@0
|
916 |
CHECK(0,==,process.ExitReason());
|
sl@0
|
917 |
CLOSE_AND_WAIT(process);
|
sl@0
|
918 |
}
|
sl@0
|
919 |
|
sl@0
|
920 |
test.Next(_L("Close handles"));
|
sl@0
|
921 |
TheChunk.Close();
|
sl@0
|
922 |
CHECK(1,==,Ldd.CloseChunk());
|
sl@0
|
923 |
|
sl@0
|
924 |
if(aCommitType&EPhysicalMask)
|
sl@0
|
925 |
{
|
sl@0
|
926 |
// For Physical commit tests, check correct allocation by creating a new chunk
|
sl@0
|
927 |
// and checking that pages comitted contain the old TAGs placed there by the
|
sl@0
|
928 |
// tests above.
|
sl@0
|
929 |
|
sl@0
|
930 |
test.Next(_L("Check commit uses correct physical pages"));
|
sl@0
|
931 |
|
sl@0
|
932 |
test.Start(_L("Create chunk"));
|
sl@0
|
933 |
CHECK(KErrNone,==,Ldd.CreateChunk(ChunkAttribs));
|
sl@0
|
934 |
|
sl@0
|
935 |
test.Next(_L("Open user handle"));
|
sl@0
|
936 |
CHECK(KErrNone,==,Ldd.GetChunkHandle(TheChunk));
|
sl@0
|
937 |
|
sl@0
|
938 |
TInt offset = 0;
|
sl@0
|
939 |
for(list=CommitList; list->iOffset>=0; ++list)
|
sl@0
|
940 |
{
|
sl@0
|
941 |
if(list->iExpectedResult!=KErrNone)
|
sl@0
|
942 |
continue;
|
sl@0
|
943 |
|
sl@0
|
944 |
TInt size = list->iSize*PageSize;
|
sl@0
|
945 |
TBuf<100> text;
|
sl@0
|
946 |
text.AppendFormat(_L("Commit pages: offset=%08x size=%08x"),offset,size);
|
sl@0
|
947 |
test.Next(text);
|
sl@0
|
948 |
CHECK(KErrNone,==,Ldd.CommitMemory(aCommitType|offset,size));
|
sl@0
|
949 |
|
sl@0
|
950 |
test.Next(_L("Check RAM contents preserved from previous usage"));
|
sl@0
|
951 |
CheckOldTags(*list,offset);
|
sl@0
|
952 |
offset += size;
|
sl@0
|
953 |
}
|
sl@0
|
954 |
|
sl@0
|
955 |
test.Next(_L("Close handles"));
|
sl@0
|
956 |
TheChunk.Close();
|
sl@0
|
957 |
CHECK(1,==,Ldd.CloseChunk());
|
sl@0
|
958 |
|
sl@0
|
959 |
test.End();
|
sl@0
|
960 |
}
|
sl@0
|
961 |
else
|
sl@0
|
962 |
{
|
sl@0
|
963 |
// We don't do these OOM tests for Physical commit because we can't do it reliably
|
sl@0
|
964 |
// (as only a couple of page tables come from the free pool not the whole memory
|
sl@0
|
965 |
// to be comitted)
|
sl@0
|
966 |
test.Next(_L("Check Out Of Memory conditions"));
|
sl@0
|
967 |
|
sl@0
|
968 |
// Make sure any clean up has happened otherwise the amount of free RAM may change.
|
sl@0
|
969 |
UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
|
sl@0
|
970 |
|
sl@0
|
971 |
test.Start(_L("Gobble up most of RAM"));
|
sl@0
|
972 |
test.Next(_L("Load gobbler LDD"));
|
sl@0
|
973 |
TInt r = User::LoadLogicalDevice(KGobblerLddFileName);
|
sl@0
|
974 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
975 |
RGobbler gobbler;
|
sl@0
|
976 |
r = gobbler.Open();
|
sl@0
|
977 |
test(r==KErrNone);
|
sl@0
|
978 |
TUint32 taken = gobbler.GobbleRAM(2*1024*1024);
|
sl@0
|
979 |
test.Printf(_L("Gobbled: %dK\n"), taken/1024);
|
sl@0
|
980 |
test.Printf(_L("Free RAM 0x%08X bytes\n"),FreeRam());
|
sl@0
|
981 |
|
sl@0
|
982 |
test.Next(_L("Get baseline free memory"));
|
sl@0
|
983 |
__KHEAP_MARK;
|
sl@0
|
984 |
TInt freeRam1 = FreeRam();
|
sl@0
|
985 |
|
sl@0
|
986 |
test.Next(_L("Create shared chunk"));
|
sl@0
|
987 |
CHECK(KErrNone,==,Ldd.CreateChunk(ChunkAttribs));
|
sl@0
|
988 |
TInt freeRam2 = FreeRam();
|
sl@0
|
989 |
|
sl@0
|
990 |
test.Next(_L("Commit memory which will causes OOM"));
|
sl@0
|
991 |
CHECK(KErrNoMemory,==,Ldd.CommitMemory(aCommitType,4096*1024));
|
sl@0
|
992 |
|
sl@0
|
993 |
test.Next(_L("Check free RAM unchanged"));
|
sl@0
|
994 |
CHECK(freeRam2,==,FreeRam());
|
sl@0
|
995 |
|
sl@0
|
996 |
test.Next(_L("Check OOM during ChunkCommit"));
|
sl@0
|
997 |
TInt failResult=KErrGeneral;
|
sl@0
|
998 |
for(TInt failCount=1; failCount<1000; failCount++)
|
sl@0
|
999 |
{
|
sl@0
|
1000 |
User::__DbgSetAllocFail(ETrue,RAllocator::EFailNext,failCount);
|
sl@0
|
1001 |
failResult = Ldd.CommitMemory(aCommitType,1);
|
sl@0
|
1002 |
if(failResult==KErrNone)
|
sl@0
|
1003 |
break;
|
sl@0
|
1004 |
CHECK(KErrNoMemory,==,failResult);
|
sl@0
|
1005 |
}
|
sl@0
|
1006 |
User::__DbgSetAllocFail(ETrue,RAllocator::ENone,0);
|
sl@0
|
1007 |
CHECK(KErrNone,==,failResult);
|
sl@0
|
1008 |
|
sl@0
|
1009 |
test.Next(_L("Destroy shared chunk"));
|
sl@0
|
1010 |
CHECK(1,==,Ldd.CloseChunk());
|
sl@0
|
1011 |
CHECK(1,==,Ldd.IsDestroyed());
|
sl@0
|
1012 |
|
sl@0
|
1013 |
test.Next(_L("Check free memory returns to baseline"));
|
sl@0
|
1014 |
CHECK(freeRam1,==,FreeRam());
|
sl@0
|
1015 |
__KHEAP_MARKEND;
|
sl@0
|
1016 |
|
sl@0
|
1017 |
test.Next(_L("Free gobbled RAM"));
|
sl@0
|
1018 |
gobbler.Close();
|
sl@0
|
1019 |
|
sl@0
|
1020 |
test.End();
|
sl@0
|
1021 |
}
|
sl@0
|
1022 |
|
sl@0
|
1023 |
test.End();
|
sl@0
|
1024 |
}
|
sl@0
|
1025 |
|
sl@0
|
1026 |
|
sl@0
|
1027 |
void TestOpenSharedChunk(TUint aCreateFlags,TCommitType aCommitType)
|
sl@0
|
1028 |
{
|
sl@0
|
1029 |
SetCreateFlags(aCreateFlags,aCommitType);
|
sl@0
|
1030 |
TUint ChunkAttribs = ChunkSize|aCreateFlags;
|
sl@0
|
1031 |
|
sl@0
|
1032 |
test.Start(_L("Create chunk"));
|
sl@0
|
1033 |
CHECK(KErrNone,==,Ldd.CreateChunk(ChunkAttribs));
|
sl@0
|
1034 |
|
sl@0
|
1035 |
test.Next(_L("Open user handle"));
|
sl@0
|
1036 |
CHECK(KErrNone,==,Ldd.GetChunkHandle(TheChunk));
|
sl@0
|
1037 |
|
sl@0
|
1038 |
test.Next(_L("Commit some memory"));
|
sl@0
|
1039 |
CHECK(KErrNone,==,Ldd.CommitMemory(aCommitType|1*PageSize,PageSize));
|
sl@0
|
1040 |
CHECK(KErrNone,==,Ldd.CommitMemory(aCommitType|2*PageSize,PageSize));
|
sl@0
|
1041 |
CHECK(KErrNone,==,Ldd.CommitMemory(aCommitType|4*PageSize,PageSize));
|
sl@0
|
1042 |
|
sl@0
|
1043 |
test.Next(_L("Check OpenSharedChunk with handle"));
|
sl@0
|
1044 |
CHECK(KErrNone,==,Ldd.TestOpenHandle(TheChunk.Handle()));
|
sl@0
|
1045 |
|
sl@0
|
1046 |
test.Next(_L("Check OpenSharedChunk with wrong chunk handle"));
|
sl@0
|
1047 |
RChunk testChunk;
|
sl@0
|
1048 |
CHECK(KErrNone,==,testChunk.CreateLocal(PageSize,PageSize));
|
sl@0
|
1049 |
CHECK(KErrNotFound,==,Ldd.TestOpenHandle(testChunk.Handle()));
|
sl@0
|
1050 |
testChunk.Close();
|
sl@0
|
1051 |
|
sl@0
|
1052 |
test.Next(_L("Check OpenSharedChunk with wrong handle type"));
|
sl@0
|
1053 |
CHECK(KErrNotFound,==,Ldd.TestOpenHandle(RThread().Handle()));
|
sl@0
|
1054 |
|
sl@0
|
1055 |
test.Next(_L("Check OpenSharedChunk with bad handle"));
|
sl@0
|
1056 |
CHECK(KErrNotFound,==,Ldd.TestOpenHandle(0));
|
sl@0
|
1057 |
|
sl@0
|
1058 |
test.Next(_L("Check OpenSharedChunk with address"));
|
sl@0
|
1059 |
TUint8* Base = TheChunk.Base();
|
sl@0
|
1060 |
CHECK(KErrNone,==,Ldd.TestOpenAddress(Base));
|
sl@0
|
1061 |
CHECK(KErrNone,==,Ldd.TestOpenAddress(Base+ChunkSize-1));
|
sl@0
|
1062 |
|
sl@0
|
1063 |
test.Next(_L("Check OpenSharedChunk with bad address"));
|
sl@0
|
1064 |
CHECK(KErrNotFound,==,Ldd.TestOpenAddress(Base-1));
|
sl@0
|
1065 |
CHECK(KErrNotFound,==,Ldd.TestOpenAddress(Base+ChunkSize));
|
sl@0
|
1066 |
CHECK(KErrNotFound,==,Ldd.TestOpenAddress(0));
|
sl@0
|
1067 |
CHECK(KErrNotFound,==,Ldd.TestOpenAddress((TAny*)~0));
|
sl@0
|
1068 |
|
sl@0
|
1069 |
test.Next(_L("Check OpenSharedChunk with stack memory address"));
|
sl@0
|
1070 |
TUint8 stackMem[100];
|
sl@0
|
1071 |
CHECK(KErrNotFound,==,Ldd.TestOpenAddress(stackMem));
|
sl@0
|
1072 |
|
sl@0
|
1073 |
test.Next(_L("Check OpenSharedChunk with heap memory address"));
|
sl@0
|
1074 |
TUint8* heapMem = new TUint8[100];
|
sl@0
|
1075 |
CHECK(0,!=,heapMem);
|
sl@0
|
1076 |
CHECK(KErrNotFound,==,Ldd.TestOpenAddress(heapMem));
|
sl@0
|
1077 |
delete [] heapMem;
|
sl@0
|
1078 |
|
sl@0
|
1079 |
test.Next(_L("Check OpenSharedChunk with BSS memory address"));
|
sl@0
|
1080 |
CHECK(KErrNotFound,==,Ldd.TestOpenAddress(BssMem));
|
sl@0
|
1081 |
|
sl@0
|
1082 |
test.Next(_L("Check OpenSharedChunk with code memory address"));
|
sl@0
|
1083 |
CHECK(KErrNotFound,==,Ldd.TestOpenAddress((TAny*)&TestOpenSharedChunk));
|
sl@0
|
1084 |
|
sl@0
|
1085 |
test.Next(_L("Check OpenSharedChunk with NULL address"));
|
sl@0
|
1086 |
CHECK(KErrNotFound,==,Ldd.TestOpenAddress(0));
|
sl@0
|
1087 |
|
sl@0
|
1088 |
test.Next(_L("Check ChunkAddress for given memory region"));
|
sl@0
|
1089 |
static const TCommitRegion regions[] =
|
sl@0
|
1090 |
{
|
sl@0
|
1091 |
{0,1,KErrNotFound},
|
sl@0
|
1092 |
{0,2,KErrNotFound},
|
sl@0
|
1093 |
{0,3,KErrNotFound},
|
sl@0
|
1094 |
{1,1},
|
sl@0
|
1095 |
{1,2},
|
sl@0
|
1096 |
{1,3,KErrNotFound},
|
sl@0
|
1097 |
{2,1},
|
sl@0
|
1098 |
{2,2,KErrNotFound},
|
sl@0
|
1099 |
{2,3,KErrNotFound},
|
sl@0
|
1100 |
{3,1,KErrNotFound},
|
sl@0
|
1101 |
{3,2,KErrNotFound},
|
sl@0
|
1102 |
{3,3,KErrNotFound},
|
sl@0
|
1103 |
{4,1},
|
sl@0
|
1104 |
{4,2,KErrNotFound},
|
sl@0
|
1105 |
{4,3,KErrNotFound},
|
sl@0
|
1106 |
{0,10240,KErrArgument}, // too big
|
sl@0
|
1107 |
{1,0,KErrArgument}, // bad size
|
sl@0
|
1108 |
{1,-1,KErrArgument}, // bad size
|
sl@0
|
1109 |
{10240,1,KErrArgument}, // bad offset
|
sl@0
|
1110 |
{-2,2,KErrArgument}, // bad offset
|
sl@0
|
1111 |
{-1}
|
sl@0
|
1112 |
};
|
sl@0
|
1113 |
const TCommitRegion* region = regions;
|
sl@0
|
1114 |
for(;region->iOffset!=-1; ++region)
|
sl@0
|
1115 |
{
|
sl@0
|
1116 |
TUint32 offset = region->iOffset*PageSize;
|
sl@0
|
1117 |
TUint32 size = region->iSize*PageSize;
|
sl@0
|
1118 |
TInt expectedResult = region->iExpectedResult;
|
sl@0
|
1119 |
if((MemModelAttributes&EMemModelTypeMask)==EMemModelTypeDirect && expectedResult==KErrNotFound)
|
sl@0
|
1120 |
continue;
|
sl@0
|
1121 |
TBuf<100> text;
|
sl@0
|
1122 |
text.AppendFormat(_L("Memory region: offset=%08x size=%08x expectedResult=%d"),offset,size,expectedResult);
|
sl@0
|
1123 |
test.Next(text);
|
sl@0
|
1124 |
CHECK(expectedResult,==,Ldd.TestAddress(offset,size));
|
sl@0
|
1125 |
}
|
sl@0
|
1126 |
|
sl@0
|
1127 |
test.Next(_L("Close handles"));
|
sl@0
|
1128 |
TheChunk.Close();
|
sl@0
|
1129 |
CHECK(1,==,Ldd.CloseChunk());
|
sl@0
|
1130 |
|
sl@0
|
1131 |
test.End();
|
sl@0
|
1132 |
}
|
sl@0
|
1133 |
|
sl@0
|
1134 |
|
sl@0
|
1135 |
void AccessSpeed(TCreateFlags aCreateFlags, TInt& aRead,TInt& aWrite)
|
sl@0
|
1136 |
{
|
sl@0
|
1137 |
// test.Start(_L("Create chunk"));
|
sl@0
|
1138 |
CHECK(KErrNone,==,Ldd.CreateChunk(ChunkSize|ESingle|EOwnsMemory|aCreateFlags));
|
sl@0
|
1139 |
|
sl@0
|
1140 |
// test.Next(_L("Commit some memory"));
|
sl@0
|
1141 |
if((MemModelAttributes&EMemModelTypeMask)==EMemModelTypeDirect)
|
sl@0
|
1142 |
{
|
sl@0
|
1143 |
CHECK(KErrNone,==,Ldd.CommitMemory(EDiscontiguous|0*PageSize,PageSize));
|
sl@0
|
1144 |
}
|
sl@0
|
1145 |
else
|
sl@0
|
1146 |
{
|
sl@0
|
1147 |
// Allocate contiguous memory when possible so that the
|
sl@0
|
1148 |
// Cache::SyncMemoryBeforeXxxx calls in the test driver get exercised
|
sl@0
|
1149 |
CHECK(KErrNone,==,Ldd.CommitMemory(EContiguous|0*PageSize,PageSize));
|
sl@0
|
1150 |
}
|
sl@0
|
1151 |
|
sl@0
|
1152 |
// test.Next(_L("Open user handle"));
|
sl@0
|
1153 |
CHECK(KErrNone,==,Ldd.GetChunkHandle(TheChunk));
|
sl@0
|
1154 |
volatile TUint32* p = (TUint32*)TheChunk.Base();
|
sl@0
|
1155 |
|
sl@0
|
1156 |
TUint32 time;
|
sl@0
|
1157 |
TInt itterCount=128;
|
sl@0
|
1158 |
do
|
sl@0
|
1159 |
{
|
sl@0
|
1160 |
itterCount *= 2;
|
sl@0
|
1161 |
TUint32 lastCount=User::NTickCount();
|
sl@0
|
1162 |
for(TInt i=itterCount; i>0; --i)
|
sl@0
|
1163 |
{
|
sl@0
|
1164 |
TUint32 x=p[0]; x=p[1]; x=p[2]; x=p[3]; x=p[4]; x=p[5]; x=p[6]; x=p[7];
|
sl@0
|
1165 |
}
|
sl@0
|
1166 |
time = User::NTickCount()-lastCount;
|
sl@0
|
1167 |
}
|
sl@0
|
1168 |
while(time<200);
|
sl@0
|
1169 |
aRead = itterCount*8/time;
|
sl@0
|
1170 |
|
sl@0
|
1171 |
itterCount=128;
|
sl@0
|
1172 |
do
|
sl@0
|
1173 |
{
|
sl@0
|
1174 |
itterCount *= 2;
|
sl@0
|
1175 |
TUint32 lastCount=User::NTickCount();
|
sl@0
|
1176 |
for(TInt i=itterCount; i>0; --i)
|
sl@0
|
1177 |
{
|
sl@0
|
1178 |
p[0]=i; p[1]=i; p[2]=i; p[3]=i; p[4]=i; p[5]=i; p[6]=i; p[7]=i;
|
sl@0
|
1179 |
}
|
sl@0
|
1180 |
time = User::NTickCount()-lastCount;
|
sl@0
|
1181 |
}
|
sl@0
|
1182 |
while(time<200);
|
sl@0
|
1183 |
aWrite = itterCount*8/time;
|
sl@0
|
1184 |
|
sl@0
|
1185 |
TBuf<100> text;
|
sl@0
|
1186 |
text.AppendFormat(_L("Read speed=%7d Write speed=%7d\n"),aRead,aWrite);
|
sl@0
|
1187 |
test.Printf(text);
|
sl@0
|
1188 |
|
sl@0
|
1189 |
// test.Next(_L("Close handles"));
|
sl@0
|
1190 |
TheChunk.Close();
|
sl@0
|
1191 |
CHECK(1,==,Ldd.CloseChunk());
|
sl@0
|
1192 |
|
sl@0
|
1193 |
// test.End();
|
sl@0
|
1194 |
}
|
sl@0
|
1195 |
|
sl@0
|
1196 |
void TestMappingAttributes()
|
sl@0
|
1197 |
{
|
sl@0
|
1198 |
test.Start(_L("Fully Blocking"));
|
sl@0
|
1199 |
TInt blockedRead;
|
sl@0
|
1200 |
TInt blockedWrite;
|
sl@0
|
1201 |
AccessSpeed(EBlocking,blockedRead,blockedWrite);
|
sl@0
|
1202 |
|
sl@0
|
1203 |
TInt read;
|
sl@0
|
1204 |
TInt write;
|
sl@0
|
1205 |
|
sl@0
|
1206 |
test.Next(_L("Write Buffered"));
|
sl@0
|
1207 |
AccessSpeed(EBuffered,read,write);
|
sl@0
|
1208 |
CHECK(2*blockedRead,>,read);
|
sl@0
|
1209 |
// CHECK(2*blockedWrite,<,write); // Write buffering doesn't seem to work when cache disabled (?)
|
sl@0
|
1210 |
|
sl@0
|
1211 |
test.Next(_L("Fully Cached"));
|
sl@0
|
1212 |
AccessSpeed(ECached,read,write);
|
sl@0
|
1213 |
CHECK(2*blockedRead,<,read);
|
sl@0
|
1214 |
#ifndef __X86__ // X86 seems to do always do write buffering
|
sl@0
|
1215 |
// Following check disabled because most dev boards only seem to be a bit faster
|
sl@0
|
1216 |
// and asserting a particular speed improvement is unreliable
|
sl@0
|
1217 |
// CHECK(2*blockedWrite,<,write);
|
sl@0
|
1218 |
#endif
|
sl@0
|
1219 |
|
sl@0
|
1220 |
test.End();
|
sl@0
|
1221 |
}
|
sl@0
|
1222 |
|
sl@0
|
1223 |
class RSession : public RSessionBase
|
sl@0
|
1224 |
{
|
sl@0
|
1225 |
public:
|
sl@0
|
1226 |
inline TInt CreateSession(const TDesC& aServer,const TVersion& aVersion)
|
sl@0
|
1227 |
{ return RSessionBase::CreateSession(aServer,aVersion); }
|
sl@0
|
1228 |
inline TInt SendReceive(TInt aFunction,const TIpcArgs& aArgs) const
|
sl@0
|
1229 |
{ return RSessionBase::SendReceive(aFunction,aArgs); }
|
sl@0
|
1230 |
};
|
sl@0
|
1231 |
|
sl@0
|
1232 |
TInt SlaveCommand(TSlaveCommand aCommand)
|
sl@0
|
1233 |
{
|
sl@0
|
1234 |
RDebug::Print(_L("Slave Process - Command %d\n"),aCommand);
|
sl@0
|
1235 |
CHECK(KErrNone,==,UserHal::PageSizeInBytes(PageSize));
|
sl@0
|
1236 |
CHECK(KErrNone,==,((RBusLogicalChannel&)Ldd).Open(2,EOwnerProcess));
|
sl@0
|
1237 |
switch(aCommand)
|
sl@0
|
1238 |
{
|
sl@0
|
1239 |
case ESlaveCheckChunk:
|
sl@0
|
1240 |
{
|
sl@0
|
1241 |
RDebug::Print(_L("Slave Process - TheChunk.Open()\n"));
|
sl@0
|
1242 |
CHECK(KErrNone,==,TheChunk.Open(3));
|
sl@0
|
1243 |
RDebug::Print(_L("Slave Process - Get Region Count\n"));
|
sl@0
|
1244 |
TInt regionCount;
|
sl@0
|
1245 |
CHECK(KErrNone,==,User::GetTIntParameter(4,regionCount));
|
sl@0
|
1246 |
RDebug::Print(_L("Slave Process - CheckCommitedContents(%d)\n"),regionCount);
|
sl@0
|
1247 |
CheckCommitedContents(regionCount);
|
sl@0
|
1248 |
RDebug::Print(_L("Slave Process - CheckCommitState(%d)\n"),regionCount);
|
sl@0
|
1249 |
CheckCommitState(regionCount);
|
sl@0
|
1250 |
RDebug::Print(_L("Slave Process - Done\n"));
|
sl@0
|
1251 |
return 0;
|
sl@0
|
1252 |
}
|
sl@0
|
1253 |
|
sl@0
|
1254 |
case ESlaveCreateChunk:
|
sl@0
|
1255 |
{
|
sl@0
|
1256 |
RDebug::Print(_L("Slave Process - Get parameters\n"));
|
sl@0
|
1257 |
TInt createFlags;
|
sl@0
|
1258 |
TInt commitType;
|
sl@0
|
1259 |
TInt commitSize;
|
sl@0
|
1260 |
CHECK(KErrNone,==,User::GetTIntParameter(3,createFlags));
|
sl@0
|
1261 |
CHECK(KErrNone,==,User::GetTIntParameter(4,commitType));
|
sl@0
|
1262 |
CHECK(KErrNone,==,User::GetTIntParameter(5,commitSize));
|
sl@0
|
1263 |
|
sl@0
|
1264 |
RDebug::Print(_L("Slave Process - Create Chunk\n"));
|
sl@0
|
1265 |
CHECK(KErrNone,==,Ldd.CreateChunk(createFlags));
|
sl@0
|
1266 |
CHECK(KErrNone,==,Ldd.CommitMemory(commitType,commitSize));
|
sl@0
|
1267 |
CHECK(KErrNone,==,Ldd.GetChunkHandle(TheChunk));
|
sl@0
|
1268 |
TUint8* chunkBase=TheChunk.Base();
|
sl@0
|
1269 |
memcpy(chunkBase,KTestString().Ptr(),KTestString().Size());
|
sl@0
|
1270 |
|
sl@0
|
1271 |
RDebug::Print(_L("Slave Process - Connecting to test server\n"));
|
sl@0
|
1272 |
RSession session;
|
sl@0
|
1273 |
CHECK(KErrNone,==,session.CreateSession(KSecondProcessName,TVersion()));
|
sl@0
|
1274 |
|
sl@0
|
1275 |
RDebug::Print(_L("Slave Process - Sending message\n"));
|
sl@0
|
1276 |
TPtr8 ptr(chunkBase,commitSize,commitSize);
|
sl@0
|
1277 |
session.SendReceive(0,TIpcArgs(&ptr));
|
sl@0
|
1278 |
|
sl@0
|
1279 |
RDebug::Print(_L("Slave Process - Destroy Chunk\n"));
|
sl@0
|
1280 |
TheChunk.Close();
|
sl@0
|
1281 |
CHECK(1,==,Ldd.CloseChunk()); // 1==DObject::EObjectDeleted
|
sl@0
|
1282 |
CHECK(1,==,Ldd.IsDestroyed());
|
sl@0
|
1283 |
return 0;
|
sl@0
|
1284 |
}
|
sl@0
|
1285 |
|
sl@0
|
1286 |
default:
|
sl@0
|
1287 |
RDebug::Print(_L("Slave Process - Bad Command\n"));
|
sl@0
|
1288 |
return KErrArgument;
|
sl@0
|
1289 |
}
|
sl@0
|
1290 |
}
|
sl@0
|
1291 |
|
sl@0
|
1292 |
void TestChunkUserBase()
|
sl@0
|
1293 |
{
|
sl@0
|
1294 |
TUint ChunkAttribs = ChunkSize|ESingle|EOwnsMemory;
|
sl@0
|
1295 |
|
sl@0
|
1296 |
test.Start(_L("Create chunk"));
|
sl@0
|
1297 |
CHECK(KErrNone,==,Ldd.CreateChunk(ChunkAttribs));
|
sl@0
|
1298 |
|
sl@0
|
1299 |
test.Next(_L("Open user handle"));
|
sl@0
|
1300 |
CHECK(KErrNone,==,Ldd.GetChunkHandle(TheChunk));
|
sl@0
|
1301 |
|
sl@0
|
1302 |
test.Next(_L("Commit some memory"));
|
sl@0
|
1303 |
CHECK(KErrNone,==,Ldd.CommitMemory(EDiscontiguous|1*PageSize,PageSize));
|
sl@0
|
1304 |
|
sl@0
|
1305 |
test.Next(_L("Check OpenSharedChunk with handle"));
|
sl@0
|
1306 |
CHECK(KErrNone,==,Ldd.TestOpenHandle(TheChunk.Handle()));
|
sl@0
|
1307 |
|
sl@0
|
1308 |
test.Next(_L("Get Kernel's user base"));
|
sl@0
|
1309 |
TAny *kernelUserAddress;
|
sl@0
|
1310 |
CHECK(KErrNone,==,Ldd.GetChunkUserBase(&kernelUserAddress));
|
sl@0
|
1311 |
TAny *userAddress = TheChunk.Base();
|
sl@0
|
1312 |
test(kernelUserAddress == userAddress);
|
sl@0
|
1313 |
|
sl@0
|
1314 |
TheChunk.Close();
|
sl@0
|
1315 |
CHECK(1,==,Ldd.CloseChunk());
|
sl@0
|
1316 |
|
sl@0
|
1317 |
test.End();
|
sl@0
|
1318 |
}
|
sl@0
|
1319 |
|
sl@0
|
1320 |
|
sl@0
|
1321 |
TInt E32Main()
|
sl@0
|
1322 |
{
|
sl@0
|
1323 |
// Running as slave?
|
sl@0
|
1324 |
TInt slaveCommand;
|
sl@0
|
1325 |
if(User::GetTIntParameter(1,slaveCommand)==KErrNone)
|
sl@0
|
1326 |
return SlaveCommand((TSlaveCommand)slaveCommand);
|
sl@0
|
1327 |
|
sl@0
|
1328 |
// Turn off lazy dll unloading
|
sl@0
|
1329 |
RLoader l;
|
sl@0
|
1330 |
test(l.Connect()==KErrNone);
|
sl@0
|
1331 |
test(l.CancelLazyDllUnload()==KErrNone);
|
sl@0
|
1332 |
l.Close();
|
sl@0
|
1333 |
|
sl@0
|
1334 |
test.Title();
|
sl@0
|
1335 |
|
sl@0
|
1336 |
MemModelAttributes=UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, NULL, NULL);
|
sl@0
|
1337 |
TUint mm=MemModelAttributes&EMemModelTypeMask;
|
sl@0
|
1338 |
#ifdef __T_SHAREDCHUNKF__
|
sl@0
|
1339 |
if(mm!=EMemModelTypeMoving)
|
sl@0
|
1340 |
{
|
sl@0
|
1341 |
test.Start(_L("TESTS NOT RUN - Only valid on Moving Memory Model"));
|
sl@0
|
1342 |
test.End();
|
sl@0
|
1343 |
return 0;
|
sl@0
|
1344 |
}
|
sl@0
|
1345 |
#endif
|
sl@0
|
1346 |
|
sl@0
|
1347 |
test.Start(_L("Initialise"));
|
sl@0
|
1348 |
CHECK(KErrNone,==,UserHal::PageSizeInBytes(PageSize));
|
sl@0
|
1349 |
PhysicalCommitSupported = mm!=EMemModelTypeDirect && mm!=EMemModelTypeEmul;
|
sl@0
|
1350 |
CachingAttributesSupported = mm!=EMemModelTypeDirect && mm!=EMemModelTypeEmul;
|
sl@0
|
1351 |
|
sl@0
|
1352 |
|
sl@0
|
1353 |
test.Next(_L("Loading test driver"));
|
sl@0
|
1354 |
TInt r = User::LoadLogicalDevice(KSharedChunkLddName);
|
sl@0
|
1355 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
1356 |
|
sl@0
|
1357 |
test.Next(_L("Opening channel"));
|
sl@0
|
1358 |
CHECK(KErrNone,==,Ldd.Open());
|
sl@0
|
1359 |
|
sl@0
|
1360 |
// now 'unload' test driver, however, it will remain loaded whilst
|
sl@0
|
1361 |
// we still have a channel open with it...
|
sl@0
|
1362 |
User::FreeLogicalDevice(KSharedChunkLddName);
|
sl@0
|
1363 |
|
sl@0
|
1364 |
test.Next(_L("Test chunk create"));
|
sl@0
|
1365 |
TestCreate();
|
sl@0
|
1366 |
|
sl@0
|
1367 |
test.Next(_L("Test handles"));
|
sl@0
|
1368 |
TestHandles();
|
sl@0
|
1369 |
|
sl@0
|
1370 |
test.Next(_L("Test handle ownership"));
|
sl@0
|
1371 |
TestHandleOwnership();
|
sl@0
|
1372 |
|
sl@0
|
1373 |
test.Next(_L("Test restrictions for multiply shared chunks"));
|
sl@0
|
1374 |
TestRestrictions(EMultiple);
|
sl@0
|
1375 |
test.Next(_L("Test restrictions for singly shared chunks"));
|
sl@0
|
1376 |
TestRestrictions(ESingle);
|
sl@0
|
1377 |
|
sl@0
|
1378 |
test.Next(_L("Test memory access for multiply shared chunks"));
|
sl@0
|
1379 |
TestAccess(EMultiple|EOwnsMemory,EDiscontiguous);
|
sl@0
|
1380 |
test.Next(_L("Test memory access for singly shared chunks"));
|
sl@0
|
1381 |
TestAccess(ESingle|EOwnsMemory,EDiscontiguous);
|
sl@0
|
1382 |
|
sl@0
|
1383 |
test.Next(_L("Test Discontiguous memory commit for multiply shared chunks"));
|
sl@0
|
1384 |
TestCommit(EMultiple,EDiscontiguous);
|
sl@0
|
1385 |
test.Next(_L("Test Discontiguous memory commit for singly shared chunks"));
|
sl@0
|
1386 |
TestCommit(ESingle,EDiscontiguous);
|
sl@0
|
1387 |
|
sl@0
|
1388 |
if((MemModelAttributes&EMemModelTypeMask)!=EMemModelTypeDirect)
|
sl@0
|
1389 |
{
|
sl@0
|
1390 |
test.Next(_L("Test Contiguous memory commit for multiply shared chunks"));
|
sl@0
|
1391 |
TestCommit(EMultiple,EContiguous);
|
sl@0
|
1392 |
test.Next(_L("Test Contiguous memory commit for singly shared chunks"));
|
sl@0
|
1393 |
TestCommit(ESingle,EContiguous);
|
sl@0
|
1394 |
}
|
sl@0
|
1395 |
|
sl@0
|
1396 |
if(PhysicalCommitSupported)
|
sl@0
|
1397 |
{
|
sl@0
|
1398 |
test.Next(_L("Test Discontiguous Physical commit for multiply shared chunks"));
|
sl@0
|
1399 |
TestCommit(EMultiple,EDiscontiguousPhysical);
|
sl@0
|
1400 |
test.Next(_L("Test Discontiguous Physical commit for singly shared chunks"));
|
sl@0
|
1401 |
TestCommit(ESingle,EDiscontiguousPhysical);
|
sl@0
|
1402 |
|
sl@0
|
1403 |
test.Next(_L("Test Contiguous Physical commit for multiply shared chunks"));
|
sl@0
|
1404 |
TestCommit(EMultiple,EContiguousPhysical);
|
sl@0
|
1405 |
test.Next(_L("Test Contiguous Physical commit for singly shared chunks"));
|
sl@0
|
1406 |
TestCommit(ESingle,EContiguousPhysical);
|
sl@0
|
1407 |
}
|
sl@0
|
1408 |
|
sl@0
|
1409 |
test.Next(_L("Test Kern::OpenSharedChunk for multiply shared chunks"));
|
sl@0
|
1410 |
TestOpenSharedChunk(EMultiple,EDiscontiguous);
|
sl@0
|
1411 |
test.Next(_L("Test Kern::OpenSharedChunk for singly shared chunks"));
|
sl@0
|
1412 |
TestOpenSharedChunk(ESingle,EDiscontiguous);
|
sl@0
|
1413 |
|
sl@0
|
1414 |
if(CachingAttributesSupported)
|
sl@0
|
1415 |
{
|
sl@0
|
1416 |
test.Next(_L("Test Mapping Attributes"));
|
sl@0
|
1417 |
TestMappingAttributes();
|
sl@0
|
1418 |
}
|
sl@0
|
1419 |
|
sl@0
|
1420 |
test.Next(_L("Testing Kern::ChunkUserBase for shared chunks"));
|
sl@0
|
1421 |
TestChunkUserBase();
|
sl@0
|
1422 |
|
sl@0
|
1423 |
if (PhysicalCommitSupported)
|
sl@0
|
1424 |
{
|
sl@0
|
1425 |
test.Next(_L("Testing Kern::ChunkClose allows immediate freeing of physical ram"));
|
sl@0
|
1426 |
test_KErrNone(Ldd.TestChunkCloseAndFree());
|
sl@0
|
1427 |
}
|
sl@0
|
1428 |
|
sl@0
|
1429 |
test.Next(_L("Close test driver"));
|
sl@0
|
1430 |
Ldd.Close();
|
sl@0
|
1431 |
|
sl@0
|
1432 |
test.End();
|
sl@0
|
1433 |
|
sl@0
|
1434 |
return 0;
|
sl@0
|
1435 |
}
|