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 18 for exhausting mid size pools
|
|
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 |
|
|
30 |
#include "TestStepCTMbufmgr.h"
|
|
31 |
|
|
32 |
#include "test18exhaustmidsizepools.h"
|
|
33 |
|
|
34 |
// RHeap information
|
|
35 |
#include <comms-infras/mbufallocator.h>
|
|
36 |
#include <comms-infras/commsbufpond.h>
|
|
37 |
|
|
38 |
CTest18ExhaustMidSizePools::CTest18ExhaustMidSizePools()
|
|
39 |
{
|
|
40 |
SetTestStepName( _L("MBufMgrTest18") ); // Store the name of this test case
|
|
41 |
}
|
|
42 |
|
|
43 |
CTest18ExhaustMidSizePools::~CTest18ExhaustMidSizePools()
|
|
44 |
{
|
|
45 |
}
|
|
46 |
|
|
47 |
void CTest18ExhaustMidSizePools::FillDes(TDes8 &aBuf, TInt aStartPos, TInt anEndPos, TUint aStartChar, TUint anEndChar)
|
|
48 |
{
|
|
49 |
StripeDes(aBuf, aStartPos, anEndPos, aStartChar, anEndChar);
|
|
50 |
}
|
|
51 |
|
|
52 |
enum TVerdict CTest18ExhaustMidSizePools::doTestStepL(void)
|
|
53 |
{
|
|
54 |
//-------------- substep 1 --------------------
|
|
55 |
INFO_PRINTF1(_L(" 01 Create CMBufManager and install active scheduler:"));
|
|
56 |
CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler );
|
|
57 |
CActiveScheduler::Install(iActSch);
|
|
58 |
|
|
59 |
|
|
60 |
// Create some initial pools
|
|
61 |
// AddL(KMBuf_MBufSize, KMBuf_InitialAllocation, KMBuf_MinGrowth, KMBuf_GrowthThreshold)
|
|
62 |
// Background memory allocation (CMBufPoolManager::RunL) is used more frequently if
|
|
63 |
// the KMBuf_MinGrowth and the KMBuf_GrowthThreshold are similar in size
|
|
64 |
// Synchronous allocation (AllocPool(*poolChain, growth, ETrue)) occurs when the
|
|
65 |
// requested size (iChain.CopyIn(size)) is larger than the KMBuf_MinGrowth
|
|
66 |
// Multiple threads attempt to grow different poolchains at the same time when there
|
|
67 |
// are a greater variety of pool sizes to grow.
|
|
68 |
// 16384
|
|
69 |
TInt totalPools = 5;
|
|
70 |
TInt poolSize = (KMBufDefaultHeapSize / 2)/totalPools;
|
|
71 |
|
|
72 |
RArray<TCommsBufPoolCreateInfo> createInfoArray;
|
|
73 |
|
|
74 |
TCommsBufPoolCreateInfo createInfo;
|
|
75 |
createInfo.iBufSize = 128;
|
|
76 |
createInfo.iInitialBufs = 128;
|
|
77 |
createInfo.iGrowByBufs = 64;
|
|
78 |
createInfo.iMinFreeBufs = 40;
|
|
79 |
createInfo.iCeiling = poolSize/createInfo.iBufSize;
|
|
80 |
|
|
81 |
TCommsBufPoolCreateInfo createInfo2;
|
|
82 |
createInfo2.iBufSize = 256;
|
|
83 |
createInfo2.iInitialBufs = 64;
|
|
84 |
createInfo2.iGrowByBufs = 7;
|
|
85 |
createInfo2.iMinFreeBufs = 6;
|
|
86 |
createInfo2.iCeiling = poolSize/createInfo.iBufSize;
|
|
87 |
|
|
88 |
TCommsBufPoolCreateInfo createInfo3;
|
|
89 |
createInfo3.iBufSize = 512;
|
|
90 |
createInfo3.iInitialBufs = 32;
|
|
91 |
createInfo3.iGrowByBufs = 6;
|
|
92 |
createInfo3.iMinFreeBufs = 5;
|
|
93 |
createInfo3.iCeiling = poolSize/createInfo.iBufSize;
|
|
94 |
|
|
95 |
TCommsBufPoolCreateInfo createInfo4;
|
|
96 |
createInfo4.iBufSize = 1024;
|
|
97 |
createInfo4.iInitialBufs = 16;
|
|
98 |
createInfo4.iGrowByBufs = 5;
|
|
99 |
createInfo4.iMinFreeBufs = 4;
|
|
100 |
createInfo4.iCeiling = poolSize/createInfo.iBufSize;
|
|
101 |
|
|
102 |
TCommsBufPoolCreateInfo createInfo5;
|
|
103 |
createInfo5.iBufSize = 2048;
|
|
104 |
createInfo5.iInitialBufs = 8;
|
|
105 |
createInfo5.iGrowByBufs = 4;
|
|
106 |
createInfo5.iMinFreeBufs = 3;
|
|
107 |
createInfo5.iCeiling = poolSize/createInfo.iBufSize;
|
|
108 |
|
|
109 |
createInfoArray.Append(createInfo);
|
|
110 |
createInfoArray.Append(createInfo2);
|
|
111 |
createInfoArray.Append(createInfo3);
|
|
112 |
createInfoArray.Append(createInfo4);
|
|
113 |
createInfoArray.Append(createInfo5);
|
|
114 |
|
|
115 |
// Create 262144
|
|
116 |
CreateInstanceMBufMgrL(createInfoArray);
|
|
117 |
CleanupClosePushL(iBufPond);
|
|
118 |
createInfoArray.Close ();
|
|
119 |
|
|
120 |
RMBufAllocator allocator;
|
|
121 |
|
|
122 |
TInt allocTime128 = 0;
|
|
123 |
TInt allocTime256 = 0;
|
|
124 |
TInt allocTime512 = 0;
|
|
125 |
TInt allocTime1024 = 0;
|
|
126 |
TInt allocTime2048 = 0;
|
|
127 |
|
|
128 |
TInt allocCount128 = 0;
|
|
129 |
TInt allocCount256 = 0;
|
|
130 |
TInt allocCount512 = 0;
|
|
131 |
TInt allocCount1024 = 0;
|
|
132 |
TInt allocCount2048 = 0;
|
|
133 |
|
|
134 |
TInt allocIndex128 = 0;
|
|
135 |
TInt allocIndex256 = 0;
|
|
136 |
TInt allocIndex512 = 0;
|
|
137 |
TInt allocIndex1024 = 0;
|
|
138 |
TInt allocIndex2048 = 0;
|
|
139 |
|
|
140 |
TInt failedSizeCount = 0;
|
|
141 |
|
|
142 |
TInt counter = 0;
|
|
143 |
|
|
144 |
TUint time;
|
|
145 |
RMBufChain aChain, bChain;
|
|
146 |
RMBufChain mbuf1, mbuf2, mbuf3, mbuf4, mbuf5, mbuf6;
|
|
147 |
|
|
148 |
//-------------- substep 2 --------------------
|
|
149 |
INFO_PRINTF1(_L(" 02 Fill in the Des1 with a pattern:"));
|
|
150 |
TBuf8<2500> *aDes1 = NULL;
|
|
151 |
TRAPD(ret, aDes1 = new(ELeave) TBuf8<2500>);
|
|
152 |
if(ret != KErrNone)
|
|
153 |
{
|
|
154 |
SetTestStepResult(EFail);
|
|
155 |
return TestStepResult();
|
|
156 |
}
|
|
157 |
|
|
158 |
aDes1->SetLength(2500);
|
|
159 |
FillDes(*aDes1, 0, 2500, 1, 1);
|
|
160 |
|
|
161 |
//-------------- substep 3 --------------------
|
|
162 |
INFO_PRINTF1(_L(" 03 Start to allocate 500-bytes long RMBufs:"));
|
|
163 |
|
|
164 |
time = User::FastCounter();
|
|
165 |
ret = aChain.Alloc(500, allocator);
|
|
166 |
time = User::FastCounter() - time;
|
|
167 |
while (ret == KErrNone)
|
|
168 |
{
|
|
169 |
//Copy in Des1 into Chain
|
|
170 |
aChain.CopyIn(aDes1->LeftTPtr(500));
|
|
171 |
if (aChain.Length() != 500)
|
|
172 |
{
|
|
173 |
INFO_PRINTF1(_L("Error: Allocated RMBufChain size does not match requested:"));
|
|
174 |
failedSizeCount++;
|
|
175 |
}
|
|
176 |
|
|
177 |
switch (aChain.First()->Size())
|
|
178 |
{
|
|
179 |
case 128:
|
|
180 |
if (allocator.BytesAvailable(256) / 256 > 0)
|
|
181 |
{
|
|
182 |
INFO_PRINTF1(_L("Error: 256-bytes long RMBuf available, but allocated 128-bytes long RMBuf:"));
|
|
183 |
}
|
|
184 |
else if (allocIndex128 == 0)
|
|
185 |
{
|
|
186 |
counter++;
|
|
187 |
allocIndex128 = counter;
|
|
188 |
}
|
|
189 |
allocCount128++;
|
|
190 |
allocTime128 += time;
|
|
191 |
break;
|
|
192 |
case 256:
|
|
193 |
if (allocator.BytesAvailable(2048) / 2048 > 0)
|
|
194 |
{
|
|
195 |
INFO_PRINTF1(_L("Error: 2048-bytes long RMBuf available, but allocated 256-bytes long RMBuf:"));
|
|
196 |
}
|
|
197 |
else if (allocIndex256 == 0)
|
|
198 |
{
|
|
199 |
counter++;
|
|
200 |
allocIndex256 = counter;
|
|
201 |
}
|
|
202 |
allocCount256++;
|
|
203 |
allocTime256 += time;
|
|
204 |
break;
|
|
205 |
case 512:
|
|
206 |
if (allocIndex512 == 0)
|
|
207 |
{
|
|
208 |
counter++;
|
|
209 |
allocIndex512 = counter;
|
|
210 |
}
|
|
211 |
allocCount512++;
|
|
212 |
allocTime512 += time;
|
|
213 |
break;
|
|
214 |
case 1024:
|
|
215 |
if (allocator.BytesAvailable(512) / 512 > 0)
|
|
216 |
{
|
|
217 |
INFO_PRINTF1(_L("Error: 512-bytes long RMBuf available, but allocated 1024-bytes long RMBuf:"));
|
|
218 |
}
|
|
219 |
else if (allocIndex1024 == 0)
|
|
220 |
{
|
|
221 |
counter++;
|
|
222 |
allocIndex1024 = counter;
|
|
223 |
}
|
|
224 |
allocCount1024++;
|
|
225 |
allocTime1024 += time;
|
|
226 |
break;
|
|
227 |
case 2048:
|
|
228 |
if (allocator.BytesAvailable(1024) / 1024 > 0)
|
|
229 |
{
|
|
230 |
INFO_PRINTF1(_L("Error: 1024-bytes long RMBuf available, but allocated 2048-bytes long RMBuf:"));
|
|
231 |
}
|
|
232 |
else if (allocIndex2048 == 0)
|
|
233 |
{
|
|
234 |
counter++;
|
|
235 |
allocIndex2048 = counter;
|
|
236 |
}
|
|
237 |
allocCount2048++;
|
|
238 |
allocTime2048 += time;
|
|
239 |
break;
|
|
240 |
}
|
|
241 |
|
|
242 |
// Now grow the chain
|
|
243 |
if (allocCount256 == 1)
|
|
244 |
{
|
|
245 |
mbuf1.Append(aChain);
|
|
246 |
}
|
|
247 |
else if (allocCount512 == 1)
|
|
248 |
{
|
|
249 |
mbuf2.Append(aChain);
|
|
250 |
}
|
|
251 |
else if (allocCount512 == 2)
|
|
252 |
{
|
|
253 |
mbuf3.Append(aChain);
|
|
254 |
}
|
|
255 |
else if (allocCount512 == 3)
|
|
256 |
{
|
|
257 |
mbuf4.Append(aChain);
|
|
258 |
}
|
|
259 |
else if (allocCount2048 == 1)
|
|
260 |
{
|
|
261 |
mbuf5.Append(aChain);
|
|
262 |
}
|
|
263 |
else if (allocCount2048 == 2)
|
|
264 |
{
|
|
265 |
mbuf6.Append(aChain);
|
|
266 |
}
|
|
267 |
else
|
|
268 |
{
|
|
269 |
bChain.Append(aChain);
|
|
270 |
}
|
|
271 |
|
|
272 |
time = User::FastCounter();
|
|
273 |
ret = aChain.Alloc(500, allocator);
|
|
274 |
time = User::FastCounter() - time;
|
|
275 |
}
|
|
276 |
|
|
277 |
if (allocIndex512 == 1)
|
|
278 |
{
|
|
279 |
_LIT(aLog1," Info: %d. Time to alloc %d 512-bytes long RMBuf: %d Average: %d");
|
|
280 |
INFO_PRINTF5(aLog1, allocIndex512, allocCount512, allocTime512, allocTime512/allocCount512);
|
|
281 |
}
|
|
282 |
if (allocIndex1024 == 2)
|
|
283 |
{
|
|
284 |
_LIT(aLog2," Info: %d. Time to alloc %d 1024-bytes long RMBuf: %d Average: %d");
|
|
285 |
INFO_PRINTF5(aLog2, allocIndex1024, allocCount1024, allocTime1024, allocTime1024/allocCount1024);
|
|
286 |
}
|
|
287 |
if (allocIndex2048 == 3)
|
|
288 |
{
|
|
289 |
_LIT(aLog3," Info: %d. Time to alloc %d 2048-bytes long RMBuf: %d Average: %d");
|
|
290 |
INFO_PRINTF5(aLog3, allocIndex2048, allocCount2048, allocTime2048, allocTime2048/allocCount2048);
|
|
291 |
}
|
|
292 |
if (allocIndex256 == 4)
|
|
293 |
{
|
|
294 |
_LIT(aLog4," Info: %d. Time to alloc %d 256-bytes long RMBuf: %d Average: %d");
|
|
295 |
INFO_PRINTF5(aLog4, allocIndex256, allocCount256, allocTime256, allocTime256/allocCount256);
|
|
296 |
}
|
|
297 |
if (allocIndex128 == 5)
|
|
298 |
{
|
|
299 |
_LIT(aLog5," Info: %d. Time to alloc %d 128-bytes long RMBuf: %d Average: %d");
|
|
300 |
INFO_PRINTF5(aLog5, allocIndex128, allocCount128, allocTime128, allocTime128/allocCount128);
|
|
301 |
}
|
|
302 |
|
|
303 |
TBool firstSuccess = ETrue;
|
|
304 |
TBool secondSuccess = ETrue;
|
|
305 |
TBool thirdSuccess = ETrue;
|
|
306 |
|
|
307 |
//-------------------substep 4-----------------------------
|
|
308 |
INFO_PRINTF1(_L(" 04 Allocate 750-byte long RMBuf after deallocating 1 256-byte and 2 512-byte long RMBufs:"));
|
|
309 |
mbuf1.TrimEnd(244); // 256-byte mbuf
|
|
310 |
mbuf2.Free(); // 512-byte mbuf
|
|
311 |
mbuf3.Free(); // 512-byte mbuf
|
|
312 |
|
|
313 |
ret = aChain.Alloc(750, allocator);
|
|
314 |
if (ret != KErrNone)
|
|
315 |
{
|
|
316 |
INFO_PRINTF1(_L("Error: Couldn't allocate RMBuf:"));
|
|
317 |
firstSuccess = EFalse;
|
|
318 |
}
|
|
319 |
else
|
|
320 |
{
|
|
321 |
//Copy in Des1 into Chain
|
|
322 |
aChain.CopyIn(aDes1->LeftTPtr(750));
|
|
323 |
if (aChain.Length() != 750)
|
|
324 |
{
|
|
325 |
INFO_PRINTF1(_L("Error: Allocated RMBufChain size does not match requested:"));
|
|
326 |
firstSuccess = EFalse;
|
|
327 |
}
|
|
328 |
|
|
329 |
// 1 512-byte long RMBuf should be free
|
|
330 |
if (allocator.BytesAvailable(512) == 512)
|
|
331 |
{
|
|
332 |
INFO_PRINTF1(_L(" Info: 1 512-byte long RMBuf is free:"));
|
|
333 |
}
|
|
334 |
else
|
|
335 |
{
|
|
336 |
INFO_PRINTF1(_L("Error: 1 512-byte long RMBuf should be free, but not:"));
|
|
337 |
firstSuccess = EFalse;
|
|
338 |
}
|
|
339 |
}
|
|
340 |
|
|
341 |
bChain.Append(aChain);
|
|
342 |
|
|
343 |
//-------------------substep 5-----------------------------
|
|
344 |
INFO_PRINTF1(_L(" 05 Allocate 750-byte long RMBuf after deallocating 2 512-byte long RMBufs:"));
|
|
345 |
mbuf4.Free(); // 512-byte mbuf
|
|
346 |
|
|
347 |
ret = aChain.Alloc(750, allocator);
|
|
348 |
if (ret != KErrNone)
|
|
349 |
{
|
|
350 |
INFO_PRINTF1(_L("Error: Couldn't allocate RMBuf:"));
|
|
351 |
secondSuccess = EFalse;
|
|
352 |
}
|
|
353 |
else
|
|
354 |
{
|
|
355 |
//Copy in Des1 into Chain
|
|
356 |
aChain.CopyIn(aDes1->LeftTPtr(750));
|
|
357 |
if (aChain.Length() != 750)
|
|
358 |
{
|
|
359 |
INFO_PRINTF1(_L("Error: Allocated RMBufChain size does not match requested:"));
|
|
360 |
secondSuccess = EFalse;
|
|
361 |
}
|
|
362 |
}
|
|
363 |
|
|
364 |
bChain.Append(aChain);
|
|
365 |
|
|
366 |
//-------------------substep 6-----------------------------
|
|
367 |
INFO_PRINTF1(_L(" 06 Allocate 2100-byte long RMBuf after deallocating 2 2048-byte long RMBufs:"));
|
|
368 |
mbuf5.Free(); // 2048-byte mbuf
|
|
369 |
mbuf6.Free(); // 2048-byte mbuf
|
|
370 |
|
|
371 |
ret = aChain.Alloc(2100, allocator);
|
|
372 |
if (ret != KErrNone)
|
|
373 |
{
|
|
374 |
INFO_PRINTF1(_L("Error: Couldn't allocate RMBuf:"));
|
|
375 |
thirdSuccess = EFalse;
|
|
376 |
}
|
|
377 |
else
|
|
378 |
{
|
|
379 |
//Copy in Des1 into Chain
|
|
380 |
aChain.CopyIn(aDes1->LeftTPtr(2100));
|
|
381 |
if (aChain.Length() != 2100)
|
|
382 |
{
|
|
383 |
INFO_PRINTF1(_L("Error: Allocated RMBufChain size does not match requested:"));
|
|
384 |
thirdSuccess = EFalse;
|
|
385 |
}
|
|
386 |
}
|
|
387 |
|
|
388 |
bChain.Append(aChain);
|
|
389 |
|
|
390 |
mbuf1.Free();
|
|
391 |
bChain.Free();
|
|
392 |
|
|
393 |
delete aDes1;
|
|
394 |
|
|
395 |
//-------------- substep 7 --------------------
|
|
396 |
INFO_PRINTF1(_L(" 07 Clean up stack:"));
|
|
397 |
CleanupStack::PopAndDestroy();
|
|
398 |
CActiveScheduler::Install(NULL);
|
|
399 |
CleanupStack::PopAndDestroy(iActSch);
|
|
400 |
|
|
401 |
if (ret != KErrNone || failedSizeCount > 0 || !firstSuccess || !secondSuccess || !thirdSuccess)
|
|
402 |
{
|
|
403 |
SetTestStepResult(EFail);
|
|
404 |
return TestStepResult();
|
|
405 |
}
|
|
406 |
|
|
407 |
SetTestStepResult(EPass);
|
|
408 |
return TestStepResult();
|
|
409 |
}
|