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