kerneltest/e32test/mmu/t_cachechunk.cpp
author hgs
Wed, 23 Jun 2010 12:52:28 +0100
changeset 176 af6ec97d9189
parent 132 e4a7b1cbe40c
child 229 07a685bbdd3d
permissions -rw-r--r--
201023_13
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
     1
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
     2
// All rights reserved.
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
     3
// This component and the accompanying materials are made available
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
     4
// under the terms of the License "Eclipse Public License v1.0"
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
     5
// which accompanies this distribution, and is available
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
     7
//
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
     8
// Initial Contributors:
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    10
//
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    11
// Contributors:
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    12
//
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    13
// Description:
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    14
// e32test\mmu\t_chunk.cpp
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    15
// Tests on RChunk objects in connection with demand paging.
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    16
// Tests exercise the locking, unlocking, commiting and decommiting of 
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    17
// pages to chunk objects.
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    18
// 1  Check Unlocked page gets counted as free memory
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    19
// 2  Check Unlock/Lock preserves page contents
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    20
// 3  Tests at chunk offset '0'
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    21
// 4    Check Lock is idempotent
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    22
// 5    Check non page aligned Unlock/Lock
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    23
// 6    Check unlocked pages get reclaimed for new memory allocation
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    24
// 7    Check reclaimed memory is unmapped from original location
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    25
// 8    Check Lock fails when memory is reclaimed
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    26
// 9    Check Lock failure Decommits memory
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    27
// 10   Recommit memory to chunk
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    28
// 11   Check Commit on unlocked pages
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    29
// 12   Check Commit on unlocked and reclaimed pages
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    30
// 13   Restore chunk
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    31
// 14 Tests at chunk offset 'PageSize'
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    32
// 15   Check Lock is idempotent
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    33
// 16   Check non page aligned Unlock/Lock
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    34
// 17   Check unlocked pages get reclaimed for new memory allocation
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    35
// 18   Check reclaimed memory is unmapped from original location
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    36
// 19   Check Lock fails when memory is reclaimed
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    37
// 20   Check Lock failure Decommits memory
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    38
// 21   Recommit memory to chunk
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    39
// 22   Check Commit on unlocked pages
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    40
// 23   Check Commit on unlocked and reclaimed pages
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    41
// 24   Restore chunk
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    42
// 25 Tests at chunk offset '0x100000-PageSize'
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    43
// 26   Check Lock is idempotent
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    44
// 27   Check non page aligned Unlock/Lock
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    45
// 28   Check unlocked pages get reclaimed for new memory allocation
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    46
// 29   Check reclaimed memory is unmapped from original location
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    47
// 30   Check Lock fails when memory is reclaimed
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    48
// 31   Check Lock failure Decommits memory
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    49
// 32   Recommit memory to chunk
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    50
// 33   Check Commit on unlocked pages
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    51
// 34   Check Commit on unlocked and reclaimed pages
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    52
// 35   Restore chunk
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    53
// 36 Tests at chunk offset '0x400000-PageSize'
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    54
// 37   Check Lock is idempotent
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    55
// 38   Check non page aligned Unlock/Lock
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    56
// 39   Check unlocked pages get reclaimed for new memory allocation
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    57
// 40   Check reclaimed memory is unmapped from original location
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    58
// 41   Check Lock fails when memory is reclaimed
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    59
// 42   Check Lock failure Decommits memory
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    60
// 43   Recommit memory to chunk
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    61
// 44 Check Commit on unlocked pages
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    62
// 45 Check Commit on unlocked and reclaimed pages
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    63
// 46 Restore chunk
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    64
// 47 Big Unlock/Lock
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    65
// 48 Benchmarks...
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    66
// 49 Close chunk with unlocked pages which have been flushed
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    67
// 
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    68
//
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    69
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    70
//! @SYMTestCaseID			KBASE-T_CACHECHUNK-0336
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    71
//! @SYMTestType			UT
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    72
//! @SYMPREQ				PREQ1110
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    73
//! @SYMTestCaseDesc		Demand Paging Loader Stress Tests
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    74
//! @SYMTestActions			0  Commit all of memory
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    75
//! @SYMTestExpectedResults All tests should pass.
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    76
//! @SYMTestPriority        High
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    77
//! @SYMTestStatus          Implemented
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    78
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    79
#define __E32TEST_EXTENSION__
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    80
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    81
#include <e32test.h>
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    82
#include <e32panic.h>
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    83
#include <e32svr.h>
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    84
#include <hal.h>
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    85
#include "mmudetect.h"
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    86
#include "d_memorytest.h"
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    87
#include "d_gobble.h"
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    88
#include <dptest.h>
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    89
#include "freeram.h"
176
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
    90
#include "..\demandpaging\t_dpcmn.h"
0
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    91
176
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
    92
RTest test(_L("T_CACHECHUNK"));
0
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    93
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    94
RMemoryTestLdd MemoryTest;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    95
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    96
RChunk TestChunk;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    97
TUint8* TestChunkBase;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    98
TInt CommitEnd;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
    99
TInt PageSize;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   100
TInt NoFreeRam;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   101
RTimer Timer;
132
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   102
TBool gFmm;
0
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   103
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   104
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   105
void FillPage(TUint aOffset)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   106
	{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   107
	TUint8* ptr = TestChunkBase+aOffset;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   108
	TUint8* ptrEnd = ptr+PageSize;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   109
	do *((TUint32*&)ptr)++ = aOffset+=4;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   110
	while(ptr<ptrEnd);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   111
	}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   112
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   113
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   114
TBool CheckPage(TUint aOffset)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   115
	{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   116
	TUint8* ptr = TestChunkBase+aOffset;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   117
	TUint8* ptrEnd = ptr+PageSize;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   118
	do if(*((TUint32*&)ptr)++ != (aOffset+=4)) break;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   119
	while(ptr<ptrEnd);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   120
	return ptr==ptrEnd;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   121
	}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   122
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   123
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   124
TBool CheckPages(TUint aOffset, TInt aNumPages)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   125
	{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   126
	while(aNumPages--)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   127
		if(!CheckPage(aOffset+=PageSize))
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   128
			return EFalse;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   129
	return ETrue;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   130
	}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   131
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   132
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   133
TBool IsPageMapped(TUint aOffset)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   134
	{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   135
	TUint32 value;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   136
	TInt r=MemoryTest.ReadMemory(TestChunkBase+aOffset,value);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   137
	return r==KErrNone;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   138
	}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   139
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   140
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   141
void Tests(TInt aOffset)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   142
	{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   143
	if(aOffset+5*PageSize>=CommitEnd)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   144
		{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   145
		test.Start(_L("TEST NOT RUN - Not enough system RAM"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   146
		test.End();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   147
		return;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   148
		}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   149
	TInt r;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   150
	TInt freeRam;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   151
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   152
	TUint origChunkSize = TestChunk.Size();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   153
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   154
	test.Start(_L("Check Unlock is idempotent"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   155
	r = TestChunk.Unlock(aOffset+PageSize,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   156
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   157
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   158
	test(freeRam==NoFreeRam+PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   159
	r = TestChunk.Unlock(aOffset+PageSize,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   160
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   161
	test_Equal(FreeRam(), freeRam);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   162
	// Ensure unlock on reclaimed pages is idempotent
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   163
	TInt flushSupported = UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   164
	r = TestChunk.Unlock(aOffset+PageSize,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   165
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   166
	test_Equal(FreeRam(), freeRam);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   167
	test_Equal(origChunkSize, TestChunk.Size());
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   168
	
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   169
	if (flushSupported == KErrNotSupported)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   170
		{// Flush cache not supported so lock won't fail so no need to recommit the pages.
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   171
		test_KErrNone(TestChunk.Lock(aOffset+PageSize,PageSize));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   172
		}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   173
	else
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   174
		{// Recommit the reclaimed pages.
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   175
		test_KErrNone(flushSupported);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   176
		test_Equal(KErrNotFound, TestChunk.Lock(aOffset+PageSize,PageSize));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   177
		test_KErrNone(TestChunk.Commit(aOffset+PageSize,PageSize));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   178
		}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   179
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   180
	test.Next(_L("Check Lock is idempotent"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   181
	r = TestChunk.Lock(aOffset,3*PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   182
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   183
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   184
	test(freeRam==NoFreeRam);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   185
	CheckPages(aOffset,3);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   186
	r = TestChunk.Lock(aOffset,3*PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   187
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   188
	CheckPages(aOffset,3);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   189
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   190
	test(freeRam==NoFreeRam);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   191
	test_Equal(origChunkSize, TestChunk.Size());
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   192
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   193
	test.Next(_L("Check non page aligned Unlock/Lock"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   194
	r = TestChunk.Unlock(aOffset+PageSize-1,1);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   195
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   196
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   197
	test(freeRam==NoFreeRam+PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   198
	r = TestChunk.Lock(aOffset+PageSize-1,1);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   199
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   200
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   201
	test(freeRam==NoFreeRam);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   202
	r = TestChunk.Unlock(aOffset+PageSize-1,2);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   203
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   204
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   205
	test(freeRam==NoFreeRam+PageSize*2);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   206
	r = TestChunk.Lock(aOffset+PageSize-1,2);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   207
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   208
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   209
	test(freeRam==NoFreeRam);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   210
	test_Equal(origChunkSize, TestChunk.Size());
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   211
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   212
	test.Next(_L("Check unlocked pages get reclaimed for new memory allocation"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   213
	r=TestChunk.Commit(CommitEnd,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   214
	test(r==KErrNoMemory);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   215
	r = TestChunk.Unlock(aOffset,4*PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   216
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   217
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   218
	test(freeRam==NoFreeRam+PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   219
	r=TestChunk.Commit(CommitEnd,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   220
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   221
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   222
	test(freeRam<NoFreeRam+PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   223
	r=TestChunk.Decommit(CommitEnd,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   224
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   225
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   226
	test(freeRam==NoFreeRam+PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   227
	UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0); // make sure unlocked page is gone
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   228
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   229
	test(freeRam==NoFreeRam+PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   230
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   231
#ifndef __WINS__ // wins fakery doesn't actually do this
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   232
	test.Next(_L("Check reclaimed memory is unmapped and decommitted from original location"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   233
	TInt mappedPages = IsPageMapped(aOffset+PageSize*0);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   234
	mappedPages += IsPageMapped(aOffset+PageSize*1);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   235
	mappedPages += IsPageMapped(aOffset+PageSize*2);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   236
	mappedPages += IsPageMapped(aOffset+PageSize*3);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   237
	test(mappedPages<4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   238
#endif
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   239
	if(aOffset>PageSize)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   240
		{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   241
		test(CheckPage(aOffset+PageSize*-1)); // should be left mapped
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   242
		}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   243
	test(CheckPage(aOffset+PageSize*4)); // should be left mapped
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   244
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   245
	test.Next(_L("Check Lock fails when memory is reclaimed"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   246
	r = TestChunk.Lock(aOffset,4*PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   247
	test(r==KErrNotFound);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   248
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   249
	test(freeRam==NoFreeRam+PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   250
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   251
	test.Next(_L("Check Lock failure Decommits memory"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   252
	test(!IsPageMapped(aOffset+PageSize*0));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   253
	test(!IsPageMapped(aOffset+PageSize*1));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   254
	test(!IsPageMapped(aOffset+PageSize*2));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   255
	test(!IsPageMapped(aOffset+PageSize*3));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   256
	test_Equal(origChunkSize-PageSize*4, TestChunk.Size());
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   257
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   258
	test.Next(_L("Recommit memory to chunk"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   259
	TInt offset;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   260
	for(offset=aOffset; offset<aOffset+PageSize*4; offset+=PageSize)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   261
		{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   262
		r=TestChunk.Commit(offset,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   263
		test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   264
		FillPage(offset);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   265
		}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   266
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   267
	test(freeRam==NoFreeRam);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   268
	test_Equal(origChunkSize, TestChunk.Size());
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   269
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   270
	test.Next(_L("Check Commit on unlocked pages"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   271
	r = TestChunk.Unlock(aOffset,4*PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   272
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   273
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   274
	test(freeRam>=NoFreeRam+PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   275
	r=TestChunk.Commit(aOffset,4*PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   276
	test(r==KErrAlreadyExists);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   277
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   278
	test(freeRam>=NoFreeRam+PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   279
	test_Equal(origChunkSize, TestChunk.Size());
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   280
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   281
	test.Next(_L("Check Commit on unlocked and reclaimed pages"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   282
	// unlock and force a page to be reclaimed...
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   283
	r=TestChunk.Commit(CommitEnd,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   284
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   285
	r=TestChunk.Decommit(CommitEnd,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   286
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   287
	UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0); // make sure unlocked page is gone
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   288
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   289
	test(freeRam>=NoFreeRam+PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   290
	// check can't commit any pages (because they are unlocked, not decommitted)...
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   291
	r=TestChunk.Commit(aOffset+PageSize*0,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   292
	test(r==KErrAlreadyExists);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   293
	r=TestChunk.Commit(aOffset+PageSize*1,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   294
	test(r==KErrAlreadyExists);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   295
	r=TestChunk.Commit(aOffset+PageSize*2,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   296
	test(r==KErrAlreadyExists);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   297
	r=TestChunk.Commit(aOffset+PageSize*3,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   298
	test(r==KErrAlreadyExists);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   299
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   300
	test(freeRam>=NoFreeRam+PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   301
	test_Equal(origChunkSize, TestChunk.Size());
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   302
	// Restore the chunk to original size.
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   303
	r = TestChunk.Lock(aOffset,4*PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   304
	test_Equal(r, KErrNotFound);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   305
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   306
	test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   307
	test_Equal(origChunkSize - PageSize*4, TestChunk.Size());
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   308
	r = TestChunk.Commit(aOffset, PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   309
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   310
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   311
	test.Next(_L("Check Decommit on unlocked pages"));
132
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   312
	// Get orignal page cache size
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   313
	TUint minCache = 0;
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   314
	TUint maxCache = 0;
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   315
	TUint oldCache = 0;
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   316
	TUint newCache = 0;
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   317
	if (gFmm)
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   318
		{
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   319
		r = DPTest::CacheSize(minCache, maxCache, oldCache);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   320
		test_KErrNone(r);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   321
		}
0
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   322
	r = TestChunk.Unlock(aOffset,PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   323
	test_KErrNone(r);
132
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   324
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   325
	TUint spareCache = maxCache - oldCache;
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   326
	if (gFmm && spareCache)
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   327
		{// Cache wasn't at maximum so should have grown when unlocked pages were added.
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   328
		r = DPTest::CacheSize(minCache, maxCache, newCache);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   329
		test_KErrNone(r);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   330
		TUint extraCache = (spareCache > (TUint)PageSize*4)? PageSize*4 : spareCache;
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   331
		test_Equal(oldCache + extraCache, newCache);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   332
		}
0
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   333
	test(FreeRam() >= NoFreeRam+PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   334
	r=TestChunk.Decommit(aOffset, PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   335
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   336
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   337
	test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   338
	test_Equal(origChunkSize - PageSize*4, TestChunk.Size());
132
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   339
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   340
	if (gFmm)
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   341
		{// Cache should have shrunk after pages were decommited.
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   342
		r = DPTest::CacheSize(minCache, maxCache, newCache);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   343
		test_KErrNone(r);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   344
		test_Equal(oldCache, newCache);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   345
		}
0
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   346
	// Restore chunk back to original state
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   347
	r = TestChunk.Commit(aOffset, PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   348
	test_KErrNone(r);
132
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   349
	test_Equal(NoFreeRam, FreeRam());
0
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   350
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   351
	test.Next(_L("Check Decommit on unlocked and reclaimed pages"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   352
	r = TestChunk.Unlock(aOffset,PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   353
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   354
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   355
	test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   356
	r=TestChunk.Commit(CommitEnd,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   357
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   358
	r=TestChunk.Decommit(CommitEnd,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   359
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   360
	UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0); // make sure unlocked page is gone
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   361
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   362
	test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   363
	r=TestChunk.Decommit(aOffset, PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   364
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   365
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   366
	test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   367
	test_Equal(origChunkSize - PageSize*4, TestChunk.Size());
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   368
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   369
	test.Next(_L("Restore chunk"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   370
	test_Equal(origChunkSize-PageSize*4, TestChunk.Size());
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   371
	for(offset=aOffset; offset<aOffset+PageSize*4; offset+=PageSize)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   372
		{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   373
		r=TestChunk.Commit(offset,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   374
		test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   375
		FillPage(offset);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   376
		}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   377
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   378
	test(freeRam==NoFreeRam);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   379
	test_Equal(origChunkSize, TestChunk.Size());
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   380
132
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   381
	test.Next(_L("Check Decommit on a mixture of locked and unlocked pages"));
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   382
	// Get orignal page cache size
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   383
	if (gFmm)
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   384
		{
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   385
		r = DPTest::CacheSize(minCache, maxCache, oldCache);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   386
		test_KErrNone(r);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   387
		}
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   388
	r = TestChunk.Unlock(aOffset,PageSize);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   389
	test_KErrNone(r);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   390
	r = TestChunk.Unlock(aOffset + PageSize*2, PageSize);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   391
	test_KErrNone(r);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   392
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   393
	spareCache = maxCache - oldCache;
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   394
	if (gFmm && spareCache)
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   395
		{// Cache wasn't at maximum so should have grown when unlocked pages were added.
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   396
		r = DPTest::CacheSize(minCache, maxCache, newCache);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   397
		test_KErrNone(r);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   398
		TUint extraCache = (spareCache > (TUint)PageSize*2)? PageSize*2 : spareCache;
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   399
		test_Equal(oldCache + extraCache, newCache);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   400
		}
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   401
	test(FreeRam() >= NoFreeRam+PageSize*2);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   402
	r=TestChunk.Decommit(aOffset, PageSize*4);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   403
	test_KErrNone(r);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   404
	freeRam = FreeRam();
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   405
	test_Compare(freeRam, >=, NoFreeRam+PageSize*4);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   406
	test_Equal(origChunkSize - PageSize*4, TestChunk.Size());
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   407
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   408
	if (gFmm)
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   409
		{// Cache should have shrunk after pages were decommited.
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   410
		r = DPTest::CacheSize(minCache, maxCache, newCache);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   411
		test_KErrNone(r);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   412
		test_Equal(oldCache, newCache);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   413
		}
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   414
	// Restore chunk back to original state
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   415
	r = TestChunk.Commit(aOffset, PageSize*4);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   416
	test_KErrNone(r);
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   417
	test_Equal(NoFreeRam, FreeRam());
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   418
0
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   419
	test.End();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   420
	}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   421
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   422
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   423
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   424
void TestBenchmarks()
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   425
	{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   426
	TInt r = TestChunk.Unlock(0,CommitEnd); // start with everthing unlocked
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   427
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   428
	TInt testSizes[] = { PageSize,1<<16,1<<20,0 };
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   429
	TInt* sizes = testSizes;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   430
	TInt size;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   431
	while((size=*sizes++)!=0)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   432
		{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   433
		TRequestStatus status;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   434
		Timer.After(status,1);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   435
		User::WaitForRequest(status);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   436
		TInt KRunTime = 1*1000*1000;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   437
		Timer.After(status,KRunTime);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   438
		TInt count = 0;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   439
		while(status==KRequestPending)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   440
			{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   441
			r = TestChunk.Lock(0,size);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   442
			test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   443
			r = TestChunk.Unlock(0,size);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   444
			test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   445
			++count;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   446
			}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   447
		User::WaitForRequest(status);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   448
		test.Printf(_L("Unlock/Lock of %d kB takes %d us\n"),size>>10,KRunTime/count);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   449
		}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   450
	}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   451
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   452
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   453
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   454
void TestUnlockOld()
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   455
	{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   456
	// we start with TestChunk being locked and no or little free RAM
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   457
	// (hence live list should be close to minimum size.)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   458
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   459
	// get sizes...
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   460
	TUint min = 0;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   461
	TUint max = 0;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   462
	TUint cur = 0;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   463
	TInt r = DPTest::CacheSize(min,max,cur);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   464
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   465
	// manipulate demand paging live list so we end up with zero old pages...
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   466
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   467
	r = TestChunk.Unlock(0,min*2); // dump 2*min bytes at start of live list
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   468
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   469
	// live list now cur+2*min bytes
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   470
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   471
	r = TestChunk.Commit(CommitEnd,cur); // use up 'cur' bytes of RAM from end of live list
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   472
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   473
	// live list now 2*min bytes of pages which were unlocked from our test chunk
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   474
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   475
	// lock pages until free RAM is <= 2 pages.
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   476
	// this should remove all of the 'old' pages
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   477
	TUint i = 0;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   478
	while(FreeRam()>2*PageSize)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   479
		{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   480
		TestChunk.Lock(i,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   481
		i += PageSize;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   482
		test(i<=min);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   483
		}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   484
	// live list now min+2*PageSize bytes, with no old pages
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   485
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   486
	// now commit memory, which forces allocation from the demand paging live list
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   487
	// which doesn't have any old pages (the purpose of this test)...
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   488
	TUint extra = 0;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   489
	for(;;)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   490
		{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   491
		r = TestChunk.Commit(CommitEnd+min+extra,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   492
		if(r==KErrNoMemory)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   493
			break;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   494
		extra += PageSize;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   495
		}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   496
	test(extra>0);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   497
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   498
	// restore commit state...
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   499
	r = TestChunk.Decommit(CommitEnd,min+extra);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   500
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   501
	r = TestChunk.Decommit(0,min*2);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   502
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   503
	r = TestChunk.Commit(0,min*2);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   504
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   505
	}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   506
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   507
176
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   508
TBool StopCacheThreads;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   509
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   510
TInt CacheThreadFunc(TAny* aMax)
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   511
	{
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   512
	RThread::Rendezvous(KErrNone);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   513
	while (!StopCacheThreads)
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   514
		{
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   515
		TInt maxSize = (TInt)aMax;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   516
		TInt minSize;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   517
		TInt r = KErrNone;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   518
		for (minSize = PageSize << 4; r == KErrNone && !StopCacheThreads; minSize += PageSize)
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   519
			{
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   520
			r = UserSvr::HalFunction(EHalGroupVM,EVMHalSetCacheSize,(TAny*)minSize,(TAny*)maxSize);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   521
			User::After(minSize/PageSize);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   522
			}
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   523
		for (minSize -= PageSize; 
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   524
			minSize > PageSize << 4 && r == KErrNone  && !StopCacheThreads;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   525
			minSize -= PageSize)
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   526
			{
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   527
			r = UserSvr::HalFunction(EHalGroupVM,EVMHalSetCacheSize,(TAny*)minSize,(TAny*)maxSize);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   528
			User::After(minSize/PageSize);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   529
			}
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   530
		}
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   531
	return KErrNone;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   532
	}
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   533
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   534
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   535
TInt DonateThreadFunc(TAny*)
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   536
	{
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   537
	TChunkCreateInfo createInfo;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   538
	createInfo.SetCache(100 * PageSize);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   539
	RChunk chunk;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   540
	TInt r = chunk.Create(createInfo);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   541
	if (r != KErrNone)
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   542
		{
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   543
		RDebug::Printf("DonateThreadFunc: Failed to create cache chunk %d", r);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   544
		return r;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   545
		}
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   546
	TUint chunkEnd = 0;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   547
	while (chunk.Commit(chunkEnd, PageSize) == KErrNone)
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   548
		chunkEnd += PageSize;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   549
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   550
	RThread::Rendezvous(KErrNone);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   551
	while (!StopCacheThreads)
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   552
		{
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   553
		for (TUint i = PageSize; i <= chunkEnd && !StopCacheThreads; i += PageSize)
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   554
			{
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   555
			chunk.Unlock(0, i);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   556
			if (chunk.Lock(0, i) != KErrNone)
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   557
				{// Recommit as many pages as possible.
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   558
				while (chunk.Commit(0, chunkEnd) != KErrNone && !StopCacheThreads)
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   559
					chunkEnd -= PageSize;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   560
				i = 0;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   561
				}
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   562
			User::After(i/PageSize);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   563
			}
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   564
		}
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   565
	CLOSE_AND_WAIT(chunk);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   566
	return KErrNone;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   567
	}
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   568
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   569
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   570
TInt DirtyThreadFunc(TAny*)
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   571
	{
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   572
	RThread::Rendezvous(KErrNone);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   573
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   574
	RChunk chunk;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   575
	TChunkCreateInfo createInfo;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   576
	createInfo.SetNormal(PageSize * 100, PageSize *100);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   577
	createInfo.SetPaging(TChunkCreateInfo::EPaged);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   578
	TInt r = chunk.Create(createInfo);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   579
	if (r != KErrNone)
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   580
		{
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   581
		RDebug::Printf("Failed to create a cache chunk %d", r);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   582
		return r;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   583
		}
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   584
	TUint8* base = chunk.Base();
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   585
	// Dirty each page in the chunk so that there are dirty pages in the live 
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   586
	// list while it is being resized and pages are being unlocked.
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   587
	while (!StopCacheThreads)
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   588
		{
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   589
		TUint8* p = base;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   590
		TUint8* pEnd = base + chunk.Size();
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   591
		for (; p < pEnd && !StopCacheThreads; p += PageSize)
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   592
			{
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   593
			*p = (TUint8)(pEnd - p);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   594
			User::After((TUint8)(pEnd - p));
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   595
			}
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   596
		}
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   597
	CLOSE_AND_WAIT(chunk);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   598
	return KErrNone;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   599
	}
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   600
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   601
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   602
void TestResizeExcess()
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   603
	{
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   604
	test.Printf(_L("Commit all of memory again leaving 100 free pages\n"));
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   605
	CommitEnd = 0;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   606
	TInt r;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   607
	while(KErrNone==(r=TestChunk.Commit(CommitEnd,PageSize)))
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   608
		{
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   609
		CommitEnd += PageSize;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   610
		}
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   611
	test(r==KErrNoMemory);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   612
	test_KErrNone(TestChunk.Unlock(0, 100 * PageSize));
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   613
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   614
	SVMCacheInfo info;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   615
	test_KErrNone(UserSvr::HalFunction(EHalGroupVM, EVMHalGetCacheSize, &info, 0));
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   616
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   617
	StopCacheThreads = EFalse;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   618
	RThread cacheThread;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   619
	r = cacheThread.Create(	KNullDesC, CacheThreadFunc, KDefaultStackSize, PageSize,
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   620
							PageSize, (TAny*)info.iMaxSize);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   621
	test_KErrNone(r);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   622
	TRequestStatus threadStarted;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   623
	cacheThread.Rendezvous(threadStarted);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   624
	TRequestStatus cacheStatus;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   625
	cacheThread.Logon(cacheStatus);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   626
	cacheThread.Resume();
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   627
	User::WaitForRequest(threadStarted);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   628
	test_KErrNone(threadStarted.Int());
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   629
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   630
	// Create the dirty thread before the donate thread as the donate thread may
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   631
	// consume all the free ram periodically.
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   632
	RThread dirtyThread;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   633
	r = dirtyThread.Create(KNullDesC, DirtyThreadFunc, KDefaultStackSize, PageSize, PageSize, NULL);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   634
	test_KErrNone(r);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   635
	dirtyThread.Rendezvous(threadStarted);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   636
	TRequestStatus dirtyStatus;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   637
	dirtyThread.Logon(dirtyStatus);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   638
	dirtyThread.Resume();
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   639
	User::WaitForRequest(threadStarted);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   640
	test_KErrNone(threadStarted.Int());
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   641
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   642
	RThread donateThread;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   643
	r = donateThread.Create(KNullDesC, DonateThreadFunc, KDefaultStackSize, PageSize, PageSize, NULL);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   644
	test_KErrNone(r);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   645
	donateThread.Rendezvous(threadStarted);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   646
	TRequestStatus donateStatus;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   647
	donateThread.Logon(donateStatus);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   648
	donateThread.Resume();
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   649
	User::WaitForRequest(threadStarted);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   650
	test_KErrNone(threadStarted.Int());
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   651
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   652
	// Run test for 10 secs.
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   653
	User::After(10000000);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   654
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   655
	// End the test.
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   656
	StopCacheThreads = ETrue;
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   657
	User::WaitForRequest(donateStatus);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   658
	test_Equal(EExitKill, donateThread.ExitType());
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   659
	test_KErrNone(donateThread.ExitReason());
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   660
	User::WaitForRequest(dirtyStatus);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   661
	test_Equal(EExitKill, dirtyThread.ExitType());
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   662
	test_KErrNone(dirtyThread.ExitReason());
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   663
	User::WaitForRequest(cacheStatus);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   664
	test_Equal(EExitKill, cacheThread.ExitType());
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   665
	test_KErrNone(cacheThread.ExitReason());
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   666
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   667
	CLOSE_AND_WAIT(donateThread);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   668
	CLOSE_AND_WAIT(cacheThread);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   669
	CLOSE_AND_WAIT(dirtyThread);
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   670
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   671
	test_KErrNone(UserSvr::HalFunction(	EHalGroupVM,
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   672
										EVMHalSetCacheSize,
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   673
										(TAny*)info.iMinSize,
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   674
										(TAny*)info.iMaxSize));
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   675
	}
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   676
0
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   677
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   678
TInt E32Main()
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   679
	{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   680
	test.Title();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   681
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   682
	if (!HaveVirtMem())
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   683
		{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   684
		test.Printf(_L("This test requires an MMU\n"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   685
		return KErrNone;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   686
		}
132
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   687
	// See if were running on the Flexible Memory Model or newer.
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   688
  	TUint32 memModelAttrib = (TUint32)UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, NULL, NULL);	
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   689
	gFmm = (memModelAttrib & EMemModelTypeMask) >= EMemModelTypeFlexible;
e4a7b1cbe40c 201019_01
hgs
parents: 0
diff changeset
   690
0
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   691
	test.Start(_L("Initialise test"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   692
	test.Next(_L("Load gobbler LDD"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   693
	TInt r = User::LoadLogicalDevice(KGobblerLddFileName);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   694
	test(r==KErrNone || r==KErrAlreadyExists);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   695
	RGobbler gobbler;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   696
	r = gobbler.Open();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   697
	test(r==KErrNone);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   698
	TUint32 taken = gobbler.GobbleRAM(496*1024*1024);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   699
	test.Printf(_L("Gobbled: %dK\n"), taken/1024);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   700
	test.Printf(_L("Free RAM 0x%08X bytes\n"),FreeRam());
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   701
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   702
	test_KErrNone(HAL::Get(HAL::EMemoryPageSize,PageSize));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   703
	TInt totalRAM;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   704
	test_KErrNone(HAL::Get(HAL::EMemoryRAM, totalRAM));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   705
	totalRAM -= taken;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   706
	test.Printf(_L("totalRAM=%dK\n"), totalRAM/1024);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   707
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   708
	test(KErrNone==MemoryTest.Open());
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   709
	// Create the test chunk.  It must not be paged otherwise
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   710
	// unlocking its pages will have no effect.
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   711
	TChunkCreateInfo createInfo;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   712
	createInfo.SetCache(totalRAM);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   713
	test_KErrNone(TestChunk.Create(createInfo));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   714
	TestChunkBase = TestChunk.Base();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   715
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   716
	test(KErrNone==Timer.CreateLocal());
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   717
	UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   718
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   719
	test.Next(_L("Commit all of memory"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   720
	CommitEnd = 0;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   721
	while(KErrNone==(r=TestChunk.Commit(CommitEnd,PageSize)))
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   722
		{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   723
		FillPage(CommitEnd);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   724
		CommitEnd += PageSize;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   725
		}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   726
	test(r==KErrNoMemory);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   727
	NoFreeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   728
	test(NoFreeRam<=PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   729
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   730
	test.Next(_L("Check Unlocked page gets counted as free memory"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   731
	r = TestChunk.Unlock(0,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   732
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   733
	TInt freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   734
	test(freeRam==NoFreeRam+PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   735
	r = TestChunk.Lock(0,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   736
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   737
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   738
	test(freeRam==NoFreeRam);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   739
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   740
	test.Next(_L("Check Unlock/Lock preserves page contents"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   741
	TInt offset;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   742
	for(offset=0; offset<CommitEnd; offset+=PageSize)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   743
		{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   744
		test(CheckPage(offset));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   745
		r = TestChunk.Unlock(offset,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   746
		test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   747
		r = TestChunk.Lock(offset,PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   748
		test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   749
		test(CheckPage(offset));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   750
		freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   751
		test(freeRam==NoFreeRam);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   752
		}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   753
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   754
	test.Next(_L("Tests at chunk offset '0'"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   755
	Tests(0);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   756
	test.Next(_L("Tests at chunk offset 'PageSize'"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   757
	Tests(PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   758
	test.Next(_L("Tests at chunk offset '0x100000-PageSize'"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   759
	Tests(0x100000-PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   760
	test.Next(_L("Tests at chunk offset '0x400000-PageSize'"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   761
	Tests(0x400000-PageSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   762
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   763
	// Remove limit on max size of live list
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   764
	TUint originalMin = 0;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   765
	TUint originalMax = 0;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   766
	TUint currentSize = 0;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   767
	r = DPTest::CacheSize(originalMin, originalMax, currentSize);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   768
	test(r == KErrNone || r == KErrNotSupported);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   769
	TBool resizeCache = r == KErrNone;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   770
	if (resizeCache)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   771
		test_KErrNone(DPTest::SetCacheSize(originalMin, KMaxTUint));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   772
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   773
	test.Next(_L("Big Unlock/Lock"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   774
	r = TestChunk.Unlock(0,CommitEnd);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   775
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   776
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   777
	test(freeRam>=NoFreeRam+CommitEnd);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   778
	r = TestChunk.Lock(0,CommitEnd);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   779
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   780
	freeRam = FreeRam();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   781
	test_Equal(NoFreeRam, freeRam);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   782
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   783
	if (resizeCache)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   784
		{
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   785
		test.Next(_L("Check Unlock of old pages doesn't cause problems"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   786
		TestUnlockOld();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   787
		}
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   788
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   789
	test.Next(_L("Benchmarks..."));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   790
	TestBenchmarks();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   791
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   792
	test.Next(_L("Close chunk with unlocked pages which have been flushed"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   793
	r = TestChunk.Unlock(0,CommitEnd);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   794
	test_KErrNone(r);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   795
	UserSvr::HalFunction(EHalGroupVM,EVMHalFlushCache,0,0);
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   796
	TestChunk.Close();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   797
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   798
	test.Next(_L("Check can't lock/unlock non-cache chunks"));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   799
	RChunk chunk;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   800
	test_KErrNone(chunk.CreateDisconnectedLocal(0,PageSize,2*PageSize));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   801
	test_Equal(KErrGeneral,chunk.Lock(PageSize,PageSize));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   802
	test_Equal(KErrGeneral,chunk.Unlock(0,PageSize));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   803
	chunk.Close();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   804
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   805
	// Restore original settings for live list size
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   806
	if (resizeCache)
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   807
		test_KErrNone(DPTest::SetCacheSize(originalMin, originalMax));
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   808
176
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   809
	test_KErrNone(GetGlobalPolicies());
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   810
	if (gDataPagingSupported)
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   811
		{
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   812
		test.Next(_L("Test interactions of chunk unlocking and page cache resizing"));
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   813
		// Do this after the live list limit is restored.
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   814
		test_KErrNone(TestChunk.Create(createInfo));
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   815
		TestResizeExcess();
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   816
		TestChunk.Close();
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   817
		}
af6ec97d9189 201023_13
hgs
parents: 132
diff changeset
   818
0
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   819
	// end...
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   820
	test.End();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   821
	MemoryTest.Close();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   822
	gobbler.Close();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   823
	test.Close();
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   824
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   825
	return KErrNone;
a41df078684a Convert Kernelhwsrv package from SFL to EPL
John Imhofe
parents:
diff changeset
   826
	}