os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0485.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-0485.cpp
    15 // @internalComponent
    16 // 
    17 //
    18 
    19 #include "PBASE-T_USBDI-0485.h"
    20 #include "testpolicy.h"
    21 #include "testdebug.h"
    22 #include "modelleddevices.h"
    23 
    24 namespace NUnitTesting_USBDI
    25 	{
    26 	
    27 _LIT(KTestCaseId,"PBASE-T_USBDI-0485");
    28 const TFunctorTestCase<CUT_PBASE_T_USBDI_0485,TBool> CUT_PBASE_T_USBDI_0485::iFunctor(KTestCaseId);	
    29 
    30 CUT_PBASE_T_USBDI_0485* CUT_PBASE_T_USBDI_0485::NewL(TBool aHostRole)
    31 	{
    32 	CUT_PBASE_T_USBDI_0485* self = new (ELeave) CUT_PBASE_T_USBDI_0485(aHostRole);
    33 	CleanupStack::PushL(self);
    34 	self->ConstructL();
    35 	CleanupStack::Pop(self);
    36 	return self;
    37 	} 
    38 	
    39 
    40 CUT_PBASE_T_USBDI_0485::CUT_PBASE_T_USBDI_0485(TBool aHostRole)
    41 :	CBaseTestCase(KTestCaseId,aHostRole),
    42 	iCaseStep(EInProgress)
    43 	{
    44 	} 
    45 
    46 
    47 void CUT_PBASE_T_USBDI_0485::ConstructL()
    48 	{
    49 	iTestDevice = new RUsbDeviceVendor(this);
    50 	BaseConstructL();
    51 	}
    52 
    53 
    54 CUT_PBASE_T_USBDI_0485::~CUT_PBASE_T_USBDI_0485()
    55 	{
    56 	LOG_FUNC
    57 	
    58 	Cancel();
    59 	
    60 	// Close the interface
    61 	iUsbInterface0.Close();
    62 	
    63 	delete iControlEp0;
    64 	delete iActorFDF;
    65 	if(!IsHost() && iTestDevice)
    66 		{
    67 		iTestDevice->Close();
    68 		}		
    69 	delete iTestDevice;
    70 	}
    71 	
    72 void CUT_PBASE_T_USBDI_0485::ExecuteHostTestCaseL()	
    73 	{
    74 	LOG_FUNC
    75 
    76 	// Create the actor for the Function Driver Framework 
    77 	
    78 	iActorFDF = CActorFDF::NewL(*this);
    79 
    80 	// Create the control transfer for requests
    81 
    82 	iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
    83 	
    84 	// Monitor for devices
    85 
    86 	iActorFDF->Monitor();
    87 	
    88 	// Start the connection timeout timer
    89 
    90 	TimeoutIn(30);
    91 	}
    92 
    93 
    94 void CUT_PBASE_T_USBDI_0485::ExecuteDeviceTestCaseL()	
    95 	{
    96 	LOG_FUNC
    97 	
    98 	// Create the test device
    99 	
   100 	iTestDevice->OpenL(TestCaseId());
   101 	iTestDevice->SubscribeToReports(iStatus);
   102 	SetActive();
   103 	
   104 	// Connect the device to the host
   105 	
   106 	iTestDevice->SoftwareConnect();
   107 	}
   108 
   109 
   110 void CUT_PBASE_T_USBDI_0485::HostDoCancel()
   111 	{
   112 	LOG_FUNC
   113 	
   114 	// Cancel the test step action timeout timer
   115 	
   116 	CancelTimeout();
   117 	}
   118 
   119 	
   120 void CUT_PBASE_T_USBDI_0485::DeviceDoCancel()
   121 	{
   122 	LOG_FUNC
   123 	
   124 	// Cancel the device (the activity timer and the error reporting)
   125 	
   126 	iTestDevice->CancelSubscriptionToReports();
   127 	}
   128 	
   129 	
   130 void CUT_PBASE_T_USBDI_0485::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
   131 		RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
   132 	{
   133 	LOG_FUNC
   134 	
   135 	}
   136 	
   137 	
   138 void CUT_PBASE_T_USBDI_0485::DeviceInsertedL(TUint aDeviceHandle)
   139 	{
   140 	LOG_FUNC
   141 
   142 	// Cancel the timeout timer
   143 	
   144 	Cancel();
   145 	
   146 	TInt err(KErrNone);
   147 	
   148 	// Validate that device is as expected
   149 	
   150 	CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
   151 	if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
   152 		{
   153 		// Incorrect device for this test case	
   154 
   155 		RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
   156 			KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
   157 
   158 		// Start the connection timeout again
   159 
   160 		TimeoutIn(30);
   161 		return;
   162 		}	
   163 	
   164 	// Get the token for the interface
   165 	
   166 	err = testDevice.Device().GetTokenForInterface(0,iToken0);
   167 	if(err != KErrNone)
   168 		{
   169 		RDebug::Printf("<Error %d> Unable to retrieve token for interface 0",err);
   170 		TestFailed(err);
   171 		}
   172 	
   173 	// Open the interface	
   174 	err = iUsbInterface0.Open(iToken0);
   175 	if(err != KErrNone)
   176 		{
   177 		RDebug::Printf("<Error %d> Unable to open interface 0");
   178 		TestFailed(err);
   179 		}
   180 	
   181 
   182 	// Send a request to control endpoint 0 to continuously NAK the request
   183 	
   184 	iCaseStep = EInProgress;
   185 	TNakRequest request(0);
   186 	iControlEp0->SendRequest(request,this);
   187 	
   188 	// Wait 1 second then close the interface	
   189 	User::After(1000000);
   190 	RDebug::Printf("Closing interface 0");
   191 	iUsbInterface0.Close();
   192 	}
   193 	
   194 void CUT_PBASE_T_USBDI_0485::Ep0TransferCompleteL(TInt aCompletionCode)
   195 	{
   196 	LOG_FUNC
   197 	
   198 	RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
   199 		
   200 	switch(iCaseStep)
   201 		{
   202 		case EInProgress:
   203 			{
   204 			if(aCompletionCode != KErrCancel)
   205 				{
   206 				RDebug::Printf("<Error %d> Nakking request was not cancelled by stack",aCompletionCode);
   207 				return TestFailed(aCompletionCode);
   208 				}
   209 		
   210 			// No panic or leave so passed
   211 			
   212 			RDebug::Printf("No leave or panic occured so open interface again and send test passed");
   213 			
   214 			// Open the interface
   215 			
   216 			TInt err(iUsbInterface0.Open(iToken0));
   217 			if(err != KErrNone)
   218 				{
   219 				RDebug::Printf("<Error %d> Unable to open interface 0");
   220 				return TestFailed(err);
   221 				}
   222 			
   223 			RDebug::Printf("Interface 0 re-opened");
   224 			
   225 			iCaseStep = EPassed;
   226 			TTestCasePassed request;
   227 			iControlEp0->SendRequest(request,this);			
   228 			}
   229 			break;
   230 			
   231 		case EPassed:
   232 			TestPassed();
   233 			break;
   234 			
   235 		case EFailed:
   236 		default:
   237 			TestFailed(KErrCompletion);
   238 			break;
   239 		}
   240 	}
   241 	
   242 void CUT_PBASE_T_USBDI_0485::DeviceRemovedL(TUint aDeviceHandle)
   243 	{
   244 	LOG_FUNC
   245 
   246 	// The test device should not be removed until the test case has passed
   247 	// so this test case has not completed, and state this event as an error
   248 
   249 	TestFailed(KErrDisconnected);
   250 	}
   251 	
   252 	
   253 void CUT_PBASE_T_USBDI_0485::BusErrorL(TInt aError)
   254 	{
   255 	LOG_FUNC
   256 
   257 	// This test case handles no failiures on the bus
   258 
   259 	TestFailed(aError);
   260 	}
   261 
   262 
   263 void CUT_PBASE_T_USBDI_0485::HostRunL()
   264 	{
   265 	LOG_FUNC
   266 	
   267 	// Obtain the completion code
   268 	TInt completionCode(iStatus.Int());
   269 	
   270 	if(completionCode == KErrNone)
   271 		{
   272 		// Action timeout
   273 		RDebug::Printf("<Error> Action timeout");
   274 		TestFailed(KErrTimedOut);
   275 		}
   276 	else
   277 		{
   278 		RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
   279 		TestFailed(completionCode);
   280 		}
   281 	}
   282 
   283 /**
   284 Called when the device has reported any kind of error in its opertaion
   285 or when the device has been informed by the host to report success
   286 */
   287 void CUT_PBASE_T_USBDI_0485::DeviceRunL()
   288 	{
   289 	LOG_FUNC
   290 	
   291 	// Disconnect the device
   292 	
   293 	iTestDevice->SoftwareDisconnect();
   294 	
   295 	// Complete the test case request
   296 	
   297 	TestPolicy().SignalTestComplete(iStatus.Int());
   298 	}
   299 
   300 	
   301 	}