commsfwutils/commsbufs/TE_mbufmgr/src/Test12General.cpp
changeset 72 ae47d0499bee
equal deleted inserted replaced
68:5da8188e392b 72:ae47d0499bee
       
     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 12 General Test
       
    15 // 
       
    16 //
       
    17 
       
    18 // EPOC includes
       
    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 "Test12General.h"
       
    31 #include <comms-infras/commsbufpond.h>
       
    32 
       
    33 // constructor
       
    34 CTest12General::CTest12General()
       
    35 	{
       
    36 	SetTestStepName(_L("MBufMgrTest12"));// Store the name of this test case
       
    37 	}
       
    38 
       
    39 // destructor
       
    40 CTest12General::~CTest12General() 
       
    41 	{
       
    42 	}
       
    43 
       
    44 void CTest12General::LeaveIfErrorL(TInt aErr, RMBufChain& aChain, const TDesC& aMsg)
       
    45 	{
       
    46 	if(aErr != KErrNone)
       
    47 		{
       
    48 		TBuf<129> logLine;
       
    49 		logLine.Format(_L("Error %d from %S"), aErr, &aMsg);
       
    50 		INFO_PRINTF2(_L("%S"), &logLine);
       
    51 		aChain.Free();
       
    52 		User::Leave(EFail);
       
    53 		}
       
    54 	}
       
    55 
       
    56 void CTest12General::LeaveIfDifferentL(TInt aLHS, TInt aRHS, RMBufChain& aChain, const TDesC& aMsg)
       
    57 	{
       
    58 	if(aLHS != aRHS)
       
    59 		{
       
    60 		TBuf<129> logLine;
       
    61 		logLine.Format(_L("%d != %d in %S"), aLHS, aRHS, &aMsg);
       
    62 		INFO_PRINTF2(_L("%S"), &logLine);
       
    63 		aChain.Free();
       
    64 		User::Leave(EFail);
       
    65 		}
       
    66 	}
       
    67 //
       
    68 enum TVerdict CTest12General::doTestStepL(void)
       
    69 	{
       
    70 	SetTestStepResult(EFail);
       
    71 	//-------------- substep 1 -------------------- 
       
    72 	INFO_PRINTF1(_L("  01 - Create CMBufManager and install active scheduler:"));
       
    73     CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler );
       
    74 	CActiveScheduler::Install(iActSch);
       
    75 	CreateInstanceMBufMgrL(KMBufDefaultHeapSize);
       
    76 	CleanupClosePushL(iBufPond);
       
    77 
       
    78 	//-------------- substep 2 -------------------- 
       
    79 	INFO_PRINTF1(_L("  02 - Allocate two desc. (Des1 & Des2) of length 12345."));
       
    80 	INFO_PRINTF1(_L("     - Fill Des1 with a pattern, and Des2 with zeros:"));
       
    81 	TBuf8<12345> *aDes1, *aDes2;
       
    82     CleanupStack::PushL( aDes1 = new(ELeave) TBuf8<12345> );
       
    83     CleanupStack::PushL( aDes2 = new(ELeave) TBuf8<12345> );
       
    84 	aDes1->SetLength(12345);
       
    85 	aDes2->SetLength(12345);
       
    86 	StripeDes(*aDes1, 0, 12345, '@', 'Z');
       
    87 	StripeDes(*aDes2, 0, 12345, 0, 0);
       
    88 
       
    89 	//-------------- substep 3 -------------------- 
       
    90 	INFO_PRINTF1(_L("  03 - Copy in Des1 into Chain:"));
       
    91 	RMBufChain aChain;
       
    92 	TRAPD(ret,aChain.AllocL(12345));
       
    93 	if (ret != KErrNone)
       
    94 		{
       
    95 		INFO_PRINTF1(_L("Error: Couldn't allocate RMBufChain:"));
       
    96 		User::Leave(EFail);
       
    97 		}
       
    98 	aChain.CopyIn(*aDes1);
       
    99 
       
   100 	//-------------- substep 4 -------------------- 
       
   101 	INFO_PRINTF1(_L("  04 - Split Chain into  packets of 5000 bytes. Prepend Header1 to each:"));
       
   102 	INFO_PRINTF1(_L("     - Place them into Outq1 packet queue. Print the content of Outq1:"));
       
   103 	int len = aChain.Length();
       
   104 	RMBufChain aTempChain;
       
   105 	Test_str aHeader1;
       
   106 	StripeMem((TUint8 *)&aHeader1, 0, sizeof(aHeader1), 'a', 'm');
       
   107 	RMBufPktQ aOutq1;
       
   108 
       
   109 	while (len>5000)
       
   110 		{
       
   111 		TRAP(ret,aChain.SplitL(5000, aTempChain));
       
   112 		if (ret != KErrNone)
       
   113 			{
       
   114 			INFO_PRINTF1(_L("Error: Couldn't Split chain:"));
       
   115 			aChain.Free();
       
   116 			User::Leave(EFail);
       
   117 			}
       
   118 		TRAP(ret,aChain.PrependL(sizeof(aHeader1)));
       
   119 		if (ret != KErrNone)
       
   120 			{
       
   121 			INFO_PRINTF1(_L("Error: Couldn't prepend header to the chain:"));
       
   122 			aChain.Free();
       
   123 			User::Leave(EFail);
       
   124 			}
       
   125 		aChain.CopyIn(TPtrC8((TUint8 *)&aHeader1, sizeof(aHeader1)));
       
   126 		aOutq1.Append(aChain);
       
   127 		aChain.Append(aTempChain);
       
   128 		len -= 5000;
       
   129 		}
       
   130 	TRAP(ret,aChain.PrependL(sizeof(aHeader1)));
       
   131 	if (ret != KErrNone)
       
   132 		{
       
   133 		INFO_PRINTF1(_L("Error: Couldn't prepend header to the chain:"));
       
   134 		aChain.Free();
       
   135 		User::Leave(EFail);
       
   136 		}
       
   137 	aChain.CopyIn(TPtrC8((TUint8 *)&aHeader1, sizeof(aHeader1)));
       
   138 	aOutq1.Append(aChain);
       
   139 
       
   140 	Test_QueueStats(aOutq1, _S("OutQ1"));
       
   141 
       
   142 	//-------------- substep 5 -------------------- 
       
   143 	INFO_PRINTF1(_L("  05 - Split packets of Outq1 into 556-byte long packets and prepend another Header2 onto each. Place them all into packet queue Outq2:"));
       
   144 	INFO_PRINTF1(_L("     - Place them all into packet queue Outq2. Print the contents of Outq1 & Outq2"));
       
   145 	Test_str aHeader2;
       
   146 	StripeMem((TUint8 *)&aHeader2, 0, sizeof(aHeader2), 'n', 'z');
       
   147 	RMBufPktQ aOutq2;
       
   148 	while (!aOutq1.IsEmpty())
       
   149 		{
       
   150 		(void)aOutq1.Remove(aChain);
       
   151 		len = aChain.Length();
       
   152 		while (len>556)
       
   153 			{
       
   154 			TRAP(ret,aChain.SplitL(556, aTempChain));
       
   155 			if (ret != KErrNone)
       
   156 				{
       
   157 				INFO_PRINTF1(_L("Error: Couldn't Split chain:"));
       
   158 				aChain.Free();
       
   159 				User::Leave(EFail);
       
   160 				}
       
   161 			TRAP(ret,aChain.PrependL(sizeof(aHeader2)));
       
   162 			if (ret != KErrNone)
       
   163 				{
       
   164 				INFO_PRINTF1(_L("Error: Couldn't prepend header to the chain:"));
       
   165 				aChain.Free();
       
   166 				User::Leave(EFail);
       
   167 				}
       
   168 			aChain.CopyIn(TPtrC8((TUint8 *)&aHeader2, sizeof(aHeader2)));
       
   169 			aOutq2.Append(aChain);
       
   170 			aChain.Append(aTempChain);
       
   171 			len -= 556;
       
   172 			}
       
   173 		TRAP(ret,aChain.PrependL(sizeof(aHeader2)));
       
   174 		if (ret != KErrNone)
       
   175 			{
       
   176 			INFO_PRINTF1(_L("Error: Couldn't prepend header to the chain:"));
       
   177 			aChain.Free();
       
   178 			User::Leave(EFail);
       
   179 			}
       
   180 		aChain.CopyIn(TPtrC8((TUint8 *)&aHeader2, sizeof(aHeader2)));
       
   181 		aOutq2.Append(aChain);
       
   182 		}
       
   183 	Test_QueueStats(aOutq1, _S("OutQ1"));
       
   184 	Test_QueueStats(aOutq2, _S("OutQ2"));
       
   185 
       
   186 	//-------------- substep 6 -------------------- 
       
   187 	INFO_PRINTF1(_L("  06 - Copy the chains from Outq2 into another packet queue Inq2."));
       
   188 	INFO_PRINTF1(_L("     - Print the contents of Outq2 & Inq1:"));
       
   189 	RMBufPktQ aInq2;
       
   190 
       
   191 	while (!aOutq2.IsEmpty())
       
   192 		{
       
   193 		(void)aOutq2.Remove(aChain);
       
   194 		TRAP(ret,aChain.CopyL(aTempChain));
       
   195 		if (ret != KErrNone)
       
   196 			{
       
   197 			INFO_PRINTF1(_L("Error: Couldn't copy chain"));
       
   198 			aChain.Free();
       
   199 			User::Leave(EFail);
       
   200 			}
       
   201 		aChain.Free();
       
   202 		aChain.Assign(aTempChain);
       
   203 		aInq2.Append(aChain);
       
   204 		}
       
   205 
       
   206 	Test_QueueStats(aOutq2, _S("OutQ2"));
       
   207 	Test_QueueStats(aInq2, _S("InQ2"));
       
   208 
       
   209 	//-------------- substep 7 -------------------- 
       
   210 	INFO_PRINTF1(_L("  07 - Group the chains back to 5000+Header1 long packets (Including removal of Header2)."));
       
   211 	INFO_PRINTF1(_L("     - Check the content of each Header2 that is removed."));
       
   212 	INFO_PRINTF1(_L("     - Place them in packet queue Inq1. Print the contents of Inq2 & Inq1:"));
       
   213 	RMBufPktQ aInq1;
       
   214 	Test_str aTempHeader;
       
   215 	aChain.Init();
       
   216 	len = 0;
       
   217 	while (!aInq2.IsEmpty())
       
   218 		{
       
   219 		while (len<5020 && !aInq2.IsEmpty())
       
   220 			{
       
   221 			(void)aInq2.Remove(aTempChain);
       
   222 			TPtr8 dest((TUint8 *)&aTempHeader, sizeof(aTempHeader),sizeof(aTempHeader));
       
   223 			aTempChain.CopyOut(dest);
       
   224 			aTempChain.TrimStart(sizeof(aTempHeader));
       
   225 			len += aTempChain.Length();
       
   226 			aChain.Append(aTempChain);
       
   227 			if(Mem::Compare((TUint8 *)&aHeader2, sizeof(aHeader2), 
       
   228 				            (TUint8 *)&aTempHeader, sizeof(aTempHeader))!=0)
       
   229 				{
       
   230 				INFO_PRINTF1(_L("Error: The content of header is not the same"));
       
   231 				aChain.Free();
       
   232 				User::Leave(EFail);
       
   233 				}
       
   234 			}
       
   235 		aInq1.Append(aChain);
       
   236 		aChain.Init();
       
   237 		len = 0;
       
   238 		}
       
   239 	Test_QueueStats(aInq2, _S("InQ2"));
       
   240 	Test_QueueStats(aInq1, _S("InQ1"));
       
   241 
       
   242 	//-------------- substep 8 -------------------- 
       
   243 	INFO_PRINTF1(_L("  08 - Group the packets into a single packet (Removing Header1, as well)."));
       
   244 	INFO_PRINTF1(_L("     - Check the content of each Header1 that is removed."));
       
   245 	INFO_PRINTF1(_L("     - Place it in Chain. Print the contents of Inq1:"));
       
   246 
       
   247 	while (!aInq1.IsEmpty())
       
   248 		{
       
   249 		(void)aInq1.Remove(aTempChain);
       
   250 		TPtr8 dest1((TUint8 *)&aTempHeader, sizeof(aTempHeader), sizeof(aTempHeader));
       
   251 		aTempChain.CopyOut(dest1);
       
   252 		aTempChain.TrimStart(sizeof(aTempHeader));
       
   253 		len = aTempChain.Length();
       
   254 		len = len;
       
   255 		aChain.Append(aTempChain);
       
   256 		if(Mem::Compare((TUint8 *)&aHeader1, sizeof(aHeader1), 
       
   257 				  (TUint8 *)&aTempHeader, sizeof(aTempHeader))!=0)
       
   258 			{
       
   259 			INFO_PRINTF1(_L("Error: The content of header is not the same"));
       
   260 			aChain.Free();
       
   261 			User::Leave(EFail);
       
   262 			}
       
   263 		}
       
   264 	len = aChain.Length();
       
   265 	len = len;
       
   266 	Test_QueueStats(aInq1, _S("InQ1"));
       
   267 
       
   268 	//-------------- substep 9 -------------------- 
       
   269 	INFO_PRINTF1(_L("  09 - Copy out Chain into Des2.:"));
       
   270 	aChain.CopyOut(*aDes2);
       
   271 
       
   272 	//-------------- substep 10 -------------------- 
       
   273 	INFO_PRINTF1(_L("  10 - Compare the content of Des1 & Des2:"));
       
   274 	if(aDes1->Compare(*aDes2))
       
   275 		{
       
   276 		aChain.Free();
       
   277 		INFO_PRINTF1(_L("Error: The content is not the same"));
       
   278 		User::Leave(EFail);
       
   279 		}
       
   280 	aChain.Free();
       
   281 
       
   282 	//-------------- substep 11 --------------------
       
   283 	INFO_PRINTF1(_L("  11 - RMBufChain::ReallocL():"));
       
   284 	TRAP(ret, aChain.AllocL(32));
       
   285 	// ...32 bytes at start
       
   286 	LeaveIfErrorL(ret, aChain, _L("AllocL(32)") );
       
   287 	TRAP(ret, aChain.ReAllocL(24));
       
   288 	// ...24 bytes at start
       
   289 	LeaveIfErrorL(ret, aChain, _L("ReAllocL(24)") );	
       
   290 	LeaveIfDifferentL(24, aChain.Length(), aChain, _L("length check") );
       
   291 	aChain.TrimStart(8);
       
   292 	// ...16 bytes starting at offset 8
       
   293 	LeaveIfDifferentL(16, aChain.Length(), aChain, _L("length check") );
       
   294 	TRAP(ret, aChain.ReAllocL(32));
       
   295 	// ...32 bytes starting at offset 8
       
   296 	LeaveIfErrorL(ret, aChain, _L("ReAllocL(32)") );
       
   297 	LeaveIfDifferentL(32, aChain.Length(), aChain, _L("length check") );
       
   298 	TRAP(ret, aChain.ReAllocL(120));
       
   299 	// ...120 bytes starting at offset 8, only one buffer
       
   300 	LeaveIfErrorL(ret, aChain, _L("ReAllocL(120)") );
       
   301 	LeaveIfDifferentL(120, aChain.Length(), aChain, _L("length check") );
       
   302 	LeaveIfDifferentL((TInt) aChain.First(), (TInt) aChain.Last(), aChain, _L("single buff check") );
       
   303 	TRAP(ret, aChain.ReAllocL(121));
       
   304 	// ...121 bytes starting at offset 8, two buffers
       
   305 	LeaveIfErrorL(ret, aChain, _L("ReAllocL(121)") );
       
   306 	LeaveIfDifferentL(121, aChain.Length(), aChain, _L("length check") );
       
   307 	TBool sameBuff = aChain.First() == aChain.Last();
       
   308 	LeaveIfDifferentL(sameBuff, 0, aChain, _L("two buffs check") );
       
   309 	aChain.Free();
       
   310 
       
   311 	//-------------- substep 12 -------------------- 
       
   312 	INFO_PRINTF1(_L("  12 - Clean up stack:"));
       
   313     CleanupStack::PopAndDestroy(aDes2);
       
   314     CleanupStack::PopAndDestroy(aDes1);
       
   315     CleanupStack::PopAndDestroy();
       
   316 	CActiveScheduler::Install(NULL);
       
   317 	CleanupStack::PopAndDestroy(iActSch);
       
   318         SetTestStepResult(EPass);
       
   319 
       
   320 	return TestStepResult();
       
   321 	}
       
   322 
       
   323 void CTest12General::Test_QueueStats(RMBufPktQ &aQueue, const TText *aName)
       
   324 	{
       
   325 	RMBufChain chain = (RMBufChain)aQueue.First();
       
   326 
       
   327 	INFO_PRINTF2(_L("    Queue stats %5s    : "), aName);
       
   328 	
       
   329 	if (chain.IsEmpty()) 
       
   330 		INFO_PRINTF1(_L("        Empty"));
       
   331 	else
       
   332 		{
       
   333 		TInt n = 0;
       
   334 		while (!chain.IsEmpty())
       
   335 			{
       
   336 			n++;
       
   337 			INFO_PRINTF3(_L("        chain #%2d:%d "), n, chain.Length());
       
   338 			chain = chain.Next();
       
   339 			}
       
   340 		}
       
   341 	}