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.
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_mmubm.cpp
sl@0
    15
// Overview:
sl@0
    16
// Time MMU allocation & deallocation
sl@0
    17
// API Information:
sl@0
    18
// RChunk
sl@0
    19
// Details:
sl@0
    20
// - Allocate and release a 1 MB chunk 100 times and time how long it takes.
sl@0
    21
// - Allocate and release a 2 MB chunk 100 times and time how long it takes.
sl@0
    22
// - Allocate and release a 7 MB chunk 100 times and time how long it takes.
sl@0
    23
// - Allocate a 7 MB chunk once and time how long it takes.
sl@0
    24
// - Deallocate a 7 MB chunk once and time how long it takes.
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
sl@0
    35
#include <e32test.h>
sl@0
    36
#include "mmudetect.h"
sl@0
    37
#include "d_gobble.h"
sl@0
    38
#include "d_memorytest.h"
sl@0
    39
#include "freeram.h"
sl@0
    40
sl@0
    41
RTest test(_L("T_MMUBM"));
sl@0
    42
sl@0
    43
typedef TInt (*TestFunction)(TUint32 aIters, TUint32 aSize);
sl@0
    44
sl@0
    45
RMemoryTestLdd MemoryTest;
sl@0
    46
RChunk TheChunk;
sl@0
    47
sl@0
    48
LOCAL_C TInt AllocPhysical(TUint32 aIters, TUint32 aSize)
sl@0
    49
	{
sl@0
    50
	return MemoryTest.AllocPhysTest(aIters, aSize * 0x00100000);
sl@0
    51
	}
sl@0
    52
sl@0
    53
LOCAL_C TInt AllocPhysical1(TUint32 aIters, TUint32 aSize)
sl@0
    54
	{
sl@0
    55
	return MemoryTest.AllocPhysTest1(aIters, aSize * 0x00100000);
sl@0
    56
	}
sl@0
    57
sl@0
    58
LOCAL_C TInt AdjustChunk(TUint32 aIters, TUint32 aSize)
sl@0
    59
	{
sl@0
    60
	TUint32 i;
sl@0
    61
	for (i=0; i<aIters; i++)
sl@0
    62
		{
sl@0
    63
		TInt r=TheChunk.Adjust(aSize * 0x00100000);
sl@0
    64
		if (r!=KErrNone)
sl@0
    65
			return r;
sl@0
    66
		r=TheChunk.Adjust(0);
sl@0
    67
		if (r!=KErrNone)
sl@0
    68
			return r;
sl@0
    69
		}
sl@0
    70
	return KErrNone;
sl@0
    71
	}
sl@0
    72
sl@0
    73
LOCAL_C TInt AllocateChunk(TUint32 aIters, TUint32 aSize)
sl@0
    74
	{
sl@0
    75
	aIters = aSize;
sl@0
    76
	return TheChunk.Adjust(aSize * 0x00100000);
sl@0
    77
	}
sl@0
    78
sl@0
    79
LOCAL_C TInt DeallocateChunk(TUint32 , TUint32 )
sl@0
    80
	{
sl@0
    81
	return TheChunk.Adjust(0);
sl@0
    82
	}
sl@0
    83
sl@0
    84
LOCAL_C TInt TimedCall(TestFunction aFunction, TUint32& aTime, TUint32 aIters, TUint32 aSize)
sl@0
    85
	{
sl@0
    86
	TUint32 before=User::NTickCount();
sl@0
    87
	TInt r=(*aFunction)(aIters, aSize);
sl@0
    88
	TUint32 after=User::NTickCount();
sl@0
    89
	aTime=after-before;
sl@0
    90
	return r;
sl@0
    91
	}
sl@0
    92
sl@0
    93
#define DO_TEST(__ret, __func, __time, __iters, __size)\
sl@0
    94
	tempSize = __size;\
sl@0
    95
	__ret=TimedCall(__func, __time, __iters, __size);\
sl@0
    96
	if (__ret==KErrNone)\
sl@0
    97
		{\
sl@0
    98
		test.Printf(_L("  %dMb %d times ... %d ms\n"),__size, __iters,__time);\
sl@0
    99
		}\
sl@0
   100
	else if (tempSize < 7)\
sl@0
   101
		{\
sl@0
   102
		test(__ret==KErrNone);\
sl@0
   103
		}
sl@0
   104
sl@0
   105
#define DO_TEST_GOB(__ret, __func, __time, __iters, __size, __rem,__taken)\
sl@0
   106
	tempSize = __size;\
sl@0
   107
	__ret = gobbler.Open();\
sl@0
   108
	test(__ret==KErrNone);\
sl@0
   109
	/* gobble leaving x+1MB then test adjusting to x...*/\
sl@0
   110
	__taken = gobbler.GobbleRAM(__rem*1024*1024);\
sl@0
   111
	test.Printf(_L("Gobbled: %dK freeRam %dK\n"), __taken/1024, FreeRam()/1024);\
sl@0
   112
	/* adjust to 1MB*/\
sl@0
   113
	__ret=TimedCall(__func, __time, __iters, __size);\
sl@0
   114
	if (__ret==KErrNone)\
sl@0
   115
		{\
sl@0
   116
		test.Printf(_L(" %dMb %d times ... %d ms\n"),__size, __iters,__time);\
sl@0
   117
		}\
sl@0
   118
	else if (tempSize < 7)\
sl@0
   119
		{\
sl@0
   120
		test(__ret==KErrNone);\
sl@0
   121
		}\
sl@0
   122
	gobbler.Close();
sl@0
   123
	
sl@0
   124
sl@0
   125
GLDEF_C TInt E32Main()
sl@0
   126
	{
sl@0
   127
sl@0
   128
	test.Title();
sl@0
   129
	if (!HaveVirtMem())
sl@0
   130
		{
sl@0
   131
		test.Printf(_L("This test requires an MMU\n"));
sl@0
   132
		return KErrNone;
sl@0
   133
		}
sl@0
   134
	test.Start(_L("Timing MMU allocation/deallocation..."));
sl@0
   135
sl@0
   136
	test(KErrNone==MemoryTest.Open());
sl@0
   137
sl@0
   138
	TInt r;
sl@0
   139
	TUint32 t;
sl@0
   140
	TUint32 tempSize;
sl@0
   141
	r=TheChunk.CreateLocal(0,0x01000000);
sl@0
   142
	test(r==KErrNone);
sl@0
   143
sl@0
   144
	test.Printf(_L("Adjusting Chunks\n"));
sl@0
   145
	DO_TEST(r, AdjustChunk, t, 100, 1);
sl@0
   146
	DO_TEST(r, AdjustChunk, t, 100, 2);
sl@0
   147
	DO_TEST(r, AdjustChunk, t, 100, 7);
sl@0
   148
	r=TimedCall(AllocateChunk,t,1,7);
sl@0
   149
	if (r==KErrNone)
sl@0
   150
		{
sl@0
   151
		test.Printf(_L("Allocate 7Mb once ... %d ms\n"),t);
sl@0
   152
		r=TimedCall(DeallocateChunk,t, 1, 0);
sl@0
   153
		test.Printf(_L("Deallocate 7Mb once ... %d ms\n"),t);
sl@0
   154
		}
sl@0
   155
	else
sl@0
   156
		{
sl@0
   157
		test.Printf(_L("Alloc chunk 7Mb failed! %d\n"), r);
sl@0
   158
		}
sl@0
   159
	
sl@0
   160
	test.Next(_L("Test physical memory allocations...."));
sl@0
   161
sl@0
   162
	DO_TEST(r, AllocPhysical, t, 100, 1);
sl@0
   163
	DO_TEST(r, AllocPhysical1, t, 100, 1);
sl@0
   164
	DO_TEST(r, AllocPhysical, t, 100, 2);
sl@0
   165
	DO_TEST(r, AllocPhysical1, t, 100, 2);
sl@0
   166
	DO_TEST(r, AllocPhysical, t, 100, 7);
sl@0
   167
	DO_TEST(r, AllocPhysical1, t, 100, 7);
sl@0
   168
sl@0
   169
	test.Next(_L("Now the test with low memory...."));
sl@0
   170
sl@0
   171
	r = User::LoadLogicalDevice(KGobblerLddFileName);
sl@0
   172
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   173
sl@0
   174
	RGobbler gobbler;
sl@0
   175
	TUint32 taken = 0;
sl@0
   176
sl@0
   177
	DO_TEST_GOB(r, AdjustChunk, t, 100, 1, 2, taken);
sl@0
   178
	DO_TEST_GOB(r, AdjustChunk, t, 100, 2, 3, taken);
sl@0
   179
	DO_TEST_GOB(r, AdjustChunk, t, 100, 7, 8, taken);
sl@0
   180
sl@0
   181
	r=TimedCall(AllocateChunk,t,1,7);
sl@0
   182
	if (r==KErrNone)
sl@0
   183
		{
sl@0
   184
		test.Printf(_L("Allocate 7Mb once ... %d ms\n"),t);
sl@0
   185
		r=TimedCall(DeallocateChunk,t, 1, 0);
sl@0
   186
		test.Printf(_L("Deallocate 7Mb once ... %d ms\n"),t);
sl@0
   187
		}
sl@0
   188
sl@0
   189
	// gobble leaving 8MB then test allocing 7...
sl@0
   190
	r = gobbler.Open();
sl@0
   191
	test(r==KErrNone);
sl@0
   192
	taken = gobbler.GobbleRAM(8*1024*1024);
sl@0
   193
	test.Printf(_L("Gobbled: %dK freeRam %dK\n"), taken/1024, FreeRam()/1024);
sl@0
   194
	// allocate 7mb
sl@0
   195
	r=TimedCall(AllocateChunk,t,1,7);
sl@0
   196
	if (r==KErrNone)
sl@0
   197
		{
sl@0
   198
		test.Printf(_L("Allocate 7Mb once ... %d ms\n"),t);
sl@0
   199
		r=TimedCall(DeallocateChunk,t, 1, 0);
sl@0
   200
		test.Printf(_L("Deallocate 7Mb once ... %d ms\n"),t);
sl@0
   201
		}
sl@0
   202
	else
sl@0
   203
		test.Printf(_L("Alloc chunk 7Mb failed! %d\n"), r);
sl@0
   204
	gobbler.Close();
sl@0
   205
sl@0
   206
	test.Next(_L("Test physical memory allocations with low memory...."));
sl@0
   207
	DO_TEST_GOB(r, AllocPhysical, t, 100, 1, 2, taken);
sl@0
   208
	DO_TEST_GOB(r, AllocPhysical1, t, 100, 1, 2, taken);
sl@0
   209
	DO_TEST_GOB(r, AllocPhysical, t, 100, 2, 3, taken);
sl@0
   210
	DO_TEST_GOB(r, AllocPhysical1, t, 100, 2, 3, taken);
sl@0
   211
	DO_TEST_GOB(r, AllocPhysical, t, 100, 7, 8, taken);
sl@0
   212
	DO_TEST_GOB(r, AllocPhysical1, t, 100, 7, 8, taken);
sl@0
   213
sl@0
   214
	test.End();
sl@0
   215
	return 0;
sl@0
   216
	}