72
|
1 |
// Copyright (c) 2002-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 "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 |
// Contains MBufMgr Test Step 17 for getting mbufs within request size limits
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
|
|
19 |
#include <e32base.h>
|
|
20 |
|
|
21 |
// Test system includes
|
|
22 |
//#ifdef SYMBIAN_OLD_EXPORT_LOCATION
|
|
23 |
//#include "networking/log.h"
|
|
24 |
//#include "networking/teststep.h"
|
|
25 |
//#else
|
|
26 |
//#include <networking/log.h>
|
|
27 |
//#include <networking/teststep.h>
|
|
28 |
//#endif
|
|
29 |
#include "TestStepCTMbufmgr.h"
|
|
30 |
|
|
31 |
#include "test17requestsizelimits.h"
|
|
32 |
|
|
33 |
// RHeap information
|
|
34 |
#include <comms-infras/mbufallocator.h>
|
|
35 |
#include <comms-infras/commsbufpond.h>
|
|
36 |
|
|
37 |
CTest17RequestSizeLimits::CTest17RequestSizeLimits()
|
|
38 |
{
|
|
39 |
SetTestStepName( _L("MBufMgrTest17") ); // Store the name of this test case
|
|
40 |
}
|
|
41 |
|
|
42 |
CTest17RequestSizeLimits::~CTest17RequestSizeLimits()
|
|
43 |
{
|
|
44 |
}
|
|
45 |
|
|
46 |
void CTest17RequestSizeLimits::FillDes(TDes8 &aBuf, TInt aStartPos, TInt anEndPos, TUint aStartChar, TUint anEndChar)
|
|
47 |
{
|
|
48 |
StripeDes(aBuf, aStartPos, anEndPos, aStartChar, anEndChar);
|
|
49 |
}
|
|
50 |
|
|
51 |
enum TVerdict CTest17RequestSizeLimits::doTestStepL(void)
|
|
52 |
{
|
|
53 |
//-------------- substep 1 --------------------
|
|
54 |
INFO_PRINTF1(_L(" 01 Create CMBufManager and install active scheduler:"));
|
|
55 |
CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler );
|
|
56 |
CActiveScheduler::Install(iActSch);
|
|
57 |
|
|
58 |
// Create some initial pools
|
|
59 |
// AddL(KMBuf_MBufSize, KMBuf_InitialAllocation, KMBuf_MinGrowth, KMBuf_GrowthThreshold)
|
|
60 |
// Background memory allocation (CMBufPoolManager::RunL) is used more frequently if
|
|
61 |
// the KMBuf_MinGrowth and the KMBuf_GrowthThreshold are similar in size
|
|
62 |
// Synchronous allocation (AllocPool(*poolChain, growth, ETrue)) occurs when the
|
|
63 |
// requested size (iChain.CopyIn(size)) is larger than the KMBuf_MinGrowth
|
|
64 |
// Multiple threads attempt to grow different poolchains at the same time when there
|
|
65 |
// are a greater variety of pool sizes to grow.
|
|
66 |
// 16384
|
|
67 |
TInt totalPools = 5;
|
|
68 |
TInt poolSize = KMBufDefaultHeapSize/totalPools;
|
|
69 |
RArray<TCommsBufPoolCreateInfo> createInfoArray;
|
|
70 |
|
|
71 |
TCommsBufPoolCreateInfo createInfo;
|
|
72 |
createInfo.iBufSize = 128;
|
|
73 |
createInfo.iInitialBufs = 128;
|
|
74 |
createInfo.iGrowByBufs = 64;
|
|
75 |
createInfo.iMinFreeBufs = 40;
|
|
76 |
createInfo.iCeiling = poolSize/createInfo.iBufSize;
|
|
77 |
|
|
78 |
TCommsBufPoolCreateInfo createInfo2;
|
|
79 |
createInfo2.iBufSize = 256;
|
|
80 |
createInfo2.iInitialBufs = 64;
|
|
81 |
createInfo2.iGrowByBufs = 7;
|
|
82 |
createInfo2.iMinFreeBufs = 6;
|
|
83 |
createInfo2.iCeiling = poolSize/createInfo.iBufSize;
|
|
84 |
|
|
85 |
TCommsBufPoolCreateInfo createInfo3;
|
|
86 |
createInfo3.iBufSize = 512;
|
|
87 |
createInfo3.iInitialBufs = 32;
|
|
88 |
createInfo3.iGrowByBufs = 6;
|
|
89 |
createInfo3.iMinFreeBufs = 5;
|
|
90 |
createInfo3.iCeiling = poolSize/createInfo.iBufSize;
|
|
91 |
|
|
92 |
TCommsBufPoolCreateInfo createInfo4;
|
|
93 |
createInfo4.iBufSize = 1024;
|
|
94 |
createInfo4.iInitialBufs = 16;
|
|
95 |
createInfo4.iGrowByBufs = 5;
|
|
96 |
createInfo4.iMinFreeBufs = 4;
|
|
97 |
createInfo4.iCeiling = poolSize/createInfo.iBufSize;
|
|
98 |
|
|
99 |
TCommsBufPoolCreateInfo createInfo5;
|
|
100 |
createInfo5.iBufSize = 2048;
|
|
101 |
createInfo5.iInitialBufs = 8;
|
|
102 |
createInfo5.iGrowByBufs = 4;
|
|
103 |
createInfo5.iMinFreeBufs = 3;
|
|
104 |
createInfo5.iCeiling = poolSize/createInfo.iBufSize;
|
|
105 |
|
|
106 |
createInfoArray.Append(createInfo);
|
|
107 |
createInfoArray.Append(createInfo2);
|
|
108 |
createInfoArray.Append(createInfo3);
|
|
109 |
createInfoArray.Append(createInfo4);
|
|
110 |
createInfoArray.Append(createInfo5);
|
|
111 |
// Create 262144
|
|
112 |
CreateInstanceMBufMgrL(createInfoArray);
|
|
113 |
CleanupClosePushL(iBufPond);
|
|
114 |
createInfoArray.Close ();
|
|
115 |
RMBufAllocator allocator;
|
|
116 |
|
|
117 |
//-------------- substep 2 --------------------
|
|
118 |
INFO_PRINTF1(_L(" 02 Fill in the Des1 with a pattern:"));
|
|
119 |
TBuf8<5000> *aDes1 = NULL;
|
|
120 |
TRAPD(ret, aDes1 = new(ELeave) TBuf8<5000>);
|
|
121 |
if(ret != KErrNone)
|
|
122 |
return EFail;
|
|
123 |
|
|
124 |
aDes1->SetLength(5000);
|
|
125 |
FillDes(*aDes1, 0, 5000, 1, 1);
|
|
126 |
|
|
127 |
TBool firstAllocFail = EFalse;
|
|
128 |
TBool secondAllocFail = EFalse;
|
|
129 |
TBool thirdAllocFail = EFalse;
|
|
130 |
|
|
131 |
TUint time;
|
|
132 |
RMBufChain aChain;
|
|
133 |
|
|
134 |
//-------------- substep 3 --------------------
|
|
135 |
INFO_PRINTF1(_L(" 03 Allocate 5000-bytes long RMBufChain with 128-bytes long RMBuf:"));
|
|
136 |
|
|
137 |
time = User::FastCounter();
|
|
138 |
ret = aChain.Alloc(5000, 128, 128, allocator);
|
|
139 |
time = User::FastCounter() - time;
|
|
140 |
if (ret != KErrNone)
|
|
141 |
{
|
|
142 |
INFO_PRINTF1(_L("Error: Couldn't allocate RMBufChain:"));
|
|
143 |
User::Leave(EFail);
|
|
144 |
}
|
|
145 |
|
|
146 |
//Copy in Des1 into Chain
|
|
147 |
aChain.CopyIn(aDes1->LeftTPtr(5000));
|
|
148 |
if (aChain.Length() != 5000)
|
|
149 |
{
|
|
150 |
INFO_PRINTF1(_L("Error: Allocated RMBufChain size does not match requested:"));
|
|
151 |
firstAllocFail = ETrue;
|
|
152 |
}
|
|
153 |
|
|
154 |
TInt count = 0;
|
|
155 |
//Check RMBuf size is really 128
|
|
156 |
RMBuf* mBuf = aChain.First();
|
|
157 |
while (mBuf != NULL)
|
|
158 |
{
|
|
159 |
count++;
|
|
160 |
if (mBuf->Size() != 128)
|
|
161 |
{
|
|
162 |
INFO_PRINTF1(_L("Error: RMBuf size does not match requested:"));
|
|
163 |
firstAllocFail = ETrue;
|
|
164 |
break;
|
|
165 |
}
|
|
166 |
mBuf = mBuf->Next();
|
|
167 |
}
|
|
168 |
|
|
169 |
if (firstAllocFail == EFalse)
|
|
170 |
{
|
|
171 |
_LIT(aLog1, " Info: Time to allocate 5000-bytes long RMBufChain with %d 128-bytes long RMBuf: %d");
|
|
172 |
INFO_PRINTF3(aLog1, count, time);
|
|
173 |
}
|
|
174 |
|
|
175 |
//-------------- substep 4 --------------------
|
|
176 |
INFO_PRINTF1(_L(" 04 Deallocating RMBufChain"));
|
|
177 |
aChain.Free();
|
|
178 |
|
|
179 |
//-------------- substep 5 --------------------
|
|
180 |
INFO_PRINTF1(_L(" 05 Allocate 50-bytes long RMBufChain with 1024-bytes long RMBuf:"));
|
|
181 |
|
|
182 |
time = User::FastCounter();
|
|
183 |
ret = aChain.Alloc(50, 1024, 1024, allocator);
|
|
184 |
time = User::FastCounter() - time;
|
|
185 |
if (ret != KErrNone)
|
|
186 |
{
|
|
187 |
INFO_PRINTF1(_L("Error: Couldn't allocate RMBufChain:"));
|
|
188 |
User::Leave(EFail);
|
|
189 |
}
|
|
190 |
|
|
191 |
//Copy in Des1 into Chain
|
|
192 |
aChain.CopyIn(aDes1->LeftTPtr(50));
|
|
193 |
if (aChain.Length() != 50)
|
|
194 |
{
|
|
195 |
INFO_PRINTF1(_L("Error: Allocated RMBufChain size does not match requested:"));
|
|
196 |
secondAllocFail = ETrue;
|
|
197 |
}
|
|
198 |
|
|
199 |
count = 0;
|
|
200 |
//Check RMBuf size is really 1024
|
|
201 |
mBuf = aChain.First();
|
|
202 |
while (mBuf != NULL)
|
|
203 |
{
|
|
204 |
count++;
|
|
205 |
if (mBuf->Size() != 1024)
|
|
206 |
{
|
|
207 |
INFO_PRINTF1(_L("Error: RMBuf size does not match requested:"));
|
|
208 |
secondAllocFail = ETrue;
|
|
209 |
break;
|
|
210 |
}
|
|
211 |
mBuf = mBuf->Next();
|
|
212 |
}
|
|
213 |
|
|
214 |
if (secondAllocFail == EFalse)
|
|
215 |
{
|
|
216 |
_LIT(aLog2, " Info: Time to allocate 50-bytes long RMBufChain with %d 1024-bytes long RMBuf: %d");
|
|
217 |
INFO_PRINTF3(aLog2, count, time);
|
|
218 |
}
|
|
219 |
|
|
220 |
//-------------- substep 6 --------------------
|
|
221 |
INFO_PRINTF1(_L(" 06 Deallocating RMBufChain"));
|
|
222 |
aChain.Free();
|
|
223 |
|
|
224 |
//-------------- substep 7 --------------------
|
|
225 |
INFO_PRINTF1(_L(" 07 Allocate 1500-bytes long RMBufChain with RMBuf size between 1100 and 2000:"));
|
|
226 |
|
|
227 |
ret = aChain.Alloc(1500, 1100, 2000, allocator);
|
|
228 |
if (ret == KErrNone)
|
|
229 |
{
|
|
230 |
INFO_PRINTF1(_L("Error: Allocated with false size RMBuf:"));
|
|
231 |
thirdAllocFail = ETrue;
|
|
232 |
aChain.Free();
|
|
233 |
}
|
|
234 |
else
|
|
235 |
INFO_PRINTF1(_L(" Info: Couldn't allocate because no MBuf with size between 1100 and 2000:"));
|
|
236 |
|
|
237 |
//-------------- substep 8 --------------------
|
|
238 |
INFO_PRINTF1(_L(" 08 Allocate 1500-bytes long RMBufChain with RMBuf min. size 2100:"));
|
|
239 |
|
|
240 |
ret = aChain.Alloc(1500, 2100, allocator);
|
|
241 |
if (ret == KErrNone)
|
|
242 |
{
|
|
243 |
INFO_PRINTF1(_L("Error: Allocated with false size RMBuf:"));
|
|
244 |
thirdAllocFail = ETrue;
|
|
245 |
aChain.Free();
|
|
246 |
}
|
|
247 |
else
|
|
248 |
INFO_PRINTF1(_L(" Info: Couldn't allocate because no MBuf with size greater than 2100:"));
|
|
249 |
|
|
250 |
//-------------- substep 9 --------------------
|
|
251 |
INFO_PRINTF1(_L(" 09 Allocate 1500-bytes long RMBufChain with RMBuf max. size 100:"));
|
|
252 |
|
|
253 |
ret = aChain.Alloc(1500, 0, 100, allocator);
|
|
254 |
if (ret == KErrNone)
|
|
255 |
{
|
|
256 |
INFO_PRINTF1(_L("Error: Allocated with false size RMBuf:"));
|
|
257 |
thirdAllocFail = ETrue;
|
|
258 |
aChain.Free();
|
|
259 |
}
|
|
260 |
else
|
|
261 |
INFO_PRINTF1(_L(" Info: Couldn't allocate because no MBuf with size smaller than 100:"));
|
|
262 |
|
|
263 |
//-------------- substep 10 --------------------
|
|
264 |
INFO_PRINTF1(_L(" 10 Exhaust 512-bytes long RMBufChain :"));
|
|
265 |
|
|
266 |
RMBufChain bChain;
|
|
267 |
|
|
268 |
while (allocator.BytesAvailable(512) / 512 > 0)
|
|
269 |
{
|
|
270 |
ret = aChain.Alloc(500, allocator);
|
|
271 |
if (ret != KErrNone)
|
|
272 |
{
|
|
273 |
INFO_PRINTF1(_L("Error: Couldn't allocate RMBufChain:"));
|
|
274 |
User::Leave(EFail);
|
|
275 |
}
|
|
276 |
|
|
277 |
// Now grow the chain
|
|
278 |
bChain.Append(aChain);
|
|
279 |
}
|
|
280 |
|
|
281 |
//-------------- substep 11 --------------------
|
|
282 |
INFO_PRINTF1(_L(" 15 Allocate 500-bytes long RMBufChain with 512-bytes long RMBuf:"));
|
|
283 |
|
|
284 |
ret = aChain.Alloc(500, 512, 512, allocator);
|
|
285 |
if (ret == KErrNone)
|
|
286 |
{
|
|
287 |
INFO_PRINTF1(_L("Error: Allocated with false size RMBuf:"));
|
|
288 |
thirdAllocFail = ETrue;
|
|
289 |
aChain.Free();
|
|
290 |
}
|
|
291 |
else
|
|
292 |
INFO_PRINTF1(_L(" Info: Couldn't allocate because no more 512-bytes long RMBuf:"));
|
|
293 |
|
|
294 |
//-------------- substep 12 --------------------
|
|
295 |
INFO_PRINTF1(_L(" 12 Deallocating RMBufChain"));
|
|
296 |
bChain.Free();
|
|
297 |
|
|
298 |
delete aDes1;
|
|
299 |
|
|
300 |
//-------------- substep 13 --------------------
|
|
301 |
INFO_PRINTF1(_L(" 13 Clean up stack:"));
|
|
302 |
CleanupStack::PopAndDestroy();
|
|
303 |
CActiveScheduler::Install(NULL);
|
|
304 |
CleanupStack::PopAndDestroy(iActSch);
|
|
305 |
|
|
306 |
if (firstAllocFail || secondAllocFail || thirdAllocFail)
|
|
307 |
{
|
|
308 |
SetTestStepResult(EFail);
|
|
309 |
return TestStepResult();
|
|
310 |
}
|
|
311 |
|
|
312 |
SetTestStepResult(EPass);
|
|
313 |
return TestStepResult();
|
|
314 |
}
|