author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 15 Mar 2010 12:45:50 +0200 | |
branch | RCL_3 |
changeset 81 | e7d2d738d3c2 |
parent 39 | 5d2844f35677 |
child 293 | 0659d0e1a03c |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
// All rights reserved. |
|
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32test\mmu\t_pin.cpp |
|
15 |
// Tests kernel APIs for logical pinning by pinning memory and using a realtime thread to check that |
|
16 |
// no page faults are taken while accessing it. |
|
17 |
// |
|
18 |
// |
|
19 |
||
20 |
#define __E32TEST_EXTENSION__ |
|
21 |
#include <e32test.h> |
|
22 |
#include <e32svr.h> |
|
23 |
#include <e32rom.h> |
|
24 |
#include <e32kpan.h> |
|
25 |
#include <u32hal.h> |
|
26 |
#include <dptest.h> |
|
27 |
#include "d_memorytest.h" |
|
28 |
#include "t_codepaging_dll.h" |
|
29 |
#include "mmudetect.h" |
|
30 |
#include "freeram.h" |
|
31 |
||
32 |
RTest test(_L("T_PIN")); |
|
33 |
||
34 |
_LIT(KTCodePagingDll4, "t_codepaging_dll4.dll"); |
|
35 |
const TInt KMinBufferSize = 16384; |
|
36 |
||
37 |
RMemoryTestLdd Ldd; |
|
38 |
RMemoryTestLdd Ldd2; |
|
39 |
RLibrary PagedLibrary; |
|
40 |
const TUint8* PagedBuffer = NULL; |
|
41 |
const TUint8* UnpagedBuffer = NULL; |
|
42 |
TInt PageSize; |
|
43 |
||
44 |
TInt FreeRamNoWait() |
|
45 |
{ |
|
46 |
TMemoryInfoV1Buf meminfo; |
|
47 |
UserHal::MemoryInfo(meminfo); |
|
48 |
return meminfo().iFreeRamInBytes; |
|
49 |
} |
|
50 |
||
51 |
void CheckMemoryPresent(const TUint8* aBuffer, TInt aSize, TBool aExpected) |
|
52 |
{ |
|
53 |
if (aExpected) |
|
54 |
test.Printf(_L(" Checking memory at %08x is present\n"), aBuffer); |
|
55 |
else |
|
56 |
test.Printf(_L(" Checking memory at %08x is not present\n"), aBuffer); |
|
57 |
for (TInt i = 0 ; i < aSize ; i += PageSize) |
|
58 |
test_Equal(aExpected, Ldd.IsMemoryPresent(aBuffer + i)); |
|
59 |
} |
|
60 |
||
61 |
void FlushPagingCache() |
|
62 |
{ |
|
63 |
test_KErrNone(DPTest::FlushCache()); |
|
64 |
} |
|
65 |
||
66 |
void TestPinVirtualMemoryUnpaged() |
|
67 |
{ |
|
68 |
test.Printf(_L("Create logical pin object\n")); |
|
69 |
test_KErrNone(Ldd.CreateVirtualPinObject()); |
|
70 |
#ifdef __EPOC32__ |
|
71 |
CheckMemoryPresent(UnpagedBuffer, KMinBufferSize, ETrue); |
|
72 |
test.Printf(_L("Perform logical pin operation on zero-length buffer\n")); |
|
73 |
test_KErrNone(Ldd.PinVirtualMemory((TLinAddr)UnpagedBuffer, 0)); |
|
74 |
CheckMemoryPresent(UnpagedBuffer, KMinBufferSize, ETrue); |
|
75 |
test.Printf(_L("Perform logical unpin operation\n")); |
|
76 |
test_KErrNone(Ldd.UnpinVirtualMemory()); |
|
77 |
CheckMemoryPresent(UnpagedBuffer, KMinBufferSize, ETrue); |
|
78 |
test.Printf(_L("Perform logical pin operation on whole buffer\n")); |
|
79 |
test_KErrNone(Ldd.PinVirtualMemory((TLinAddr)UnpagedBuffer, KMinBufferSize)); |
|
80 |
CheckMemoryPresent(UnpagedBuffer, KMinBufferSize, ETrue); |
|
81 |
test.Printf(_L("Perform logical unpin operation\n")); |
|
82 |
test_KErrNone(Ldd.UnpinVirtualMemory()); |
|
83 |
CheckMemoryPresent(UnpagedBuffer, KMinBufferSize, ETrue); |
|
84 |
#else |
|
85 |
// Don't check for memory presence on emulator as paging not supported. |
|
86 |
test.Printf(_L("Perform logical pin operation on zero-length buffer\n")); |
|
87 |
test_KErrNone(Ldd.PinVirtualMemory((TLinAddr)UnpagedBuffer, 0)); |
|
88 |
test.Printf(_L("Perform logical unpin operation\n")); |
|
89 |
test_KErrNone(Ldd.UnpinVirtualMemory()); |
|
90 |
test.Printf(_L("Perform logical pin operation on whole buffer\n")); |
|
91 |
test_KErrNone(Ldd.PinVirtualMemory((TLinAddr)UnpagedBuffer, KMinBufferSize)); |
|
92 |
test.Printf(_L("Perform logical unpin operation\n")); |
|
93 |
test_KErrNone(Ldd.UnpinVirtualMemory()); |
|
94 |
#endif |
|
95 |
test.Printf(_L("Perform logical unpin operation (again)\n")); |
|
96 |
test_KErrNone(Ldd.UnpinVirtualMemory()); // test double unpin ok |
|
97 |
test.Printf(_L("Destroy logical pin object\n")); |
|
98 |
test_KErrNone(Ldd.DestroyVirtualPinObject()); |
|
99 |
test.Printf(_L("Destroy logical pin object (again)\n")); |
|
100 |
test_KErrNone(Ldd.DestroyVirtualPinObject()); // test double destroy ok |
|
101 |
} |
|
102 |
||
103 |
void TestPinPhysicalMemory() |
|
104 |
{ |
|
105 |
||
106 |
TInt mm = UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, 0, 0) & EMemModelTypeMask; |
|
107 |
if (mm < EMemModelTypeFlexible) |
|
108 |
{ |
|
109 |
test.Printf(_L("Memory model (%d) doesn't support physical pining\n"),mm); |
|
110 |
return; |
|
111 |
} |
|
112 |
TInt i; |
|
113 |
TInt8* UCBase; |
|
114 |
RChunk chunk; |
|
115 |
||
116 |
test.Printf(_L("Allocate user chunk\n")); |
|
117 |
TChunkCreateInfo createInfo; |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
118 |
createInfo.SetDisconnected(0,KUCPageCount*PageSize,KUCPageCount*PageSize); |
0 | 119 |
createInfo.SetPaging(TChunkCreateInfo::EPaged); |
120 |
test_KErrNone(chunk.Create(createInfo)); |
|
121 |
UCBase = (TInt8*)chunk.Base(); |
|
122 |
||
123 |
test.Printf(_L("Create physical pin object\n")); |
|
124 |
test_KErrNone(Ldd.CreatePhysicalPinObject()); |
|
125 |
||
126 |
test.Printf(_L("Perform physical pin operation on zero-length buffer\n")); |
|
127 |
test_KErrNone(Ldd.PinPhysicalMemory((TLinAddr)UCBase, 0)); |
|
128 |
||
129 |
test.Printf(_L("Perform physical unpin operation\n")); |
|
130 |
test_KErrNone(Ldd.UnpinPhysicalMemory()); |
|
131 |
||
132 |
test.Printf(_L("Perform Physical pin operation on the chunk\n")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
133 |
test_KErrNone(Ldd.PinPhysicalMemory((TLinAddr)UCBase, KUCPageCount*PageSize)); |
0 | 134 |
|
135 |
test.Printf(_L("Test that pinned physical memory preserves its mapping when recommited\n")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
136 |
test_KErrNone(chunk.Decommit(0,KUCPageCount*PageSize)); //Decommit all |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
137 |
for (i=KUCPageCount-1;i>=0;i--) test_KErrNone(chunk.Commit(i*PageSize,PageSize)); //Commit in reverse order |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
138 |
for (i=0;i<KUCPageCount;i++) // Recommited memory is not paged in. So, write into each page, before driver |
0 | 139 |
{ // calls Kern::LinearToPhysical or it will get KErrInvalidMemory in return. |
140 |
volatile TInt8* ptr = (volatile TInt8*)(UCBase+i*PageSize); |
|
141 |
*ptr = 10; |
|
142 |
} |
|
143 |
test_KErrNone(Ldd.CheckPageList(chunk.Base())); // Check that the mapping is preserved. |
|
144 |
||
145 |
test.Printf(_L("Sync cache & memory of User Chunk\n"));//Test Cache::SyncPhysicalMemoryBeforeDmaWrite |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
test_KErrNone(Ldd.SyncPinnedPhysicalMemory(0,KUCPageCount*PageSize)); |
0 | 147 |
|
148 |
test.Printf(_L("Invalidate cache of User Chunk\n"));//Test Cache::SyncPhysicalMemoryBefore/AfterDmaRead |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
test_KErrNone(Ldd.InvalidatePinnedPhysicalMemory(0,KUCPageCount*PageSize)); |
0 | 150 |
|
151 |
test.Printf(_L("Try to move pinned phys. memory...\n")); //RAM defrag should return error code here. |
|
152 |
i = Ldd.MovePinnedPhysicalMemory(0); |
|
153 |
test.Printf(_L("...returned %d\n"),i); |
|
154 |
test(i!=KErrNone); |
|
155 |
||
156 |
test.Printf(_L("Close the chunk\n")); // Phys. memory is pinned and shouldn't be ... |
|
157 |
chunk.Close(); // ... mapped to another virtual memory. |
|
158 |
||
159 |
test.Printf(_L("Allocate & initilise the second chunk\n"));// Kernel sholudn't commit pinned physical memory ... |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
test_KErrNone(chunk.CreateLocal(KUCPageCount*PageSize,KUCPageCount*PageSize)); // ...that has been just decommited from the first chunk. |
0 | 161 |
UCBase = (TInt8*)chunk.Base(); |
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
for (i=0;i<KUCPageCount*PageSize;i++) UCBase[i]=0; //Initialise user buffer |
0 | 163 |
|
164 |
test.Printf(_L("Invalidate cache of pinned memory\n"));//This shouldn't affect the second chunk. |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
test_KErrNone(Ldd.InvalidatePinnedPhysicalMemory(0,KUCPageCount*PageSize)); |
0 | 166 |
|
167 |
test.Printf(_L("Check data in the second chunk is unaffected\n")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
168 |
for (i=0;i<KUCPageCount*PageSize;i++) test(UCBase[i]==0); |
0 | 169 |
|
170 |
test.Printf(_L("Close the second chunk\n")); |
|
171 |
chunk.Close(); |
|
172 |
||
173 |
test.Printf(_L("Perform physical unpin operation\n")); |
|
174 |
test_KErrNone(Ldd.UnpinPhysicalMemory()); |
|
175 |
||
176 |
test.Printf(_L("Perform physical unpin operation (again)\n")); |
|
177 |
test_KErrNone(Ldd.UnpinPhysicalMemory()); // test double unpin ok |
|
178 |
||
179 |
test.Printf(_L("Destroy physical pin object\n")); |
|
180 |
test_KErrNone(Ldd.DestroyPhysicalPinObject()); |
|
181 |
||
182 |
test.Printf(_L("Destroy physical pin object (again)\n")); |
|
183 |
test_KErrNone(Ldd.DestroyPhysicalPinObject()); // test double destroy ok |
|
184 |
||
185 |
test.Printf(_L("Test phys. pinning and sync of kernel memory.\n")); |
|
186 |
test_KErrNone(Ldd.PinKernelPhysicalMemory());// Simple test of phys. pinning of kernel memory |
|
187 |
} |
|
188 |
||
189 |
void TestPhysicalPinOutOfMemory() |
|
190 |
{ |
|
191 |
TInt mm = UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, 0, 0) & EMemModelTypeMask; |
|
192 |
if (mm < EMemModelTypeFlexible) |
|
193 |
{ |
|
194 |
test.Printf(_L("Memory model (%d) doesn't support physical pining\n"),mm); |
|
195 |
return; |
|
196 |
} |
|
197 |
||
198 |
TInt8* UCBase; |
|
199 |
RChunk chunk; |
|
200 |
||
201 |
test.Printf(_L("Allocate user chunk\n")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
202 |
test_KErrNone(chunk.CreateDisconnectedLocal(0,KUCPageCount*PageSize,KUCPageCount*PageSize)); |
0 | 203 |
UCBase = (TInt8*)chunk.Base(); |
204 |
||
205 |
const TInt KMaxKernelAllocations = 1024; |
|
206 |
TInt r=KErrNoMemory; |
|
207 |
TInt i; |
|
208 |
||
209 |
__KHEAP_MARK; |
|
210 |
for (i = 0; i < KMaxKernelAllocations && r == KErrNoMemory; i++) |
|
211 |
{ |
|
212 |
__KHEAP_FAILNEXT(i); |
|
213 |
test.Printf(_L("Create physical pin object\n")); |
|
214 |
r = Ldd.CreatePhysicalPinObject(); |
|
215 |
__KHEAP_RESET; |
|
216 |
} |
|
217 |
test.Printf(_L("Create physical pin object took %d tries\n"),i); |
|
218 |
test_KErrNone(r); |
|
219 |
||
220 |
r = KErrNoMemory; |
|
221 |
||
222 |
for (i = 0; i < KMaxKernelAllocations && r == KErrNoMemory; i++) |
|
223 |
{ |
|
224 |
__KHEAP_FAILNEXT(i); |
|
225 |
test.Printf(_L("Perform physical pin operation\n")); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
226 |
r = Ldd.PinPhysicalMemory((TLinAddr)UCBase, KUCPageCount*PageSize); |
0 | 227 |
__KHEAP_RESET; |
228 |
} |
|
229 |
test.Printf(_L("Perform physical pin operation took %d tries\n"),i); |
|
230 |
if (r == KErrNone) |
|
231 |
{ |
|
232 |
test.Printf(_L("Perform physical unpin operation\n")); |
|
233 |
Ldd.UnpinPhysicalMemory(); |
|
234 |
} |
|
235 |
||
236 |
test.Printf(_L("Destroy physical pin object\n")); |
|
237 |
Ldd.DestroyPhysicalPinObject(); |
|
238 |
||
239 |
// wait for any async cleanup in the supervisor to finish first... |
|
240 |
UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0); |
|
241 |
__KHEAP_MARKEND; |
|
242 |
||
243 |
test.Printf(_L("Close the chunk\n")); |
|
244 |
chunk.Close(); |
|
245 |
||
246 |
test_KErrNone(r); |
|
247 |
} |
|
248 |
||
249 |
||
250 |
void TestPinVirtualMemoryInvalid() |
|
251 |
{ |
|
252 |
test.Printf(_L("Create logical pin object\n")); |
|
253 |
test_KErrNone(Ldd.CreateVirtualPinObject()); |
|
254 |
test.Printf(_L("Attempt logical pin on bad memory address\n")); |
|
255 |
TLinAddr bad = (TLinAddr)0x10000; |
|
256 |
TInt r = Ldd.PinVirtualMemory(bad,KMinBufferSize); |
|
257 |
test.Printf(_L("%08x r=%d"),bad,r); |
|
258 |
if(r==KErrNone) |
|
259 |
test_KErrNone(Ldd.UnpinVirtualMemory()); |
|
260 |
if ((MemModelAttributes() & EMemModelTypeMask) == EMemModelTypeMultiple) |
|
261 |
{ |
|
262 |
// test unused part of code chunk... |
|
263 |
bad = (TLinAddr)0x7f000000; |
|
264 |
r = Ldd.PinVirtualMemory(bad,KMinBufferSize); |
|
265 |
test.Printf(_L("%08x r=%d"),bad,r); |
|
266 |
if(r==KErrNone) |
|
267 |
test_KErrNone(Ldd.UnpinVirtualMemory()); |
|
268 |
} |
|
269 |
test.Printf(_L("Destroy logical pin object\n")); |
|
270 |
test_KErrNone(Ldd.DestroyVirtualPinObject()); |
|
271 |
} |
|
272 |
||
273 |
void TestPinVirtualMemoryPaged() |
|
274 |
{ |
|
275 |
test.Printf(_L("Create logical pin object\n")); |
|
276 |
test_KErrNone(Ldd.CreateVirtualPinObject()); |
|
277 |
FlushPagingCache(); |
|
278 |
CheckMemoryPresent(PagedBuffer, KMinBufferSize, EFalse); |
|
279 |
test.Printf(_L("Perform logical pin operation on zero-length buffer\n")); |
|
280 |
test_KErrNone(Ldd.PinVirtualMemory((TLinAddr)PagedBuffer, 0)); |
|
281 |
CheckMemoryPresent(PagedBuffer, KMinBufferSize, EFalse); |
|
282 |
test.Printf(_L("Perform logical unpin operation\n")); |
|
283 |
test_KErrNone(Ldd.UnpinVirtualMemory()); |
|
284 |
CheckMemoryPresent(PagedBuffer, KMinBufferSize, EFalse); |
|
285 |
test.Printf(_L("Perform logical pin operation on whole buffer\n")); |
|
286 |
test_KErrNone(Ldd.PinVirtualMemory((TLinAddr)PagedBuffer, KMinBufferSize)); |
|
287 |
CheckMemoryPresent(PagedBuffer, KMinBufferSize, ETrue); |
|
288 |
FlushPagingCache(); |
|
289 |
CheckMemoryPresent(PagedBuffer, KMinBufferSize, ETrue); |
|
290 |
test.Printf(_L("Perform logical unpin operation\n")); |
|
291 |
test_KErrNone(Ldd.UnpinVirtualMemory()); |
|
292 |
CheckMemoryPresent(PagedBuffer, KMinBufferSize, ETrue); |
|
293 |
FlushPagingCache(); |
|
294 |
CheckMemoryPresent(PagedBuffer, KMinBufferSize, EFalse); |
|
295 |
test.Printf(_L("Perform logical unpin operation (again)\n")); |
|
296 |
test_KErrNone(Ldd.UnpinVirtualMemory()); // test double unpin ok |
|
297 |
test.Printf(_L("Destroy logical pin object\n")); |
|
298 |
test_KErrNone(Ldd.DestroyVirtualPinObject()); |
|
299 |
test.Printf(_L("Destroy logical pin object (again)\n")); |
|
300 |
test_KErrNone(Ldd.DestroyVirtualPinObject()); // test double destroy ok |
|
301 |
} |
|
302 |
||
303 |
||
304 |
volatile TBool SoakEnd = false; |
|
305 |
||
306 |
class TRandom |
|
307 |
{ |
|
308 |
public: |
|
309 |
TRandom(TUint32 aSeed) |
|
310 |
: iSeed(aSeed) {}; |
|
311 |
inline TUint32 Next() |
|
312 |
{ iSeed = iSeed*69069+1; return iSeed; } |
|
313 |
TUint32 operator()(TUint32 aRange) |
|
314 |
{ return (TUint32)((TUint64(Next())*TUint64(aRange))>>32); } |
|
315 |
private: |
|
316 |
TUint iSeed; |
|
317 |
}; |
|
318 |
||
319 |
#define SOAK_CHECK(r) \ |
|
320 |
if(r!=KErrNone) \ |
|
321 |
{ \ |
|
322 |
RDebug::Printf("SOAK_CHECK fail at line %d",__LINE__); \ |
|
323 |
return r; \ |
|
324 |
} \ |
|
325 |
||
326 |
TInt SoakThread(TAny*) |
|
327 |
{ |
|
328 |
RMemoryTestLdd ldd; |
|
329 |
TInt r = ldd.Open(); |
|
330 |
SOAK_CHECK(r) |
|
331 |
||
332 |
r = ldd.CreateVirtualPinObject(); |
|
333 |
SOAK_CHECK(r) |
|
334 |
||
335 |
TRandom random((TUint32)&ldd); |
|
336 |
||
337 |
while(!SoakEnd) |
|
338 |
{ |
|
339 |
TUint start = random(KMinBufferSize); |
|
340 |
TUint end = random(KMinBufferSize); |
|
341 |
if(start>end) |
|
342 |
{ |
|
343 |
TUint temp = start; |
|
344 |
start = end; |
|
345 |
end = temp; |
|
346 |
} |
|
347 |
const TUint32 KPageMask = 0xfff; |
|
348 |
start &= ~KPageMask; |
|
349 |
end = (end+KPageMask)&~KPageMask; |
|
350 |
||
351 |
r = ldd.PinVirtualMemory((TLinAddr)(PagedBuffer+start),end-start); |
|
352 |
SOAK_CHECK(r) |
|
353 |
||
354 |
r = ldd.UnpinVirtualMemory(); |
|
355 |
SOAK_CHECK(r) |
|
356 |
} |
|
357 |
||
358 |
r = ldd.DestroyVirtualPinObject(); |
|
359 |
SOAK_CHECK(r) |
|
360 |
||
361 |
CLOSE_AND_WAIT(ldd); |
|
362 |
return KErrNone; |
|
363 |
} |
|
364 |
||
365 |
||
366 |
void TestPinVirtualMemoryPagedSoak() |
|
367 |
{ |
|
368 |
test.Start(_L("Create timer")); |
|
369 |
RTimer timer; |
|
370 |
test_KErrNone(timer.CreateLocal()); |
|
371 |
||
372 |
test.Next(_L("Create threads")); |
|
373 |
const TUint KNumThreads = 4; |
|
374 |
TRequestStatus status[KNumThreads]; |
|
375 |
RThread thread[KNumThreads]; |
|
376 |
TUint i; |
|
377 |
for(i=0; i<KNumThreads; i++) |
|
378 |
{ |
|
379 |
test_KErrNone(thread[i].Create(KNullDesC, SoakThread, 0x1000, NULL, 0)); |
|
380 |
thread[i].Logon(status[i]); |
|
381 |
test(status[i].Int()==KRequestPending); |
|
382 |
} |
|
383 |
||
384 |
test.Next(_L("Start threads")); |
|
385 |
RThread().SetPriority(EPriorityMore); // make sure we are higher priority than soak threads |
|
386 |
for(i=0; i<KNumThreads; i++) |
|
387 |
thread[i].Resume(); |
|
388 |
||
389 |
test.Next(_L("Wait...")); |
|
390 |
TRequestStatus timeoutStatus; |
|
391 |
timer.After(timeoutStatus,10*1000000); |
|
392 |
User::WaitForAnyRequest(); |
|
393 |
test_KErrNone(timeoutStatus.Int()); // we should have timed out if soak threads are still running OK |
|
394 |
||
395 |
test.Next(_L("Stop threads and check results")); |
|
396 |
for(i=0; i<KNumThreads; i++) |
|
397 |
test_Equal(KRequestPending,status[i].Int()); |
|
398 |
SoakEnd = true; |
|
399 |
timer.After(timeoutStatus,10*1000000); |
|
400 |
for(i=0; i<KNumThreads; i++) |
|
401 |
{ |
|
402 |
User::WaitForAnyRequest(); |
|
403 |
test_Equal(KRequestPending,timeoutStatus.Int()); |
|
404 |
} |
|
405 |
timer.Cancel(); |
|
406 |
User::WaitForRequest(timeoutStatus); |
|
407 |
RThread().SetPriority(EPriorityNormal); // restore thread priority |
|
408 |
||
409 |
// cleanup... |
|
410 |
CLOSE_AND_WAIT(timer); |
|
411 |
for(i=0; i<KNumThreads; i++) |
|
412 |
CLOSE_AND_WAIT(thread[i]); |
|
413 |
||
414 |
test.End(); |
|
415 |
} |
|
416 |
||
417 |
||
418 |
void TestPinVirtualMemoryDecommit() |
|
419 |
{ |
|
420 |
const TInt KChunk = 4*1024*1024; // offset of page table boundary on X86 and ARM |
|
421 |
const TInt KPage = PageSize; |
|
422 |
const TInt TestData[][2] = |
|
423 |
{ |
|
424 |
{0, KPage}, |
|
425 |
{KPage, KPage}, |
|
426 |
{KPage, 2*KPage}, |
|
427 |
{KChunk-KPage, KPage}, |
|
428 |
{KChunk-2*KPage,2*KPage}, |
|
429 |
{KChunk-KPage, 2*KPage}, |
|
430 |
{0,0} // end marker |
|
431 |
}; |
|
432 |
||
433 |
for(TInt i=0; TestData[i][1]; ++i) |
|
434 |
{ |
|
435 |
TInt commitOffset = TestData[i][0]; |
|
436 |
TInt commitSize = TestData[i][1]; |
|
437 |
test.Printf(_L("Create chunk 0x%x+0x%x\n"),commitOffset,commitSize); |
|
438 |
||
439 |
TChunkCreateInfo createInfo; |
|
440 |
createInfo.SetDisconnected(commitOffset,commitOffset+commitSize,commitOffset+commitSize); |
|
441 |
createInfo.SetPaging(TChunkCreateInfo::EPaged); |
|
442 |
RChunk chunk; |
|
443 |
test_KErrNone(chunk.Create(createInfo)); |
|
444 |
TUint8* buffer = chunk.Base()+commitOffset; |
|
445 |
TUint bufferSize = commitSize; |
|
446 |
FlushPagingCache(); // start with blank slate as far as paged memory is concerned |
|
447 |
||
448 |
test.Printf(_L("Create virtual pin object\n")); |
|
449 |
test_KErrNone(Ldd.CreateVirtualPinObject()); |
|
450 |
test_KErrNone(Ldd2.CreateVirtualPinObject()); |
|
451 |
CheckMemoryPresent(buffer, bufferSize, EFalse); |
|
452 |
TInt initialFreeRam = FreeRam(); |
|
453 |
||
454 |
test.Printf(_L("Pin memory\n")); |
|
455 |
test_KErrNone(Ldd.PinVirtualMemory((TLinAddr)buffer, bufferSize)); |
|
456 |
CheckMemoryPresent(buffer, bufferSize, ETrue); |
|
457 |
TInt pinnedFreeRam = FreeRam(); |
|
458 |
test_Compare(pinnedFreeRam,<,initialFreeRam); |
|
459 |
TUint8 c = *buffer; |
|
460 |
memset(buffer,~c,bufferSize); // invert memory |
|
461 |
||
462 |
test.Printf(_L("Decommit pinned memory\n")); |
|
463 |
test_KErrNone(chunk.Decommit(commitOffset,commitSize)); |
|
464 |
CheckMemoryPresent(buffer, bufferSize, EFalse); |
|
465 |
test_Equal(pinnedFreeRam,FreeRam()); // decommited memory should not be freed as it is pinned |
|
466 |
||
467 |
test.Printf(_L("Unpin memory\n")); |
|
468 |
test_KErrNone(Ldd.UnpinVirtualMemory()); |
|
469 |
CheckMemoryPresent(buffer, bufferSize, EFalse); |
|
470 |
test_Equal(initialFreeRam,FreeRam()); // memory should be now freed |
|
471 |
||
472 |
// |
|
473 |
// test recommitting decommitted pinned memory... |
|
474 |
// |
|
475 |
||
476 |
test.Printf(_L("Commit memory\n")); |
|
477 |
test_KErrNone(chunk.Commit(commitOffset,commitSize)); |
|
478 |
CheckMemoryPresent(buffer, bufferSize, EFalse); |
|
479 |
test_Equal(initialFreeRam,FreeRam()); |
|
480 |
||
481 |
test.Printf(_L("Read memory\n")); |
|
482 |
volatile TUint8* p = buffer; |
|
483 |
volatile TUint8* pEnd = buffer+bufferSize; |
|
484 |
while(p<pEnd) |
|
485 |
test_Equal(c,*p++); // memory should have been wiped |
|
486 |
test_Equal(initialFreeRam,FreeRam()); // memory now paged in |
|
487 |
||
488 |
test.Printf(_L("Pin memory which is already paged in\n")); |
|
489 |
test_KErrNone(Ldd.PinVirtualMemory((TLinAddr)buffer, bufferSize)); |
|
490 |
CheckMemoryPresent(buffer, bufferSize, ETrue); |
|
491 |
test_Equal(pinnedFreeRam,FreeRam()); |
|
492 |
memset(buffer,~c,bufferSize); // invert memory |
|
493 |
||
494 |
test.Printf(_L("Decommit pinned memory\n")); |
|
495 |
test_KErrNone(chunk.Decommit(commitOffset,commitSize)); |
|
496 |
CheckMemoryPresent(buffer, bufferSize, EFalse); |
|
497 |
test_Equal(pinnedFreeRam,FreeRam()); |
|
498 |
||
499 |
test.Printf(_L("Commit pinned memory again\n")); |
|
500 |
test_KErrNone(chunk.Commit(commitOffset,commitSize)); |
|
501 |
CheckMemoryPresent(buffer, bufferSize, EFalse); |
|
502 |
test_Equal(pinnedFreeRam,FreeRam()); |
|
503 |
p = buffer; |
|
504 |
pEnd = buffer+bufferSize; |
|
505 |
while(p<pEnd) |
|
506 |
test_Equal(c,*p++); // memory should have been wiped |
|
507 |
||
508 |
test.Printf(_L("Unpin memory\n")); |
|
509 |
test_KErrNone(Ldd.UnpinVirtualMemory()); |
|
510 |
CheckMemoryPresent(buffer, bufferSize, ETrue); |
|
511 |
test_Equal(initialFreeRam,FreeRam()); |
|
512 |
||
513 |
test.Printf(_L("Decommit memory\n")); |
|
514 |
test_KErrNone(chunk.Decommit(commitOffset,commitSize)); |
|
515 |
CheckMemoryPresent(buffer, bufferSize, EFalse); |
|
516 |
test_Compare(FreeRam(),<=,initialFreeRam); |
|
517 |
||
518 |
// |
|
519 |
// test pin twice... |
|
520 |
// |
|
521 |
||
522 |
test.Printf(_L("Commit memory\n")); |
|
523 |
test_KErrNone(chunk.Commit(commitOffset,commitSize)); |
|
524 |
CheckMemoryPresent(buffer, bufferSize, EFalse); |
|
525 |
test_Equal(initialFreeRam,FreeRam()); |
|
526 |
||
527 |
test.Printf(_L("Pin memory\n")); |
|
528 |
test_KErrNone(Ldd.PinVirtualMemory((TLinAddr)buffer, bufferSize)); |
|
529 |
CheckMemoryPresent(buffer, bufferSize, ETrue); |
|
530 |
test_Equal(pinnedFreeRam,FreeRam()); |
|
531 |
||
532 |
test.Printf(_L("Pin memory again\n")); |
|
533 |
test_KErrNone(Ldd2.PinVirtualMemory((TLinAddr)buffer, bufferSize)); |
|
534 |
CheckMemoryPresent(buffer, bufferSize, ETrue); |
|
535 |
test_Equal(pinnedFreeRam,FreeRam()); |
|
536 |
||
537 |
test.Printf(_L("Decommit pinned memory\n")); |
|
538 |
test_KErrNone(chunk.Decommit(commitOffset,commitSize)); |
|
539 |
CheckMemoryPresent(buffer, bufferSize, EFalse); |
|
540 |
test_Equal(pinnedFreeRam,FreeRam()); // decommited memory should not be freed as it is pinned |
|
541 |
||
542 |
test.Printf(_L("Unpin memory\n")); |
|
543 |
test_KErrNone(Ldd2.UnpinVirtualMemory()); |
|
544 |
CheckMemoryPresent(buffer, bufferSize, EFalse); |
|
545 |
test_Equal(pinnedFreeRam,FreeRam()); // memory shouldn't be freed as another pin exists |
|
546 |
||
547 |
test.Printf(_L("Unpin memory again\n")); |
|
548 |
test_KErrNone(Ldd.UnpinVirtualMemory()); |
|
549 |
CheckMemoryPresent(buffer, bufferSize, EFalse); |
|
550 |
test_Equal(initialFreeRam,FreeRam()); // memory should be now freed |
|
551 |
||
552 |
// |
|
553 |
// test page stealing of decommited memory |
|
554 |
// |
|
555 |
||
556 |
test.Printf(_L("Commit memory\n")); |
|
557 |
test_KErrNone(chunk.Commit(commitOffset,commitSize)); |
|
558 |
CheckMemoryPresent(buffer, bufferSize, EFalse); |
|
559 |
test_Equal(initialFreeRam,FreeRam()); |
|
560 |
||
561 |
test.Printf(_L("Pin memory\n")); |
|
562 |
test_KErrNone(Ldd.PinVirtualMemory((TLinAddr)buffer, bufferSize)); |
|
563 |
CheckMemoryPresent(buffer, bufferSize, ETrue); |
|
564 |
test_Equal(pinnedFreeRam,FreeRam()); |
|
565 |
||
566 |
test.Printf(_L("Decommit pinned memory\n")); |
|
567 |
test_KErrNone(chunk.Decommit(commitOffset,commitSize)); |
|
568 |
CheckMemoryPresent(buffer, bufferSize, EFalse); |
|
569 |
test_Equal(pinnedFreeRam,FreeRam()); |
|
570 |
||
571 |
test.Printf(_L("Unpin memory a higher priority that supervisor thread\n")); |
|
572 |
RThread().SetPriority(EPriorityRealTime); |
|
573 |
test_KErrNone(Ldd.UnpinVirtualMemory()); |
|
574 |
// on single core system, supervisor thread can't run and free pages yet |
|
575 |
// because we're a higher priority... |
|
576 |
test.Printf(_L("memory freed = %d\n"),initialFreeRam==FreeRamNoWait()); |
|
577 |
||
578 |
test.Printf(_L("Force decommited unpinned pages out of live list\n")); |
|
579 |
FlushPagingCache(); |
|
580 |
RThread().SetPriority(EPriorityNormal); |
|
581 |
test_Equal(initialFreeRam,FreeRam()); // memory should be now freed |
|
582 |
||
583 |
// |
|
584 |
// cleanup... |
|
585 |
// |
|
586 |
||
587 |
test.Printf(_L("Destroy pin object\n")); |
|
588 |
test_KErrNone(Ldd.DestroyVirtualPinObject()); |
|
589 |
test_KErrNone(Ldd2.DestroyVirtualPinObject()); |
|
590 |
chunk.Close(); |
|
591 |
} |
|
592 |
||
593 |
test.Printf(_L("Flush paging cache\n")); |
|
594 |
FlushPagingCache(); // this is a test that has shown up bugs in the past |
|
595 |
} |
|
596 |
||
597 |
||
598 |
void TestPinOutOfMemory() |
|
599 |
{ |
|
600 |
// Ensure that if pinning fails with KErrNoMemory, |
|
601 |
// there isn't a memory leak |
|
602 |
const TInt KMaxKernelAllocations = 1024; |
|
603 |
TInt r=KErrNoMemory; |
|
604 |
TInt i; |
|
605 |
const TUint8* buffer = NULL; |
|
606 |
if (PagedBuffer) |
|
607 |
{ |
|
608 |
buffer = PagedBuffer; |
|
609 |
} |
|
610 |
else |
|
611 |
{ |
|
612 |
buffer = UnpagedBuffer; |
|
613 |
} |
|
614 |
test_NotNull(buffer); |
|
615 |
||
616 |
__KHEAP_MARK; |
|
617 |
for (i = 0; i < KMaxKernelAllocations && r == KErrNoMemory; i++) |
|
618 |
{ |
|
619 |
__KHEAP_FAILNEXT(i); |
|
620 |
test.Printf(_L("Create logical pin object\n")); |
|
621 |
r = Ldd.CreateVirtualPinObject(); |
|
622 |
__KHEAP_RESET; |
|
623 |
} |
|
624 |
test.Printf(_L("Create logical pin object took %d tries\n"),i); |
|
625 |
test_KErrNone(r); |
|
626 |
||
627 |
r = KErrNoMemory; |
|
628 |
for (i = 0; i < KMaxKernelAllocations && r == KErrNoMemory; i++) |
|
629 |
{ |
|
630 |
__KHEAP_FAILNEXT(i); |
|
631 |
test.Printf(_L("Perform logical pin operation\n")); |
|
632 |
r = Ldd.PinVirtualMemory((TLinAddr)buffer, KMinBufferSize); |
|
633 |
__KHEAP_RESET; |
|
634 |
} |
|
635 |
test.Printf(_L("Perform logical pin operation took %d tries\n"),i); |
|
636 |
if (r == KErrNone) |
|
637 |
{ |
|
638 |
test.Printf(_L("Perform logical unpin operation\n")); |
|
639 |
Ldd.UnpinVirtualMemory(); |
|
640 |
} |
|
641 |
||
642 |
test.Printf(_L("Destroy logical pin object\n")); |
|
643 |
Ldd.DestroyVirtualPinObject(); |
|
644 |
// wait for any async cleanup in the supervisor to finish first... |
|
645 |
UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0); |
|
646 |
__KHEAP_MARKEND; |
|
647 |
||
648 |
test_KErrNone(r); |
|
649 |
} |
|
650 |
||
651 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
652 |
TInt KernelModifyData(TAny*) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
653 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
654 |
Ldd.KernelMapReadAndModifyMemory(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
655 |
return KErrNone; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
656 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
657 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
658 |
void TestMapAndPinMemory() |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
659 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
660 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
661 |
TInt mm = UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, 0, 0) & EMemModelTypeMask; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
662 |
if (mm < EMemModelTypeFlexible) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
663 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
664 |
test.Printf(_L("Memory model (%d) doesn't support physical pining\n"),mm); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
665 |
return; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
666 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
667 |
TInt i; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
668 |
TUint KUCBytes = KUCPageCount * PageSize; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
669 |
RChunk chunk; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
670 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
671 |
test.Printf(_L("Allocate user chunk\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
672 |
TChunkCreateInfo createInfo; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
673 |
createInfo.SetDisconnected(0, KUCBytes, KUCBytes); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
674 |
createInfo.SetPaging(TChunkCreateInfo::EPaged); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
675 |
test_KErrNone(chunk.Create(createInfo)); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
676 |
TUint8* chunkBase = (TUint8*)chunk.Base(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
677 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
678 |
test.Printf(_L("Create kernel map object\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
679 |
test_KErrNone(Ldd.CreateKernelMapObject(0)); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
680 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
681 |
test.Printf(_L("Perform kernel map operation on zero-length buffer\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
682 |
test_KErrNone(Ldd.KernelMapMemory((TLinAddr)chunkBase, 0)); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
683 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
684 |
test.Printf(_L("Perform kernel unmap operation\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
685 |
test_KErrNone(Ldd.KernelUnmapMemory()); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
686 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
687 |
test.Printf(_L("Perform kernel map operation on the chunk\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
688 |
test_KErrNone(Ldd.KernelMapMemory((TLinAddr)chunkBase, KUCBytes)); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
689 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
690 |
test.Printf(_L("Attempt to map the memory again while already mapped\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
691 |
test_Equal(KErrInUse, Ldd.KernelMapMemory((TLinAddr)chunkBase, KUCBytes)); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
692 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
693 |
test.Printf(_L("Use the kernel mapping to modify the data and verify it\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
694 |
TUint8* p = chunkBase; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
695 |
for (i = 0; i < (TInt)KUCBytes; i++) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
696 |
*p++ = (TUint8)i; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
697 |
test_KErrNone(Ldd.KernelMapReadAndModifyMemory()); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
698 |
p = chunkBase; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
699 |
for (i = 0; i < (TInt)KUCBytes; i++) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
700 |
test_Equal((TUint8)(i + 1), *p++); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
701 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
702 |
test.Printf(_L("Test that kernel mapped memory preserves its mapping when recommited\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
703 |
test_KErrNone(chunk.Decommit(0,KUCPageCount*PageSize)); //Decommit all |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
704 |
for (i=KUCPageCount-1;i>=0;i--) test_KErrNone(chunk.Commit(i*PageSize,PageSize)); //Commit in reverse order |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
705 |
for (i=0;i<KUCPageCount;i++) // Recommited memory is not paged in. So, write into each page, before driver |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
706 |
{ // calls Kern::LinearToPhysical or it will get KErrInvalidMemory in return. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
707 |
volatile TInt8* ptr = (volatile TInt8*)(chunkBase+i*PageSize); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
708 |
*ptr = 10; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
709 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
710 |
test_KErrNone(Ldd.KernelMapCheckPageList(chunkBase)); // Check that the mapping is preserved. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
711 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
712 |
test.Printf(_L("Sync cache & memory of User Chunk\n")); //Test Cache::SyncMemoryBeforeDmaWrite |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
713 |
test_KErrNone(Ldd.KernelMapSyncMemory()); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
714 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
715 |
test.Printf(_L("Invalidate cache of User Chunk\n"));//Test Cache::SyncMemoryBefore/AfterDmaRead |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
716 |
test_KErrNone(Ldd.KernelMapInvalidateMemory()); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
717 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
718 |
test.Printf(_L("Try to move kernel map memory...\n")); //RAM defrag should return error code here. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
719 |
for (i = 0; i < KUCPageCount; i++) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
720 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
721 |
TInt r = Ldd.KernelMapMoveMemory(0); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
722 |
test.Printf(_L("...[%d] returned %d\n"), i, r); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
723 |
test(r != KErrNone); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
724 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
725 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
726 |
test.Printf(_L("Unmap the memory and attempt to map with invalid attributes\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
727 |
test_KErrNone(Ldd.KernelUnmapMemory()); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
728 |
test_Equal(KErrArgument, Ldd.KernelMapMemoryInvalid((TLinAddr)chunkBase, KUCBytes)); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
729 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
730 |
test.Printf(_L("Map the memory read only and attempt to modify it kernel side\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
731 |
test_KErrNone(Ldd.KernelMapMemoryRO((TLinAddr)chunkBase, KUCBytes)); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
732 |
// Reset the contents of the memory. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
733 |
p = chunkBase; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
734 |
for (i = 0; i < (TInt)KUCBytes; i++) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
735 |
*p++ = (TUint8)i; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
736 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
737 |
RThread modThread; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
738 |
test_KErrNone(modThread.Create(KNullDesC, KernelModifyData, PageSize, PageSize, PageSize, (TAny*)NULL)); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
739 |
TRequestStatus status; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
740 |
modThread.Logon(status); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
741 |
test_Equal(KRequestPending, status.Int()); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
742 |
modThread.Resume(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
743 |
User::WaitForRequest(status); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
744 |
test_Equal(EExitPanic, modThread.ExitType()); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
745 |
test(modThread.ExitCategory() == _L("KERN-EXEC")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
746 |
test_Equal(ECausedException, modThread.ExitReason()); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
747 |
CLOSE_AND_WAIT(modThread); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
748 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
749 |
test.Printf(_L("Close the chunk\n")); // Phys. memory is pinned and shouldn't be ... |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
750 |
chunk.Close(); // ... mapped to another virtual memory. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
751 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
752 |
test.Printf(_L("Allocate & initilise the second chunk\n"));// Kernel shouldn't commit pinned physical memory ... |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
753 |
test_KErrNone(chunk.CreateLocal(KUCBytes, KUCBytes)); // ...that has just been decommited from the first chunk. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
754 |
chunkBase = (TUint8*)chunk.Base(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
755 |
for (i = 0; i < KUCPageCount * PageSize; i++) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
756 |
chunkBase[i] = 0; //Initialise user buffer |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
757 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
758 |
test.Printf(_L("Invalidate cache of pinned memory\n"));//This shouldn't affect the second chunk. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
759 |
test_KErrNone(Ldd.KernelMapInvalidateMemory()); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
760 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
761 |
test.Printf(_L("Check data in the second chunk is unaffected\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
762 |
for (i=0; i < KUCPageCount * PageSize; i++) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
763 |
test(chunkBase[i]==0); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
764 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
765 |
test.Printf(_L("Close the second chunk\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
766 |
chunk.Close(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
767 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
768 |
test.Printf(_L("Perform kernel unmap operation\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
769 |
test_KErrNone(Ldd.KernelUnmapMemory()); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
770 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
771 |
test.Printf(_L("Perform physical unpin operation (again)\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
772 |
test_KErrNone(Ldd.KernelUnmapMemory()); // test double unpin ok |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
773 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
774 |
test.Printf(_L("Destroy physical pin object\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
775 |
test_KErrNone(Ldd.DestroyKernelMapObject()); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
776 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
777 |
test.Printf(_L("Destroy physical pin object (again)\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
778 |
test_KErrNone(Ldd.DestroyKernelMapObject()); // test double destroy ok |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
779 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
780 |
// |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
781 |
// Test a kernel mapping with preserved resources doesn't allocate when mapping and pinning. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
782 |
// |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
783 |
test.Printf(_L("Create a pre-reserving kernel mapping object\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
784 |
TUint mappingSize = KUCBytes>>1; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
785 |
// This test step relies on mapping objet being smaller than the user chunk |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
786 |
// and as mapping object will always be >=2 pages, user chunk must be at least 4. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
787 |
__ASSERT_COMPILE(KUCPageCount >= 4); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
788 |
test_KErrNone(Ldd.CreateKernelMapObject(mappingSize)); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
789 |
TChunkCreateInfo chunkInfo; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
790 |
chunkInfo.SetNormal(KUCBytes, KUCBytes); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
791 |
chunkInfo.SetPaging(TChunkCreateInfo::EUnpaged); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
792 |
test_KErrNone(chunk.Create(chunkInfo)); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
793 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
794 |
test.Printf(_L("Map and pin an unpaged chunk with pre-reserved resources\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
795 |
__KHEAP_FAILNEXT(1); // Ensure any attempted kernel heap allocations fail. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
796 |
test_KErrNone(Ldd.KernelMapMemory((TLinAddr)chunk.Base(), mappingSize)); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
797 |
test_KErrNone(Ldd.KernelUnmapMemory()); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
798 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
799 |
test.Printf(_L("Map more memory than we have pre-reserved resources for\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
800 |
test_Equal(KErrArgument, Ldd.KernelMapMemory((TLinAddr)chunk.Base(), mappingSize*2)); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
801 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
802 |
test.Printf(_L("Destroy the kernel map object with pre-reserved resources\n")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
803 |
test_KErrNone(Ldd.DestroyKernelMapObject()); // This will also unpin the memory. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
804 |
// Clear the kernel heap fail next. |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
805 |
__KHEAP_RESET; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
806 |
chunk.Close(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
807 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
808 |
|
0 | 809 |
TInt E32Main() |
810 |
{ |
|
811 |
test.Title(); |
|
812 |
test.Start(_L("Test kernel pinning APIs")); |
|
813 |
||
814 |
if (DPTest::Attributes() & DPTest::ERomPaging) |
|
815 |
test.Printf(_L("Rom paging supported\n")); |
|
816 |
if (DPTest::Attributes() & DPTest::ECodePaging) |
|
817 |
test.Printf(_L("Code paging supported\n")); |
|
818 |
if (DPTest::Attributes() & DPTest::EDataPaging) |
|
819 |
test.Printf(_L("Data paging supported\n")); |
|
820 |
||
821 |
test.Next(_L("Loading test drivers")); |
|
822 |
test_KErrNone(Ldd.Open()); |
|
823 |
test_KErrNone(Ldd2.Open()); |
|
824 |
||
825 |
test.Next(_L("Getting page size")); |
|
826 |
test_KErrNone(UserSvr::HalFunction(EHalGroupKernel,EKernelHalPageSizeInBytes,&PageSize,0)); |
|
827 |
||
828 |
test.Next(_L("Setting up paged and unpaged buffers")); |
|
829 |
||
830 |
#ifdef __EPOC32__ |
|
831 |
// Use unpaged rom for our unpaged buffer |
|
832 |
TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress(); |
|
833 |
UnpagedBuffer = (TUint8*)romHeader; |
|
834 |
TInt size = romHeader->iPageableRomStart ? romHeader->iPageableRomStart : romHeader->iUncompressedSize; |
|
835 |
test(size >= KMinBufferSize); |
|
836 |
||
837 |
if (DPTest::Attributes() & DPTest::ERomPaging) |
|
838 |
{ |
|
839 |
// Use end of paged ROM for our paged buffer |
|
840 |
test(romHeader->iPageableRomStart); |
|
841 |
TInt offset = romHeader->iPageableRomStart + romHeader->iPageableRomSize - KMinBufferSize; |
|
842 |
offset &= ~0xfff; |
|
843 |
test(offset>=romHeader->iPageableRomStart); |
|
844 |
PagedBuffer = (TUint8*)romHeader + offset; |
|
845 |
} |
|
846 |
else if (DPTest::Attributes() & DPTest::ECodePaging) |
|
847 |
{ |
|
848 |
// Use code paged DLL for our paged buffer |
|
849 |
test_KErrNone(PagedLibrary.Load(KTCodePagingDll4)); |
|
850 |
TGetAddressOfDataFunction func = (TGetAddressOfDataFunction)PagedLibrary.Lookup(KGetAddressOfDataFunctionOrdinal); |
|
851 |
TInt size; |
|
852 |
PagedBuffer = (TUint8*)func(size); |
|
853 |
test_NotNull(PagedBuffer); |
|
854 |
test(size >= KMinBufferSize); |
|
855 |
} |
|
856 |
#else |
|
857 |
UnpagedBuffer = (TUint8*)User::Alloc(KMinBufferSize); |
|
858 |
test_NotNull(UnpagedBuffer); |
|
859 |
#endif |
|
860 |
||
861 |
RDebug::Printf("UnpagedBuffer=%x\n",UnpagedBuffer); |
|
862 |
RDebug::Printf("PagedBuffer=%x\n",PagedBuffer); |
|
863 |
||
864 |
__KHEAP_MARK; |
|
865 |
||
866 |
test.Next(_L("Logical pin unpaged memory")); |
|
867 |
TestPinVirtualMemoryUnpaged(); |
|
868 |
||
869 |
test.Next(_L("Logical pin invalid memory")); |
|
870 |
TestPinVirtualMemoryInvalid(); |
|
871 |
||
872 |
test.Next(_L("Physical pinning")); |
|
873 |
TestPinPhysicalMemory(); |
|
874 |
||
875 |
test.Next(_L("Physical pinning OOM")); |
|
876 |
TestPhysicalPinOutOfMemory(); |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
877 |
|
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
878 |
test.Next(_L("Kernel pin mapping")); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
879 |
TestMapAndPinMemory(); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
880 |
|
0 | 881 |
test.Next(_L("Pin OOM Tests")); |
882 |
TestPinOutOfMemory(); |
|
883 |
||
884 |
if (PagedBuffer) |
|
885 |
{ |
|
886 |
test.Next(_L("Logical pin paged memory")); |
|
887 |
TestPinVirtualMemoryPaged(); |
|
888 |
||
889 |
test.Next(_L("Logical pin paged memory soak test")); |
|
890 |
TestPinVirtualMemoryPagedSoak(); |
|
891 |
} |
|
892 |
||
893 |
if (DPTest::Attributes() & DPTest::EDataPaging) |
|
894 |
{ |
|
895 |
test.Next(_L("Logical pin then decommit memory")); |
|
896 |
TestPinVirtualMemoryDecommit(); |
|
897 |
} |
|
898 |
||
899 |
// wait for any async cleanup in the supervisor to finish first... |
|
900 |
UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0); |
|
901 |
__KHEAP_MARKEND; |
|
902 |
||
903 |
#ifndef __EPOC32__ |
|
904 |
User::Free((TAny*)UnpagedBuffer); |
|
905 |
#endif |
|
906 |
||
907 |
PagedLibrary.Close(); |
|
908 |
Ldd.Close(); |
|
909 |
Ldd2.Close(); |
|
910 |
test.End(); |
|
911 |
||
912 |
return KErrNone; |
|
913 |
} |