|
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 #include <networking/log.h> |
|
23 #include <networking/teststep.h> |
|
24 #include "TestStepCTMbufmgr.h" |
|
25 #include "TestSuiteCTMbufmgr.h" |
|
26 |
|
27 #include "test17requestsizelimits.h" |
|
28 |
|
29 // RHeap information |
|
30 #include <comms-infras/mbufallocator.h> |
|
31 |
|
32 CTest17RequestSizeLimits::CTest17RequestSizeLimits() |
|
33 { |
|
34 iTestStepName = _L("MBufMgrTest17");// Store the name of this test case |
|
35 } |
|
36 |
|
37 CTest17RequestSizeLimits::~CTest17RequestSizeLimits() |
|
38 { |
|
39 } |
|
40 |
|
41 void CTest17RequestSizeLimits::FillDes(TDes8 &aBuf, TInt aStartPos, TInt anEndPos, TUint aStartChar, TUint anEndChar) |
|
42 { |
|
43 StripeDes(aBuf, aStartPos, anEndPos, aStartChar, anEndChar); |
|
44 } |
|
45 |
|
46 enum TVerdict CTest17RequestSizeLimits::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 262144 |
|
63 CleanupStack::PushL(CreateInstanceMBufMgrL(KMBufDefaultHeapSize, 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 //-------------- substep 2 -------------------- |
|
87 Log(_L(" 02 Fill in the Des1 with a pattern:")); |
|
88 TBuf8<5000> *aDes1 = NULL; |
|
89 TRAPD(ret, aDes1 = new(ELeave) TBuf8<5000>); |
|
90 if(ret != KErrNone) |
|
91 return EFail; |
|
92 |
|
93 aDes1->SetLength(5000); |
|
94 FillDes(*aDes1, 0, 5000, 1, 1); |
|
95 |
|
96 TBool firstAllocFail = EFalse; |
|
97 TBool secondAllocFail = EFalse; |
|
98 TBool thirdAllocFail = EFalse; |
|
99 |
|
100 TUint time; |
|
101 RMBufChain aChain; |
|
102 |
|
103 //-------------- substep 3 -------------------- |
|
104 Log(_L(" 03 Allocate 5000-bytes long RMBufChain with 128-bytes long RMBuf:")); |
|
105 |
|
106 time = User::FastCounter(); |
|
107 ret = aChain.Alloc(5000, 128, 128, allocator); |
|
108 time = User::FastCounter() - time; |
|
109 if (ret != KErrNone) |
|
110 { |
|
111 Log(_L("Error: Couldn't allocate RMBufChain:")); |
|
112 User::Leave(EFail); |
|
113 } |
|
114 |
|
115 //Copy in Des1 into Chain |
|
116 aChain.CopyIn(aDes1->LeftTPtr(5000)); |
|
117 if (aChain.Length() != 5000) |
|
118 { |
|
119 Log(_L("Error: Allocated RMBufChain size does not match requested:")); |
|
120 firstAllocFail = ETrue; |
|
121 } |
|
122 |
|
123 TInt count = 0; |
|
124 //Check RMBuf size is really 128 |
|
125 RMBuf* mBuf = aChain.First(); |
|
126 while (mBuf != NULL) |
|
127 { |
|
128 count++; |
|
129 if (mBuf->Size() != 128) |
|
130 { |
|
131 Log(_L("Error: RMBuf size does not match requested:")); |
|
132 firstAllocFail = ETrue; |
|
133 break; |
|
134 } |
|
135 mBuf = mBuf->Next(); |
|
136 } |
|
137 |
|
138 if (firstAllocFail == EFalse) |
|
139 { |
|
140 _LIT(aLog1, " Info: Time to allocate 5000-bytes long RMBufChain with %d 128-bytes long RMBuf: %d"); |
|
141 Log(aLog1, count, time); |
|
142 } |
|
143 |
|
144 //-------------- substep 4 -------------------- |
|
145 Log(_L(" 04 Deallocating RMBufChain")); |
|
146 aChain.Free(); |
|
147 |
|
148 //-------------- substep 5 -------------------- |
|
149 Log(_L(" 05 Allocate 50-bytes long RMBufChain with 1024-bytes long RMBuf:")); |
|
150 |
|
151 time = User::FastCounter(); |
|
152 ret = aChain.Alloc(50, 1024, 1024, allocator); |
|
153 time = User::FastCounter() - time; |
|
154 if (ret != KErrNone) |
|
155 { |
|
156 Log(_L("Error: Couldn't allocate RMBufChain:")); |
|
157 User::Leave(EFail); |
|
158 } |
|
159 |
|
160 //Copy in Des1 into Chain |
|
161 aChain.CopyIn(aDes1->LeftTPtr(50)); |
|
162 if (aChain.Length() != 50) |
|
163 { |
|
164 Log(_L("Error: Allocated RMBufChain size does not match requested:")); |
|
165 secondAllocFail = ETrue; |
|
166 } |
|
167 |
|
168 count = 0; |
|
169 //Check RMBuf size is really 1024 |
|
170 mBuf = aChain.First(); |
|
171 while (mBuf != NULL) |
|
172 { |
|
173 count++; |
|
174 if (mBuf->Size() != 1024) |
|
175 { |
|
176 Log(_L("Error: RMBuf size does not match requested:")); |
|
177 secondAllocFail = ETrue; |
|
178 break; |
|
179 } |
|
180 mBuf = mBuf->Next(); |
|
181 } |
|
182 |
|
183 if (secondAllocFail == EFalse) |
|
184 { |
|
185 _LIT(aLog2, " Info: Time to allocate 50-bytes long RMBufChain with %d 1024-bytes long RMBuf: %d"); |
|
186 Log(aLog2, count, time); |
|
187 } |
|
188 |
|
189 //-------------- substep 6 -------------------- |
|
190 Log(_L(" 06 Deallocating RMBufChain")); |
|
191 aChain.Free(); |
|
192 |
|
193 //-------------- substep 7 -------------------- |
|
194 Log(_L(" 07 Allocate 1500-bytes long RMBufChain with RMBuf size between 1100 and 2000:")); |
|
195 |
|
196 ret = aChain.Alloc(1500, 1100, 2000, allocator); |
|
197 if (ret == KErrNone) |
|
198 { |
|
199 Log(_L("Error: Allocated with false size RMBuf:")); |
|
200 thirdAllocFail = ETrue; |
|
201 aChain.Free(); |
|
202 } |
|
203 else |
|
204 Log(_L(" Info: Couldn't allocate because no MBuf with size between 1100 and 2000:")); |
|
205 |
|
206 //-------------- substep 8 -------------------- |
|
207 Log(_L(" 08 Allocate 1500-bytes long RMBufChain with RMBuf min. size 2100:")); |
|
208 |
|
209 ret = aChain.Alloc(1500, 2100, allocator); |
|
210 if (ret == KErrNone) |
|
211 { |
|
212 Log(_L("Error: Allocated with false size RMBuf:")); |
|
213 thirdAllocFail = ETrue; |
|
214 aChain.Free(); |
|
215 } |
|
216 else |
|
217 Log(_L(" Info: Couldn't allocate because no MBuf with size greater than 2100:")); |
|
218 |
|
219 //-------------- substep 9 -------------------- |
|
220 Log(_L(" 09 Allocate 1500-bytes long RMBufChain with RMBuf max. size 100:")); |
|
221 |
|
222 ret = aChain.Alloc(1500, 0, 100, allocator); |
|
223 if (ret == KErrNone) |
|
224 { |
|
225 Log(_L("Error: Allocated with false size RMBuf:")); |
|
226 thirdAllocFail = ETrue; |
|
227 aChain.Free(); |
|
228 } |
|
229 else |
|
230 Log(_L(" Info: Couldn't allocate because no MBuf with size smaller than 100:")); |
|
231 |
|
232 //-------------- substep 10 -------------------- |
|
233 Log(_L(" 10 Exhaust 512-bytes long RMBufChain :")); |
|
234 |
|
235 RMBufChain bChain; |
|
236 |
|
237 while (allocator.BytesAvailable(512) / 512 > 0) |
|
238 { |
|
239 ret = aChain.Alloc(500, allocator); |
|
240 if (ret != KErrNone) |
|
241 { |
|
242 Log(_L("Error: Couldn't allocate RMBufChain:")); |
|
243 User::Leave(EFail); |
|
244 } |
|
245 |
|
246 // Now grow the chain |
|
247 bChain.Append(aChain); |
|
248 } |
|
249 |
|
250 //-------------- substep 11 -------------------- |
|
251 Log(_L(" 15 Allocate 500-bytes long RMBufChain with 512-bytes long RMBuf:")); |
|
252 |
|
253 ret = aChain.Alloc(500, 512, 512, allocator); |
|
254 if (ret == KErrNone) |
|
255 { |
|
256 Log(_L("Error: Allocated with false size RMBuf:")); |
|
257 thirdAllocFail = ETrue; |
|
258 aChain.Free(); |
|
259 } |
|
260 else |
|
261 Log(_L(" Info: Couldn't allocate because no more 512-bytes long RMBuf:")); |
|
262 |
|
263 //-------------- substep 12 -------------------- |
|
264 Log(_L(" 12 Deallocating RMBufChain")); |
|
265 bChain.Free(); |
|
266 |
|
267 delete aDes1; |
|
268 |
|
269 //-------------- substep 13 -------------------- |
|
270 Log(_L(" 13 Clean up stack:")); |
|
271 CleanupStack::PopAndDestroy(iMBMngr); |
|
272 CActiveScheduler::Install(NULL); |
|
273 CleanupStack::PopAndDestroy(iActSch); |
|
274 |
|
275 #ifdef __CFLOG_ACTIVE |
|
276 __CFLOG_CLOSE; |
|
277 __CFLOG_DELETE; |
|
278 #endif |
|
279 |
|
280 if (firstAllocFail || secondAllocFail || thirdAllocFail) |
|
281 return EFail; |
|
282 |
|
283 __UHEAP_MARKEND; |
|
284 return EPass; |
|
285 } |