author | Simon Howkins <simonh@symbian.org> |
Fri, 05 Mar 2010 15:41:00 +0000 | |
branch | RCL_3 |
changeset 73 | 9c2a3e4960cf |
parent 31 | 56f325a607ea |
child 110 | c734af59ce98 |
child 132 | e4a7b1cbe40c |
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_ramall.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#define __E32TEST_EXTENSION__ |
|
19 |
||
20 |
#include <e32test.h> |
|
21 |
#include <e32uid.h> |
|
22 |
#include <e32hal.h> |
|
23 |
#include "d_shadow.h" |
|
24 |
#include "mmudetect.h" |
|
25 |
#include "freeram.h" |
|
26 |
||
27 |
LOCAL_D RTest test(_L("T_RAMALL")); |
|
28 |
||
29 |
_LIT(KLddFileName,"D_SHADOW.LDD"); |
|
30 |
||
31 |
TInt PageSize; |
|
32 |
TInt PageShift; |
|
33 |
RShadow Shadow; |
|
34 |
TInt InitFreeRam; |
|
35 |
||
36 |
TInt AllocPhysicalRam(TUint32& aAddr, TInt aSize, TInt aAlign) |
|
37 |
{ |
|
38 |
return Shadow.AllocPhysicalRam(aAddr,aSize,aAlign); |
|
39 |
} |
|
40 |
||
41 |
TInt FreePhysicalRam(TUint32 aAddr, TInt aSize) |
|
42 |
{ |
|
43 |
return Shadow.FreePhysicalRam(aAddr,aSize); |
|
44 |
} |
|
45 |
||
46 |
TInt ClaimPhysicalRam(TUint32 aAddr, TInt aSize) |
|
47 |
{ |
|
48 |
return Shadow.ClaimPhysicalRam(aAddr,aSize); |
|
49 |
} |
|
50 |
||
51 |
void TestAlignedAllocs() |
|
52 |
{ |
|
53 |
TInt align; |
|
54 |
TInt size; |
|
55 |
for (align=PageShift; align<=20; ++align) |
|
56 |
{ |
|
57 |
for (size=PageSize; size<=0x100000; size+=PageSize) |
|
58 |
{ |
|
59 |
TInt free=FreeRam(); |
|
60 |
TUint32 pa=0; |
|
61 |
TInt r=AllocPhysicalRam(pa,size,align); |
|
62 |
test.Printf(_L("Size %08x Align %d r=%d pa=%08x\n"),size,align,r,pa); |
|
63 |
if (r==KErrNone) |
|
64 |
{ |
|
65 |
TUint32 as=1u<<align; |
|
66 |
TUint32 am=as-1; |
|
67 |
test(FreeRam()==free-size); |
|
68 |
test((pa&am)==0); |
|
69 |
r=FreePhysicalRam(pa,size); |
|
70 |
test(r==KErrNone); |
|
71 |
} |
|
72 |
test(FreeRam()==free); |
|
73 |
} |
|
74 |
} |
|
75 |
} |
|
76 |
||
77 |
void TestClaimPhys() |
|
78 |
{ |
|
79 |
TInt free=FreeRam(); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
80 |
|
0 | 81 |
TUint32 pa=0; |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
82 |
TInt r=AllocPhysicalRam(pa,4*PageSize,0); |
0 | 83 |
test(r==KErrNone); |
84 |
test(FreeRam()==free-4*PageSize); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
|
0 | 86 |
r=FreePhysicalRam(pa,4*PageSize); |
87 |
test(r==KErrNone); |
|
88 |
test(FreeRam()==free); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
r=ClaimPhysicalRam(pa,4*PageSize); |
0 | 91 |
test(r==KErrNone); |
92 |
test(FreeRam()==free-4*PageSize); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
93 |
|
0 | 94 |
r=FreePhysicalRam(pa,3*PageSize); |
95 |
test(r==KErrNone); |
|
96 |
test(FreeRam()==free-PageSize); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
|
0 | 98 |
r=ClaimPhysicalRam(pa,4*PageSize); |
99 |
test(r==KErrInUse); |
|
100 |
test(FreeRam()==free-PageSize); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
102 |
#ifdef MANUAL_PANIC_TEST |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
103 |
//This section of the test should be run as a manual test as it results in |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
104 |
// a panic due to attempting to Free an unclaimed page |
0 | 105 |
if (HaveVirtMem()) |
106 |
{ |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
107 |
test.Printf(_L("HaveVirtMem() \n")); |
0 | 108 |
r=FreePhysicalRam(pa,4*PageSize); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
109 |
test.Printf(_L("FreePhysicalRam() \n")); |
0 | 110 |
test(r==KErrGeneral); |
111 |
test(FreeRam()==free-PageSize); |
|
112 |
} |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
113 |
#endif |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
114 |
|
0 | 115 |
r=FreePhysicalRam(pa+3*PageSize,PageSize); |
116 |
test(r==KErrNone); |
|
117 |
test(FreeRam()==free); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
118 |
|
0 | 119 |
} |
120 |
||
121 |
GLDEF_C TInt E32Main() |
|
122 |
// |
|
123 |
// Test RAM allocation |
|
124 |
// |
|
125 |
{ |
|
126 |
test.Title(); |
|
127 |
test.Start(_L("Load test LDD")); |
|
128 |
TInt r=User::LoadLogicalDevice(KLddFileName); |
|
129 |
test(r==KErrNone || r==KErrAlreadyExists); |
|
130 |
||
131 |
r=UserHal::PageSizeInBytes(PageSize); |
|
132 |
test(r==KErrNone); |
|
133 |
||
134 |
TInt psz=PageSize; |
|
135 |
PageShift=-1; |
|
136 |
for (; psz; psz>>=1, ++PageShift); |
|
137 |
||
138 |
InitFreeRam=FreeRam(); |
|
139 |
test.Printf(_L("Free RAM=%08x, Page size=%x, Page shift=%d\n"),InitFreeRam,PageSize,PageShift); |
|
140 |
||
141 |
test.Next(_L("Open test LDD")); |
|
142 |
r=Shadow.Open(); |
|
143 |
test(r==KErrNone); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
144 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
145 |
test.Next(_L("TestAlignedAllocs")); |
0 | 146 |
TestAlignedAllocs(); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
test.Next(_L("TestClaimPhys")); |
0 | 149 |
TestClaimPhys(); |
150 |
||
151 |
Shadow.Close(); |
|
152 |
test.End(); |
|
153 |
return(KErrNone); |
|
154 |
} |
|
155 |