author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 02 Sep 2010 21:54:16 +0300 | |
changeset 259 | 57b9594f5772 |
parent 109 | b3a1d9898418 |
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 |
||
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
198 |
// Remove limit on max size of live list |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
199 |
TUint originalMin = 0; |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
200 |
TUint originalMax = 0; |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
201 |
TUint currentSize = 0; |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
202 |
TInt r = DPTest::CacheSize(originalMin, originalMax, currentSize); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
203 |
test_Value(r, r == KErrNone || r == KErrNotSupported); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
204 |
TBool resizeCache = r == KErrNone; |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
205 |
if (resizeCache) |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
206 |
test_KErrNone(DPTest::SetCacheSize(originalMin, KMaxTUint)); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
207 |
|
0 | 208 |
test.Next(_L("Load gobbler LDD")); |
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
209 |
r = User::LoadLogicalDevice(KGobblerLddFileName); |
0 | 210 |
test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
211 |
RGobbler gobbler, gobbler2; |
0 | 212 |
test_KErrNone(gobbler.Open()); |
213 |
TUint32 taken = gobbler.GobbleRAM(496*1024*1024); |
|
214 |
test.Printf(_L(" Gobbled: %dK\n"), taken/1024); |
|
215 |
test.Printf(_L(" Free RAM 0x%08X bytes\n"),FreeRam()); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
216 |
// Open 2nd globber here, while we still have some free pages. |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
217 |
test_KErrNone(gobbler2.Open()); |
0 | 218 |
|
219 |
||
220 |
// put all of free RAM in a chunk... |
|
221 |
TChunkCreateInfo createInfo; |
|
222 |
createInfo.SetCache(512*1024*1024); |
|
223 |
RChunk testChunk; |
|
224 |
test_KErrNone(testChunk.Create(createInfo)); |
|
225 |
TInt commitEnd = 0; |
|
226 |
while(KErrNone==(r=testChunk.Commit(commitEnd,PageSize))) |
|
227 |
commitEnd += PageSize; |
|
228 |
test_Equal(KErrNoMemory,r); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
229 |
|
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
230 |
// Now we have some memory in a cache chunk ensure definitely no |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
231 |
// other free pages. |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
232 |
taken = gobbler2.GobbleRAM(0); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
233 |
test.Printf(_L(" Gobbled: %dK\n"), taken/1024); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
234 |
test_Equal(0, FreeRam()); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
235 |
|
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
236 |
|
0 | 237 |
// no memory to allocate shadow page... |
238 |
test_Equal(KErrNoMemory,Shadow.Alloc(aPageAddr)); |
|
239 |
// unlock all of RAM in chunk... |
|
240 |
test_KErrNone(testChunk.Unlock(0,commitEnd)); |
|
241 |
// should have memory now... |
|
242 |
test_KErrNone(Shadow.Alloc(aPageAddr)); |
|
243 |
// tidy up... |
|
244 |
test_KErrNone(Shadow.Free(aPageAddr)); |
|
245 |
testChunk.Close(); |
|
246 |
||
247 |
// Restore original settings for live list size |
|
248 |
if (resizeCache) |
|
249 |
test_KErrNone(DPTest::SetCacheSize(originalMin, originalMax)); |
|
250 |
||
251 |
gobbler.Close(); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
252 |
gobbler2.Close(); |
0 | 253 |
test.End(); |
254 |
} |
|
255 |
||
256 |
void TestShadowPageOOM(TLinAddr aPageAddr) |
|
257 |
{ |
|
258 |
test.Start(_L("Test OOM while shadowing a page")); |
|
259 |
test.Printf(_L(" addr == 0x%08x\n"), aPageAddr); |
|
260 |
||
261 |
test.Next(_L("Copy page to be shadowed and following page to local buffers")); |
|
262 |
Mem::Move(PageBuffer1,(TAny*)aPageAddr,PageSize); |
|
263 |
||
264 |
__KHEAP_MARK; |
|
265 |
||
266 |
TInt r; |
|
267 |
TInt failCount = 0; |
|
268 |
test.Next(_L("Allocate a shadow ROM page")); |
|
269 |
do |
|
270 |
{ |
|
271 |
__KHEAP_FAILNEXT(failCount); |
|
272 |
r = Shadow.Alloc(aPageAddr); |
|
273 |
if (r == KErrNoMemory) |
|
274 |
++failCount; |
|
275 |
} |
|
276 |
while (r == KErrNoMemory); |
|
277 |
__KHEAP_RESET; |
|
278 |
test.Printf(_L(" returned %d after %d allocations\n"), r, failCount); |
|
279 |
test_KErrNone(r); |
|
280 |
||
281 |
test.Next(_L("Try to shadow the page again")); |
|
282 |
__KHEAP_FAILNEXT(0); |
|
283 |
test_Equal(KErrAlreadyExists, Shadow.Alloc(aPageAddr)); |
|
284 |
__KHEAP_RESET; |
|
285 |
||
286 |
test.Next(_L("Check data copied into shadow page")); |
|
287 |
test_Equal(0, Mem::Compare((TUint8*)aPageAddr,PageSize,PageBuffer1,PageSize)); |
|
288 |
||
289 |
test.Next(_L("Write data into shadow page")); |
|
290 |
for(TInt i=0; i<PageSize; i++) |
|
291 |
{ |
|
292 |
TInt i2=i*i; |
|
293 |
PageBuffer2[i]=TUint8(i2^(i2>>8)^(i2>>16)); |
|
294 |
} |
|
295 |
test_KErrNone(Shadow.Write(aPageAddr,PageBuffer2)); |
|
296 |
||
297 |
test.Next(_L("Check data written into shadow page")); |
|
298 |
test_Equal(0, Mem::Compare((TUint8*)aPageAddr,PageSize,PageBuffer2,PageSize)); |
|
299 |
||
300 |
test.Next(_L("Free the original shadow page")); |
|
301 |
__KHEAP_FAILNEXT(0); |
|
302 |
test_KErrNone(Shadow.Free(aPageAddr)); |
|
303 |
__KHEAP_RESET; |
|
304 |
||
305 |
test.Next(_L("Check original ROM data restored")); |
|
306 |
test_Equal(0, Mem::Compare((TUint8*)aPageAddr,PageSize,PageBuffer1,PageSize)); |
|
307 |
||
308 |
test.Next(_L("Check kernel heap balance")); |
|
309 |
__KHEAP_MARKEND; |
|
310 |
||
311 |
test.End(); |
|
312 |
} |
|
313 |
||
314 |
void TestInteractionWithPinning(TLinAddr aPageAddr) |
|
315 |
{ |
|
316 |
test.Start(_L("Test pinning of shadow pages")); |
|
317 |
||
318 |
// Create pin object to use for all pinnings |
|
319 |
test_KErrNone(MemoryTest.CreateVirtualPinObject()); |
|
320 |
||
321 |
test.Next(_L("Test pin - shadow - unpin - unshadow")); |
|
322 |
test_Equal(KErrNone, MemoryTest.PinVirtualMemory((TLinAddr)aPageAddr, PageSize)); |
|
323 |
test_KErrNone(Shadow.Alloc(aPageAddr)); |
|
324 |
test_Equal(KErrNone, MemoryTest.UnpinVirtualMemory()); |
|
325 |
test_KErrNone(Shadow.Free(aPageAddr)); |
|
326 |
||
327 |
test.Next(_L("Test pin - shadow - unshadow - unpin")); |
|
328 |
test_Equal(KErrNone, MemoryTest.PinVirtualMemory((TLinAddr)aPageAddr, PageSize)); |
|
329 |
test_KErrNone(Shadow.Alloc(aPageAddr)); |
|
330 |
test_KErrNone(Shadow.Free(aPageAddr)); |
|
331 |
test_Equal(KErrNone, MemoryTest.UnpinVirtualMemory()); |
|
332 |
||
333 |
test.Next(_L("Test shadow - pin - unpin - unshadow")); |
|
334 |
test_KErrNone(Shadow.Alloc(aPageAddr)); |
|
335 |
test_Equal(KErrNone, MemoryTest.PinVirtualMemory((TLinAddr)aPageAddr, PageSize)); |
|
336 |
test_Equal(KErrNone, MemoryTest.UnpinVirtualMemory()); |
|
337 |
test_KErrNone(Shadow.Free(aPageAddr)); |
|
338 |
||
339 |
test.Next(_L("Test shadow - pin - unshadow - unpin")); |
|
340 |
test_KErrNone(Shadow.Alloc(aPageAddr)); |
|
341 |
test_Equal(KErrNone, MemoryTest.PinVirtualMemory((TLinAddr)aPageAddr, PageSize)); |
|
342 |
test_KErrNone(Shadow.Free(aPageAddr)); |
|
343 |
test_Equal(KErrNone, MemoryTest.UnpinVirtualMemory()); |
|
344 |
||
345 |
test_KErrNone(MemoryTest.DestroyVirtualPinObject()); |
|
346 |
test.End(); |
|
347 |
} |
|
348 |
||
349 |
const TUint KChunkShift = 20; |
|
350 |
const TUint KChunkSize = 1 << KChunkShift; |
|
351 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
352 |
const TUint KRomSizeAlign = 16; // This should match CFG_RomSizeAlign defined in bootcpu.inc |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
353 |
const TUint KRomSizeAlignMask = (1 << KRomSizeAlign) - 1; |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
354 |
|
0 | 355 |
void TestRomIsSectionMapped() |
356 |
{ |
|
357 |
test.Start(_L("Test ROM is section mapped")); |
|
358 |
||
359 |
TUint pdSize; |
|
360 |
TUint pdBase; |
|
361 |
TUint offset; |
|
362 |
||
363 |
#ifdef __MARM__ |
|
364 |
test_KErrNone(Shadow.GetPdInfo(KGlobalPageDirectory, pdSize, pdBase, offset)); |
|
365 |
test.Printf(_L("pd base == %08x, pd size == %08x, pd offset == %08x\n"), pdBase, pdSize, offset); |
|
366 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
367 |
TUint romSize = RomUnpagedEnd - RomUnpagedStart; |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
368 |
test.Printf(_L("rom size == %x\n"), romSize); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
369 |
if (RomPagedStart == RomPagedEnd) |
0 | 370 |
{ |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
371 |
// If rom is not paged then we must round the ROM size up to a mutiple of 64KB (or whatever |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
372 |
// the CFG_RomSizeAlign settings is), because that's how the bootstrap maps it |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
373 |
romSize = (romSize + KRomSizeAlignMask) & ~KRomSizeAlignMask; |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
374 |
test.Printf(_L("rom size rounded up to %x\n"), romSize); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
375 |
} |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
376 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
377 |
for (TUint pos = 0 ; pos < romSize ; pos += KChunkSize) |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
378 |
{ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
379 |
TLinAddr addr = RomUnpagedStart + pos; |
0 | 380 |
TUint i = (addr >> KChunkShift) - offset; |
381 |
TUint pde = Shadow.Read(pdBase + i*4); |
|
382 |
test.Printf(_L(" %08x: PDE %08x\n"), addr, pde); |
|
383 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
384 |
TUint expectedPdeType = (romSize - pos) >= KChunkSize ? 2 : 1; |
0 | 385 |
test_Equal(expectedPdeType, pde & 3); |
386 |
} |
|
387 |
#else |
|
388 |
test.Printf(_L("Test not supported on this architecture\n")); |
|
389 |
#endif |
|
390 |
||
391 |
test.End(); |
|
392 |
} |
|
393 |
||
394 |
void Initialise() |
|
395 |
{ |
|
396 |
test.Start(_L("Load test LDDs")); |
|
397 |
||
398 |
TInt r=User::LoadLogicalDevice(KLddFileName); |
|
399 |
test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
|
400 |
if (PageMovingSupported) |
|
401 |
{ |
|
402 |
r=User::LoadLogicalDevice(KMoveLddFileName); |
|
403 |
test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
|
404 |
} |
|
405 |
||
406 |
test_KErrNone(UserHal::PageSizeInBytes(PageSize)); |
|
407 |
||
408 |
test.Next(_L("Open test LDDs")); |
|
409 |
test_KErrNone(Shadow.Open()); |
|
410 |
test_KErrNone(MemoryTest.Open()); |
|
411 |
if (PageMovingSupported) |
|
412 |
test_KErrNone(PageMove.Open()); |
|
413 |
||
414 |
test.Next(_L("Allocate some RAM")); |
|
415 |
PageBuffer1=(TUint8*)User::Alloc(PageSize); |
|
416 |
test_NotNull(PageBuffer1); |
|
417 |
PageBuffer2=(TUint8*)User::Alloc(PageSize); |
|
418 |
test_NotNull(PageBuffer2); |
|
419 |
PageBuffer3=(TUint8*)User::Alloc(PageSize); |
|
420 |
test_NotNull(PageBuffer3); |
|
421 |
||
422 |
test.Next(_L("Discover ROM addresses")); |
|
423 |
TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress(); |
|
424 |
RomUnpagedStart = (TLinAddr)romHeader; |
|
425 |
test_Equal(0, RomUnpagedStart & (PageSize - 1)); |
|
426 |
||
427 |
//Round up to page size (May already be rounded, but doesnt hurt) |
|
428 |
TUint romSize = (romHeader->iUncompressedSize + PageSize - 1) & ~(PageSize - 1); |
|
429 |
||
430 |
if (DPTest::Attributes() & DPTest::ERomPaging) |
|
431 |
{ |
|
432 |
// Use paged part of rom for testing |
|
433 |
test_NotNull(romHeader->iPageableRomStart); |
|
434 |
RomUnpagedEnd = RomUnpagedStart + romHeader->iPageableRomStart; |
|
435 |
test_Equal(0, RomUnpagedEnd & (PageSize - 1)); |
|
436 |
RomPagedStart = RomUnpagedEnd; |
|
437 |
RomPagedEnd = RomUnpagedStart + romSize; |
|
438 |
RomPagingSupported = ETrue; |
|
439 |
} |
|
440 |
else |
|
441 |
{ |
|
442 |
RomUnpagedEnd = RomUnpagedStart + romSize; |
|
443 |
RomPagedStart = RomUnpagedEnd; |
|
444 |
RomPagedEnd = RomPagedStart; |
|
445 |
} |
|
446 |
||
447 |
test.Printf(_L("Unpaged ROM: %08x -> %08x\n"), RomUnpagedStart, RomUnpagedEnd); |
|
448 |
test.Printf(_L("Paged ROM: %08x -> %08x\n"), RomPagedStart, RomPagedEnd); |
|
449 |
||
450 |
test.End(); |
|
451 |
} |
|
452 |
||
453 |
void Finalise() |
|
454 |
{ |
|
455 |
PageMove.Close(); |
|
456 |
MemoryTest.Close(); |
|
457 |
||
458 |
User::Free(PageBuffer1); |
|
459 |
User::Free(PageBuffer2); |
|
460 |
User::Free(PageBuffer3); |
|
461 |
} |
|
462 |
||
463 |
GLDEF_C TInt E32Main() |
|
464 |
// |
|
465 |
// Test ROM shadowing |
|
466 |
// |
|
467 |
{ |
|
468 |
test.Title(); |
|
469 |
||
470 |
if (!HaveMMU()) |
|
471 |
{ |
|
472 |
test.Printf(_L("This test requires an MMU\n")); |
|
473 |
return KErrNone; |
|
474 |
} |
|
475 |
#ifdef __WINS__ |
|
476 |
test.Printf(_L("Test not valid in WINS\n")); |
|
477 |
#else |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
478 |
// Turn off lazy dll unloading |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
479 |
RLoader l; |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
480 |
test_KErrNone(l.Connect()); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
481 |
test_KErrNone(l.CancelLazyDllUnload()); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
482 |
l.Close(); |
0 | 483 |
|
484 |
test.Start(_L("Testing ROM shadowing")); |
|
485 |
Initialise(); |
|
486 |
||
487 |
TestRomIsSectionMapped(); |
|
488 |
||
489 |
TestShadowPage(RomUnpagedStart, EUnpaged); |
|
490 |
TestShadowPage(RomUnpagedStart + PageSize, EUnpaged); |
|
491 |
TestShadowPage(RomUnpagedEnd - PageSize, EUnpaged); |
|
492 |
TestNoFreeRAM(RomUnpagedStart); |
|
493 |
TestShadowPageOOM(RomUnpagedStart); |
|
494 |
||
495 |
if (RomPagingSupported) |
|
496 |
{ |
|
497 |
TestShadowPage(RomPagedStart, EPaged); |
|
498 |
TestShadowPage(RomPagedStart + PageSize, EPaged); |
|
499 |
TestShadowPage(RomPagedEnd - PageSize, EPaged); |
|
500 |
TestNoFreeRAM(RomPagedEnd - PageSize); |
|
501 |
TestShadowPageOOM(RomPagedStart); |
|
502 |
TestInteractionWithPinning(RomPagedStart); |
|
503 |
} |
|
504 |
||
505 |
// todo: add test when reforming section mappings is implemented |
|
506 |
// TestRomIsSectionMapped(); |
|
507 |
||
508 |
Finalise(); |
|
509 |
test.End(); |
|
510 |
||
511 |
#endif |
|
512 |
return(KErrNone); |
|
513 |
} |
|
514 |