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