Update contrib.
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\heap\d_kheap.cpp
19 #include <kernel/kern_priv.h>
21 class DKHeap : public DLogicalChannelBase
26 static TBool Handler (const TDesC8& aText, TTraceSource aTraceSource);
28 virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
29 virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2);
31 TInt TestBurstFailNext(TUint aCount, TUint aBurst);
32 TInt TestBurstDeterministic(TUint aRate, TUint aBurst);
43 TInt DKHeap::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& /*aVer*/)
46 /**User side request entry point.*/
47 TInt DKHeap::Request(TInt aFunction, TAny* a1, TAny* a2)
52 case RKHeapDevice::ESetThreadPriorityHigh:
54 NKern::ThreadEnterCS();
55 Kern::SetThreadPriority(47);
56 NKern::ThreadLeaveCS();
60 case RKHeapDevice::ECreateSharedChunk:
62 TChunkCreateInfo info;
63 info.iType = TChunkCreateInfo::ESharedKernelSingle;
64 info.iMaxSize = 0x40000;
66 info.iMapAttr = EMapAttrSupRw | EMapAttrCachedWBWA | EMapAttrL2CachedWBWA;
68 info.iOwnsMemory = ETrue; // Use memory from system's free pool
69 info.iDestroyedDfc = NULL;
75 NKern::ThreadEnterCS();
76 if (KErrNone != (r = Kern::ChunkCreate(info, chunk, chunkAddr, mapAttr)))
78 NKern::ThreadLeaveCS();
81 Kern::ChunkClose(chunk);
82 NKern::ThreadLeaveCS();
87 case RKHeapDevice::ECreatHwChunk:
89 const TInt KSize = 4*1024;
92 NKern::ThreadEnterCS();
93 r = Epoc::AllocPhysicalRam(KSize, physbase);
94 if (r) {NKern::ThreadLeaveCS();break;}
96 DPlatChunkHw* hwchunk;
97 r = DPlatChunkHw::New(hwchunk, physbase, KSize, EMapAttrSupRw);
98 if (r==KErrNone) hwchunk->Close(NULL);
100 Epoc::FreePhysicalRam(physbase, KSize);
101 NKern::ThreadLeaveCS();
106 case RKHeapDevice::ETestBurstFailNext:
107 r = TestBurstFailNext((TUint)a1, (TUint)a2);
110 case RKHeapDevice::ETestBurstDeterministic:
111 r = TestBurstDeterministic((TUint)a1, (TUint)a2);
122 TInt DKHeap::TestBurstFailNext(TUint aCount, TUint aBurst)
124 NKern::ThreadEnterCS();
129 for (; i < aCount; i++)
135 {// Shouldn't have failed
143 for (TUint j = 0; j < aBurst; j++)
147 {// Should be failing
156 NKern::ThreadLeaveCS();
160 TInt DKHeap::TestBurstDeterministic(TUint aRate, TUint aBurst)
162 NKern::ThreadEnterCS();
166 for (TUint i = 1; i <= aRate * KHeapFailCycles; i++)
170 for (TUint j = 0; j < aBurst; j++)
174 {// Should have failed but didn't
185 {// Shouldn't have failed but did
193 NKern::ThreadLeaveCS();
197 //////////////////////////////////////////
198 class DTestFactory : public DLogicalDevice
202 // from DLogicalDevice
203 virtual TInt Install();
204 virtual void GetCaps(TDes8& aDes) const;
205 virtual TInt Create(DLogicalChannelBase*& aChannel);
208 DTestFactory::DTestFactory()
210 iParseMask = KDeviceAllowUnit;
214 TInt DTestFactory::Create(DLogicalChannelBase*& aChannel)
216 KHeapDriver = new DKHeap;
217 aChannel = KHeapDriver;
218 return (aChannel ? KErrNone : KErrNoMemory);
221 TInt DTestFactory::Install()
222 {return SetName(&KHeapTestDriverName);}
224 void DTestFactory::GetCaps(TDes8& /*aDes*/) const
227 DECLARE_STANDARD_LDD()
228 {return new DTestFactory;}