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