os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0484.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-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-0484.cpp
    15 // @internalComponent
    16 // 
    17 //
    18 
    19 #include "PBASE-T_USBDI-0484.h"
    20 #include "testpolicy.h"
    21 #include "modelleddevices.h"
    22 
    23 
    24  
    25 
    26 namespace NUnitTesting_USBDI
    27 	{	
    28 _LIT8(KDataPayload1,"opqrstuvwxyzabcdefghijklmnopqrstuvwxyz12345abcdefghijklmnopqrstuvwxyz");
    29 _LIT8(KDataPayload2,"12345opqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
    30 _LIT8(KDataPayload3,"abcdefghijklmnopqrstuvwxyzopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); // 64bytes
    31 
    32 const TInt KBulkTransferId1 = 0x01;
    33 const TInt KBulkTransferId2 = 0x02;
    34 const TInt KBulkTransferId3 = 0x03;
    35 _LIT(KTestCaseId,"PBASE-T_USBDI-0484");
    36 const TFunctorTestCase<CUT_PBASE_T_USBDI_0484,TBool> CUT_PBASE_T_USBDI_0484::iFunctor(KTestCaseId);	
    37 
    38 CUT_PBASE_T_USBDI_0484* CUT_PBASE_T_USBDI_0484::NewL(TBool aHostRole)
    39 	{
    40 	CUT_PBASE_T_USBDI_0484* self = new (ELeave) CUT_PBASE_T_USBDI_0484(aHostRole);
    41 	CleanupStack::PushL(self);
    42 	self->ConstructL();
    43 	CleanupStack::Pop(self);
    44 	return self;
    45 	}
    46 	
    47 
    48 CUT_PBASE_T_USBDI_0484::CUT_PBASE_T_USBDI_0484(TBool aHostRole)
    49 :	CBaseBulkTestCase(KTestCaseId,aHostRole),
    50 	iCaseStep(EInProgress)
    51 	{
    52 	} 
    53 
    54 
    55 void CUT_PBASE_T_USBDI_0484::ConstructL()
    56 	{
    57 	BaseBulkConstructL();
    58 	}
    59 
    60 
    61 CUT_PBASE_T_USBDI_0484::~CUT_PBASE_T_USBDI_0484()
    62 	{
    63 	LOG_FUNC
    64 	}
    65 	
    66 void CUT_PBASE_T_USBDI_0484::Ep0TransferCompleteL(TInt aCompletionCode)
    67 	{
    68 	LOG_FUNC
    69 	Cancel();	
    70 	
    71 	RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
    72 	
    73 	if(aCompletionCode != KErrNone)
    74 		{	
    75 		TBuf<256> msg;
    76 		msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
    77 		RDebug::Print(msg);
    78 		}
    79 
    80 	if(iCaseStep == EPassed)
    81 		{	
    82 		if(aCompletionCode == KErrNone)
    83 			{
    84 			return TestPassed();
    85 			}
    86 		// else error
    87 	    iCaseStep = EFailed;
    88 		}
    89 	
    90 	if(iCaseStep == EFailed)
    91 		{
    92 		return TestFailed(KErrCompletion);
    93 		}
    94 	}
    95 	
    96 	
    97 void CUT_PBASE_T_USBDI_0484::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
    98 	{
    99 	Cancel();
   100 	TInt err(KErrNone);
   101 	RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
   102 
   103 	if(aTransferId == KBulkTransferId1)
   104 		{
   105 		if(iCaseStep == EStalled)
   106 			{						
   107 			if(aCompletionCode != KErrUsbStalled)
   108 				{
   109 				TBuf<256> msg;
   110 				msg.Format(_L("<Error %d> The transfer completed with no errors but should have stalled"),aCompletionCode);
   111 				RDebug::Print(msg);
   112 				TTestCaseFailed request(KErrCorrupt,msg);
   113 				return iControlEp0->SendRequest(request,this);
   114 				}
   115 			else 
   116 				{
   117 				// Acknowledge the stall and clear				
   118 				err = iTestPipeInterface1BulkIn.ClearRemoteStall();
   119 				if(err != KErrNone)
   120 					{
   121 					TBuf<256> msg;
   122 					msg.Format(_L("<Error %d> The remote stall cannot be cleared"),err);
   123 					RDebug::Print(msg);
   124 					iCaseStep = EFailed;
   125 					TTestCaseFailed request(err,msg);
   126 					return iControlEp0->SendRequest(request,this);
   127 					}
   128 					
   129 				// try to get data now, after EP has been stalled
   130 				RDebug::Printf("try to get data now, after EP has been stalled");
   131 				iInTransfer[0]->TransferIn(KDataPayload1().Length());
   132 				iInTransfer[1]->TransferIn(KDataPayload2().Length());
   133 				iInTransfer[2]->TransferIn(KDataPayload3().Length());
   134 									
   135 				iCaseStep = ETransferAfterStall;
   136 				TEndpointWriteRequest request(1,1,KDataPayload1);// EP1 because 1st writter EP
   137 				iControlEp0->SendRequest(request,this);	
   138 				return;		
   139 				}
   140 			}
   141 		if(iCaseStep == ETransferAfterStall)
   142 			{
   143 			if(aCompletionCode != KErrNone)
   144 				{
   145 				TBuf<256> msg;
   146 				msg.Format(_L("<Error %d> No data got after EP2 being stalled"),aCompletionCode);
   147 				RDebug::Print(msg);
   148 				iCaseStep = EFailed;
   149 				TTestCaseFailed request(err,msg);
   150 				return iControlEp0->SendRequest(request,this);
   151 				}	
   152 				
   153 			// else ok, compare data rcvd now
   154 			TPtrC8 data(iInTransfer[0]->DataPolled());		
   155 			// Compare the data to what is expected		
   156 			if(data.Compare(KDataPayload1) != 0)
   157 				{
   158 				TBuf<256> msg;
   159 				msg.Format(_L("<Error %d> Interrupt data received does not match data sent"),KErrCompletion);
   160 				RDebug::Print(msg);
   161 				iCaseStep = EFailed;
   162 				TTestCaseFailed request(KErrCompletion,msg);
   163 				return iControlEp0->SendRequest(request,this);
   164 				}			 
   165 			// Comparison is a match, wait for next transfer
   166 			RDebug::Printf("Comparison is a match, wait for transfer 2");
   167 			User::After(500000);
   168 			TEndpointWriteRequest request(1,1,KDataPayload2);// EP1 because 1st writter EP
   169 			iControlEp0->SendRequest(request,this);						
   170 			}
   171 		}
   172 	else if(aTransferId == KBulkTransferId2)
   173 		{
   174 		if(aCompletionCode != KErrNone)
   175 			{
   176 			TBuf<256> msg;
   177 			msg.Format(_L("<Error %d> No data got after EP2 being stalled"),aCompletionCode);
   178 			RDebug::Print(msg);
   179 			iCaseStep = EFailed;
   180 			TTestCaseFailed request(err,msg);
   181 			return iControlEp0->SendRequest(request,this);
   182 			}	
   183 			
   184 		// else ok, compare data rcvd now
   185 		TPtrC8 data(iInTransfer[1]->DataPolled());		
   186 		// Compare the data to what is expected		
   187 		if(data.Compare(KDataPayload2) != 0)
   188 			{
   189 			TBuf<256> msg;
   190 			msg.Format(_L("<Error %d> Interrupt data received does not match data sent"),KErrCompletion);
   191 			RDebug::Print(msg);
   192 			iCaseStep = EFailed;
   193 			TTestCaseFailed request(KErrCompletion,msg);
   194 			return iControlEp0->SendRequest(request,this);
   195 			}			 
   196 		// Comparison is a match, wait for next transfer
   197 		RDebug::Printf("Comparison is a match, wait for transfer 3");
   198 		User::After(500000);
   199 		TEndpointWriteRequest request(1,1,KDataPayload3);// EP1 because 1st writter EP
   200 		iControlEp0->SendRequest(request,this);					
   201 		}
   202 	else if(aTransferId == KBulkTransferId3)
   203 		{		
   204 		if(aCompletionCode != KErrNone)
   205 			{
   206 			TBuf<256> msg;
   207 			msg.Format(_L("<Error %d> No data got after EP2 being stalled"),aCompletionCode);
   208 			RDebug::Print(msg);
   209 			iCaseStep = EFailed;
   210 			TTestCaseFailed request(err,msg);
   211 			return iControlEp0->SendRequest(request,this);
   212 			}			
   213 		// else ok, compare data rcvd now
   214 		TPtrC8 data(iInTransfer[2]->DataPolled());		
   215 		// Compare the data to what is expected		
   216 		if(data.Compare(KDataPayload3) != 0)
   217 			{
   218 			TBuf<256> msg;
   219 			msg.Format(_L("<Error %d> Interrupt data received does not match data sent"),KErrCompletion);
   220 			RDebug::Print(msg);
   221 			iCaseStep = EFailed;
   222 			TTestCaseFailed request(KErrCompletion,msg);
   223 			return iControlEp0->SendRequest(request,this);
   224 			}			 
   225 		// Comparison is a match, test passes
   226 		iCaseStep = EPassed;
   227 		TTestCasePassed request;
   228 		return iControlEp0->SendRequest(request,this);
   229 		}
   230 	else
   231 		{
   232 		RDebug::Printf("<Error> a transfer completed (id=%d) that was not expected",aTransferId);
   233 		return TestFailed(KErrCorrupt);
   234 		}	
   235 	}
   236 
   237 
   238 void CUT_PBASE_T_USBDI_0484::DeviceInsertedL(TUint aDeviceHandle)
   239 	{
   240 	LOG_FUNC
   241 	
   242 	Cancel();
   243 	RDebug::Printf("this - %08x", this);
   244 	
   245 	TBuf<256> msg;
   246 	TInt err = KErrNone;
   247 	if(BaseBulkDeviceInsertedL(aDeviceHandle, EFalse) == EDeviceConfigurationError)
   248 		// Prepare for response from control transfer to client
   249 		{
   250 		err = KErrGeneral;
   251 		msg.Format(_L("Base class DeviceInsertedL failed"));
   252 		}
   253 	else
   254 		{
   255 		// Create the bulk transfers	
   256 		iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,256,*this,KBulkTransferId1);	
   257 		iInTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,256,*this,KBulkTransferId2);	
   258 		iInTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,256,*this,KBulkTransferId3);	
   259 		
   260 		// Initialise the descriptors for transfer		
   261 		RDebug::Printf("Initialising the transfer descriptors - interface 1");
   262 		err = iUsbInterface1.InitialiseTransferDescriptors();
   263 		if(err != KErrNone)
   264 			{
   265 			_LIT(lit, "<Error %d> Unable to initialise transfer descriptors");
   266 			msg.Format(lit,err);
   267 			}
   268 		}
   269 	if(err != KErrNone)
   270 		{
   271 		RDebug::Print(msg);
   272 		iCaseStep = EFailed;
   273 		TTestCaseFailed request(err,msg);
   274 		iControlEp0->SendRequest(request,this);
   275 		}
   276 	else
   277 		{
   278 		iCaseStep = EStalled;	
   279 		iInTransfer[0]->TransferIn(KDataPayload1().Length());
   280 		
   281 		TStallEndpointRequest r2(2,1); // Stall endpoint 2 interface 1
   282 		iControlEp0->SendRequest(r2,this);		
   283 		}
   284 	}
   285 	
   286 	}