os/kernelhwsrv/kerneltest/e32test/mmu/t_mmubm.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32test\mmu\t_mmubm.cpp
    15 // Overview:
    16 // Time MMU allocation & deallocation
    17 // API Information:
    18 // RChunk
    19 // Details:
    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:
    26 // All.
    27 // Assumptions/Requirement/Pre-requisites:
    28 // Failures and causes:
    29 // Base Port information:
    30 // 
    31 //
    32 
    33 #define __E32TEST_EXTENSION__
    34 
    35 #include <e32test.h>
    36 #include "mmudetect.h"
    37 #include "d_gobble.h"
    38 #include "d_memorytest.h"
    39 #include "freeram.h"
    40 
    41 RTest test(_L("T_MMUBM"));
    42 
    43 typedef TInt (*TestFunction)(TUint32 aIters, TUint32 aSize);
    44 
    45 RMemoryTestLdd MemoryTest;
    46 RChunk TheChunk;
    47 
    48 LOCAL_C TInt AllocPhysical(TUint32 aIters, TUint32 aSize)
    49 	{
    50 	return MemoryTest.AllocPhysTest(aIters, aSize * 0x00100000);
    51 	}
    52 
    53 LOCAL_C TInt AllocPhysical1(TUint32 aIters, TUint32 aSize)
    54 	{
    55 	return MemoryTest.AllocPhysTest1(aIters, aSize * 0x00100000);
    56 	}
    57 
    58 LOCAL_C TInt AdjustChunk(TUint32 aIters, TUint32 aSize)
    59 	{
    60 	TUint32 i;
    61 	for (i=0; i<aIters; i++)
    62 		{
    63 		TInt r=TheChunk.Adjust(aSize * 0x00100000);
    64 		if (r!=KErrNone)
    65 			return r;
    66 		r=TheChunk.Adjust(0);
    67 		if (r!=KErrNone)
    68 			return r;
    69 		}
    70 	return KErrNone;
    71 	}
    72 
    73 LOCAL_C TInt AllocateChunk(TUint32 aIters, TUint32 aSize)
    74 	{
    75 	aIters = aSize;
    76 	return TheChunk.Adjust(aSize * 0x00100000);
    77 	}
    78 
    79 LOCAL_C TInt DeallocateChunk(TUint32 , TUint32 )
    80 	{
    81 	return TheChunk.Adjust(0);
    82 	}
    83 
    84 LOCAL_C TInt TimedCall(TestFunction aFunction, TUint32& aTime, TUint32 aIters, TUint32 aSize)
    85 	{
    86 	TUint32 before=User::NTickCount();
    87 	TInt r=(*aFunction)(aIters, aSize);
    88 	TUint32 after=User::NTickCount();
    89 	aTime=after-before;
    90 	return r;
    91 	}
    92 
    93 #define DO_TEST(__ret, __func, __time, __iters, __size)\
    94 	tempSize = __size;\
    95 	__ret=TimedCall(__func, __time, __iters, __size);\
    96 	if (__ret==KErrNone)\
    97 		{\
    98 		test.Printf(_L("  %dMb %d times ... %d ms\n"),__size, __iters,__time);\
    99 		}\
   100 	else if (tempSize < 7)\
   101 		{\
   102 		test(__ret==KErrNone);\
   103 		}
   104 
   105 #define DO_TEST_GOB(__ret, __func, __time, __iters, __size, __rem,__taken)\
   106 	tempSize = __size;\
   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);\
   112 	/* adjust to 1MB*/\
   113 	__ret=TimedCall(__func, __time, __iters, __size);\
   114 	if (__ret==KErrNone)\
   115 		{\
   116 		test.Printf(_L(" %dMb %d times ... %d ms\n"),__size, __iters,__time);\
   117 		}\
   118 	else if (tempSize < 7)\
   119 		{\
   120 		test(__ret==KErrNone);\
   121 		}\
   122 	gobbler.Close();
   123 	
   124 
   125 GLDEF_C TInt E32Main()
   126 	{
   127 
   128 	test.Title();
   129 	if (!HaveVirtMem())
   130 		{
   131 		test.Printf(_L("This test requires an MMU\n"));
   132 		return KErrNone;
   133 		}
   134 	test.Start(_L("Timing MMU allocation/deallocation..."));
   135 
   136 	test(KErrNone==MemoryTest.Open());
   137 
   138 	TInt r;
   139 	TUint32 t;
   140 	TUint32 tempSize;
   141 	r=TheChunk.CreateLocal(0,0x01000000);
   142 	test(r==KErrNone);
   143 
   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);
   149 	if (r==KErrNone)
   150 		{
   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);
   154 		}
   155 	else
   156 		{
   157 		test.Printf(_L("Alloc chunk 7Mb failed! %d\n"), r);
   158 		}
   159 	
   160 	test.Next(_L("Test physical memory allocations...."));
   161 
   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);
   168 
   169 	test.Next(_L("Now the test with low memory...."));
   170 
   171 	r = User::LoadLogicalDevice(KGobblerLddFileName);
   172 	test(r==KErrNone || r==KErrAlreadyExists);
   173 
   174 	RGobbler gobbler;
   175 	TUint32 taken = 0;
   176 
   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);
   180 
   181 	r=TimedCall(AllocateChunk,t,1,7);
   182 	if (r==KErrNone)
   183 		{
   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);
   187 		}
   188 
   189 	// gobble leaving 8MB then test allocing 7...
   190 	r = gobbler.Open();
   191 	test(r==KErrNone);
   192 	taken = gobbler.GobbleRAM(8*1024*1024);
   193 	test.Printf(_L("Gobbled: %dK freeRam %dK\n"), taken/1024, FreeRam()/1024);
   194 	// allocate 7mb
   195 	r=TimedCall(AllocateChunk,t,1,7);
   196 	if (r==KErrNone)
   197 		{
   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);
   201 		}
   202 	else
   203 		test.Printf(_L("Alloc chunk 7Mb failed! %d\n"), r);
   204 	gobbler.Close();
   205 
   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);
   213 
   214 	test.End();
   215 	return 0;
   216 	}