os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0493.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2008-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 the License "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 // @file PBASE-T_USBDI-0493.cpp
    15 // @internalComponent
    16 // 
    17 //
    18 
    19 #include "PBASE-T_USBDI-0493.h"
    20 #include "testpolicy.h"
    21 #include "modelleddevices.h"
    22 #include "testliterals.h"
    23 
    24 
    25  
    26 
    27 namespace NUnitTesting_USBDI
    28 	{
    29 const TInt  KLiteralEnglish8Length = KLiteralEnglish8().Length(); 
    30 const TUint KBulkTransferMaxSize = 320;
    31 const TUint KHostNumWriteBytes = 256;
    32 const TUint KHostNumReadBytes = 256;
    33 const TUint KHostFinalNumReadBytes = 300;
    34 
    35 const TUint KStartNumTransferBytes = 1023;
    36 const TUint KFinishNumTransferBytes = 1025;
    37 
    38 const TUint KClientNumReadBytes = 2000;
    39 
    40 //Make these single bit values ... 
    41 // ... so that their completion can be easily recorded in a bit mask!
    42 const TInt KBulkTransferInId0 = 1<<0;
    43 const TInt KBulkTransferInId1 = 1<<1;
    44 const TInt KBulkTransferInId2 = 1<<2;
    45 const TInt KBulkTransferInId3 = 1<<3;
    46 const TInt KBulkTransferOutId0 = 1<<4;
    47 const TInt KBulkTransferOutId1 = 1<<5;
    48 const TInt KBulkTransferOutId2 = 1<<6;
    49 const TInt KBulkTransferOutId3 = 1<<7;
    50 
    51 const TInt KUnexpectedTransferID = -101;
    52 const TInt KUndefinedStep	 = -102;
    53 
    54 
    55 _LIT(KTestCaseId,"PBASE-T_USBDI-0493");
    56 const TFunctorTestCase<CUT_PBASE_T_USBDI_0493,TBool> CUT_PBASE_T_USBDI_0493::iFunctor(KTestCaseId);	
    57 
    58 CUT_PBASE_T_USBDI_0493* CUT_PBASE_T_USBDI_0493::NewL(TBool aHostRole)
    59 	{
    60 	CUT_PBASE_T_USBDI_0493* self = new (ELeave) CUT_PBASE_T_USBDI_0493(aHostRole);
    61 	CleanupStack::PushL(self);
    62 	self->ConstructL();
    63 	CleanupStack::Pop(self);
    64 	return self;
    65 	}
    66 	
    67 
    68 CUT_PBASE_T_USBDI_0493::CUT_PBASE_T_USBDI_0493(TBool aHostRole)
    69 :	CBaseBulkTestCase(KTestCaseId,aHostRole),
    70 	iNumTransferBytes(KStartNumTransferBytes),
    71 	iCaseStep(EInProgress)
    72 	{
    73 	} 
    74 
    75 
    76 void CUT_PBASE_T_USBDI_0493::ConstructL()
    77 	{
    78 	BaseBulkConstructL();
    79 	}
    80 
    81 
    82 CUT_PBASE_T_USBDI_0493::~CUT_PBASE_T_USBDI_0493()
    83 	{
    84 	LOG_FUNC
    85 	}
    86 
    87 void CUT_PBASE_T_USBDI_0493::Ep0TransferCompleteL(TInt aCompletionCode)
    88 	{
    89 	LOG_FUNC
    90 	
    91 	RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
    92 	
    93 	if(aCompletionCode != KErrNone)
    94 		{
    95 		if(iCaseStep == EFailed)
    96 			{// todo, cope with errors
    97 			}
    98 		else
    99 			{
   100 			TBuf<256> msg;
   101 			msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
   102 			RDebug::Print(msg);
   103 			iCaseStep = EFailed;
   104 			TTestCaseFailed request(aCompletionCode,msg);
   105 			iControlEp0->SendRequest(request,this);
   106 			return;
   107 			}
   108 		}
   109 	
   110 	switch(iCaseStep)
   111 		{
   112 		// Test case passed
   113 		case EPassed:
   114 			TestPassed();
   115 			break;
   116 		
   117 		// Test case failed	
   118 		case EFailed:
   119 			TestFailed(KErrCompletion);
   120 			break;
   121 			
   122 		case ETransferOut:
   123 			RDebug::Printf("Try to send %d bytes of data", iNumTransferBytes);
   124 			RDebug::RawPrint(KLiteralEnglish8().Mid(0*KHostNumWriteBytes, KHostNumWriteBytes));
   125 			iOutTransfer[0]->TransferOut(KLiteralEnglish8().Mid(0*KHostNumWriteBytes, KHostNumWriteBytes), EFalse);
   126 			iOutTransfer[1]->TransferOut(KLiteralEnglish8().Mid(1*KHostNumWriteBytes, KHostNumWriteBytes), EFalse);
   127 			iOutTransfer[2]->TransferOut(KLiteralEnglish8().Mid(2*KHostNumWriteBytes, KHostNumWriteBytes), EFalse);
   128 			iOutTransfer[3]->TransferOut(KLiteralEnglish8().Mid(3*KHostNumWriteBytes, iNumTransferBytes - 3*KHostNumWriteBytes), ETrue);
   129 			break;
   130 		
   131 		case ETransferIn:
   132 			RDebug::Printf("Try to receive max %d bytes of data", 3*KHostNumReadBytes + KHostFinalNumReadBytes);
   133 			iInTransfer[0]->TransferIn(KHostNumReadBytes);
   134 			iInTransfer[1]->TransferIn(KHostNumReadBytes);
   135 			iInTransfer[2]->TransferIn(KHostNumReadBytes);
   136 			iInTransfer[3]->TransferIn(KHostFinalNumReadBytes);
   137 			break;
   138 	
   139 		default:
   140 			RDebug::Printf("<Error> Unknown test step");
   141 			TestFailed(KErrUnknown);
   142 			break;
   143 		}
   144 	}
   145 	
   146 void CUT_PBASE_T_USBDI_0493::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
   147 	{
   148 	LOG_FUNC
   149 	Cancel();
   150 	
   151 	TInt err(KErrNone);
   152 	TBuf<256> msg;
   153 	RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
   154 
   155 	switch(iCaseStep)
   156 		{
   157 		case ETransferOut:
   158 			if(aCompletionCode != KErrNone)
   159 				{
   160 				err = KErrCorrupt;
   161 				msg.Format(_L("<Error %d> No data sent on bulk OUT request"),aCompletionCode);
   162 				break; //switch(iCaseStep)
   163 				}
   164 
   165 			switch(aTransferId)
   166 				{
   167 				case KBulkTransferOutId0:
   168 				case KBulkTransferOutId1:
   169 				case KBulkTransferOutId2:		
   170 				case KBulkTransferOutId3:
   171 					iTransferComplete |= aTransferId;
   172 					RDebug::Printf("Transfer %d completed", aTransferId);
   173 					break; //switch(aTransferId)
   174 					
   175 				default:
   176 					iTransferComplete = 0; //reset
   177 					err = KUnexpectedTransferID;
   178 					msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d or %d or %d, got %d"),
   179 							       err, KBulkTransferOutId0, KBulkTransferOutId1, KBulkTransferOutId2, KBulkTransferOutId3, aTransferId);					
   180 					break; //switch(aTransferId)
   181 				}
   182 
   183 			if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1 | KBulkTransferOutId2 | KBulkTransferOutId3))
   184 				{
   185 				RDebug::Printf("Try to receive back sent data. Transfers Completed %d", iTransferComplete);
   186 				iCaseStep = ETransferIn;
   187 				TWriteSynchronousCachedReadDataRequest request(1,1,1);  //Use first read EP and first write EP (on interface 1)
   188 				iControlEp0->SendRequest(request,this);	
   189 				iTransferComplete = 0; //reset
   190 				}
   191 			break; //switch(iCaseStep)
   192 
   193 		case ETransferIn:
   194 			if(aCompletionCode != KErrNone)
   195 				{
   196 				err = KErrCorrupt;
   197 				msg.Format(_L("<Error %d> No data sent on bulk IN request"),aCompletionCode);
   198 				break; //switch(iCaseStep)
   199 				}
   200 			switch(aTransferId)
   201 				{
   202 				case KBulkTransferInId0:
   203 				case KBulkTransferInId1:
   204 				case KBulkTransferInId2:
   205 				case KBulkTransferInId3:
   206 					iTransferComplete |= aTransferId;
   207 					break; //switch(aTransferId)
   208 					
   209 				default:
   210 					RDebug::Printf("Bad Transfer ID");
   211 					iTransferComplete = 0; //reset
   212 					err = KUnexpectedTransferID;
   213 					msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d or %d or %d, got %d"),
   214 						       err, KBulkTransferInId0, KBulkTransferInId1, KBulkTransferInId2, KBulkTransferInId3, aTransferId);
   215 					break; //switch(aTransferId)
   216 				}
   217 				
   218 			if(err==KErrNone && iTransferComplete == (KBulkTransferInId0 | KBulkTransferInId1 | KBulkTransferInId2 | KBulkTransferInId3))
   219 				{
   220 				// compare data rcvd now
   221 				TPtrC8 data1(iInTransfer[0]->DataPolled());		
   222 				TPtrC8 data2(iInTransfer[1]->DataPolled());		
   223 				TPtrC8 data3(iInTransfer[2]->DataPolled());		
   224 				TPtrC8 data4(iInTransfer[3]->DataPolled());		
   225 				if(ValidateData(data1, KLiteralEnglish8().Mid(0*KHostNumReadBytes, KHostNumReadBytes)) == EFalse)
   226 					{
   227 					err = KErrCompletion; //indicates data validation failure
   228 					break; //switch(iCaseStep)
   229 					}
   230 
   231 				if(ValidateData(data2, KLiteralEnglish8().Mid(1*KHostNumReadBytes, KHostNumReadBytes)) == EFalse)
   232 					{
   233 					err = KErrCompletion; //indicates data validation failure
   234 					break; //switch(iCaseStep)
   235 					}
   236 
   237 				if(ValidateData(data3, KLiteralEnglish8().Mid(2*KHostNumReadBytes, KHostNumReadBytes)) == EFalse)
   238 					{
   239 					err = KErrCompletion; //indicates data validation failure
   240 					break; //switch(iCaseStep)
   241 					}
   242 
   243 				if(ValidateData(data4, KLiteralEnglish8().Mid(3*KHostNumReadBytes, iNumTransferBytes - 3*KHostNumReadBytes)) == EFalse)
   244 					{
   245 					err = KErrCompletion; //indicates data validation failure
   246 					break; //switch(iCaseStep)
   247 					}
   248 
   249 				if(err == KErrNone)
   250 					{
   251 					// Comparison is a match
   252 					RDebug::Printf("Comparison for IN transfer is a match - Number of Transfer Bytes %d", iNumTransferBytes);
   253 					iTransferComplete = 0; //reset
   254 					if(++iNumTransferBytes<=KFinishNumTransferBytes)
   255 						/*
   256 						Loop round again having added one to 
   257 						the number of transfer bytes to be used.
   258 						In this test there should be three repeats of the underlying 
   259 						"Transfer Out followed by Transfer In" test.
   260 						The repeats will use
   261 						KStartNumTransferBytes, 
   262 						KStartNumTransferBytes+1,
   263 						and finally
   264 						KFinishNumTransferBytes.
   265 						*/
   266 						{
   267 						iCaseStep = ETransferOut;
   268 						TEndpointReadUntilShortRequest request(1,1,KClientNumReadBytes);// EP1 because 1st reader EP
   269 						iControlEp0->SendRequest(request,this);
   270 						break; //switch(iCaseStep)
   271 						}
   272 					iCaseStep = EPassed;
   273 					TTestCasePassed request;
   274 					iControlEp0->SendRequest(request,this);
   275 					}
   276 				}
   277 			break; //switch(iCaseStep)
   278 			
   279 		default:
   280 			err = KUndefinedStep;
   281 			msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep);
   282 			break; //switch(iCaseStep)
   283 		}
   284 	
   285 	if(err!=KErrNone)
   286 		{	
   287 		RDebug::Print(msg);
   288 		iCaseStep = EFailed;
   289 		TTestCaseFailed request(err,msg);
   290 		iControlEp0->SendRequest(request,this);
   291 		return;
   292 		}	
   293 	}
   294 	
   295 
   296 void CUT_PBASE_T_USBDI_0493::DeviceInsertedL(TUint aDeviceHandle)
   297 	{
   298 	LOG_FUNC
   299 	Cancel();
   300 	RDebug::Printf("****** Father William Pattern Length is %d bytes! *********", KLiteralEnglish8Length);
   301 	if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
   302 		// Prepare for response from control transfer to client
   303 		{
   304 		iCaseStep = EFailed;
   305 		}
   306 	
   307 	// Create the bulk transfers	
   308 	RDebug::Printf("Trying to create the bulk transfers - size 0x%u", KBulkTransferMaxSize);
   309 	iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferInId0);
   310 	iInTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferInId1);
   311 	iInTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferInId2);
   312 	iInTransfer[3] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferInId3);
   313 	iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferOutId0);
   314 	iOutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferOutId1);
   315 	iOutTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferOutId2);
   316 	iOutTransfer[3] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferOutId3);
   317 		
   318 	// Initialise the descriptors for transfer		
   319 	RDebug::Printf("Initialising the transfer descriptors");
   320 	TInt err = iUsbInterface1.InitialiseTransferDescriptors();
   321 	if(err != KErrNone)
   322 		{
   323 		TBuf<256> msg;
   324 		msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
   325 		RDebug::Print(msg);
   326 		iCaseStep = EFailed;
   327 		TTestCaseFailed request(err,msg);
   328 		iControlEp0->SendRequest(request,this);
   329 		return;
   330 		}
   331 			
   332 	RDebug::Printf("Ask client to read %d bytes of data", KClientNumReadBytes);
   333 	iCaseStep = ETransferOut;
   334 	TEndpointReadUntilShortRequest request(1,1,KClientNumReadBytes);// EP1 because 1st reader EP
   335 	iControlEp0->SendRequest(request,this);
   336 	}
   337 	
   338 	} //end namespace