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