author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 21 Jun 2010 17:12:14 +0300 | |
branch | RCL_3 |
changeset 198 | 2bb754abd467 |
parent 110 | c734af59ce98 |
child 215 | 8096a832df02 |
child 244 | a77889bee936 |
child 259 | 57b9594f5772 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1997-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_shadow.cpp |
|
15 |
// Overview: |
|
16 |
// Test ROM shadowing |
|
17 |
// API Information: |
|
18 |
// RBusLogicalChannel |
|
19 |
// Details: |
|
20 |
// - Load and open the logical device driver ("D_SHADOW.LDD"). Verify |
|
21 |
// results. |
|
22 |
// - Allocate a shadow ROM page, verify data is copied into shadow page |
|
23 |
// without altering the following page. |
|
24 |
// - Move the shadow page and the original rom page. |
|
25 |
// - Write and verify data in the shadow page. |
|
26 |
// - Free the shadow page and verify original ROM data is restored. |
|
27 |
// - Test pinning of shadow pages. |
|
28 |
// Platforms/Drives/Compatibility: |
|
29 |
// All. |
|
30 |
// Assumptions/Requirement/Pre-requisites: |
|
31 |
// Failures and causes: |
|
32 |
// Base Port information: |
|
33 |
// |
|
34 |
// |
|
35 |
||
36 |
#define __E32TEST_EXTENSION__ |
|
37 |
||
38 |
#include <e32test.h> |
|
39 |
#include <e32uid.h> |
|
40 |
#include <e32hal.h> |
|
41 |
#include "d_shadow.h" |
|
42 |
#include "d_gobble.h" |
|
43 |
#include "..\defrag\d_pagemove.h" |
|
44 |
#include "d_memorytest.h" |
|
45 |
#include <dptest.h> |
|
46 |
#include "mmudetect.h" |
|
47 |
#include "freeram.h" |
|
48 |
||
49 |
enum TPaged |
|
50 |
{ |
|
51 |
EUnpaged, |
|
52 |
EPaged |
|
53 |
}; |
|
54 |
||
55 |
_LIT(KLddFileName, "D_SHADOW.LDD"); |
|
56 |
_LIT(KMoveLddFileName, "D_PAGEMOVE.LDD"); |
|
57 |
||
58 |
LOCAL_D RTest test(_L("T_SHADOW")); |
|
59 |
||
60 |
RPageMove PageMove; |
|
61 |
RShadow Shadow; |
|
62 |
RMemoryTestLdd MemoryTest; |
|
63 |
||
64 |
TInt PageSize; |
|
65 |
LOCAL_D TBool RomPagingSupported = EFalse; |
|
66 |
#ifndef __X86__ |
|
67 |
LOCAL_D TBool PageMovingSupported = ETrue; |
|
68 |
#else |
|
69 |
LOCAL_D TBool PageMovingSupported = EFalse; |
|
70 |
#endif |
|
71 |
||
72 |
TLinAddr RomUnpagedStart = 0; |
|
73 |
TLinAddr RomUnpagedEnd = 0; |
|
74 |
TLinAddr RomPagedStart = 0; |
|
75 |
TLinAddr RomPagedEnd = 0; |
|
76 |
||
77 |
TUint8* PageBuffer1 = NULL; |
|
78 |
TUint8* PageBuffer2 = NULL; |
|
79 |
TUint8* PageBuffer3 = NULL; |
|
80 |
||
81 |
void TestShadowPage(TLinAddr aPageAddr, TPaged aPageType) |
|
82 |
{ |
|
83 |
test.Start(_L("Test shadowing a page")); |
|
84 |
test.Printf(_L(" addr == 0x%08x, type == %d\n"), aPageAddr, aPageType); |
|
85 |
||
86 |
test.Next(_L("Copy page to be shadowed and following page to local buffers")); |
|
87 |
TLinAddr secondPage = aPageAddr + PageSize; |
|
88 |
if (secondPage >= RomPagedEnd) |
|
89 |
secondPage = RomUnpagedStart; |
|
90 |
Mem::Move(PageBuffer1,(TAny*)aPageAddr,PageSize); |
|
91 |
Mem::Move(PageBuffer3,(TAny*)(secondPage),PageSize); |
|
92 |
||
93 |
TUint origPhysAddr = 0xffffffff; // The physical address of the rom page to be shadowed |
|
94 |
||
95 |
if (PageMovingSupported && aPageType == EPaged) |
|
96 |
{ |
|
97 |
test.Next(_L("Test page can be moved")); |
|
98 |
TUint dummy = *(volatile TUint32*)aPageAddr; // ensure paged in |
|
99 |
test_KErrNone(PageMove.TryMovingUserPage((TAny*)aPageAddr)); |
|
100 |
||
101 |
test.Next(_L("Get page's physical address")); |
|
102 |
dummy += *(volatile TUint32*)aPageAddr; // ensure paged in |
|
103 |
test_KErrNone(PageMove.GetPhysAddr((TAny*)aPageAddr, (TAny*)&origPhysAddr)); |
|
104 |
test.Printf(_L(" physical address: %08x\n"), origPhysAddr); |
|
105 |
} |
|
106 |
||
107 |
test.Next(_L("Allocate a shadow ROM page")); |
|
108 |
test_KErrNone(Shadow.Alloc(aPageAddr)); |
|
109 |
||
110 |
test.Next(_L("Try to shadow the page again")); |
|
111 |
test_Equal(KErrAlreadyExists, Shadow.Alloc(aPageAddr)); |
|
112 |
||
113 |
if (PageMovingSupported && aPageType == EPaged) |
|
114 |
{ |
|
115 |
test.Next(_L("Check page's physical address has changed")); |
|
116 |
TUint newPhysAddr; |
|
117 |
test_KErrNone(PageMove.GetPhysAddr((TAny*)aPageAddr, (TAny*)&newPhysAddr)); |
|
118 |
test(newPhysAddr != origPhysAddr); |
|
119 |
||
120 |
test.Next(_L("Test moving a shadowed page is not allowed")); |
|
121 |
test_Equal(KErrNotSupported, PageMove.TryMovingUserPage((TAny*)aPageAddr)); |
|
122 |
||
123 |
test.Next(_L("Test moving the original page fails (it should be pinned)")); |
|
124 |
test_Equal(KErrInUse, PageMove.TryMovingPhysAddr((TAny*)origPhysAddr, (TAny*)&newPhysAddr)); |
|
125 |
} |
|
126 |
||
127 |
test.Next(_L("Check data copied into shadow page")); |
|
128 |
test_Equal(0, Mem::Compare((TUint8*)aPageAddr,PageSize,PageBuffer1,PageSize)); |
|
129 |
||
130 |
test.Next(_L("Check page following shadow page is unaltered")); |
|
131 |
test_Equal(0, Mem::Compare((TUint8*)(secondPage),PageSize,PageBuffer3,PageSize)); |
|
132 |
||
133 |
test.Next(_L("Write data into shadow page")); |
|
134 |
for(TInt i=0; i<PageSize; i++) |
|
135 |
{ |
|
136 |
TInt i2=i*i; |
|
137 |
PageBuffer2[i]=TUint8(i2^(i2>>8)^(i2>>16)); |
|
138 |
} |
|
139 |
test_KErrNone(Shadow.Write(aPageAddr,PageBuffer2)); |
|
140 |
||
141 |
test.Next(_L("Check data written into shadow page")); |
|
142 |
test_Equal(0, Mem::Compare((TUint8*)aPageAddr,PageSize,PageBuffer2,PageSize)); |
|
143 |
||
144 |
test.Next(_L("Check page following shadow page is unaltered")); |
|
145 |
test_Equal(0, Mem::Compare((TUint8*)(secondPage),PageSize,PageBuffer3,PageSize)); |
|
146 |
||
147 |
test.Next(_L("Allocate another shadow ROM page")); |
|
148 |
test_KErrNone(Shadow.Alloc(secondPage)); |
|
149 |
||
150 |
test.Next(_L("Free the original shadow page")); |
|
151 |
test_KErrNone(Shadow.Free(aPageAddr)); |
|
152 |
||
153 |
test.Next(_L("Check original ROM data restored")); |
|
154 |
test_Equal(0, Mem::Compare((TUint8*)aPageAddr,PageSize,PageBuffer1,PageSize)); |
|
155 |
||
156 |
if (PageMovingSupported && aPageType == EPaged) |
|
157 |
{ |
|
158 |
test.Next(_L("Test page can be moved again")); |
|
159 |
test_KErrNone(PageMove.TryMovingUserPage((TAny*)aPageAddr)); |
|
160 |
} |
|
161 |
||
162 |
test.Next(_L("Free the second shadow page")); |
|
163 |
test_KErrNone(Shadow.Free(secondPage)); |
|
164 |
||
165 |
test.Next(_L("Check original ROM data restored")); |
|
166 |
test_Equal(0, Mem::Compare((TUint8*)(secondPage),PageSize,PageBuffer3,PageSize)); |
|
167 |
test.End(); |
|
168 |
} |
|
169 |
||
170 |
/* |
|
171 |
Reintroduce this when RTest can report whether the test is |
|
172 |
being run in automatic or manual mode |
|
173 |
*/ |
|
174 |
void TestFreeze(TLinAddr aPageAddr) |
|
175 |
{ |
|
176 |
test.Start(_L("Test freezing a shadow page")); |
|
177 |
test.Printf(_L("Press 0 to test Freeze (causes kernel fault)\n")); |
|
178 |
test.Printf(_L("Press any other key to skip this test\n")); |
|
179 |
TKeyCode key=test.Getch(); |
|
180 |
if (key==TKeyCode('0')) |
|
181 |
{ |
|
182 |
test.Next(_L("Freeze first shadow page")); |
|
183 |
test_KErrNone(Shadow.Freeze(aPageAddr)); |
|
184 |
||
185 |
test.Printf(_L("Press a key to attempt write after freezing\n")); |
|
186 |
test.Printf(_L("Should get Kernel Exception 9, Data Address 50000xxx\n")); |
|
187 |
test.Getch(); |
|
188 |
Shadow.Write(aPageAddr,PageBuffer2); |
|
189 |
test(0); |
|
190 |
} |
|
191 |
test.End(); |
|
192 |
} |
|
193 |
||
194 |
void TestNoFreeRAM(TLinAddr aPageAddr) |
|
195 |
{ |
|
196 |
test.Start(_L("Test allocating a shadow page when all free RAM is in 'chunk caches'")); |
|
197 |
||
198 |
test.Next(_L("Load gobbler LDD")); |
|
199 |
TInt r = User::LoadLogicalDevice(KGobblerLddFileName); |
|
200 |
test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
|
201 |
RGobbler gobbler; |
|
202 |
test_KErrNone(gobbler.Open()); |
|
203 |
TUint32 taken = gobbler.GobbleRAM(496*1024*1024); |
|
204 |
test.Printf(_L(" Gobbled: %dK\n"), taken/1024); |
|
205 |
test.Printf(_L(" Free RAM 0x%08X bytes\n"),FreeRam()); |
|
206 |
||
207 |
// Remove limit on max size of live list |
|
208 |
TUint originalMin = 0; |
|
209 |
TUint originalMax = 0; |
|
210 |
TUint currentSize = 0; |
|
211 |
r = DPTest::CacheSize(originalMin, originalMax, currentSize); |
|
212 |
test_Value(r, r == KErrNone || r == KErrNotSupported); |
|
213 |
TBool resizeCache = r == KErrNone; |
|
214 |
if (resizeCache) |
|
215 |
test_KErrNone(DPTest::SetCacheSize(originalMin, KMaxTUint)); |
|
216 |
||
217 |
// put all of free RAM in a chunk... |
|
218 |
TChunkCreateInfo createInfo; |
|
219 |
createInfo.SetCache(512*1024*1024); |
|
220 |
RChunk testChunk; |
|
221 |
test_KErrNone(testChunk.Create(createInfo)); |
|
222 |
TInt commitEnd = 0; |
|
223 |
while(KErrNone==(r=testChunk.Commit(commitEnd,PageSize))) |
|
224 |
commitEnd += PageSize; |
|
225 |
test_Equal(KErrNoMemory,r); |
|
226 |
||
227 |
// no memory to allocate shadow page... |
|
228 |
test_Equal(KErrNoMemory,Shadow.Alloc(aPageAddr)); |
|
229 |
// unlock all of RAM in chunk... |
|
230 |
test_KErrNone(testChunk.Unlock(0,commitEnd)); |
|
231 |
// should have memory now... |
|
232 |
test_KErrNone(Shadow.Alloc(aPageAddr)); |
|
233 |
// tidy up... |
|
234 |
test_KErrNone(Shadow.Free(aPageAddr)); |
|
235 |
testChunk.Close(); |
|
236 |
||
237 |
// Restore original settings for live list size |
|
238 |
if (resizeCache) |
|
239 |
test_KErrNone(DPTest::SetCacheSize(originalMin, originalMax)); |
|
240 |
||
241 |
gobbler.Close(); |
|
242 |
test.End(); |
|
243 |
} |
|
244 |
||
245 |
void TestShadowPageOOM(TLinAddr aPageAddr) |
|
246 |
{ |
|
247 |
test.Start(_L("Test OOM while shadowing a page")); |
|
248 |
test.Printf(_L(" addr == 0x%08x\n"), aPageAddr); |
|
249 |
||
250 |
test.Next(_L("Copy page to be shadowed and following page to local buffers")); |
|
251 |
Mem::Move(PageBuffer1,(TAny*)aPageAddr,PageSize); |
|
252 |
||
253 |
__KHEAP_MARK; |
|
254 |
||
255 |
TInt r; |
|
256 |
TInt failCount = 0; |
|
257 |
test.Next(_L("Allocate a shadow ROM page")); |
|
258 |
do |
|
259 |
{ |
|
260 |
__KHEAP_FAILNEXT(failCount); |
|
261 |
r = Shadow.Alloc(aPageAddr); |
|
262 |
if (r == KErrNoMemory) |
|
263 |
++failCount; |
|
264 |
} |
|
265 |
while (r == KErrNoMemory); |
|
266 |
__KHEAP_RESET; |
|
267 |
test.Printf(_L(" returned %d after %d allocations\n"), r, failCount); |
|
268 |
test_KErrNone(r); |
|
269 |
||
270 |
test.Next(_L("Try to shadow the page again")); |
|
271 |
__KHEAP_FAILNEXT(0); |
|
272 |
test_Equal(KErrAlreadyExists, Shadow.Alloc(aPageAddr)); |
|
273 |
__KHEAP_RESET; |
|
274 |
||
275 |
test.Next(_L("Check data copied into shadow page")); |
|
276 |
test_Equal(0, Mem::Compare((TUint8*)aPageAddr,PageSize,PageBuffer1,PageSize)); |
|
277 |
||
278 |
test.Next(_L("Write data into shadow page")); |
|
279 |
for(TInt i=0; i<PageSize; i++) |
|
280 |
{ |
|
281 |
TInt i2=i*i; |
|
282 |
PageBuffer2[i]=TUint8(i2^(i2>>8)^(i2>>16)); |
|
283 |
} |
|
284 |
test_KErrNone(Shadow.Write(aPageAddr,PageBuffer2)); |
|
285 |
||
286 |
test.Next(_L("Check data written into shadow page")); |
|
287 |
test_Equal(0, Mem::Compare((TUint8*)aPageAddr,PageSize,PageBuffer2,PageSize)); |
|
288 |
||
289 |
test.Next(_L("Free the original shadow page")); |
|
290 |
__KHEAP_FAILNEXT(0); |
|
291 |
test_KErrNone(Shadow.Free(aPageAddr)); |
|
292 |
__KHEAP_RESET; |
|
293 |
||
294 |
test.Next(_L("Check original ROM data restored")); |
|
295 |
test_Equal(0, Mem::Compare((TUint8*)aPageAddr,PageSize,PageBuffer1,PageSize)); |
|
296 |
||
297 |
test.Next(_L("Check kernel heap balance")); |
|
298 |
__KHEAP_MARKEND; |
|
299 |
||
300 |
test.End(); |
|
301 |
} |
|
302 |
||
303 |
void TestInteractionWithPinning(TLinAddr aPageAddr) |
|
304 |
{ |
|
305 |
test.Start(_L("Test pinning of shadow pages")); |
|
306 |
||
307 |
// Create pin object to use for all pinnings |
|
308 |
test_KErrNone(MemoryTest.CreateVirtualPinObject()); |
|
309 |
||
310 |
test.Next(_L("Test pin - shadow - unpin - unshadow")); |
|
311 |
test_Equal(KErrNone, MemoryTest.PinVirtualMemory((TLinAddr)aPageAddr, PageSize)); |
|
312 |
test_KErrNone(Shadow.Alloc(aPageAddr)); |
|
313 |
test_Equal(KErrNone, MemoryTest.UnpinVirtualMemory()); |
|
314 |
test_KErrNone(Shadow.Free(aPageAddr)); |
|
315 |
||
316 |
test.Next(_L("Test pin - shadow - unshadow - unpin")); |
|
317 |
test_Equal(KErrNone, MemoryTest.PinVirtualMemory((TLinAddr)aPageAddr, PageSize)); |
|
318 |
test_KErrNone(Shadow.Alloc(aPageAddr)); |
|
319 |
test_KErrNone(Shadow.Free(aPageAddr)); |
|
320 |
test_Equal(KErrNone, MemoryTest.UnpinVirtualMemory()); |
|
321 |
||
322 |
test.Next(_L("Test shadow - pin - unpin - unshadow")); |
|
323 |
test_KErrNone(Shadow.Alloc(aPageAddr)); |
|
324 |
test_Equal(KErrNone, MemoryTest.PinVirtualMemory((TLinAddr)aPageAddr, PageSize)); |
|
325 |
test_Equal(KErrNone, MemoryTest.UnpinVirtualMemory()); |
|
326 |
test_KErrNone(Shadow.Free(aPageAddr)); |
|
327 |
||
328 |
test.Next(_L("Test shadow - pin - unshadow - unpin")); |
|
329 |
test_KErrNone(Shadow.Alloc(aPageAddr)); |
|
330 |
test_Equal(KErrNone, MemoryTest.PinVirtualMemory((TLinAddr)aPageAddr, PageSize)); |
|
331 |
test_KErrNone(Shadow.Free(aPageAddr)); |
|
332 |
test_Equal(KErrNone, MemoryTest.UnpinVirtualMemory()); |
|
333 |
||
334 |
test_KErrNone(MemoryTest.DestroyVirtualPinObject()); |
|
335 |
test.End(); |
|
336 |
} |
|
337 |
||
338 |
const TUint KChunkShift = 20; |
|
339 |
const TUint KChunkSize = 1 << KChunkShift; |
|
340 |
||
110
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
341 |
const TUint KRomSizeAlign = 16; // This should match CFG_RomSizeAlign defined in bootcpu.inc |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
342 |
const TUint KRomSizeAlignMask = (1 << KRomSizeAlign) - 1; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
343 |
|
0 | 344 |
void TestRomIsSectionMapped() |
345 |
{ |
|
346 |
test.Start(_L("Test ROM is section mapped")); |
|
347 |
||
348 |
TUint pdSize; |
|
349 |
TUint pdBase; |
|
350 |
TUint offset; |
|
351 |
||
352 |
#ifdef __MARM__ |
|
353 |
test_KErrNone(Shadow.GetPdInfo(KGlobalPageDirectory, pdSize, pdBase, offset)); |
|
354 |
test.Printf(_L("pd base == %08x, pd size == %08x, pd offset == %08x\n"), pdBase, pdSize, offset); |
|
355 |
||
110
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
356 |
TUint romSize = RomUnpagedEnd - RomUnpagedStart; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
357 |
test.Printf(_L("rom size == %x\n"), romSize); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
358 |
if (RomPagedStart == RomPagedEnd) |
0 | 359 |
{ |
110
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
360 |
// If rom is not paged then we must round the ROM size up to a mutiple of 64KB (or whatever |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
361 |
// the CFG_RomSizeAlign settings is), because that's how the bootstrap maps it |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
362 |
romSize = (romSize + KRomSizeAlignMask) & ~KRomSizeAlignMask; |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
363 |
test.Printf(_L("rom size rounded up to %x\n"), romSize); |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
364 |
} |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
365 |
|
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
366 |
for (TUint pos = 0 ; pos < romSize ; pos += KChunkSize) |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
367 |
{ |
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
368 |
TLinAddr addr = RomUnpagedStart + pos; |
0 | 369 |
TUint i = (addr >> KChunkShift) - offset; |
370 |
TUint pde = Shadow.Read(pdBase + i*4); |
|
371 |
test.Printf(_L(" %08x: PDE %08x\n"), addr, pde); |
|
372 |
||
110
c734af59ce98
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
373 |
TUint expectedPdeType = (romSize - pos) >= KChunkSize ? 2 : 1; |
0 | 374 |
test_Equal(expectedPdeType, pde & 3); |
375 |
} |
|
376 |
#else |
|
377 |
test.Printf(_L("Test not supported on this architecture\n")); |
|
378 |
#endif |
|
379 |
||
380 |
test.End(); |
|
381 |
} |
|
382 |
||
383 |
void Initialise() |
|
384 |
{ |
|
385 |
test.Start(_L("Load test LDDs")); |
|
386 |
||
387 |
TInt r=User::LoadLogicalDevice(KLddFileName); |
|
388 |
test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
|
389 |
if (PageMovingSupported) |
|
390 |
{ |
|
391 |
r=User::LoadLogicalDevice(KMoveLddFileName); |
|
392 |
test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
|
393 |
} |
|
394 |
||
395 |
test_KErrNone(UserHal::PageSizeInBytes(PageSize)); |
|
396 |
||
397 |
test.Next(_L("Open test LDDs")); |
|
398 |
test_KErrNone(Shadow.Open()); |
|
399 |
test_KErrNone(MemoryTest.Open()); |
|
400 |
if (PageMovingSupported) |
|
401 |
test_KErrNone(PageMove.Open()); |
|
402 |
||
403 |
test.Next(_L("Allocate some RAM")); |
|
404 |
PageBuffer1=(TUint8*)User::Alloc(PageSize); |
|
405 |
test_NotNull(PageBuffer1); |
|
406 |
PageBuffer2=(TUint8*)User::Alloc(PageSize); |
|
407 |
test_NotNull(PageBuffer2); |
|
408 |
PageBuffer3=(TUint8*)User::Alloc(PageSize); |
|
409 |
test_NotNull(PageBuffer3); |
|
410 |
||
411 |
test.Next(_L("Discover ROM addresses")); |
|
412 |
TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress(); |
|
413 |
RomUnpagedStart = (TLinAddr)romHeader; |
|
414 |
test_Equal(0, RomUnpagedStart & (PageSize - 1)); |
|
415 |
||
416 |
//Round up to page size (May already be rounded, but doesnt hurt) |
|
417 |
TUint romSize = (romHeader->iUncompressedSize + PageSize - 1) & ~(PageSize - 1); |
|
418 |
||
419 |
if (DPTest::Attributes() & DPTest::ERomPaging) |
|
420 |
{ |
|
421 |
// Use paged part of rom for testing |
|
422 |
test_NotNull(romHeader->iPageableRomStart); |
|
423 |
RomUnpagedEnd = RomUnpagedStart + romHeader->iPageableRomStart; |
|
424 |
test_Equal(0, RomUnpagedEnd & (PageSize - 1)); |
|
425 |
RomPagedStart = RomUnpagedEnd; |
|
426 |
RomPagedEnd = RomUnpagedStart + romSize; |
|
427 |
RomPagingSupported = ETrue; |
|
428 |
} |
|
429 |
else |
|
430 |
{ |
|
431 |
RomUnpagedEnd = RomUnpagedStart + romSize; |
|
432 |
RomPagedStart = RomUnpagedEnd; |
|
433 |
RomPagedEnd = RomPagedStart; |
|
434 |
} |
|
435 |
||
436 |
test.Printf(_L("Unpaged ROM: %08x -> %08x\n"), RomUnpagedStart, RomUnpagedEnd); |
|
437 |
test.Printf(_L("Paged ROM: %08x -> %08x\n"), RomPagedStart, RomPagedEnd); |
|
438 |
||
439 |
test.End(); |
|
440 |
} |
|
441 |
||
442 |
void Finalise() |
|
443 |
{ |
|
444 |
PageMove.Close(); |
|
445 |
MemoryTest.Close(); |
|
446 |
||
447 |
User::Free(PageBuffer1); |
|
448 |
User::Free(PageBuffer2); |
|
449 |
User::Free(PageBuffer3); |
|
450 |
} |
|
451 |
||
452 |
GLDEF_C TInt E32Main() |
|
453 |
// |
|
454 |
// Test ROM shadowing |
|
455 |
// |
|
456 |
{ |
|
457 |
test.Title(); |
|
458 |
||
459 |
if (!HaveMMU()) |
|
460 |
{ |
|
461 |
test.Printf(_L("This test requires an MMU\n")); |
|
462 |
return KErrNone; |
|
463 |
} |
|
464 |
#ifdef __WINS__ |
|
465 |
test.Printf(_L("Test not valid in WINS\n")); |
|
466 |
#else |
|
467 |
||
468 |
test.Start(_L("Testing ROM shadowing")); |
|
469 |
Initialise(); |
|
470 |
||
471 |
TestRomIsSectionMapped(); |
|
472 |
||
473 |
TestShadowPage(RomUnpagedStart, EUnpaged); |
|
474 |
TestShadowPage(RomUnpagedStart + PageSize, EUnpaged); |
|
475 |
TestShadowPage(RomUnpagedEnd - PageSize, EUnpaged); |
|
476 |
TestNoFreeRAM(RomUnpagedStart); |
|
477 |
TestShadowPageOOM(RomUnpagedStart); |
|
478 |
||
479 |
if (RomPagingSupported) |
|
480 |
{ |
|
481 |
TestShadowPage(RomPagedStart, EPaged); |
|
482 |
TestShadowPage(RomPagedStart + PageSize, EPaged); |
|
483 |
TestShadowPage(RomPagedEnd - PageSize, EPaged); |
|
484 |
TestNoFreeRAM(RomPagedEnd - PageSize); |
|
485 |
TestShadowPageOOM(RomPagedStart); |
|
486 |
TestInteractionWithPinning(RomPagedStart); |
|
487 |
} |
|
488 |
||
489 |
// todo: add test when reforming section mappings is implemented |
|
490 |
// TestRomIsSectionMapped(); |
|
491 |
||
492 |
Finalise(); |
|
493 |
test.End(); |
|
494 |
||
495 |
#endif |
|
496 |
return(KErrNone); |
|
497 |
} |
|
498 |