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