|
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(); |
|
80 |
|
81 TUint32 pa=0; |
|
82 TInt r=AllocPhysicalRam(pa,4*PageSize,0); |
|
83 test(r==KErrNone); |
|
84 test(FreeRam()==free-4*PageSize); |
|
85 |
|
86 r=FreePhysicalRam(pa,4*PageSize); |
|
87 test(r==KErrNone); |
|
88 test(FreeRam()==free); |
|
89 |
|
90 r=ClaimPhysicalRam(pa,4*PageSize); |
|
91 test(r==KErrNone); |
|
92 test(FreeRam()==free-4*PageSize); |
|
93 |
|
94 r=FreePhysicalRam(pa,3*PageSize); |
|
95 test(r==KErrNone); |
|
96 test(FreeRam()==free-PageSize); |
|
97 |
|
98 r=ClaimPhysicalRam(pa,4*PageSize); |
|
99 test(r==KErrInUse); |
|
100 test(FreeRam()==free-PageSize); |
|
101 |
|
102 #ifdef MANUAL_PANIC_TEST |
|
103 //This section of the test should be run as a manual test as it results in |
|
104 // a panic due to attempting to Free an unclaimed page |
|
105 if (HaveVirtMem()) |
|
106 { |
|
107 test.Printf(_L("HaveVirtMem() \n")); |
|
108 r=FreePhysicalRam(pa,4*PageSize); |
|
109 test.Printf(_L("FreePhysicalRam() \n")); |
|
110 test(r==KErrGeneral); |
|
111 test(FreeRam()==free-PageSize); |
|
112 } |
|
113 #endif |
|
114 |
|
115 r=FreePhysicalRam(pa+3*PageSize,PageSize); |
|
116 test(r==KErrNone); |
|
117 test(FreeRam()==free); |
|
118 |
|
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); |
|
144 |
|
145 test.Next(_L("TestAlignedAllocs")); |
|
146 TestAlignedAllocs(); |
|
147 |
|
148 test.Next(_L("TestClaimPhys")); |
|
149 TestClaimPhys(); |
|
150 |
|
151 Shadow.Close(); |
|
152 test.End(); |
|
153 return(KErrNone); |
|
154 } |
|
155 |