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