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