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