commsfwutils/commsbufs/TS_mbufmgr/test20poolceilingfull.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <ss_std.h>
       
    19 // Test system includes
       
    20 #ifdef SYMBIAN_OLD_EXPORT_LOCATION
       
    21 #include "networking/log.h"
       
    22 #include "networking/teststep.h"
       
    23 #else
       
    24 #include <networking/log.h>
       
    25 #include <networking/teststep.h>
       
    26 #endif
       
    27 
       
    28 #include "TestStepCTMbufmgr.h"
       
    29 #include "TestSuiteCTMbufmgr.h"
       
    30 
       
    31 #include "test20poolceilingfull.h"
       
    32 
       
    33 
       
    34 CTest20PoolCeilingFull::CTest20PoolCeilingFull()
       
    35 	{
       
    36 	iTestStepName = _L("MBufMgrTest20");// Store the name of this test case
       
    37 	}
       
    38 
       
    39 CTest20PoolCeilingFull::~CTest20PoolCeilingFull()
       
    40 	{
       
    41 	iChain.Free();
       
    42 	}
       
    43 
       
    44 TVerdict CTest20PoolCeilingFull::doTestStepL()
       
    45 	{
       
    46 	__UHEAP_MARK;
       
    47 	//-------------- substep 1 --------------------
       
    48 	Log(_L("  01 Create CMBufManager and install active scheduler:"));
       
    49 	CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler );
       
    50 	CActiveScheduler::Install(iActSch);
       
    51 
       
    52 	RArray<TCommsBufPoolCreateInfo> createInfoArray;
       
    53 	
       
    54 	TCommsBufPoolCreateInfo createInfo;
       
    55 	createInfo.iBufSize = 256;
       
    56 	createInfo.iInitialBufs = 50;
       
    57 	createInfo.iGrowByBufs = 20;
       
    58 	createInfo.iMinFreeBufs = 4;
       
    59 	createInfo.iCeiling = 100; 
       
    60 	createInfoArray.Append(createInfo);
       
    61 
       
    62 	CreateInstanceMBufMgrL(createInfoArray);
       
    63 	CleanupClosePushL(iBufPond);
       
    64 	createInfoArray.Close ();
       
    65 
       
    66 	Log(_L("  02 Create and install active object that will do the test:"));
       
    67 
       
    68 	CMBufAsyncPoolCeilingFull* poolCeilingFull;
       
    69 	CleanupStack::PushL(poolCeilingFull = new(ELeave) CMBufAsyncPoolCeilingFull(*this));
       
    70 
       
    71 	Log(_L("  03 Start the test:"));
       
    72 	if(poolCeilingFull->DoStartTest() != KErrNone)
       
    73 		{
       
    74 		Log(_L("Error: Async Alloc's failing in test run:"));
       
    75 		User::Leave(EFail);
       
    76 		}
       
    77 	//Clean up stack
       
    78 	CleanupStack::PopAndDestroy(); // poolCeilingFull
       
    79 	CleanupStack::PopAndDestroy(); // bufpond
       
    80 	CActiveScheduler::Install(NULL);
       
    81 	CleanupStack::PopAndDestroy(iActSch);
       
    82 
       
    83 	__UHEAP_MARKEND;
       
    84 	return EPass;
       
    85 	}
       
    86 
       
    87 RCommsBufPond& CTest20PoolCeilingFull::BufPond()
       
    88 	{
       
    89 	return iBufPond;
       
    90 	}
       
    91 
       
    92 CMBufAsyncPoolCeilingFull::CMBufAsyncPoolCeilingFull(CTest20PoolCeilingFull& aTestObject)
       
    93 : CActive(EPriorityStandard),
       
    94 	iTestObject(aTestObject)
       
    95 	{
       
    96 	CActiveScheduler::Add(this);
       
    97 	}
       
    98 
       
    99 
       
   100 CMBufAsyncPoolCeilingFull::~CMBufAsyncPoolCeilingFull()
       
   101 	{
       
   102 	Cancel();
       
   103 	iAsyncChain.Free();	
       
   104 	}
       
   105 
       
   106 void CMBufAsyncPoolCeilingFull::CompleteSelf()
       
   107 	{
       
   108 	TRequestStatus* pStat = &iStatus;
       
   109 	User::RequestComplete(pStat, KErrNone);
       
   110 	SetActive();
       
   111 	}
       
   112 
       
   113 void CMBufAsyncPoolCeilingFull::RunL()
       
   114 	{
       
   115 	User::LeaveIfError(iStatus.Int());
       
   116 	
       
   117 	if((iThread1.ExitType() != EExitPending))
       
   118 		{
       
   119 		CActiveScheduler::Stop();
       
   120 		return;		
       
   121 		}
       
   122 	if(iAsyncChain.IsEmpty())
       
   123 		{
       
   124 		iAsyncRequest.Alloc(iAsyncChain, 256 * 8, iStatus);	
       
   125 		SetActive();							
       
   126 		}
       
   127 	else
       
   128 		{
       
   129 		iAsyncChain.Free();			
       
   130 		CompleteSelf();		
       
   131 		}	
       
   132 	}
       
   133 
       
   134 void CMBufAsyncPoolCeilingFull::DoCancel()
       
   135 	{
       
   136 	iAsyncRequest.Cancel();
       
   137 	}
       
   138 
       
   139 
       
   140 TInt CMBufAsyncPoolCeilingFull::DoStartTest()
       
   141 	{
       
   142 	
       
   143 	TInt err=iThread1.Create(_L("testThread1Rec"),
       
   144 		                       fThread1,
       
   145  							   KDefaultStackSize,
       
   146 							   KDefaultHeapSize,
       
   147 							   KMaxHeapSize,
       
   148 							   (TAny*)&iTestObject,
       
   149 							   EOwnerProcess);
       
   150 	if (err!=KErrNone)
       
   151 		{
       
   152 		User::Leave(EFail);
       
   153 		}
       
   154 	iThread1.SetPriority(EPriorityAbsoluteHigh);
       
   155 	iThread1.Resume();
       
   156 	iAsyncRequest.Alloc(iAsyncChain, 256, iStatus);	
       
   157 	SetActive();
       
   158 	CActiveScheduler::Start();
       
   159 
       
   160 	iThread1.Close();
       
   161 	iThread2.Close();
       
   162 	iThread3.Close();
       
   163 
       
   164 	return iError;
       
   165 	}
       
   166 
       
   167 
       
   168 TInt CMBufAsyncPoolCeilingFull::fThread1(TAny* aInput)
       
   169 	{
       
   170 	TInt totalAllocation = 100;
       
   171 	CTest20PoolCeilingFull* pTestObject = (CTest20PoolCeilingFull*)aInput;
       
   172 	// We need to introduce this new client thread to the MBufMgr
       
   173 	TCommsBufPondTLSOp tls(pTestObject->BufPond());
       
   174 	tls.Set();
       
   175 	
       
   176 	CTrapCleanup* aCleanup = CTrapCleanup::New();
       
   177 	
       
   178 	//Install active scheduler
       
   179     CActiveScheduler* aActSch = new CActiveScheduler;
       
   180 	if(aActSch==NULL)
       
   181 		{
       
   182 		return KErrNoMemory;
       
   183 		}
       
   184 	CActiveScheduler::Install(aActSch);
       
   185 
       
   186 	RTimer aTimer;
       
   187 	TRequestStatus aTimerStatus;	// Request status associated with timer
       
   188 	aTimer.CreateLocal();			// Create timer for this thread
       
   189 	TBool freeMem = EFalse;
       
   190 	for(TInt i=0; i < 1000; ++i)
       
   191 		{
       
   192 		RMBufChain chain;
       
   193 		chain.Alloc(512, 256, 256);
       
   194 		if(freeMem)
       
   195 			{
       
   196 			chain.Free();
       
   197 			freeMem = EFalse;	
       
   198 			}
       
   199 		else
       
   200 			{
       
   201 			pTestObject->iChain.Append(chain);
       
   202 			freeMem = ETrue;
       
   203 			}
       
   204 		if(pTestObject->iChain.NumBufs() == totalAllocation)
       
   205 			{
       
   206 			// Free all. Will trigger the AO.
       
   207 			pTestObject->iChain.Free();
       
   208 			break;
       
   209 			}	
       
   210 		//Sleep for 5ms
       
   211 		aTimer.After(aTimerStatus,5000);
       
   212 		User::WaitForRequest(aTimerStatus);
       
   213 		}	
       
   214 	CActiveScheduler::Install(NULL);
       
   215 	delete aActSch;
       
   216 	delete aCleanup;
       
   217 	return KErrNone;
       
   218 	}
       
   219 
       
   220 
       
   221