First public contribution.
1 // Copyright (c) 1995-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\mmu\t_chunk2.cpp
20 // - Test creating local chunks and moving chunks home address, verify
21 // results are as expected.
22 // - Create numerous local chunks, test allocating more space by
23 // adjusting chunk size, check for allocation failure, verify results
25 // Platforms/Drives/Compatibility:
27 // Assumptions/Requirement/Pre-requisites:
28 // Failures and causes:
29 // Base Port information:
33 #define __E32TEST_EXTENSION__
37 #include "mmudetect.h"
41 TInt GlobalValue=299792458;
42 TInt *GlobalPtr=&GlobalValue;
44 LOCAL_D RTest test(_L("T_CHUNK2"));
45 LOCAL_D RTest t(_L("ShareThread"));
46 LOCAL_D RChunk gChunk;
48 LOCAL_D TPtr nullPtr(NULL,0);
50 LOCAL_C void TestAllocFailure(RChunk& c1, RChunk& c2)
53 test.Printf(_L("Free RAM %dK\n"),free/1024);
54 TInt size1=free-0x80000; // 512K less than available
55 TInt size2=0xFF000; // 255 pages
56 test.Printf(_L("Adjusting chunk 1 to size %dK\n"),size1/1024);
57 TInt r=c1.Adjust(size1);
59 test.Printf(_L("Attempting to adjust chunk 2 to size %dK\n"),size2/1024);
61 test(r==KErrNoMemory);
63 test.Printf(_L("Attempting to adjust chunk 2 to size %dK\n"),size3/1024);
68 test.Printf(_L("Succeeded - free RAM now %dK\n"),free2/1024);
69 test.Printf(_L("Freeing chunk 2\n"));
74 test.Printf(_L("Failed - free RAM now %dK\n"),free2/1024);
75 test.Printf(_L("Freeing chunk 1\n"));
78 test.Printf(_L("Checking free RAM\n"));
79 UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
81 test.Printf(_L("Free RAM %dK\n"),free2/1024);
85 void TestInterleavedAlloc()
91 r=UserHal::PageSizeInBytes(pageSize);
93 r=c1.CreateLocal(0,0x100000);
95 r=c2.CreateLocal(0,0x100000);
98 for (step=1; step<=32; ++step)
100 test.Printf(_L("Step size %x\n"),step*pageSize);
101 while (c1.Size()<64*pageSize)
103 r=c1.Adjust(c1.Size()+step*pageSize);
105 r=c2.Adjust(c2.Size()+step*pageSize);
124 test.Printf(_L("This test requires an MMU\n"));
127 TestInterleavedAlloc();
128 test.Start(_L("Test moving chunks home addresses"));
129 test.Printf(_L("GlobalValue=%d\n"),*GlobalPtr);
131 test.Printf(_L("GlobalValue=%d\n"),GlobalValue);
133 test.Next(_L("Load gobbler LDD"));
134 TInt r = User::LoadLogicalDevice(KGobblerLddFileName);
135 test(r==KErrNone || r==KErrAlreadyExists);
139 TUint32 taken = gobbler.GobbleRAM(128*1024*1024);
140 test.Printf(_L("Gobbled: %dK\n"), taken/1024);
143 test.Printf(_L("Free RAM 0x%08X bytes\n"),free);
146 r=chunk1.CreateLocal(0x400,0x800000);
149 TInt *p=(TInt*)chunk1.Base();
150 test.Printf(_L("Chunk 1 Base %08X\n"),p);
151 for (i=0; i<0x100; i++)
154 r=chunk2.CreateLocal(0x400,0x800000);
156 TInt *p2=(TInt*)chunk2.Base();
157 test.Printf(_L("Chunk 2 Base %08X\n"),p2);
158 for (i=0; i<0x100; i++)
160 r=chunk1.Adjust(0x120000);
162 for (i=0x100; i<0x48000; i++)
164 r=chunk2.Adjust(0x120000);
166 for (i=0x100; i<0x48000; i++)
168 p=(TInt*)chunk1.Base();
169 p2=(TInt*)chunk2.Base();
170 for(i=0; i<0x48000; i++)
174 if (read1 != (i*i+41))
176 test.Printf(_L("Chunk 1 i=%X, read %08X expected %08X\n"),i,read1,i*i+41);
179 if (read2 != (i*i*i+487))
181 test.Printf(_L("Chunk 2 i=%X, read %08X expected %08X\n"),i,read2,i*i*i+487);
188 TInt free2=FreeRam();
189 test.Printf(_L("Free RAM 0x%08X bytes\n"),free2);
192 // Chunks must not be paged otherwise they will not effect the amount
193 // of free ram reported plus on h4 swap size is less than the total ram.
194 TChunkCreateInfo createInfo;
195 createInfo.SetNormal(0, free+2097152);
196 createInfo.SetPaging(TChunkCreateInfo::EUnpaged);
198 test_KErrNone(c1.Create(createInfo));
199 createInfo.SetNormal(0, 0x1000000);
205 test_KErrNone(c2.Create(createInfo));
206 test_KErrNone(c3.Create(createInfo));
207 test_KErrNone(c4.Create(createInfo));
208 test_KErrNone(c5.Create(createInfo));
209 test_KErrNone(c6.Create(createInfo));
211 TestAllocFailure(c1,c2);
214 TestAllocFailure(c1,c2);
217 TestAllocFailure(c1,c2);
220 TestAllocFailure(c1,c2);
223 TestAllocFailure(c1,c2);