Update contrib.
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_mmubm.cpp
16 // Time MMU allocation & deallocation
20 // - Allocate and release a 1 MB chunk 100 times and time how long it takes.
21 // - Allocate and release a 2 MB chunk 100 times and time how long it takes.
22 // - Allocate and release a 7 MB chunk 100 times and time how long it takes.
23 // - Allocate a 7 MB chunk once and time how long it takes.
24 // - Deallocate a 7 MB chunk once and time how long it takes.
25 // Platforms/Drives/Compatibility:
27 // Assumptions/Requirement/Pre-requisites:
28 // Failures and causes:
29 // Base Port information:
33 #define __E32TEST_EXTENSION__
36 #include "mmudetect.h"
38 #include "d_memorytest.h"
41 RTest test(_L("T_MMUBM"));
43 typedef TInt (*TestFunction)(TUint32 aIters, TUint32 aSize);
45 RMemoryTestLdd MemoryTest;
48 LOCAL_C TInt AllocPhysical(TUint32 aIters, TUint32 aSize)
50 return MemoryTest.AllocPhysTest(aIters, aSize * 0x00100000);
53 LOCAL_C TInt AllocPhysical1(TUint32 aIters, TUint32 aSize)
55 return MemoryTest.AllocPhysTest1(aIters, aSize * 0x00100000);
58 LOCAL_C TInt AdjustChunk(TUint32 aIters, TUint32 aSize)
61 for (i=0; i<aIters; i++)
63 TInt r=TheChunk.Adjust(aSize * 0x00100000);
73 LOCAL_C TInt AllocateChunk(TUint32 aIters, TUint32 aSize)
76 return TheChunk.Adjust(aSize * 0x00100000);
79 LOCAL_C TInt DeallocateChunk(TUint32 , TUint32 )
81 return TheChunk.Adjust(0);
84 LOCAL_C TInt TimedCall(TestFunction aFunction, TUint32& aTime, TUint32 aIters, TUint32 aSize)
86 TUint32 before=User::NTickCount();
87 TInt r=(*aFunction)(aIters, aSize);
88 TUint32 after=User::NTickCount();
93 #define DO_TEST(__ret, __func, __time, __iters, __size)\
95 __ret=TimedCall(__func, __time, __iters, __size);\
98 test.Printf(_L(" %dMb %d times ... %d ms\n"),__size, __iters,__time);\
100 else if (tempSize < 7)\
102 test(__ret==KErrNone);\
105 #define DO_TEST_GOB(__ret, __func, __time, __iters, __size, __rem,__taken)\
107 __ret = gobbler.Open();\
108 test(__ret==KErrNone);\
109 /* gobble leaving x+1MB then test adjusting to x...*/\
110 __taken = gobbler.GobbleRAM(__rem*1024*1024);\
111 test.Printf(_L("Gobbled: %dK freeRam %dK\n"), __taken/1024, FreeRam()/1024);\
113 __ret=TimedCall(__func, __time, __iters, __size);\
114 if (__ret==KErrNone)\
116 test.Printf(_L(" %dMb %d times ... %d ms\n"),__size, __iters,__time);\
118 else if (tempSize < 7)\
120 test(__ret==KErrNone);\
125 GLDEF_C TInt E32Main()
131 test.Printf(_L("This test requires an MMU\n"));
134 test.Start(_L("Timing MMU allocation/deallocation..."));
136 test(KErrNone==MemoryTest.Open());
141 r=TheChunk.CreateLocal(0,0x01000000);
144 test.Printf(_L("Adjusting Chunks\n"));
145 DO_TEST(r, AdjustChunk, t, 100, 1);
146 DO_TEST(r, AdjustChunk, t, 100, 2);
147 DO_TEST(r, AdjustChunk, t, 100, 7);
148 r=TimedCall(AllocateChunk,t,1,7);
151 test.Printf(_L("Allocate 7Mb once ... %d ms\n"),t);
152 r=TimedCall(DeallocateChunk,t, 1, 0);
153 test.Printf(_L("Deallocate 7Mb once ... %d ms\n"),t);
157 test.Printf(_L("Alloc chunk 7Mb failed! %d\n"), r);
160 test.Next(_L("Test physical memory allocations...."));
162 DO_TEST(r, AllocPhysical, t, 100, 1);
163 DO_TEST(r, AllocPhysical1, t, 100, 1);
164 DO_TEST(r, AllocPhysical, t, 100, 2);
165 DO_TEST(r, AllocPhysical1, t, 100, 2);
166 DO_TEST(r, AllocPhysical, t, 100, 7);
167 DO_TEST(r, AllocPhysical1, t, 100, 7);
169 test.Next(_L("Now the test with low memory...."));
171 r = User::LoadLogicalDevice(KGobblerLddFileName);
172 test(r==KErrNone || r==KErrAlreadyExists);
177 DO_TEST_GOB(r, AdjustChunk, t, 100, 1, 2, taken);
178 DO_TEST_GOB(r, AdjustChunk, t, 100, 2, 3, taken);
179 DO_TEST_GOB(r, AdjustChunk, t, 100, 7, 8, taken);
181 r=TimedCall(AllocateChunk,t,1,7);
184 test.Printf(_L("Allocate 7Mb once ... %d ms\n"),t);
185 r=TimedCall(DeallocateChunk,t, 1, 0);
186 test.Printf(_L("Deallocate 7Mb once ... %d ms\n"),t);
189 // gobble leaving 8MB then test allocing 7...
192 taken = gobbler.GobbleRAM(8*1024*1024);
193 test.Printf(_L("Gobbled: %dK freeRam %dK\n"), taken/1024, FreeRam()/1024);
195 r=TimedCall(AllocateChunk,t,1,7);
198 test.Printf(_L("Allocate 7Mb once ... %d ms\n"),t);
199 r=TimedCall(DeallocateChunk,t, 1, 0);
200 test.Printf(_L("Deallocate 7Mb once ... %d ms\n"),t);
203 test.Printf(_L("Alloc chunk 7Mb failed! %d\n"), r);
206 test.Next(_L("Test physical memory allocations with low memory...."));
207 DO_TEST_GOB(r, AllocPhysical, t, 100, 1, 2, taken);
208 DO_TEST_GOB(r, AllocPhysical1, t, 100, 1, 2, taken);
209 DO_TEST_GOB(r, AllocPhysical, t, 100, 2, 3, taken);
210 DO_TEST_GOB(r, AllocPhysical1, t, 100, 2, 3, taken);
211 DO_TEST_GOB(r, AllocPhysical, t, 100, 7, 8, taken);
212 DO_TEST_GOB(r, AllocPhysical1, t, 100, 7, 8, taken);