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