os/kernelhwsrv/kerneltest/e32test/heap/d_kheap.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\heap\d_kheap.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "d_kheap.h"
sl@0
    19
#include <kernel/kern_priv.h>
sl@0
    20
sl@0
    21
class  DKHeap : public DLogicalChannelBase
sl@0
    22
	{
sl@0
    23
public:
sl@0
    24
	DKHeap();
sl@0
    25
	~DKHeap();
sl@0
    26
	static TBool Handler (const TDesC8& aText, TTraceSource aTraceSource);
sl@0
    27
protected:
sl@0
    28
	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
sl@0
    29
	virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
sl@0
    30
sl@0
    31
	TInt TestBurstFailNext(TUint aCount, TUint aBurst);
sl@0
    32
	TInt TestBurstDeterministic(TUint aRate, TUint aBurst);
sl@0
    33
	};
sl@0
    34
sl@0
    35
DKHeap* KHeapDriver;
sl@0
    36
sl@0
    37
DKHeap::DKHeap() 
sl@0
    38
	{}
sl@0
    39
sl@0
    40
DKHeap::~DKHeap() 
sl@0
    41
	{KHeapDriver = NULL;}
sl@0
    42
sl@0
    43
TInt DKHeap::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& /*aVer*/)
sl@0
    44
	{return KErrNone;}
sl@0
    45
sl@0
    46
/**User side request entry point.*/
sl@0
    47
TInt DKHeap::Request(TInt aFunction, TAny* a1, TAny* a2)
sl@0
    48
	{
sl@0
    49
	TInt r = KErrNone;
sl@0
    50
	switch (aFunction)
sl@0
    51
	{
sl@0
    52
		case RKHeapDevice::ESetThreadPriorityHigh:
sl@0
    53
			{
sl@0
    54
			NKern::ThreadEnterCS();
sl@0
    55
			Kern::SetThreadPriority(47);
sl@0
    56
			NKern::ThreadLeaveCS();
sl@0
    57
			}
sl@0
    58
			break;
sl@0
    59
sl@0
    60
		case RKHeapDevice::ECreateSharedChunk:
sl@0
    61
			{
sl@0
    62
			TChunkCreateInfo info;
sl@0
    63
		    info.iType         = TChunkCreateInfo::ESharedKernelSingle;
sl@0
    64
			info.iMaxSize      = 0x40000;
sl@0
    65
		#ifdef __EPOC32__
sl@0
    66
			info.iMapAttr      = EMapAttrSupRw | EMapAttrCachedWBWA | EMapAttrL2CachedWBWA;
sl@0
    67
		#endif
sl@0
    68
			info.iOwnsMemory   = ETrue; // Use memory from system's free pool
sl@0
    69
			info.iDestroyedDfc = NULL;
sl@0
    70
sl@0
    71
		    TLinAddr chunkAddr;
sl@0
    72
		    TUint32 mapAttr;
sl@0
    73
		    DChunk* chunk;
sl@0
    74
sl@0
    75
			NKern::ThreadEnterCS();
sl@0
    76
		    if (KErrNone != (r = Kern::ChunkCreate(info, chunk, chunkAddr, mapAttr)))
sl@0
    77
				{
sl@0
    78
				NKern::ThreadLeaveCS();
sl@0
    79
				break;
sl@0
    80
				}
sl@0
    81
			Kern::ChunkClose(chunk);
sl@0
    82
			NKern::ThreadLeaveCS();
sl@0
    83
			}
sl@0
    84
			break;
sl@0
    85
sl@0
    86
		#ifdef __EPOC32__
sl@0
    87
		case RKHeapDevice::ECreatHwChunk:
sl@0
    88
			{
sl@0
    89
			const TInt KSize = 4*1024;
sl@0
    90
			TPhysAddr physbase;
sl@0
    91
sl@0
    92
			NKern::ThreadEnterCS();
sl@0
    93
			r = Epoc::AllocPhysicalRam(KSize, physbase);
sl@0
    94
			if (r)	{NKern::ThreadLeaveCS();break;}
sl@0
    95
			
sl@0
    96
			DPlatChunkHw* hwchunk;
sl@0
    97
			r = DPlatChunkHw::New(hwchunk, physbase, KSize, EMapAttrSupRw);
sl@0
    98
			if (r==KErrNone)	hwchunk->Close(NULL);
sl@0
    99
			
sl@0
   100
			Epoc::FreePhysicalRam(physbase, KSize);
sl@0
   101
			NKern::ThreadLeaveCS();
sl@0
   102
			}
sl@0
   103
			break;
sl@0
   104
		#endif//__EPOC32__
sl@0
   105
sl@0
   106
		case RKHeapDevice::ETestBurstFailNext:
sl@0
   107
			r = TestBurstFailNext((TUint)a1, (TUint)a2);
sl@0
   108
			break;
sl@0
   109
sl@0
   110
		case RKHeapDevice::ETestBurstDeterministic:
sl@0
   111
			r = TestBurstDeterministic((TUint)a1, (TUint)a2);
sl@0
   112
			break;
sl@0
   113
sl@0
   114
		default:
sl@0
   115
			r=KErrNotSupported;
sl@0
   116
		}
sl@0
   117
	return r;
sl@0
   118
	}
sl@0
   119
sl@0
   120
sl@0
   121
sl@0
   122
TInt DKHeap::TestBurstFailNext(TUint aCount, TUint aBurst)
sl@0
   123
	{
sl@0
   124
	NKern::ThreadEnterCS();
sl@0
   125
sl@0
   126
	TInt r = KErrNone;
sl@0
   127
	TUint i = 0;
sl@0
   128
	TInt* p = NULL;
sl@0
   129
	for (; i < aCount; i++)
sl@0
   130
		{
sl@0
   131
		if (i < aCount - 1)
sl@0
   132
			{
sl@0
   133
			p = new TInt;
sl@0
   134
			if (p == NULL)
sl@0
   135
				{// Shouldn't have failed
sl@0
   136
				r = KErrNoMemory;
sl@0
   137
				goto exit;
sl@0
   138
				}
sl@0
   139
			delete p;
sl@0
   140
			}
sl@0
   141
		else 
sl@0
   142
			{
sl@0
   143
			for (TUint j = 0; j < aBurst; j++)
sl@0
   144
				{
sl@0
   145
				p = new TInt;
sl@0
   146
				if (p != NULL)
sl@0
   147
					{// Should be failing
sl@0
   148
					delete p;
sl@0
   149
					r = KErrGeneral;
sl@0
   150
					goto exit;
sl@0
   151
					}
sl@0
   152
				}
sl@0
   153
			} 
sl@0
   154
		}
sl@0
   155
exit:
sl@0
   156
	NKern::ThreadLeaveCS();
sl@0
   157
	return r;
sl@0
   158
	}
sl@0
   159
sl@0
   160
TInt DKHeap::TestBurstDeterministic(TUint aRate, TUint aBurst)
sl@0
   161
	{
sl@0
   162
	NKern::ThreadEnterCS();
sl@0
   163
sl@0
   164
	TInt r = KErrNone;
sl@0
   165
	TInt* p = NULL;
sl@0
   166
	for (TUint i = 1; i <= aRate * KHeapFailCycles; i++)
sl@0
   167
		{
sl@0
   168
		if (i % aRate == 0)
sl@0
   169
			{
sl@0
   170
			for (TUint j = 0; j < aBurst; j++)
sl@0
   171
				{
sl@0
   172
				p = new TInt;
sl@0
   173
				if (p != NULL)
sl@0
   174
					{// Should have failed but didn't
sl@0
   175
					delete p;
sl@0
   176
					r = KErrGeneral;
sl@0
   177
					goto exit;
sl@0
   178
					}
sl@0
   179
				}
sl@0
   180
			}
sl@0
   181
		else
sl@0
   182
			{
sl@0
   183
			p = new TInt;
sl@0
   184
			if (p == NULL)
sl@0
   185
				{// Shouldn't have failed but did
sl@0
   186
				r = KErrNoMemory;
sl@0
   187
				goto exit;
sl@0
   188
				}
sl@0
   189
			delete p;
sl@0
   190
			}
sl@0
   191
		}
sl@0
   192
exit:
sl@0
   193
	NKern::ThreadLeaveCS();
sl@0
   194
	return r;
sl@0
   195
	}
sl@0
   196
sl@0
   197
//////////////////////////////////////////
sl@0
   198
class DTestFactory : public DLogicalDevice
sl@0
   199
	{
sl@0
   200
public:
sl@0
   201
	DTestFactory();
sl@0
   202
	// from DLogicalDevice
sl@0
   203
	virtual TInt Install();
sl@0
   204
	virtual void GetCaps(TDes8& aDes) const;
sl@0
   205
	virtual TInt Create(DLogicalChannelBase*& aChannel);
sl@0
   206
	};
sl@0
   207
sl@0
   208
DTestFactory::DTestFactory()
sl@0
   209
    {
sl@0
   210
    iParseMask = KDeviceAllowUnit;
sl@0
   211
    iUnitsMask = 0x3;
sl@0
   212
    }
sl@0
   213
sl@0
   214
TInt DTestFactory::Create(DLogicalChannelBase*& aChannel)
sl@0
   215
    {
sl@0
   216
	KHeapDriver = new DKHeap;
sl@0
   217
	aChannel = KHeapDriver;
sl@0
   218
	return (aChannel ? KErrNone : KErrNoMemory);
sl@0
   219
    }
sl@0
   220
sl@0
   221
TInt DTestFactory::Install()
sl@0
   222
    {return SetName(&KHeapTestDriverName);}
sl@0
   223
sl@0
   224
void DTestFactory::GetCaps(TDes8& /*aDes*/) const	
sl@0
   225
	{}
sl@0
   226
sl@0
   227
DECLARE_STANDARD_LDD()
sl@0
   228
	{return new DTestFactory;}