kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0492.cpp
changeset 253 d37db4dcc88d
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
252:0a40b8675b23 253:d37db4dcc88d
     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-0492.h"
    19 #include "PBASE-T_USBDI-0492.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-0492Traces.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-0492");
    55 _LIT(KTestCaseId,"PBASE-T_USBDI-0492");
    52 const TFunctorTestCase<CUT_PBASE_T_USBDI_0492,TBool> CUT_PBASE_T_USBDI_0492::iFunctor(KTestCaseId);	
    56 const TFunctorTestCase<CUT_PBASE_T_USBDI_0492,TBool> CUT_PBASE_T_USBDI_0492::iFunctor(KTestCaseId);	
    53 
    57 
    54 CUT_PBASE_T_USBDI_0492* CUT_PBASE_T_USBDI_0492::NewL(TBool aHostRole)
    58 CUT_PBASE_T_USBDI_0492* CUT_PBASE_T_USBDI_0492::NewL(TBool aHostRole)
    55 	{
    59 	{
       
    60 	OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0492_NEWL_ENTRY, aHostRole );
    56 	CUT_PBASE_T_USBDI_0492* self = new (ELeave) CUT_PBASE_T_USBDI_0492(aHostRole);
    61 	CUT_PBASE_T_USBDI_0492* self = new (ELeave) CUT_PBASE_T_USBDI_0492(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_0492_NEWL_EXIT, ( TUint )( self ) );
    60 	return self;
    66 	return self;
    61 	}
    67 	}
    62 	
    68 	
    63 
    69 
    64 CUT_PBASE_T_USBDI_0492::CUT_PBASE_T_USBDI_0492(TBool aHostRole)
    70 CUT_PBASE_T_USBDI_0492::CUT_PBASE_T_USBDI_0492(TBool aHostRole)
    65 :	CBaseBulkTestCase(KTestCaseId,aHostRole),
    71 :	CBaseBulkTestCase(KTestCaseId,aHostRole),
    66 	iCaseStep(EInProgress)
    72 	iCaseStep(EInProgress)
    67 	{
    73 	{
       
    74 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0492_CUT_PBASE_T_USBDI_0492_ENTRY, this );
       
    75 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0492_CUT_PBASE_T_USBDI_0492_EXIT, this );
    68 	} 
    76 	} 
    69 
    77 
    70 
    78 
    71 void CUT_PBASE_T_USBDI_0492::ConstructL()
    79 void CUT_PBASE_T_USBDI_0492::ConstructL()
    72 	{
    80 	{
       
    81 	OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0492_CONSTRUCTL_ENTRY, this );
    73 	BaseBulkConstructL();
    82 	BaseBulkConstructL();
       
    83 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0492_CONSTRUCTL_EXIT, this );
    74 	}
    84 	}
    75 
    85 
    76 
    86 
    77 CUT_PBASE_T_USBDI_0492::~CUT_PBASE_T_USBDI_0492()
    87 CUT_PBASE_T_USBDI_0492::~CUT_PBASE_T_USBDI_0492()
    78 	{
    88 	{
    79 	LOG_FUNC
    89 	OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0492_CUT_PBASE_T_USBDI_0492_ENTRY_DUP01, this );
       
    90 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0492_CUT_PBASE_T_USBDI_0492_EXIT_DUP01, this );
    80 	}
    91 	}
    81 	
    92 	
    82 	
    93 	
    83 void CUT_PBASE_T_USBDI_0492::Ep0TransferCompleteL(TInt aCompletionCode)
    94 void CUT_PBASE_T_USBDI_0492::Ep0TransferCompleteL(TInt aCompletionCode)
    84 	{
    95 	{
    85 	LOG_FUNC
    96 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0492_EP0TRANSFERCOMPLETEL_ENTRY, this );
    86 	
    97 	
    87 	RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
    98 	OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0492_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_0492_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_0492_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_0492_EP0TRANSFERCOMPLETEL_EXIT, this );
   103 			return;
   115 			return;
   104 			}
   116 			}
   105 		}
   117 		}
   106 	
   118 	
   107 	switch(iCaseStep)
   119 	switch(iCaseStep)
   115 		case EFailed:
   127 		case EFailed:
   116 			TestFailed(KErrCompletion);
   128 			TestFailed(KErrCompletion);
   117 			break;
   129 			break;
   118 			
   130 			
   119 		case ETransferOut:
   131 		case ETransferOut:
   120 			RDebug::Printf("Try to send data");
   132 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0492_EP0TRANSFERCOMPLETEL_DUP03, "Try to send data");
   121 			iOutTransfer[0]->TransferOut(KLiteralEnglish8().Mid(0, KHostNumWriteBytes1), EFalse);
   133 			iOutTransfer[0]->TransferOut(KLiteralEnglish8().Mid(0, KHostNumWriteBytes1), EFalse);
   122 			iOutTransfer[1]->TransferOut(KLiteralEnglish8().Mid(KHostNumWriteBytes1, KHostNumWriteBytes2), EFalse);
   134 			iOutTransfer[1]->TransferOut(KLiteralEnglish8().Mid(KHostNumWriteBytes1, KHostNumWriteBytes2), EFalse);
   123 			iOutTransfer[2]->TransferOut(KLiteralEnglish8().Mid(KHostNumWriteBytes1+KHostNumWriteBytes2, KHostNumWriteBytes3), ETrue); //do not suppress ZLP on this last one  (though should be irrelevant here)    
   135 			iOutTransfer[2]->TransferOut(KLiteralEnglish8().Mid(KHostNumWriteBytes1+KHostNumWriteBytes2, KHostNumWriteBytes3), ETrue); //do not suppress ZLP on this last one  (though should be irrelevant here)    
   124 			break;
   136 			break;
   125 		
   137 		
   126 		case ETransferIn:
   138 		case ETransferIn:
   127 			RDebug::Printf("Try to receive data");
   139 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0492_EP0TRANSFERCOMPLETEL_DUP04, "Try to receive data");
   128 			iInTransfer[0]->TransferIn(KHostNumReadBytes1);
   140 			iInTransfer[0]->TransferIn(KHostNumReadBytes1);
   129 			iInTransfer[1]->TransferIn(KHostNumReadBytes2);
   141 			iInTransfer[1]->TransferIn(KHostNumReadBytes2);
   130 			iInTransfer[2]->TransferIn(KHostNumReadBytes3);
   142 			iInTransfer[2]->TransferIn(KHostNumReadBytes3);
   131 			break;
   143 			break;
   132 	
   144 	
   133 		default:
   145 		default:
   134 			RDebug::Printf("<Error> Unknown test step");
   146 			OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0492_EP0TRANSFERCOMPLETEL_DUP05, "<Error> Unknown test step");
   135 			TestFailed(KErrUnknown);
   147 			TestFailed(KErrUnknown);
   136 			break;
   148 			break;
   137 		}
   149 		}
       
   150 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0492_EP0TRANSFERCOMPLETEL_EXIT_DUP01, this );
   138 	}
   151 	}
   139 	
   152 	
   140 void CUT_PBASE_T_USBDI_0492::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
   153 void CUT_PBASE_T_USBDI_0492::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
   141 	{
   154 	{
   142 	LOG_FUNC
   155 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0492_TRANSFERCOMPLETEL_ENTRY, this );
   143 	Cancel();
   156 	Cancel();
   144 	
   157 	
   145 	TInt err(KErrNone);
   158 	TInt err(KErrNone);
   146 	TBuf<256> msg;
   159 	TBuf<256> msg;
   147 	RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
   160 	OstTraceExt2(TRACE_NORMAL, CUT_PBASE_T_USBDI_0492_TRANSFERCOMPLETEL, "Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
   148 
   161 
   149 	switch(iCaseStep)
   162 	switch(iCaseStep)
   150 		{
   163 		{
   151 		case ETransferOut:
   164 		case ETransferOut:
   152 			if(aCompletionCode != KErrNone)
   165 			if(aCompletionCode != KErrNone)
   160 				{
   173 				{
   161 				case KBulkTransferOutId0:
   174 				case KBulkTransferOutId0:
   162 				case KBulkTransferOutId1:
   175 				case KBulkTransferOutId1:
   163 				case KBulkTransferOutId2:
   176 				case KBulkTransferOutId2:
   164 					iTransferComplete |= aTransferId;
   177 					iTransferComplete |= aTransferId;
   165 					RDebug::Printf("Transfer %d completed", aTransferId);
   178 					OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0492_TRANSFERCOMPLETEL_DUP01, "Transfer %d completed", aTransferId);
   166 					break; // switch(aTransferId)
   179 					break; // switch(aTransferId)
   167 
   180 
   168 				default:
   181 				default:
   169 					iTransferComplete = 0; //reset
   182 					iTransferComplete = 0; //reset
   170 					err = KUnexpectedTransferID;
   183 					err = KUnexpectedTransferID;
   173 					break; // switch(aTransferId)
   186 					break; // switch(aTransferId)
   174 				}
   187 				}
   175 
   188 
   176 			if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1 | KBulkTransferOutId2))
   189 			if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1 | KBulkTransferOutId2))
   177 				{
   190 				{
   178 				RDebug::Printf("Try to receive back sent data. Transfers Completed %d", iTransferComplete);
   191 				OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0492_TRANSFERCOMPLETEL_DUP02, "Try to receive back sent data. Transfers Completed %d", iTransferComplete);
   179 				iCaseStep = ETransferIn;
   192 				iCaseStep = ETransferIn;
   180 				TUint numBytes[KNumSplitWriteSections] = {KHostNumReadBytes1, KHostNumReadBytes2, KHostNumReadBytes3};
   193 				TUint numBytes[KNumSplitWriteSections] = {KHostNumReadBytes1, KHostNumReadBytes2, KHostNumReadBytes3};
   181 				TSplitWriteCachedReadDataRequest request(1,1,1,numBytes);
   194 				TSplitWriteCachedReadDataRequest request(1,1,1,numBytes);
   182 				iControlEp0->SendRequest(request,this);	
   195 				iControlEp0->SendRequest(request,this);	
   183 				iTransferComplete = 0; //reset
   196 				iTransferComplete = 0; //reset
   231 					err = KErrCompletion; //indicates data validation failure
   244 					err = KErrCompletion; //indicates data validation failure
   232 					break; // switch(iCaseStep)
   245 					break; // switch(iCaseStep)
   233 					}
   246 					}
   234 
   247 
   235 				// Comparison is a match
   248 				// Comparison is a match
   236 				RDebug::Printf("Comparison for IN transfer is a match");
   249 				OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0492_TRANSFERCOMPLETEL_DUP03, "Comparison for IN transfer is a match");
   237 				iCaseStep = EPassed;
   250 				iCaseStep = EPassed;
   238 				TTestCasePassed request;
   251 				TTestCasePassed request;
   239 				iControlEp0->SendRequest(request,this);
   252 				iControlEp0->SendRequest(request,this);
   240 				iTransferComplete = 0; //reset
   253 				iTransferComplete = 0; //reset
   241 				}
   254 				}
   253 		msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
   266 		msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
   254 		}
   267 		}
   255 	
   268 	
   256 	if(err!=KErrNone)
   269 	if(err!=KErrNone)
   257 		{	
   270 		{	
   258 		RDebug::Print(msg);
   271 		OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0492_TRANSFERCOMPLETEL_DUP04, msg);
   259 		iCaseStep = EFailed;
   272 		iCaseStep = EFailed;
   260 		TTestCaseFailed request(err,msg);
   273 		TTestCaseFailed request(err,msg);
   261 		iControlEp0->SendRequest(request,this);
   274 		iControlEp0->SendRequest(request,this);
   262 		}	
   275 		}	
       
   276 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0492_TRANSFERCOMPLETEL_EXIT, this );
   263 	}
   277 	}
   264 	
   278 	
   265 void CUT_PBASE_T_USBDI_0492::DeviceInsertedL(TUint aDeviceHandle)
   279 void CUT_PBASE_T_USBDI_0492::DeviceInsertedL(TUint aDeviceHandle)
   266 	{
   280 	{
   267 	LOG_FUNC
   281 	OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0492_DEVICEINSERTEDL_ENTRY, this );
   268 	
   282 	
   269 	Cancel();
   283 	Cancel();
   270 	
   284 	
   271 	if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
   285 	if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
   272 		// Prepare for response from control transfer to client
   286 		// Prepare for response from control transfer to client
   281 	iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId0);
   295 	iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId0);
   282 	iOutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId1);
   296 	iOutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId1);
   283 	iOutTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId2);
   297 	iOutTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferSize,*this,KBulkTransferOutId2);
   284 	
   298 	
   285 	// Initialise the descriptors for transfer		
   299 	// Initialise the descriptors for transfer		
   286 	RDebug::Printf("Initialising the transfer descriptors");
   300 	OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0492_DEVICEINSERTEDL, "Initialising the transfer descriptors");
   287 	TInt err = iUsbInterface1.InitialiseTransferDescriptors();
   301 	TInt err = iUsbInterface1.InitialiseTransferDescriptors();
   288 	if(err != KErrNone)
   302 	if(err != KErrNone)
   289 		{
   303 		{
   290 		TBuf<256> msg;
   304 		TBuf<256> msg;
   291 		msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
   305 		msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
   292 		RDebug::Print(msg);
   306 		OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0492_DEVICEINSERTEDL_DUP01, msg);
   293 		iCaseStep = EFailed;
   307 		iCaseStep = EFailed;
   294 		TTestCaseFailed request(err,msg);
   308 		TTestCaseFailed request(err,msg);
   295 		iControlEp0->SendRequest(request,this);
   309 		iControlEp0->SendRequest(request,this);
       
   310 		OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0492_DEVICEINSERTEDL_EXIT, this );
   296 		return;
   311 		return;
   297 		}
   312 		}
   298 
   313 
   299 	iCaseStep = ETransferOut;	
   314 	iCaseStep = ETransferOut;	
   300 	TEndpointReadRequest request(1,1,KBulkTransferSize);// EP1 means endpoint index 1 not the actual endpoint number
   315 	TEndpointReadRequest request(1,1,KBulkTransferSize);// EP1 means endpoint index 1 not the actual endpoint number
   301 	iControlEp0->SendRequest(request,this);
   316 	iControlEp0->SendRequest(request,this);
       
   317 	OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0492_DEVICEINSERTEDL_EXIT_DUP01, this );
   302 	}
   318 	}
   303 	
   319 	
   304 	} //end namespace
   320 	} //end namespace