sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\heap\d_kheap.cpp sl@0: // sl@0: // sl@0: sl@0: #include "d_kheap.h" sl@0: #include sl@0: sl@0: class DKHeap : public DLogicalChannelBase sl@0: { sl@0: public: sl@0: DKHeap(); sl@0: ~DKHeap(); sl@0: static TBool Handler (const TDesC8& aText, TTraceSource aTraceSource); sl@0: protected: sl@0: virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); sl@0: virtual TInt Request(TInt aFunction, TAny* a1, TAny* a2); sl@0: sl@0: TInt TestBurstFailNext(TUint aCount, TUint aBurst); sl@0: TInt TestBurstDeterministic(TUint aRate, TUint aBurst); sl@0: }; sl@0: sl@0: DKHeap* KHeapDriver; sl@0: sl@0: DKHeap::DKHeap() sl@0: {} sl@0: sl@0: DKHeap::~DKHeap() sl@0: {KHeapDriver = NULL;} sl@0: sl@0: TInt DKHeap::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& /*aVer*/) sl@0: {return KErrNone;} sl@0: sl@0: /**User side request entry point.*/ sl@0: TInt DKHeap::Request(TInt aFunction, TAny* a1, TAny* a2) sl@0: { sl@0: TInt r = KErrNone; sl@0: switch (aFunction) sl@0: { sl@0: case RKHeapDevice::ESetThreadPriorityHigh: sl@0: { sl@0: NKern::ThreadEnterCS(); sl@0: Kern::SetThreadPriority(47); sl@0: NKern::ThreadLeaveCS(); sl@0: } sl@0: break; sl@0: sl@0: case RKHeapDevice::ECreateSharedChunk: sl@0: { sl@0: TChunkCreateInfo info; sl@0: info.iType = TChunkCreateInfo::ESharedKernelSingle; sl@0: info.iMaxSize = 0x40000; sl@0: #ifdef __EPOC32__ sl@0: info.iMapAttr = EMapAttrSupRw | EMapAttrCachedWBWA | EMapAttrL2CachedWBWA; sl@0: #endif sl@0: info.iOwnsMemory = ETrue; // Use memory from system's free pool sl@0: info.iDestroyedDfc = NULL; sl@0: sl@0: TLinAddr chunkAddr; sl@0: TUint32 mapAttr; sl@0: DChunk* chunk; sl@0: sl@0: NKern::ThreadEnterCS(); sl@0: if (KErrNone != (r = Kern::ChunkCreate(info, chunk, chunkAddr, mapAttr))) sl@0: { sl@0: NKern::ThreadLeaveCS(); sl@0: break; sl@0: } sl@0: Kern::ChunkClose(chunk); sl@0: NKern::ThreadLeaveCS(); sl@0: } sl@0: break; sl@0: sl@0: #ifdef __EPOC32__ sl@0: case RKHeapDevice::ECreatHwChunk: sl@0: { sl@0: const TInt KSize = 4*1024; sl@0: TPhysAddr physbase; sl@0: sl@0: NKern::ThreadEnterCS(); sl@0: r = Epoc::AllocPhysicalRam(KSize, physbase); sl@0: if (r) {NKern::ThreadLeaveCS();break;} sl@0: sl@0: DPlatChunkHw* hwchunk; sl@0: r = DPlatChunkHw::New(hwchunk, physbase, KSize, EMapAttrSupRw); sl@0: if (r==KErrNone) hwchunk->Close(NULL); sl@0: sl@0: Epoc::FreePhysicalRam(physbase, KSize); sl@0: NKern::ThreadLeaveCS(); sl@0: } sl@0: break; sl@0: #endif//__EPOC32__ sl@0: sl@0: case RKHeapDevice::ETestBurstFailNext: sl@0: r = TestBurstFailNext((TUint)a1, (TUint)a2); sl@0: break; sl@0: sl@0: case RKHeapDevice::ETestBurstDeterministic: sl@0: r = TestBurstDeterministic((TUint)a1, (TUint)a2); sl@0: break; sl@0: sl@0: default: sl@0: r=KErrNotSupported; sl@0: } sl@0: return r; sl@0: } sl@0: sl@0: sl@0: sl@0: TInt DKHeap::TestBurstFailNext(TUint aCount, TUint aBurst) sl@0: { sl@0: NKern::ThreadEnterCS(); sl@0: sl@0: TInt r = KErrNone; sl@0: TUint i = 0; sl@0: TInt* p = NULL; sl@0: for (; i < aCount; i++) sl@0: { sl@0: if (i < aCount - 1) sl@0: { sl@0: p = new TInt; sl@0: if (p == NULL) sl@0: {// Shouldn't have failed sl@0: r = KErrNoMemory; sl@0: goto exit; sl@0: } sl@0: delete p; sl@0: } sl@0: else sl@0: { sl@0: for (TUint j = 0; j < aBurst; j++) sl@0: { sl@0: p = new TInt; sl@0: if (p != NULL) sl@0: {// Should be failing sl@0: delete p; sl@0: r = KErrGeneral; sl@0: goto exit; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: exit: sl@0: NKern::ThreadLeaveCS(); sl@0: return r; sl@0: } sl@0: sl@0: TInt DKHeap::TestBurstDeterministic(TUint aRate, TUint aBurst) sl@0: { sl@0: NKern::ThreadEnterCS(); sl@0: sl@0: TInt r = KErrNone; sl@0: TInt* p = NULL; sl@0: for (TUint i = 1; i <= aRate * KHeapFailCycles; i++) sl@0: { sl@0: if (i % aRate == 0) sl@0: { sl@0: for (TUint j = 0; j < aBurst; j++) sl@0: { sl@0: p = new TInt; sl@0: if (p != NULL) sl@0: {// Should have failed but didn't sl@0: delete p; sl@0: r = KErrGeneral; sl@0: goto exit; sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: p = new TInt; sl@0: if (p == NULL) sl@0: {// Shouldn't have failed but did sl@0: r = KErrNoMemory; sl@0: goto exit; sl@0: } sl@0: delete p; sl@0: } sl@0: } sl@0: exit: sl@0: NKern::ThreadLeaveCS(); sl@0: return r; sl@0: } sl@0: sl@0: ////////////////////////////////////////// sl@0: class DTestFactory : public DLogicalDevice sl@0: { sl@0: public: sl@0: DTestFactory(); sl@0: // from DLogicalDevice sl@0: virtual TInt Install(); sl@0: virtual void GetCaps(TDes8& aDes) const; sl@0: virtual TInt Create(DLogicalChannelBase*& aChannel); sl@0: }; sl@0: sl@0: DTestFactory::DTestFactory() sl@0: { sl@0: iParseMask = KDeviceAllowUnit; sl@0: iUnitsMask = 0x3; sl@0: } sl@0: sl@0: TInt DTestFactory::Create(DLogicalChannelBase*& aChannel) sl@0: { sl@0: KHeapDriver = new DKHeap; sl@0: aChannel = KHeapDriver; sl@0: return (aChannel ? KErrNone : KErrNoMemory); sl@0: } sl@0: sl@0: TInt DTestFactory::Install() sl@0: {return SetName(&KHeapTestDriverName);} sl@0: sl@0: void DTestFactory::GetCaps(TDes8& /*aDes*/) const sl@0: {} sl@0: sl@0: DECLARE_STANDARD_LDD() sl@0: {return new DTestFactory;}