sl@0
|
1 |
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\mmu\t_chunk2.cpp
|
sl@0
|
15 |
// Overview:
|
sl@0
|
16 |
// Test RChunk class
|
sl@0
|
17 |
// API Information:
|
sl@0
|
18 |
// RChunk
|
sl@0
|
19 |
// Details:
|
sl@0
|
20 |
// - Test creating local chunks and moving chunks home address, verify
|
sl@0
|
21 |
// results are as expected.
|
sl@0
|
22 |
// - Create numerous local chunks, test allocating more space by
|
sl@0
|
23 |
// adjusting chunk size, check for allocation failure, verify results
|
sl@0
|
24 |
// are as expected.
|
sl@0
|
25 |
// Platforms/Drives/Compatibility:
|
sl@0
|
26 |
// All.
|
sl@0
|
27 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
28 |
// Failures and causes:
|
sl@0
|
29 |
// Base Port information:
|
sl@0
|
30 |
//
|
sl@0
|
31 |
//
|
sl@0
|
32 |
|
sl@0
|
33 |
#define __E32TEST_EXTENSION__
|
sl@0
|
34 |
#include <e32test.h>
|
sl@0
|
35 |
#include <e32hal.h>
|
sl@0
|
36 |
#include <e32panic.h>
|
sl@0
|
37 |
#include "mmudetect.h"
|
sl@0
|
38 |
#include "d_gobble.h"
|
sl@0
|
39 |
#include "freeram.h"
|
sl@0
|
40 |
|
sl@0
|
41 |
TInt GlobalValue=299792458;
|
sl@0
|
42 |
TInt *GlobalPtr=&GlobalValue;
|
sl@0
|
43 |
|
sl@0
|
44 |
LOCAL_D RTest test(_L("T_CHUNK2"));
|
sl@0
|
45 |
LOCAL_D RTest t(_L("ShareThread"));
|
sl@0
|
46 |
LOCAL_D RChunk gChunk;
|
sl@0
|
47 |
|
sl@0
|
48 |
LOCAL_D TPtr nullPtr(NULL,0);
|
sl@0
|
49 |
|
sl@0
|
50 |
LOCAL_C void TestAllocFailure(RChunk& c1, RChunk& c2)
|
sl@0
|
51 |
{
|
sl@0
|
52 |
TInt free=FreeRam();
|
sl@0
|
53 |
test.Printf(_L("Free RAM %dK\n"),free/1024);
|
sl@0
|
54 |
TInt size1=free-0x80000; // 512K less than available
|
sl@0
|
55 |
TInt size2=0xFF000; // 255 pages
|
sl@0
|
56 |
test.Printf(_L("Adjusting chunk 1 to size %dK\n"),size1/1024);
|
sl@0
|
57 |
TInt r=c1.Adjust(size1);
|
sl@0
|
58 |
test(r==KErrNone);
|
sl@0
|
59 |
test.Printf(_L("Attempting to adjust chunk 2 to size %dK\n"),size2/1024);
|
sl@0
|
60 |
r=c2.Adjust(size2);
|
sl@0
|
61 |
test(r==KErrNoMemory);
|
sl@0
|
62 |
TInt size3=FreeRam();
|
sl@0
|
63 |
test.Printf(_L("Attempting to adjust chunk 2 to size %dK\n"),size3/1024);
|
sl@0
|
64 |
r=c2.Adjust(size3);
|
sl@0
|
65 |
TInt free2=FreeRam();
|
sl@0
|
66 |
if (r==KErrNone)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
test.Printf(_L("Succeeded - free RAM now %dK\n"),free2/1024);
|
sl@0
|
69 |
test.Printf(_L("Freeing chunk 2\n"));
|
sl@0
|
70 |
r=c2.Adjust(0);
|
sl@0
|
71 |
test(r==KErrNone);
|
sl@0
|
72 |
}
|
sl@0
|
73 |
else
|
sl@0
|
74 |
test.Printf(_L("Failed - free RAM now %dK\n"),free2/1024);
|
sl@0
|
75 |
test.Printf(_L("Freeing chunk 1\n"));
|
sl@0
|
76 |
r=c1.Adjust(0);
|
sl@0
|
77 |
test(r==KErrNone);
|
sl@0
|
78 |
test.Printf(_L("Checking free RAM\n"));
|
sl@0
|
79 |
UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
|
sl@0
|
80 |
free2=FreeRam();
|
sl@0
|
81 |
test.Printf(_L("Free RAM %dK\n"),free2/1024);
|
sl@0
|
82 |
test(free==free2);
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
void TestInterleavedAlloc()
|
sl@0
|
86 |
{
|
sl@0
|
87 |
TInt pageSize;
|
sl@0
|
88 |
RChunk c1;
|
sl@0
|
89 |
RChunk c2;
|
sl@0
|
90 |
TInt r;
|
sl@0
|
91 |
r=UserHal::PageSizeInBytes(pageSize);
|
sl@0
|
92 |
test(r==KErrNone);
|
sl@0
|
93 |
r=c1.CreateLocal(0,0x100000);
|
sl@0
|
94 |
test(r==KErrNone);
|
sl@0
|
95 |
r=c2.CreateLocal(0,0x100000);
|
sl@0
|
96 |
test(r==KErrNone);
|
sl@0
|
97 |
TInt step;
|
sl@0
|
98 |
for (step=1; step<=32; ++step)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
test.Printf(_L("Step size %x\n"),step*pageSize);
|
sl@0
|
101 |
while (c1.Size()<64*pageSize)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
r=c1.Adjust(c1.Size()+step*pageSize);
|
sl@0
|
104 |
test(r==KErrNone);
|
sl@0
|
105 |
r=c2.Adjust(c2.Size()+step*pageSize);
|
sl@0
|
106 |
test(r==KErrNone);
|
sl@0
|
107 |
}
|
sl@0
|
108 |
c1.Adjust(0);
|
sl@0
|
109 |
c2.Adjust(0);
|
sl@0
|
110 |
}
|
sl@0
|
111 |
c1.Close();
|
sl@0
|
112 |
c2.Close();
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
TInt E32Main()
|
sl@0
|
116 |
//
|
sl@0
|
117 |
// Test RChunk class
|
sl@0
|
118 |
//
|
sl@0
|
119 |
{
|
sl@0
|
120 |
|
sl@0
|
121 |
test.Title();
|
sl@0
|
122 |
if (!HaveVirtMem())
|
sl@0
|
123 |
{
|
sl@0
|
124 |
test.Printf(_L("This test requires an MMU\n"));
|
sl@0
|
125 |
return KErrNone;
|
sl@0
|
126 |
}
|
sl@0
|
127 |
TestInterleavedAlloc();
|
sl@0
|
128 |
test.Start(_L("Test moving chunks home addresses"));
|
sl@0
|
129 |
test.Printf(_L("GlobalValue=%d\n"),*GlobalPtr);
|
sl@0
|
130 |
++*GlobalPtr;
|
sl@0
|
131 |
test.Printf(_L("GlobalValue=%d\n"),GlobalValue);
|
sl@0
|
132 |
|
sl@0
|
133 |
test.Next(_L("Load gobbler LDD"));
|
sl@0
|
134 |
TInt r = User::LoadLogicalDevice(KGobblerLddFileName);
|
sl@0
|
135 |
test(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
136 |
RGobbler gobbler;
|
sl@0
|
137 |
r = gobbler.Open();
|
sl@0
|
138 |
test(r==KErrNone);
|
sl@0
|
139 |
TUint32 taken = gobbler.GobbleRAM(128*1024*1024);
|
sl@0
|
140 |
test.Printf(_L("Gobbled: %dK\n"), taken/1024);
|
sl@0
|
141 |
|
sl@0
|
142 |
TInt free=FreeRam();
|
sl@0
|
143 |
test.Printf(_L("Free RAM 0x%08X bytes\n"),free);
|
sl@0
|
144 |
|
sl@0
|
145 |
RChunk chunk1;
|
sl@0
|
146 |
r=chunk1.CreateLocal(0x400,0x800000);
|
sl@0
|
147 |
test (r==KErrNone);
|
sl@0
|
148 |
TInt i;
|
sl@0
|
149 |
TInt *p=(TInt*)chunk1.Base();
|
sl@0
|
150 |
test.Printf(_L("Chunk 1 Base %08X\n"),p);
|
sl@0
|
151 |
for (i=0; i<0x100; i++)
|
sl@0
|
152 |
*p++=i*i+41;
|
sl@0
|
153 |
RChunk chunk2;
|
sl@0
|
154 |
r=chunk2.CreateLocal(0x400,0x800000);
|
sl@0
|
155 |
test (r==KErrNone);
|
sl@0
|
156 |
TInt *p2=(TInt*)chunk2.Base();
|
sl@0
|
157 |
test.Printf(_L("Chunk 2 Base %08X\n"),p2);
|
sl@0
|
158 |
for (i=0; i<0x100; i++)
|
sl@0
|
159 |
*p2++=i*i*i+487;
|
sl@0
|
160 |
r=chunk1.Adjust(0x120000);
|
sl@0
|
161 |
test (r==KErrNone);
|
sl@0
|
162 |
for (i=0x100; i<0x48000; i++)
|
sl@0
|
163 |
*p++=i*i+41;
|
sl@0
|
164 |
r=chunk2.Adjust(0x120000);
|
sl@0
|
165 |
test (r==KErrNone);
|
sl@0
|
166 |
for (i=0x100; i<0x48000; i++)
|
sl@0
|
167 |
*p2++=i*i*i+487;
|
sl@0
|
168 |
p=(TInt*)chunk1.Base();
|
sl@0
|
169 |
p2=(TInt*)chunk2.Base();
|
sl@0
|
170 |
for(i=0; i<0x48000; i++)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
TInt read1=*p++;
|
sl@0
|
173 |
TInt read2=*p2++;
|
sl@0
|
174 |
if (read1 != (i*i+41))
|
sl@0
|
175 |
{
|
sl@0
|
176 |
test.Printf(_L("Chunk 1 i=%X, read %08X expected %08X\n"),i,read1,i*i+41);
|
sl@0
|
177 |
//test.Getch();
|
sl@0
|
178 |
}
|
sl@0
|
179 |
if (read2 != (i*i*i+487))
|
sl@0
|
180 |
{
|
sl@0
|
181 |
test.Printf(_L("Chunk 2 i=%X, read %08X expected %08X\n"),i,read2,i*i*i+487);
|
sl@0
|
182 |
//test.Getch();
|
sl@0
|
183 |
}
|
sl@0
|
184 |
}
|
sl@0
|
185 |
chunk1.Close();
|
sl@0
|
186 |
chunk2.Close();
|
sl@0
|
187 |
|
sl@0
|
188 |
TInt free2=FreeRam();
|
sl@0
|
189 |
test.Printf(_L("Free RAM 0x%08X bytes\n"),free2);
|
sl@0
|
190 |
test(free2==free);
|
sl@0
|
191 |
|
sl@0
|
192 |
// Chunks must not be paged otherwise they will not effect the amount
|
sl@0
|
193 |
// of free ram reported plus on h4 swap size is less than the total ram.
|
sl@0
|
194 |
TChunkCreateInfo createInfo;
|
sl@0
|
195 |
createInfo.SetNormal(0, free+2097152);
|
sl@0
|
196 |
createInfo.SetPaging(TChunkCreateInfo::EUnpaged);
|
sl@0
|
197 |
RChunk c1;
|
sl@0
|
198 |
test_KErrNone(c1.Create(createInfo));
|
sl@0
|
199 |
createInfo.SetNormal(0, 0x1000000);
|
sl@0
|
200 |
RChunk c2;
|
sl@0
|
201 |
RChunk c3;
|
sl@0
|
202 |
RChunk c4;
|
sl@0
|
203 |
RChunk c5;
|
sl@0
|
204 |
RChunk c6;
|
sl@0
|
205 |
test_KErrNone(c2.Create(createInfo));
|
sl@0
|
206 |
test_KErrNone(c3.Create(createInfo));
|
sl@0
|
207 |
test_KErrNone(c4.Create(createInfo));
|
sl@0
|
208 |
test_KErrNone(c5.Create(createInfo));
|
sl@0
|
209 |
test_KErrNone(c6.Create(createInfo));
|
sl@0
|
210 |
|
sl@0
|
211 |
TestAllocFailure(c1,c2);
|
sl@0
|
212 |
r=c3.Adjust(1024);
|
sl@0
|
213 |
test(r==KErrNone);
|
sl@0
|
214 |
TestAllocFailure(c1,c2);
|
sl@0
|
215 |
r=c4.Adjust(1024);
|
sl@0
|
216 |
test(r==KErrNone);
|
sl@0
|
217 |
TestAllocFailure(c1,c2);
|
sl@0
|
218 |
r=c5.Adjust(1024);
|
sl@0
|
219 |
test(r==KErrNone);
|
sl@0
|
220 |
TestAllocFailure(c1,c2);
|
sl@0
|
221 |
r=c6.Adjust(1024);
|
sl@0
|
222 |
test(r==KErrNone);
|
sl@0
|
223 |
TestAllocFailure(c1,c2);
|
sl@0
|
224 |
|
sl@0
|
225 |
c1.Close();
|
sl@0
|
226 |
c2.Close();
|
sl@0
|
227 |
c3.Close();
|
sl@0
|
228 |
c4.Close();
|
sl@0
|
229 |
c5.Close();
|
sl@0
|
230 |
c6.Close();
|
sl@0
|
231 |
gobbler.Close();
|
sl@0
|
232 |
|
sl@0
|
233 |
test.End();
|
sl@0
|
234 |
test.Close();
|
sl@0
|
235 |
return(KErrNone);
|
sl@0
|
236 |
}
|
sl@0
|
237 |
|
sl@0
|
238 |
|