commsfwutils/commsbufs/TS_mbufmgr/TestStepCTMbufmgr.cpp
changeset 72 ae47d0499bee
parent 68 5da8188e392b
child 77 c9776eadbffd
equal deleted inserted replaced
68:5da8188e392b 72:ae47d0499bee
     1 // Copyright (c) 2001-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 definition of CTestStepCTMbufmgr which is the base class
       
    15 // for all the Mbufmgr Test Step classes
       
    16 // 
       
    17 //
       
    18 
       
    19 // EPOC includes
       
    20 //#include <e32base.h>
       
    21 //#include <es_sock.h>
       
    22 
       
    23 // Test system includes
       
    24 #include <es_mbuf.h>
       
    25 
       
    26 #ifdef SYMBIAN_OLD_EXPORT_LOCATION
       
    27 #include "networking/log.h"
       
    28 #include "networking/teststep.h"
       
    29 #include "networking/testsuite.h"
       
    30 #else
       
    31 #include <networking/log.h>
       
    32 #include <networking/teststep.h>
       
    33 #include <networking/testsuite.h>
       
    34 #endif
       
    35 
       
    36 #include "TestStepCTMbufmgr.h"
       
    37 #include "TestSuiteCTMbufmgr.h"
       
    38 #include <comms-infras/commsbufpond.h>
       
    39 #include <comms-infras/commsbufpondop.h>
       
    40 
       
    41 // constructor
       
    42 CTestStepCTMbufmgr::CTestStepCTMbufmgr()
       
    43 	{
       
    44 	}
       
    45 
       
    46 // destructor
       
    47 CTestStepCTMbufmgr::~CTestStepCTMbufmgr()
       
    48 	{
       
    49 	}
       
    50 
       
    51 void CTestStepCTMbufmgr::StripeMem(TUint8 *aBuf,
       
    52 								   TInt aStartPos,
       
    53 								   TInt anEndPos,
       
    54 								   TUint aStartChar,
       
    55 								   TUint anEndChar)
       
    56 	{
       
    57 	TUint character=aStartChar;
       
    58 	for (TInt i=aStartPos;i<anEndPos;i++)
       
    59 		{
       
    60 		aBuf[i]=(TText8)character;
       
    61 		if(++character>anEndChar) character=aStartChar;
       
    62 		}
       
    63 	}
       
    64 
       
    65 void CTestStepCTMbufmgr::StripeDes(TDes8 &aBuf,
       
    66 								   TInt aStartPos,
       
    67 								   TInt anEndPos,
       
    68 								   TUint aStartChar,
       
    69 								   TUint anEndChar)
       
    70 // Mark a buffer with repeating byte pattern
       
    71 	{
       
    72 	__ASSERT_ALWAYS(aStartChar<=anEndChar, User::Panic(_L("MBufTest"),0));
       
    73 	__ASSERT_ALWAYS(aStartPos<=anEndPos, User::Panic(_L("MBufTest"),0));
       
    74 	__ASSERT_ALWAYS(anEndPos<=aBuf.Length(), User::Panic(_L("MBufTest"),0));
       
    75 
       
    76 	StripeMem((TUint8 *)aBuf.Ptr(), aStartPos, anEndPos, aStartChar, anEndChar);
       
    77 	}
       
    78 
       
    79 // create an mbuf manager instance with some arbitrary default mbuf size alloc info
       
    80 // - refer CMBufManager::NewL notes regarding explaination of why this is deliberately not done within the mbuf manager
       
    81 static const TInt KMBuf_MBufSize = 128;
       
    82 static const TInt KMBuf_MinGrowth = 64;
       
    83 static const TInt KMBuf_GrowthThreshold = 40;
       
    84 #define SYMBIAN_MBUFMGR_BACKGROUND_ALLOCATION
       
    85 #ifndef SYMBIAN_MBUFMGR_BACKGROUND_ALLOCATION
       
    86 static const TInt KMBuf_InitialAllocation = 128;
       
    87 #endif
       
    88 void CTestStepCTMbufmgr::CreateInstanceMBufMgrL(TInt aMaxHeapSize)
       
    89 	{
       
    90 
       
    91 	RArray<TCommsBufPoolCreateInfo> poolInfoArray;
       
    92 	TCommsBufPoolCreateInfo createInfo;
       
    93 #ifdef SYMBIAN_MBUFMGR_BACKGROUND_ALLOCATION
       
    94 	
       
    95 	// this method used for tests that dont do background allocation so make the 
       
    96 	// pool big enough to fill the heap
       
    97 	createInfo.iBufSize = KMBuf_MBufSize;
       
    98 	createInfo.iInitialBufs = (aMaxHeapSize/(KMBuf_MBufSize+sizeof(RMBuf)))-1;
       
    99 	createInfo.iGrowByBufs = KMBuf_MinGrowth;
       
   100 	createInfo.iMinFreeBufs = KMBuf_GrowthThreshold;
       
   101 	createInfo.iCeiling = aMaxHeapSize/KMBuf_MBufSize;
       
   102 #else
       
   103 	createInfo.iBufSize = KMBuf_MBufSize;
       
   104 	createInfo.iInitialBufs = KMBuf_InitialAllocation;
       
   105 	createInfo.iGrowByBufs = KMBuf_MinGrowth;
       
   106 	createInfo.iMinFreeBufs = KMBuf_GrowthThreshold;
       
   107 	createInfo.iCeiling = aMaxHeapSize/KMBuf_MBufSize;	
       
   108 #endif
       
   109 	poolInfoArray.Append ( createInfo );		
       
   110 
       
   111 	User::LeaveIfError(iBufPond.Open(poolInfoArray));
       
   112 	poolInfoArray.Close ();
       
   113 	}
       
   114 
       
   115 void CTestStepCTMbufmgr::CreateInstanceMBufMgrL(RArray<TCommsBufPoolCreateInfo>& aPoolCreateInfo)
       
   116 	{
       
   117 	User::LeaveIfError(iBufPond.Open(aPoolCreateInfo));
       
   118 	}