kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0499.cpp
changeset 259 57b9594f5772
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
247:d8d70de2bd36 259:57b9594f5772
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    18 
    18 
    19 #include "PBASE-T_USBDI-0499.h"
    19 #include "PBASE-T_USBDI-0499.h"
    20 #include "testpolicy.h"
    20 #include "testpolicy.h"
    21 #include "modelleddevices.h"
    21 #include "modelleddevices.h"
    22 #include "testliterals.h"
    22 #include "testliterals.h"
       
    23 #include "OstTraceDefinitions.h"
       
    24 #ifdef OST_TRACE_COMPILER_IN_USE
       
    25 #include "PBASE-T_USBDI-0499Traces.h"
       
    26 #endif
    23 
    27 
    24 
    28 
    25  
    29  
    26 
    30 
    27 namespace NUnitTesting_USBDI
    31 namespace NUnitTesting_USBDI
    51 _LIT(KTestCaseId,"PBASE-T_USBDI-0499");
    55 _LIT(KTestCaseId,"PBASE-T_USBDI-0499");
    52 const TFunctorTestCase<CUT_PBASE_T_USBDI_0499,TBool> CUT_PBASE_T_USBDI_0499::iFunctor(KTestCaseId);	
    56 const TFunctorTestCase<CUT_PBASE_T_USBDI_0499,TBool> CUT_PBASE_T_USBDI_0499::iFunctor(KTestCaseId);	
    53 
    57 
    54 CUT_PBASE_T_USBDI_0499* CUT_PBASE_T_USBDI_0499::NewL(TBool aHostRole)
    58 CUT_PBASE_T_USBDI_0499* CUT_PBASE_T_USBDI_0499::NewL(TBool aHostRole)
    55 	{
    59 	{
       
    60 	OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0499_NEWL_ENTRY, aHostRole );
    56 	CUT_PBASE_T_USBDI_0499* self = new (ELeave) CUT_PBASE_T_USBDI_0499(aHostRole);
    61 	CUT_PBASE_T_USBDI_0499* self = new (ELeave) CUT_PBASE_T_USBDI_0499(aHostRole);
    57 	CleanupStack::PushL(self);
    62 	CleanupStack::PushL(self);
    58 	self->ConstructL();
    63 	self->ConstructL();
    59 	CleanupStack::Pop(self);
    64 	CleanupStack::Pop(self);
       
    65 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_NEWL_EXIT, ( TUint )( self ) );
    60 	return self;
    66 	return self;
    61 	}
    67 	}
    62 	
    68 	
    63 
    69 
    64 CUT_PBASE_T_USBDI_0499::CUT_PBASE_T_USBDI_0499(TBool aHostRole)
    70 CUT_PBASE_T_USBDI_0499::CUT_PBASE_T_USBDI_0499(TBool aHostRole)
    65 :	CBaseBulkTestCase(KTestCaseId,aHostRole),
    71 :	CBaseBulkTestCase(KTestCaseId,aHostRole),
    66 	iCaseStep(EInProgress)
    72 	iCaseStep(EInProgress)
    67 	{
    73 	{
       
    74 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0499_CUT_PBASE_T_USBDI_0499_ENTRY, this );
       
    75 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_CUT_PBASE_T_USBDI_0499_EXIT, this );
    68 	} 
    76 	} 
    69 
    77 
    70 
    78 
    71 void CUT_PBASE_T_USBDI_0499::ConstructL()
    79 void CUT_PBASE_T_USBDI_0499::ConstructL()
    72 	{
    80 	{
       
    81 	OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0499_CONSTRUCTL_ENTRY, this );
    73 	BaseBulkConstructL();
    82 	BaseBulkConstructL();
       
    83 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_CONSTRUCTL_EXIT, this );
    74 	}
    84 	}
    75 
    85 
    76 
    86 
    77 CUT_PBASE_T_USBDI_0499::~CUT_PBASE_T_USBDI_0499()
    87 CUT_PBASE_T_USBDI_0499::~CUT_PBASE_T_USBDI_0499()
    78 	{
    88 	{
    79 	LOG_FUNC
    89 	OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0499_CUT_PBASE_T_USBDI_0499_ENTRY_DUP01, this );
       
    90 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_CUT_PBASE_T_USBDI_0499_EXIT_DUP01, this );
    80 	}
    91 	}
    81 	
    92 	
    82 	
    93 	
    83 void CUT_PBASE_T_USBDI_0499::Ep0TransferCompleteL(TInt aCompletionCode)
    94 void CUT_PBASE_T_USBDI_0499::Ep0TransferCompleteL(TInt aCompletionCode)
    84 	{
    95 	{
    85 	LOG_FUNC
    96 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_ENTRY, this );
    86 	
    97 	
    87 	RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
    98 	OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL, "Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
    88 	
    99 	
    89 	if(aCompletionCode != KErrNone)
   100 	if(aCompletionCode != KErrNone)
    90 		{
   101 		{
    91 		if(iCaseStep == EFailed)
   102 		if(iCaseStep == EFailed)
    92 			{// ignore error, nad catch the TestFailed method called further down.
   103 			{// ignore error, nad catch the TestFailed method called further down.
    93 			RDebug::Printf("***Failure sending FAIL message to client on endpoint 0***");
   104 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_DUP01, "***Failure sending FAIL message to client on endpoint 0***");
    94 			}
   105 			}
    95 		else
   106 		else
    96 			{
   107 			{
    97 			TBuf<256> msg;
   108 			TBuf<256> msg;
    98 			msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
   109 			msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
    99 			RDebug::Print(msg);
   110 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_DUP02, msg);
   100 			iCaseStep = EFailed;
   111 			iCaseStep = EFailed;
   101 			TTestCaseFailed request(aCompletionCode,msg);
   112 			TTestCaseFailed request(aCompletionCode,msg);
   102 			iControlEp0->SendRequest(request,this);
   113 			iControlEp0->SendRequest(request,this);
       
   114 			OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_EXIT, this );
   103 			return;
   115 			return;
   104 			}
   116 			}
   105 		}
   117 		}
   106 
   118 
   107 	switch(iCaseStep)
   119 	switch(iCaseStep)
   121 			iOutTransfer[1]->TransferOut(KLiteralFrench4(), KHostNumWriteBytesPreHalt2, EFalse);
   133 			iOutTransfer[1]->TransferOut(KLiteralFrench4(), KHostNumWriteBytesPreHalt2, EFalse);
   122 			break;
   134 			break;
   123 		
   135 		
   124 		case EAwaitClearPreHalt:
   136 		case EAwaitClearPreHalt:
   125 			{
   137 			{
   126 			RDebug::Printf("Client has been asked to clear endpoint buffer");
   138 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_DUP03, "Client has been asked to clear endpoint buffer");
   127 			User::After(1000000); //Give client time to clear buffer
   139 			User::After(1000000); //Give client time to clear buffer
   128 			TEndpointCancelReadRequest request(1,1);
   140 			TEndpointCancelReadRequest request(1,1);
   129 			iControlEp0->SendRequest(request,this);
   141 			iControlEp0->SendRequest(request,this);
   130 			iCaseStep = EAwaitCancelRead;
   142 			iCaseStep = EAwaitCancelRead;
   131 			}
   143 			}
   138 			iCaseStep = ETransferOut;
   150 			iCaseStep = ETransferOut;
   139 			}
   151 			}
   140 			break;
   152 			break;
   141 			
   153 			
   142 		case ETransferOut:
   154 		case ETransferOut:
   143 			RDebug::Printf("Try to send data (post halt)");
   155 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_DUP04, "Try to send data (post halt)");
   144 			iOutTransfer[0]->TransferOut(KLiteralEnglish8().Mid(0, KHostNumWriteBytesPostHalt1), EFalse);
   156 			iOutTransfer[0]->TransferOut(KLiteralEnglish8().Mid(0, KHostNumWriteBytesPostHalt1), EFalse);
   145 			iOutTransfer[1]->TransferOut(KLiteralEnglish8().Mid(KHostNumWriteBytesPostHalt1, KHostNumWriteBytesPostHalt2), EFalse);
   157 			iOutTransfer[1]->TransferOut(KLiteralEnglish8().Mid(KHostNumWriteBytesPostHalt1, KHostNumWriteBytesPostHalt2), EFalse);
   146 			break;
   158 			break;
   147 		
   159 		
   148 		case ETransferIn:
   160 		case ETransferIn:
   149 			RDebug::Printf("Try to receive data");
   161 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_DUP05, "Try to receive data");
   150 			iInTransfer[0]->TransferIn(KHostNumReadBytesPostHalt);
   162 			iInTransfer[0]->TransferIn(KHostNumReadBytesPostHalt);
   151 			break;
   163 			break;
   152 	
   164 	
   153 		default:
   165 		default:
   154 			RDebug::Printf("<Error> Unknown test step");
   166 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_DUP06, "<Error> Unknown test step");
   155 			TestFailed(KErrUnknown);
   167 			TestFailed(KErrUnknown);
   156 			break;
   168 			break;
   157 		}
   169 		}
       
   170 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_EXIT_DUP01, this );
   158 	}
   171 	}
   159 	
   172 	
   160 void CUT_PBASE_T_USBDI_0499::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
   173 void CUT_PBASE_T_USBDI_0499::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
   161 	{
   174 	{
   162 	LOG_FUNC
   175 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL_ENTRY, this );
   163 	Cancel();
   176 	Cancel();
   164 	
   177 	
   165 	TInt err(KErrNone);
   178 	TInt err(KErrNone);
   166 	TBuf<256> msg;
   179 	TBuf<256> msg;
   167 	RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
   180 	OstTraceExt2(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL, "Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
   168 
   181 
   169 	switch(iCaseStep)
   182 	switch(iCaseStep)
   170 		{
   183 		{
   171 		case ETransferOutHalt:
   184 		case ETransferOutHalt:
   172 			{
   185 			{
   182 			switch(aTransferId)
   195 			switch(aTransferId)
   183 				{
   196 				{
   184 				case KBulkTransferOutId0:
   197 				case KBulkTransferOutId0:
   185 				case KBulkTransferOutId1:
   198 				case KBulkTransferOutId1:
   186 					iTransferComplete |= aTransferId;
   199 					iTransferComplete |= aTransferId;
   187 					RDebug::Printf("Transfer %d stalled", aTransferId);
   200 					OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL_DUP01, "Transfer %d stalled", aTransferId);
   188 					break; //switch(aTransferId)
   201 					break; //switch(aTransferId)
   189 				
   202 				
   190 				default:
   203 				default:
   191 					iTransferComplete = 0; //reset
   204 					iTransferComplete = 0; //reset
   192 					err = KUnexpectedTransferID;
   205 					err = KUnexpectedTransferID;
   195 					break; //switch(aTransferId)
   208 					break; //switch(aTransferId)
   196 				}
   209 				}
   197 
   210 
   198 			if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1))
   211 			if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1))
   199 				{
   212 				{
   200 				RDebug::Printf("Clear halt and try to send data again. Transfers Completed %d", iTransferComplete);
   213 				OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL_DUP02, "Clear halt and try to send data again. Transfers Completed %d", iTransferComplete);
   201 				// Acknowledge the stall and clear				
   214 				// Acknowledge the stall and clear				
   202 				err = iTestPipeInterface1BulkOut.ClearRemoteStall();
   215 				err = iTestPipeInterface1BulkOut.ClearRemoteStall();
   203 				if(err != KErrNone)
   216 				if(err != KErrNone)
   204 					{
   217 					{
   205 					msg.Format(_L("<Error %d> The remote stall cannot be cleared"),err);
   218 					msg.Format(_L("<Error %d> The remote stall cannot be cleared"),err);
   227 			switch(aTransferId)
   240 			switch(aTransferId)
   228 				{
   241 				{
   229 				case KBulkTransferOutId0:
   242 				case KBulkTransferOutId0:
   230 				case KBulkTransferOutId1:
   243 				case KBulkTransferOutId1:
   231 					iTransferComplete |= aTransferId;
   244 					iTransferComplete |= aTransferId;
   232 					RDebug::Printf("Transfer %d completed", aTransferId);
   245 					OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL_DUP03, "Transfer %d completed", aTransferId);
   233 					break; //switch(aTransferId)
   246 					break; //switch(aTransferId)
   234 
   247 
   235 				default:
   248 				default:
   236 					iTransferComplete = 0; //reset
   249 					iTransferComplete = 0; //reset
   237 					err = KUnexpectedTransferID;
   250 					err = KUnexpectedTransferID;
   240 					break; //switch(aTransferId)
   253 					break; //switch(aTransferId)
   241 				}
   254 				}
   242 
   255 
   243 			if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1))
   256 			if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1))
   244 				{
   257 				{
   245 				RDebug::Printf("Try to receive back sent data. Transfers Completed %d", iTransferComplete);
   258 				OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL_DUP04, "Try to receive back sent data. Transfers Completed %d", iTransferComplete);
   246 				iCaseStep = ETransferIn;
   259 				iCaseStep = ETransferIn;
   247 				TWriteSynchronousCachedReadDataRequest request(1,1,1);
   260 				TWriteSynchronousCachedReadDataRequest request(1,1,1);
   248 				iControlEp0->SendRequest(request,this);	
   261 				iControlEp0->SendRequest(request,this);	
   249 				iTransferComplete = 0; //reset
   262 				iTransferComplete = 0; //reset
   250 				}
   263 				}
   275 				msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
   288 				msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
   276 				break; //switch(iCaseStep)
   289 				break; //switch(iCaseStep)
   277 				}
   290 				}
   278 			
   291 			
   279 			// Comparison is a match
   292 			// Comparison is a match
   280 			RDebug::Printf("Comparison for IN transfer is a match");
   293 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL_DUP05, "Comparison for IN transfer is a match");
   281 			iCaseStep = EPassed;
   294 			iCaseStep = EPassed;
   282 			TTestCasePassed request;
   295 			TTestCasePassed request;
   283 			iControlEp0->SendRequest(request,this);
   296 			iControlEp0->SendRequest(request,this);
   284 			iTransferComplete = 0; //reset
   297 			iTransferComplete = 0; //reset
   285 			}
   298 			}
   297 		msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
   310 		msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
   298 		}
   311 		}
   299 	
   312 	
   300 	if(err!=KErrNone)
   313 	if(err!=KErrNone)
   301 		{	
   314 		{	
   302 		RDebug::Print(msg);
   315 		OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL_DUP06, msg);
   303 		iCaseStep = EFailed;
   316 		iCaseStep = EFailed;
   304 		TTestCaseFailed request(err,msg);
   317 		TTestCaseFailed request(err,msg);
   305 		return iControlEp0->SendRequest(request,this);
   318 		return iControlEp0->SendRequest(request,this);
   306 		}	
   319 		}	
       
   320 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL_EXIT, this );
   307 	}
   321 	}
   308 	
   322 	
   309 void CUT_PBASE_T_USBDI_0499::DeviceInsertedL(TUint aDeviceHandle)
   323 void CUT_PBASE_T_USBDI_0499::DeviceInsertedL(TUint aDeviceHandle)
   310 	{
   324 	{
   311 	LOG_FUNC
   325 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0499_DEVICEINSERTEDL_ENTRY, this );
   312 	
   326 	
   313 	Cancel();
   327 	Cancel();
   314 	
   328 	
   315 	if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
   329 	if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
   316 		// Prepare for response from control transfer to client
   330 		// Prepare for response from control transfer to client
   322 	iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxINTransferSize,*this,KBulkTransferInId0);
   336 	iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxINTransferSize,*this,KBulkTransferInId0);
   323 	iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxOUTTransferSize,*this,KBulkTransferOutId0);
   337 	iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxOUTTransferSize,*this,KBulkTransferOutId0);
   324 	iOutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxOUTTransferSize,*this,KBulkTransferOutId1);
   338 	iOutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxOUTTransferSize,*this,KBulkTransferOutId1);
   325 	
   339 	
   326 	// Initialise the descriptors for transfer		
   340 	// Initialise the descriptors for transfer		
   327 	RDebug::Printf("Initialising the transfer descriptors");
   341 	OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_DEVICEINSERTEDL, "Initialising the transfer descriptors");
   328 	TInt err = iUsbInterface1.InitialiseTransferDescriptors();
   342 	TInt err = iUsbInterface1.InitialiseTransferDescriptors();
   329 	if(err != KErrNone)
   343 	if(err != KErrNone)
   330 		{
   344 		{
   331 		TBuf<256> msg;
   345 		TBuf<256> msg;
   332 		msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
   346 		msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
   333 		RDebug::Print(msg);
   347 		OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_DEVICEINSERTEDL_DUP01, msg);
   334 		iCaseStep = EFailed;
   348 		iCaseStep = EFailed;
   335 		TTestCaseFailed request(err,msg);
   349 		TTestCaseFailed request(err,msg);
   336 		iControlEp0->SendRequest(request,this);
   350 		iControlEp0->SendRequest(request,this);
       
   351 		OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_DEVICEINSERTEDL_EXIT, this );
   337 		return;
   352 		return;
   338 		}
   353 		}
   339 
   354 
   340 	iCaseStep = ETransferOutHalt;	
   355 	iCaseStep = ETransferOutHalt;	
   341 	TEndpointReadAndHaltRequest request(1,1,KDeviceNumReadBytesPreHalt);// EP1 means endpoint index 1 not the actual endpoint number
   356 	TEndpointReadAndHaltRequest request(1,1,KDeviceNumReadBytesPreHalt);// EP1 means endpoint index 1 not the actual endpoint number
   342 	iControlEp0->SendRequest(request,this);
   357 	iControlEp0->SendRequest(request,this);
       
   358 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_DEVICEINSERTEDL_EXIT_DUP01, this );
   343 	}
   359 	}
   344 	
   360 	
   345 	} //end namespace
   361 	} //end namespace