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 16 - Memory Full |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 #include <ss_std.h> |
|
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 "test16memoryfull.h" |
|
33 |
|
34 #include <comms-infras/mbufallocator.h> |
|
35 #include <comms-infras/commsbufpond.h> |
|
36 // constructor |
|
37 CTest16MemoryFull::CTest16MemoryFull() |
|
38 { |
|
39 iTestStepName = _L("MBufMgrTest16");// Store the name of this test case |
|
40 } |
|
41 |
|
42 // destructor |
|
43 CTest16MemoryFull::~CTest16MemoryFull() |
|
44 { |
|
45 } |
|
46 |
|
47 // |
|
48 void CTest16MemoryFull::FillDes(TDes8 &aBuf, TInt aStartPos, TInt anEndPos, TUint aStartChar, TUint anEndChar) |
|
49 { |
|
50 StripeDes(aBuf, aStartPos, anEndPos, aStartChar, anEndChar); |
|
51 } |
|
52 |
|
53 RCommsBufPond& CTest16MemoryFull::BufPond() |
|
54 { |
|
55 return iBufPond; |
|
56 } |
|
57 |
|
58 |
|
59 |
|
60 enum TVerdict CTest16MemoryFull::doTestStepL(void) |
|
61 { |
|
62 __UHEAP_MARK; |
|
63 |
|
64 #ifdef __CFLOG_ACTIVE |
|
65 __CFLOG_CREATEL; |
|
66 __CFLOG_OPEN; |
|
67 #endif |
|
68 |
|
69 //-------------- substep 1 -------------------- |
|
70 Log(_L(" 01 Create CMBufManager and install active scheduler:")); |
|
71 CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler ); |
|
72 CActiveScheduler::Install(iActSch); |
|
73 |
|
74 // Create some initial pools |
|
75 // AddL(KMBuf_MBufSize, KMBuf_InitialAllocation, KMBuf_MinGrowth, KMBuf_GrowthThreshold) |
|
76 // Background memory allocation (CMBufPoolManager::RunL) is used more frequently if |
|
77 // the KMBuf_MinGrowth and the KMBuf_GrowthThreshold are similar in size |
|
78 // Synchronous allocation (AllocPool(*poolChain, growth, ETrue)) occurs when the |
|
79 // requested size (iChain.CopyIn(size)) is larger than the KMBuf_MinGrowth |
|
80 // Multiple threads attempt to grow different poolchains at the same time when there |
|
81 // are a greater variety of pool sizes to grow. |
|
82 // 16384 |
|
83 |
|
84 RArray<TCommsBufPoolCreateInfo> createInfoArray; |
|
85 |
|
86 TCommsBufPoolCreateInfo createInfo; |
|
87 createInfo.iBufSize = 128; |
|
88 createInfo.iInitialBufs = 128; |
|
89 createInfo.iGrowByBufs = 64; |
|
90 createInfo.iMinFreeBufs = 40; |
|
91 createInfo.iCeiling = 410; |
|
92 |
|
93 TCommsBufPoolCreateInfo createInfo2; |
|
94 createInfo2.iBufSize = 256; |
|
95 createInfo2.iInitialBufs = 64; |
|
96 createInfo2.iGrowByBufs = 7; |
|
97 createInfo2.iMinFreeBufs = 6; |
|
98 createInfo2.iCeiling = 204; |
|
99 |
|
100 TCommsBufPoolCreateInfo createInfo3; |
|
101 createInfo3.iBufSize = 512; |
|
102 createInfo3.iInitialBufs = 32; |
|
103 createInfo3.iGrowByBufs = 6; |
|
104 createInfo3.iMinFreeBufs = 5; |
|
105 createInfo3.iCeiling = 125; |
|
106 |
|
107 TCommsBufPoolCreateInfo createInfo4; |
|
108 createInfo4.iBufSize = 1024; |
|
109 createInfo4.iInitialBufs = 16; |
|
110 createInfo4.iGrowByBufs = 5; |
|
111 createInfo4.iMinFreeBufs = 4; |
|
112 createInfo4.iCeiling = 51; |
|
113 |
|
114 TCommsBufPoolCreateInfo createInfo5; |
|
115 createInfo5.iBufSize = 2048; |
|
116 createInfo5.iInitialBufs = 8; |
|
117 createInfo5.iGrowByBufs = 4; |
|
118 createInfo5.iMinFreeBufs = 3; |
|
119 createInfo5.iCeiling = 15; |
|
120 |
|
121 createInfoArray.Append(createInfo); |
|
122 createInfoArray.Append(createInfo2); |
|
123 createInfoArray.Append(createInfo3); |
|
124 createInfoArray.Append(createInfo4); |
|
125 createInfoArray.Append(createInfo5); |
|
126 // Create 262144 |
|
127 CreateInstanceMBufMgrL(createInfoArray); |
|
128 CleanupClosePushL(iBufPond); |
|
129 createInfoArray.Close (); |
|
130 |
|
131 TBuf8<KFactor*KFactor*KFactor*KFactor> *aDes1, *aDes2; |
|
132 CleanupStack::PushL( aDes1 = new(ELeave) TBuf8<KFactor*KFactor*KFactor*KFactor> ); |
|
133 CleanupStack::PushL( aDes2 = new(ELeave) TBuf8<KFactor*KFactor*KFactor*KFactor> ); |
|
134 |
|
135 //-------------------substep 02----------------------------- |
|
136 Log(_L(" 02 Create and install active object that will do the test:")); |
|
137 RMBufAsyncRequest async; |
|
138 CMBufAsyncMemFull* memoryfull; |
|
139 CleanupStack::PushL(memoryfull = new(ELeave) CMBufAsyncMemFull(this, async, aDes1, aDes2)); |
|
140 CActiveScheduler::Add(memoryfull); |
|
141 |
|
142 //-------------------substep 03----------------------------- |
|
143 Log(_L(" 03 Start the test:")); |
|
144 |
|
145 TInt ret = memoryfull->DoStartTest(); |
|
146 if (ret != KErrNone) |
|
147 { |
|
148 Log(_L("Error: Async Alloc's failing in test run:")); |
|
149 User::Leave(EFail); |
|
150 } |
|
151 |
|
152 // If allocation less than expected then there may be a problem. |
|
153 // So get the allocated memory for each pool chain |
|
154 RMBufAllocator allocator; |
|
155 |
|
156 TInt size = allocator.NextMBufSize(0); |
|
157 _LIT(aLogD," Info: Available MBufs in %d Pool Chain: %d"); |
|
158 while (size != KErrNotFound) |
|
159 { |
|
160 Log(aLogD, size, allocator.BytesAvailable(size) / size); |
|
161 size = allocator.NextMBufSize(size); |
|
162 } |
|
163 |
|
164 // TInt heapSize = iMBMngr->__DbgGetHeapSize(); |
|
165 |
|
166 //Clean up stack |
|
167 CleanupStack::PopAndDestroy(memoryfull); |
|
168 CleanupStack::PopAndDestroy(aDes2); |
|
169 CleanupStack::PopAndDestroy(aDes1); |
|
170 CleanupStack::PopAndDestroy(); |
|
171 CActiveScheduler::Install(NULL); |
|
172 CleanupStack::PopAndDestroy(iActSch); |
|
173 |
|
174 #ifdef __CFLOG_ACTIVE |
|
175 __CFLOG_CLOSE; |
|
176 __CFLOG_DELETE; |
|
177 #endif |
|
178 |
|
179 //-------------------substep 04----------------------------- |
|
180 _LIT(aLog1," Info: Number of main thread checkings: %d with %d fails last failure on %d"); Log(aLog1,iMainThreadTries,iMainThreadFails,iMainThreadLastFailure); |
|
181 _LIT(aLog2," Info: Number of main thread allocate size failures: %d"); Log(aLog2,iMainThreadSizeFails); |
|
182 _LIT(aLog3," Info: Number of high priority thread checkings: %d with %d fails"); Log(aLog3,iThread3Tries,iThread3Fails); |
|
183 _LIT(aLog4," Info: Number of high priority thread allocation failures: %d"); Log(aLog4,iThread3AllocFails); |
|
184 _LIT(aLog5," Info: Number of memory gobbler allocate tries and failures: %d with %d memory full last memory full on %d"); Log(aLog5,iThread1AllocTries,iThread1MemoryFull,iThread1LastMemoryFull); |
|
185 _LIT(aLog6," Info: Number of memory gobbler allocate size failures: %d"); Log(aLog6,iThread1SizeFails); |
|
186 _LIT(aLog7," Info: Number of memory gobbler allocate tries and failures: %d with %d memory full last memory full on %d"); Log(aLog7,iThread2AllocTries,iThread2MemoryFull,iThread2LastMemoryFull); |
|
187 _LIT(aLog8," Info: Number of memory gobbler allocate size failures: %d"); Log(aLog8,iThread2SizeFails); |
|
188 _LIT(aLog9," Info: Max chain length for memory gobbler allocation: %d ; %d"); Log(aLog9,iThread1MaxLen,iThread2MaxLen); |
|
189 // _LIT(aLogA," Info: Max allocated memory: %d"); Log(aLogA,heapSize); |
|
190 _LIT(aLogB," Info: Basic API (uses TLS) - Average time to allocate mbufs: %d ; Average time to free mbufs %d"); |
|
191 Log(aLogB,iThread1AllocTime/iThread1AllocTries,iThread1FreeTime/(1000 - iThread1AllocTries)); |
|
192 _LIT(aLogC," Info: Higher Speed API (no TLS) - Average time to allocate mbufs: %d ; Average time to free mbufs %d"); |
|
193 Log(aLogC,iThread2AllocTime/iThread2AllocTries,iThread2FreeTime/(1000 - iThread2AllocTries)); |
|
194 |
|
195 if (iThread3Tries <1000) |
|
196 { |
|
197 Log(_L(" Error: High priority thread ended before 1000 loops are finished")); |
|
198 |
|
199 return EFail; |
|
200 } |
|
201 |
|
202 // test to see if the byte by byte comparisons failed |
|
203 if ( iThread3Fails || iMainThreadFails || iThread1SizeFails || iThread2SizeFails) |
|
204 { |
|
205 Log(_L(" Error: MBuf allocation failure")); |
|
206 |
|
207 return EFail; |
|
208 } |
|
209 |
|
210 // Test the maximum allocated memory |
|
211 // Some of the possible problems include failing to background allocate new memory |
|
212 /* if ( KMBufDefaultHeapSize > (heapSize + KMBufDefaultHeapSize/100) ) |
|
213 { |
|
214 Log(_L(" Error: Background allocation may have failed")); |
|
215 |
|
216 return EFail; |
|
217 } |
|
218 */ async.Close(); |
|
219 __UHEAP_MARKEND; |
|
220 return EPass; |
|
221 |
|
222 } |
|
223 |
|
224 // Async request |
|
225 CMBufAsyncMemFull::CMBufAsyncMemFull(CTest16MemoryFull* aTestObject, |
|
226 RMBufAsyncRequest& aMBufAsyncReq, |
|
227 TDes8 *aDes1, |
|
228 TDes8 *aDes2) |
|
229 :CActive(EPriorityStandard) |
|
230 ,iTestObject(aTestObject) |
|
231 ,iDes1(aDes1) |
|
232 ,iDes2(aDes2) |
|
233 ,iMBufAsyncReq(aMBufAsyncReq) |
|
234 { |
|
235 } |
|
236 |
|
237 TInt CMBufAsyncMemFull::DoStartTest() |
|
238 { |
|
239 |
|
240 // Create some random sizes for allocation later |
|
241 for (TInt i=1; i<(KFactor+1); i++) |
|
242 { |
|
243 iRequested_size[i-1] = i * i * i * KFactor; |
|
244 } |
|
245 |
|
246 // Allocate two 5000-bytes long descriptors (Des1 & Des2):")); |
|
247 iDes1->SetLength(iRequested_size[KFactor-1]); |
|
248 iDes2->SetLength(iRequested_size[KFactor-1]); |
|
249 //Fill in the Des1 with a pattern:")); |
|
250 iTestObject->FillDes(*iDes1, 0, iRequested_size[KFactor-1], '@', 'Z'); |
|
251 |
|
252 //-------------------substep 01----------------------------- |
|
253 |
|
254 TInt err=iThread1.Create(_L("testThread1Rec"), |
|
255 fThread1, |
|
256 KDefaultStackSize, |
|
257 KDefaultHeapSize, |
|
258 KMaxHeapSize, |
|
259 (TAny*)iTestObject, |
|
260 EOwnerProcess); |
|
261 if (err!=KErrNone) |
|
262 { |
|
263 User::Leave(EFail); |
|
264 } |
|
265 iThread1.SetPriority(EPriorityAbsoluteHigh); |
|
266 iThread1.Resume(); |
|
267 |
|
268 //-------------------substep 02----------------------------- |
|
269 RThread aThread2; |
|
270 |
|
271 err=iThread2.Create(_L("testThread2Rec"), |
|
272 fThread2, |
|
273 KDefaultStackSize, |
|
274 KDefaultHeapSize, |
|
275 KMaxHeapSize, |
|
276 (TAny*)iTestObject, |
|
277 EOwnerProcess); |
|
278 if (err!=KErrNone) |
|
279 { |
|
280 User::Leave(EFail); |
|
281 } |
|
282 iThread2.SetPriority(EPriorityAbsoluteHigh); |
|
283 iThread2.Resume(); |
|
284 |
|
285 //-------------------substep 03----------------------------- |
|
286 RThread aThread3; |
|
287 |
|
288 err=iThread3.Create(_L("testThread3Rec"), |
|
289 fThread3, |
|
290 KDefaultStackSize, |
|
291 KDefaultHeapSize, |
|
292 KMaxHeapSize, |
|
293 (TAny*)iTestObject, |
|
294 EOwnerProcess); |
|
295 if (err!=KErrNone) |
|
296 { |
|
297 User::Leave(EFail); |
|
298 } |
|
299 iThread3.SetPriority(EPriorityAbsoluteHigh); |
|
300 iThread3.Resume(); |
|
301 |
|
302 //-------------------substep 04----------------------------- |
|
303 |
|
304 iMBufAsyncReq.Alloc(iChain, iRequested_size[iRequestloop], iStatus); |
|
305 SetActive(); |
|
306 CActiveScheduler::Start(); |
|
307 |
|
308 iThread1.Close(); |
|
309 iThread2.Close(); |
|
310 iThread3.Close(); |
|
311 |
|
312 return iStatus.Int(); |
|
313 } |
|
314 |
|
315 |
|
316 void CMBufAsyncMemFull::RunL() |
|
317 { |
|
318 if (iStatus.Int() == KErrNone) |
|
319 { |
|
320 |
|
321 //Copy in Des1 into Chain |
|
322 iChain.CopyIn(iDes1->LeftTPtr(iRequested_size[iRequestloop])); |
|
323 //Fill left most part of Des2 with zeros:")); |
|
324 iDes2->SetLength(iRequested_size[KFactor-1]); |
|
325 iTestObject->FillDes(*iDes2, 0, iRequested_size[iRequestloop], 0, 0); |
|
326 //Copy out Chain into Des2:")); |
|
327 iChain.CopyOut(*iDes2); |
|
328 //Compare the contents of Des1 & Des2: |
|
329 if((iDes1->LeftTPtr(iRequested_size[iRequestloop])). |
|
330 Compare(iDes2->Left(iRequested_size[iRequestloop]))) |
|
331 { |
|
332 iTestObject->iMainThreadFails++; |
|
333 iTestObject->iMainThreadLastFailure = iTestObject->iMainThreadTries; |
|
334 if (iChain.Length() != iRequested_size[iRequestloop]) |
|
335 { |
|
336 iTestObject->iMainThreadSizeFails++; |
|
337 } |
|
338 } |
|
339 iTestObject->iMainThreadTries++; |
|
340 //Free chain |
|
341 iChain.Free(); |
|
342 |
|
343 //Check whether the other task has finished |
|
344 TBool isRunning1 = ETrue; |
|
345 TBool isRunning2 = ETrue; |
|
346 TBool isRunning3 = ETrue; |
|
347 volatile TExitType aExit; |
|
348 aExit = iThread1.ExitType(); |
|
349 if (aExit != EExitPending) |
|
350 { |
|
351 isRunning1 = EFalse; |
|
352 } |
|
353 aExit = iThread2.ExitType(); |
|
354 if (aExit != EExitPending) |
|
355 { |
|
356 isRunning2 = EFalse; |
|
357 } |
|
358 aExit = iThread3.ExitType(); |
|
359 if (aExit != EExitPending) |
|
360 { |
|
361 isRunning3 = EFalse; |
|
362 } |
|
363 |
|
364 iRequestloop++; |
|
365 if (iRequestloop>9) |
|
366 { |
|
367 iRequestloop = 0; |
|
368 } |
|
369 |
|
370 if (isRunning1 || isRunning2 || isRunning3) |
|
371 { |
|
372 |
|
373 iMBufAsyncReq.Alloc(iChain, iRequested_size[iRequestloop], iStatus); |
|
374 |
|
375 SetActive(); |
|
376 |
|
377 return; |
|
378 } |
|
379 } |
|
380 |
|
381 CActiveScheduler::Stop(); |
|
382 |
|
383 } |
|
384 |
|
385 // The memory gobbler thread |
|
386 TInt CMBufAsyncMemFull::fThread1(TAny* aInput) |
|
387 { |
|
388 CTest16MemoryFull* pTestObject = (CTest16MemoryFull*)aInput; |
|
389 // We need to introduce this new client thread to the MBufMgr |
|
390 TCommsBufPondTLSOp tls(pTestObject->BufPond()); |
|
391 tls.Set(); |
|
392 |
|
393 CTrapCleanup* aCleanup = CTrapCleanup::New(); |
|
394 |
|
395 //Install active scheduler |
|
396 CActiveScheduler* aActSch = new CActiveScheduler; |
|
397 if(aActSch==NULL) |
|
398 { |
|
399 return KErrNoMemory; |
|
400 } |
|
401 CActiveScheduler::Install(aActSch); |
|
402 |
|
403 RTimer aTimer; |
|
404 TRequestStatus aTimerStatus; // Request status associated with timer |
|
405 aTimer.CreateLocal(); // Create timer for this thread |
|
406 //-------------- substep 1 -------------------- |
|
407 |
|
408 // Create some random sizes for allocation later |
|
409 TInt requested_size[KFactor1]; |
|
410 for (TInt i=1; i<(KFactor1+1); i++) |
|
411 { |
|
412 requested_size[i-1] = i * i * KFactor1; |
|
413 } |
|
414 |
|
415 // Allocate two 5000-bytes long descriptors (Des1 & Des2):")); |
|
416 TBuf8<KFactor1*KFactor1*KFactor1> *aDes1=NULL; |
|
417 TRAPD(ret, aDes1 = new(ELeave) TBuf8<KFactor1*KFactor1*KFactor1> ); |
|
418 if(ret!=KErrNone) |
|
419 { |
|
420 return ret; |
|
421 } |
|
422 |
|
423 aDes1->SetLength(requested_size[KFactor1-1]); |
|
424 |
|
425 //Fill in the Des1 with a pattern:")); |
|
426 pTestObject->FillDes(*aDes1, 0, requested_size[KFactor1-1], 1, 1); |
|
427 |
|
428 #ifdef __CFLOG_ACTIVE |
|
429 __CFLOG_DECLARATION_VARIABLE; |
|
430 TRAP(ret, __CFLOG_CREATEL); |
|
431 if(ret!=KErrNone) |
|
432 { |
|
433 delete aDes1; |
|
434 return ret; |
|
435 } |
|
436 __CFLOG_OPEN; |
|
437 #endif |
|
438 |
|
439 TUint time; |
|
440 RMBufChain aChain; |
|
441 RMBufChain bChain; |
|
442 TInt requestloop = 0; |
|
443 TBool isFillMe = ETrue; |
|
444 for (TInt i = 0 ; i<1000;i++) |
|
445 { |
|
446 if (isFillMe) |
|
447 { |
|
448 pTestObject->iThread1AllocTries++; |
|
449 //Use up mbuf memory by appending to a chain |
|
450 time = User::FastCounter(); |
|
451 TRAP(ret,aChain.AllocL(requested_size[requestloop])); |
|
452 time = User::FastCounter() - time; |
|
453 if (ret != KErrNone) |
|
454 { |
|
455 isFillMe = EFalse; |
|
456 pTestObject->iThread1MemoryFull++; |
|
457 pTestObject->iThread1LastMemoryFull = pTestObject->iThread1AllocTries - 1; |
|
458 } |
|
459 else |
|
460 { |
|
461 pTestObject->iThread1AllocTime += time; |
|
462 //Copy in Des1 into Chain |
|
463 aChain.CopyIn(aDes1->LeftTPtr(requested_size[requestloop])); |
|
464 if (aChain.Length() != requested_size[requestloop]) |
|
465 { |
|
466 pTestObject->iThread1SizeFails++; |
|
467 } |
|
468 // Now grow the chain |
|
469 bChain.Append(aChain); |
|
470 } |
|
471 } |
|
472 else |
|
473 { |
|
474 //Free some memory |
|
475 TInt length = bChain.Length(); |
|
476 if (length > pTestObject->iThread1MaxLen) |
|
477 { |
|
478 pTestObject->iThread1MaxLen = length; |
|
479 } |
|
480 TInt trimOffset = length - requested_size[requestloop]; |
|
481 if (trimOffset > 0) |
|
482 { |
|
483 time = User::FastCounter(); |
|
484 bChain.TrimEnd(trimOffset); |
|
485 time = User::FastCounter() - time; |
|
486 pTestObject->iThread1FreeTime += time; |
|
487 } |
|
488 else |
|
489 { |
|
490 isFillMe = ETrue; |
|
491 } |
|
492 } |
|
493 |
|
494 //Sleep for 5ms |
|
495 aTimer.After(aTimerStatus,5000); |
|
496 User::WaitForRequest(aTimerStatus); |
|
497 |
|
498 requestloop++; |
|
499 if (requestloop>(KFactor1-1)) |
|
500 { |
|
501 requestloop = 0; |
|
502 } |
|
503 } |
|
504 // Free the memory |
|
505 bChain.Free(); |
|
506 |
|
507 delete aDes1; |
|
508 CActiveScheduler::Install(NULL); |
|
509 delete aActSch; |
|
510 delete aCleanup; |
|
511 |
|
512 #ifdef __CFLOG_ACTIVE |
|
513 __CFLOG_CLOSE; |
|
514 __CFLOG_DELETE; |
|
515 #endif |
|
516 |
|
517 return ret; |
|
518 } |
|
519 |
|
520 // The memory gobbler thread |
|
521 TInt CMBufAsyncMemFull::fThread2(TAny* aInput) |
|
522 { |
|
523 CTest16MemoryFull* pTestObject = (CTest16MemoryFull*)aInput; |
|
524 // We need to introduce this new client thread to the MBufMgr |
|
525 TCommsBufPondTLSOp tls(pTestObject->BufPond()); |
|
526 tls.Set(); |
|
527 |
|
528 CTrapCleanup* aCleanup = CTrapCleanup::New(); |
|
529 |
|
530 //Install active scheduler |
|
531 CActiveScheduler* aActSch = new CActiveScheduler; |
|
532 if(aActSch==NULL) |
|
533 { |
|
534 return KErrNoMemory; |
|
535 } |
|
536 CActiveScheduler::Install(aActSch); |
|
537 |
|
538 RTimer aTimer; |
|
539 TRequestStatus aTimerStatus; // Request status associated with timer |
|
540 aTimer.CreateLocal(); // Create timer for this thread |
|
541 //-------------- substep 1 -------------------- |
|
542 |
|
543 // Create some random sizes for allocation later |
|
544 TInt requested_size[KFactor2]; |
|
545 for (TInt i=1; i<(KFactor2+1); i++) |
|
546 { |
|
547 requested_size[i-1] = i * i * KFactor2; |
|
548 } |
|
549 |
|
550 // Allocate two 5000-bytes long descriptors (Des1 & Des2):")); |
|
551 TBuf8<KFactor2*KFactor2*KFactor2> *aDes1=NULL; |
|
552 TRAPD(ret, aDes1 = new(ELeave) TBuf8<KFactor2*KFactor2*KFactor2> ); |
|
553 if(ret!=KErrNone) |
|
554 { |
|
555 return ret; |
|
556 } |
|
557 |
|
558 aDes1->SetLength(requested_size[KFactor2-1]); |
|
559 |
|
560 //Fill in the Des1 with a pattern:")); |
|
561 pTestObject->FillDes(*aDes1, 0, requested_size[KFactor2-1], 2, 2); |
|
562 |
|
563 #ifdef __CFLOG_ACTIVE |
|
564 __CFLOG_DECLARATION_VARIABLE; |
|
565 TRAP(ret, __CFLOG_CREATEL); |
|
566 if(ret!=KErrNone) |
|
567 { |
|
568 delete aDes1; |
|
569 return ret; |
|
570 } |
|
571 __CFLOG_OPEN; |
|
572 #endif |
|
573 |
|
574 RMBufAllocator allocator; |
|
575 TUint time; |
|
576 |
|
577 RMBufChain aChain; |
|
578 RMBufChain bChain; |
|
579 TInt requestloop = 0; |
|
580 TBool isFillMe = ETrue; |
|
581 for (TInt i = 0 ; i<1000;i++) |
|
582 { |
|
583 |
|
584 if (isFillMe) |
|
585 { |
|
586 pTestObject->iThread2AllocTries++; |
|
587 //Use up mbuf memory by appending to a chain |
|
588 time = User::FastCounter(); |
|
589 TRAP(ret,aChain.AllocL(requested_size[requestloop], allocator)); |
|
590 time = User::FastCounter() - time; |
|
591 if (ret != KErrNone) |
|
592 { |
|
593 isFillMe = EFalse; |
|
594 pTestObject->iThread2MemoryFull++; |
|
595 pTestObject->iThread2LastMemoryFull = pTestObject->iThread2AllocTries - 1; |
|
596 } |
|
597 else |
|
598 { |
|
599 pTestObject->iThread2AllocTime += time; |
|
600 //Copy in Des1 into Chain |
|
601 aChain.CopyIn(aDes1->LeftTPtr(requested_size[requestloop])); |
|
602 if (aChain.Length() != requested_size[requestloop]) |
|
603 { |
|
604 pTestObject->iThread2SizeFails++; |
|
605 } |
|
606 // Now grow the chain |
|
607 bChain.Append(aChain); |
|
608 } |
|
609 } |
|
610 else |
|
611 { |
|
612 //Free some memory |
|
613 TInt length = bChain.Length(); |
|
614 if (length > pTestObject->iThread2MaxLen) |
|
615 { |
|
616 pTestObject->iThread2MaxLen = length; |
|
617 } |
|
618 TInt trimOffset = length - requested_size[requestloop]; |
|
619 if (trimOffset > 0) |
|
620 { |
|
621 time = User::FastCounter(); |
|
622 bChain.TrimEnd(trimOffset); |
|
623 time = User::FastCounter() - time; |
|
624 pTestObject->iThread2FreeTime += time; |
|
625 } |
|
626 else |
|
627 { |
|
628 isFillMe = ETrue; |
|
629 } |
|
630 } |
|
631 |
|
632 //Sleep for 5ms |
|
633 aTimer.After(aTimerStatus,5000); |
|
634 User::WaitForRequest(aTimerStatus); |
|
635 |
|
636 requestloop++; |
|
637 if (requestloop>(KFactor2-1)) |
|
638 { |
|
639 requestloop = 0; |
|
640 } |
|
641 } |
|
642 // Free the memory |
|
643 bChain.Free(); |
|
644 |
|
645 delete aDes1; |
|
646 |
|
647 CActiveScheduler::Install(NULL); |
|
648 delete aActSch; |
|
649 delete aCleanup; |
|
650 |
|
651 #ifdef __CFLOG_ACTIVE |
|
652 __CFLOG_CLOSE; |
|
653 __CFLOG_DELETE; |
|
654 #endif |
|
655 |
|
656 return ret; |
|
657 } |
|
658 |
|
659 // |
|
660 TInt CMBufAsyncMemFull::fThread3(TAny* aInput) |
|
661 { |
|
662 CTest16MemoryFull* pTestObject = (CTest16MemoryFull*)aInput; |
|
663 // We need to introduce this new client thread to the MBufMgr |
|
664 TCommsBufPondTLSOp tls(pTestObject->BufPond()); |
|
665 tls.Set(); |
|
666 |
|
667 CTrapCleanup* aCleanup = CTrapCleanup::New(); |
|
668 |
|
669 //Install active scheduler |
|
670 CActiveScheduler* aActSch = new CActiveScheduler; |
|
671 if(aActSch==NULL) |
|
672 { |
|
673 return KErrNoMemory; |
|
674 } |
|
675 CActiveScheduler::Install(aActSch); |
|
676 |
|
677 RTimer aTimer; |
|
678 TRequestStatus aTimerStatus; // Request status associated with timer |
|
679 aTimer.CreateLocal(); // Create timer for this thread |
|
680 //-------------- substep 1 -------------------- |
|
681 |
|
682 // Allocate two 500-bytes long descriptors (Des1 & Des2):")); |
|
683 TBuf8<500> *aDes1 = NULL; |
|
684 TBuf8<500> *aDes2 = NULL; |
|
685 |
|
686 TRAPD(ret, aDes1 = new(ELeave) TBuf8<500>); |
|
687 if(ret!=KErrNone) |
|
688 { |
|
689 return ret; |
|
690 } |
|
691 |
|
692 TRAP(ret, aDes2 = new(ELeave) TBuf8<500>); |
|
693 if(ret!=KErrNone) |
|
694 { |
|
695 delete aDes1; |
|
696 return ret; |
|
697 } |
|
698 |
|
699 aDes1->SetLength(500); |
|
700 aDes2->SetLength(500); |
|
701 |
|
702 //Fill in the Des1 with a pattern |
|
703 pTestObject->FillDes(*aDes1, 0, 500, 'a', 'z'); |
|
704 |
|
705 #ifdef __CFLOG_ACTIVE |
|
706 __CFLOG_DECLARATION_VARIABLE; |
|
707 TRAP(ret, __CFLOG_CREATEL); |
|
708 if(ret!=KErrNone) |
|
709 { |
|
710 delete aDes1; |
|
711 delete aDes2; |
|
712 return ret; |
|
713 } |
|
714 __CFLOG_OPEN; |
|
715 #endif |
|
716 |
|
717 for (TInt i = 0 ; i<1000;i++) |
|
718 { |
|
719 //Allocate 500-bytes long RMBufChain |
|
720 RMBufChain aChain; |
|
721 TRAP(ret,aChain.AllocL(500)); |
|
722 if (ret == KErrNone) |
|
723 { |
|
724 //Copy in Des1 into Chain |
|
725 aChain.CopyIn(*aDes1); |
|
726 //Fill in Des2 with zeros |
|
727 pTestObject->FillDes(*aDes2, 0, 500, 0, 0); |
|
728 //Copy out Chain into Des2; |
|
729 aChain.CopyOut(*aDes2); |
|
730 //Compare the contents of Des1 & Des2 |
|
731 if(aDes1->Compare(*aDes2)) |
|
732 pTestObject->iThread3Fails++; |
|
733 //Free chain |
|
734 aChain.Free(); |
|
735 } |
|
736 else |
|
737 { |
|
738 pTestObject->iThread3AllocFails++; |
|
739 } |
|
740 pTestObject->iThread3Tries++; |
|
741 //Sleep for 5ms |
|
742 aTimer.After(aTimerStatus,5000); |
|
743 User::WaitForRequest(aTimerStatus); |
|
744 } |
|
745 delete aDes1; |
|
746 delete aDes2; |
|
747 CActiveScheduler::Install(NULL); |
|
748 delete aActSch; |
|
749 delete aCleanup; |
|
750 |
|
751 #ifdef __CFLOG_ACTIVE |
|
752 __CFLOG_CLOSE; |
|
753 __CFLOG_DELETE; |
|
754 #endif |
|
755 |
|
756 return ret; |
|
757 } |
|
758 |
|