os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-1236.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// @file PBASE-T_USBDI-1236.cpp
sl@0
    15
// @internalComponent
sl@0
    16
//
sl@0
    17
sl@0
    18
sl@0
    19
sl@0
    20
#include "PBASE-T_USBDI-1236.h"
sl@0
    21
#include <d32usbc.h>
sl@0
    22
#include <d32usbdescriptors.h>
sl@0
    23
#include "testdebug.h"
sl@0
    24
#include "TestPolicy.h"
sl@0
    25
sl@0
    26
namespace NUnitTesting_USBDI
sl@0
    27
	{
sl@0
    28
	
sl@0
    29
_LIT(KTestCaseId,"PBASE-T_USBDI-1236");
sl@0
    30
const TFunctorTestCase<CUT_PBASE_T_USBDI_1236,TBool> CUT_PBASE_T_USBDI_1236::iFunctor(KTestCaseId);	
sl@0
    31
sl@0
    32
CUT_PBASE_T_USBDI_1236* CUT_PBASE_T_USBDI_1236::NewL(TBool aHostRole)
sl@0
    33
	{
sl@0
    34
	CUT_PBASE_T_USBDI_1236* self = new (ELeave) CUT_PBASE_T_USBDI_1236(aHostRole);
sl@0
    35
	CleanupStack::PushL(self);
sl@0
    36
	self->ConstructL();
sl@0
    37
	CleanupStack::Pop(self);
sl@0
    38
	return self; 
sl@0
    39
	}
sl@0
    40
	   
sl@0
    41
sl@0
    42
CUT_PBASE_T_USBDI_1236::CUT_PBASE_T_USBDI_1236(TBool aHostRole)
sl@0
    43
:	CBaseTestCase(KTestCaseId,aHostRole)
sl@0
    44
	{
sl@0
    45
	} 
sl@0
    46
sl@0
    47
sl@0
    48
void CUT_PBASE_T_USBDI_1236::ConstructL()
sl@0
    49
	{
sl@0
    50
	iTestDevice = new RUsbDeviceA(this);
sl@0
    51
	BaseConstructL();
sl@0
    52
	}
sl@0
    53
sl@0
    54
sl@0
    55
CUT_PBASE_T_USBDI_1236::~CUT_PBASE_T_USBDI_1236()
sl@0
    56
	{
sl@0
    57
	LOG_FUNC
sl@0
    58
	
sl@0
    59
	// Cancel any async operations
sl@0
    60
	
sl@0
    61
	Cancel(); // Cancel host timer
sl@0
    62
	
sl@0
    63
	// Close the interfaces
sl@0
    64
	iUsbInterface1.Close();
sl@0
    65
	iUsbInterface0.Close();
sl@0
    66
	
sl@0
    67
	delete iControlEp0;
sl@0
    68
	delete iActorFDF;
sl@0
    69
	if(!IsHost() && iTestDevice)
sl@0
    70
		{
sl@0
    71
		iTestDevice->Close();
sl@0
    72
		}		
sl@0
    73
	delete iTestDevice;
sl@0
    74
	}
sl@0
    75
sl@0
    76
sl@0
    77
void CUT_PBASE_T_USBDI_1236::ExecuteHostTestCaseL()
sl@0
    78
	{
sl@0
    79
	LOG_FUNC
sl@0
    80
	iCaseStep = EStepGetInterfaceString;
sl@0
    81
	iActorFDF = CActorFDF::NewL(*this);
sl@0
    82
	iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
sl@0
    83
	
sl@0
    84
	// Monitor for device connections
sl@0
    85
	iActorFDF->Monitor();
sl@0
    86
sl@0
    87
	// Start the connection timeout	
sl@0
    88
	TimeoutIn(30);
sl@0
    89
	}
sl@0
    90
sl@0
    91
void CUT_PBASE_T_USBDI_1236::ExecuteDeviceTestCaseL()
sl@0
    92
	{
sl@0
    93
	LOG_FUNC
sl@0
    94
sl@0
    95
	// Construct the device for the test case
sl@0
    96
	iTestDevice->OpenL(TestCaseId());
sl@0
    97
	iTestDevice->SubscribeToReports(iStatus);
sl@0
    98
	SetActive();
sl@0
    99
sl@0
   100
	// Connect the test device	
sl@0
   101
	iTestDevice->SoftwareConnect();
sl@0
   102
	}
sl@0
   103
	
sl@0
   104
	
sl@0
   105
void CUT_PBASE_T_USBDI_1236::DeviceInsertedL(TUint aDeviceHandle)
sl@0
   106
	{
sl@0
   107
	LOG_FUNC
sl@0
   108
sl@0
   109
	Cancel(); // Cancel the timer
sl@0
   110
	TInt err(KErrNone);
sl@0
   111
	iDeviceHandle = aDeviceHandle;
sl@0
   112
	iActorFDF->Monitor();
sl@0
   113
	
sl@0
   114
	// Validate that device is as expected
sl@0
   115
	CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
sl@0
   116
	if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
sl@0
   117
		{
sl@0
   118
		// Incorrect device for this test case
sl@0
   119
sl@0
   120
		RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
sl@0
   121
			KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
sl@0
   122
sl@0
   123
		// Start the connection timeout again
sl@0
   124
		TimeoutIn(30);
sl@0
   125
		return;
sl@0
   126
		}	
sl@0
   127
		
sl@0
   128
	// Perform the correct test step				
sl@0
   129
	switch(iCaseStep)
sl@0
   130
		{
sl@0
   131
		case EStepGetInterfaceString:
sl@0
   132
			{
sl@0
   133
			TUint32 token1(0);
sl@0
   134
			TUint32 token2(0);
sl@0
   135
	
sl@0
   136
			RDebug::Printf("Obtaining token for interface 0");
sl@0
   137
			err = testDevice.Device().GetTokenForInterface(0,token1);
sl@0
   138
			if(err != KErrNone)
sl@0
   139
				{
sl@0
   140
				RDebug::Printf("<Error %d> Token for interface 0 could not be retrieved",err);
sl@0
   141
				return TestFailed(err);
sl@0
   142
				}
sl@0
   143
			RDebug::Printf("Token 1 (%d) retrieved",token1);
sl@0
   144
			RDebug::Printf("Opening interface 0");
sl@0
   145
			err = iUsbInterface0.Open(token1); // Alternate interface setting 0
sl@0
   146
			if(err != KErrNone)
sl@0
   147
				{
sl@0
   148
				RDebug::Printf("<Error %d> Interface 0 could not be opened",err);
sl@0
   149
				return TestFailed(err);
sl@0
   150
				}
sl@0
   151
			RDebug::Printf("Interface 0 opened");
sl@0
   152
		
sl@0
   153
																
sl@0
   154
			RDebug::Printf("Obtaining token for interface 1");
sl@0
   155
			err = testDevice.Device().GetTokenForInterface(1,token2);
sl@0
   156
			if(err != KErrNone)
sl@0
   157
				{
sl@0
   158
				RDebug::Printf("<Error %d> Token for interface 1 could not be retrieved",err);
sl@0
   159
				return TestFailed(err);			
sl@0
   160
				}	
sl@0
   161
			RDebug::Printf("Opening interface 1");
sl@0
   162
			err = iUsbInterface1.Open(token2); // Alternate interface setting 0
sl@0
   163
			if(err != KErrNone)
sl@0
   164
				{
sl@0
   165
				RDebug::Printf("<Error %d> Interface 1 could not be opened",err);
sl@0
   166
				return TestFailed(err);
sl@0
   167
				}
sl@0
   168
			RDebug::Printf("Interface 1 opened");
sl@0
   169
	
sl@0
   170
			// close it
sl@0
   171
			iUsbInterface1.Close();		
sl@0
   172
			RDebug::Printf("Interface 1 closed");
sl@0
   173
	
sl@0
   174
			//re-open now
sl@0
   175
			err = iUsbInterface1.Open(token2); // Alternate interface setting 0
sl@0
   176
			if(err != KErrNone)
sl@0
   177
				{
sl@0
   178
				RDebug::Printf("<Error %d> Interface 1 could not be re-opened",err);
sl@0
   179
				return TestFailed(err);
sl@0
   180
				}
sl@0
   181
			RDebug::Printf("Interface 1 re-opened");
sl@0
   182
			
sl@0
   183
sl@0
   184
			
sl@0
   185
			TBuf8<256> interfaceStringDes;
sl@0
   186
			const TUint16 KLangIdUsEng = 0x0409;
sl@0
   187
			TUsbInterfaceDescriptor interfaceDescriptor;
sl@0
   188
			iUsbInterface1.GetInterfaceDescriptor(interfaceDescriptor);
sl@0
   189
			TUint8 index = interfaceDescriptor.Interface();
sl@0
   190
			iUsbInterface1.GetStringDescriptor(interfaceStringDes, index, KLangIdUsEng);
sl@0
   191
			TUint8 length = interfaceStringDes[0];
sl@0
   192
			TUint8 type = interfaceStringDes[1];
sl@0
   193
			TPtr8 interfaceString = interfaceStringDes.MidTPtr(2, length-2);
sl@0
   194
			TBuf16<128> u16String((TUint16*)interfaceString.Ptr());
sl@0
   195
			u16String.SetLength(interfaceString.Length()/2);
sl@0
   196
			if (u16String.Compare(_L16("i1s0")) == 0)
sl@0
   197
				{
sl@0
   198
				RDebug::Printf("interface String match");
sl@0
   199
				iCaseStep = EPassed;
sl@0
   200
				TTestCasePassed request;
sl@0
   201
				iControlEp0->SendRequest(request,this);
sl@0
   202
				}
sl@0
   203
			else
sl@0
   204
				{
sl@0
   205
				RDebug::Printf("interface String not match %S", &interfaceString);
sl@0
   206
				iCaseStep = EFailed;
sl@0
   207
				TTestCaseFailed request(KErrCompletion, _L8("interface string not match"));
sl@0
   208
				iControlEp0->SendRequest(request,this);
sl@0
   209
				}
sl@0
   210
			}
sl@0
   211
			break;
sl@0
   212
			
sl@0
   213
		default:
sl@0
   214
			TestFailed(KErrCorrupt);
sl@0
   215
			break;
sl@0
   216
		}	
sl@0
   217
	}
sl@0
   218
sl@0
   219
sl@0
   220
	
sl@0
   221
void CUT_PBASE_T_USBDI_1236::DeviceRemovedL(TUint aDeviceHandle)
sl@0
   222
	{
sl@0
   223
	LOG_FUNC
sl@0
   224
sl@0
   225
	// The test device should not be removed until the test case has passed
sl@0
   226
	// so this test case has not completed, and state this event as an error
sl@0
   227
sl@0
   228
	TestFailed(KErrDisconnected);
sl@0
   229
	}
sl@0
   230
	
sl@0
   231
	
sl@0
   232
void CUT_PBASE_T_USBDI_1236::BusErrorL(TInt aError)
sl@0
   233
	{
sl@0
   234
	LOG_FUNC
sl@0
   235
sl@0
   236
	// This test case handles no failiures on the bus
sl@0
   237
sl@0
   238
	TestFailed(aError);
sl@0
   239
	}
sl@0
   240
	
sl@0
   241
void CUT_PBASE_T_USBDI_1236::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
sl@0
   242
	{
sl@0
   243
	LOG_FUNC
sl@0
   244
	Cancel();
sl@0
   245
	RDebug::Printf("Device State change from %d to %d err=%d",aPreviousState,aNewState,aCompletionCode);
sl@0
   246
	}
sl@0
   247
sl@0
   248
sl@0
   249
void CUT_PBASE_T_USBDI_1236::Ep0TransferCompleteL(TInt aCompletionCode)
sl@0
   250
	{
sl@0
   251
	LOG_FUNC
sl@0
   252
	RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
sl@0
   253
	switch(iCaseStep)
sl@0
   254
		{
sl@0
   255
		// Fail the test case
sl@0
   256
		default:
sl@0
   257
		case EFailed:
sl@0
   258
			TestFailed(KErrCompletion);
sl@0
   259
			break;
sl@0
   260
	
sl@0
   261
		// Pass the test case
sl@0
   262
	
sl@0
   263
		case EPassed:
sl@0
   264
			TestPassed();
sl@0
   265
			break;
sl@0
   266
			}
sl@0
   267
	}
sl@0
   268
sl@0
   269
sl@0
   270
void CUT_PBASE_T_USBDI_1236::HostRunL()
sl@0
   271
	{
sl@0
   272
	LOG_FUNC
sl@0
   273
	
sl@0
   274
	// Obtain the completion code
sl@0
   275
	TInt completionCode(iStatus.Int());
sl@0
   276
	
sl@0
   277
	if(completionCode == KErrNone)
sl@0
   278
		{
sl@0
   279
		// Action timeout
sl@0
   280
		RDebug::Printf("<Error> Action timeout");
sl@0
   281
		TestFailed(KErrTimedOut);
sl@0
   282
		}
sl@0
   283
	else
sl@0
   284
		{
sl@0
   285
		RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
sl@0
   286
		TestFailed(completionCode);
sl@0
   287
		}
sl@0
   288
	}
sl@0
   289
	
sl@0
   290
sl@0
   291
void CUT_PBASE_T_USBDI_1236::DeviceRunL()
sl@0
   292
	{
sl@0
   293
	LOG_FUNC
sl@0
   294
	
sl@0
   295
	// Disconnect the device
sl@0
   296
	
sl@0
   297
	iTestDevice->SoftwareDisconnect();
sl@0
   298
	
sl@0
   299
	// Complete the test case request
sl@0
   300
	
sl@0
   301
	TestPolicy().SignalTestComplete(iStatus.Int());
sl@0
   302
	}
sl@0
   303
sl@0
   304
void CUT_PBASE_T_USBDI_1236::HostDoCancel()
sl@0
   305
	{
sl@0
   306
	LOG_FUNC
sl@0
   307
sl@0
   308
	// Cancel the timeout timer
sl@0
   309
	CancelTimeout();
sl@0
   310
	}
sl@0
   311
sl@0
   312
sl@0
   313
void CUT_PBASE_T_USBDI_1236::DeviceDoCancel()
sl@0
   314
	{
sl@0
   315
	LOG_FUNC
sl@0
   316
	
sl@0
   317
	// Cancel the device	
sl@0
   318
	iTestDevice->CancelSubscriptionToReports();
sl@0
   319
	}
sl@0
   320
	
sl@0
   321
	}