os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0488.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-0488.cpp
sl@0
    15
// @internalComponent
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include "PBASE-T_USBDI-0488.h"
sl@0
    20
#include "testpolicy.h"
sl@0
    21
#include "modelleddevices.h"
sl@0
    22
#include <d32usbdi_errors.h>
sl@0
    23
sl@0
    24
namespace NUnitTesting_USBDI
sl@0
    25
	{
sl@0
    26
sl@0
    27
_LIT(KTestCaseId,"PBASE-T_USBDI-0488");
sl@0
    28
const TFunctorTestCase<CUT_PBASE_T_USBDI_0488,TBool> CUT_PBASE_T_USBDI_0488::iFunctor(KTestCaseId);
sl@0
    29
sl@0
    30
CUT_PBASE_T_USBDI_0488* CUT_PBASE_T_USBDI_0488::NewL(TBool aHostRole)
sl@0
    31
	{
sl@0
    32
	CUT_PBASE_T_USBDI_0488* self = new (ELeave) CUT_PBASE_T_USBDI_0488(aHostRole);
sl@0
    33
	CleanupStack::PushL(self);
sl@0
    34
	self->ConstructL();
sl@0
    35
	CleanupStack::Pop(self);
sl@0
    36
	return self;
sl@0
    37
	}
sl@0
    38
	
sl@0
    39
sl@0
    40
CUT_PBASE_T_USBDI_0488::CUT_PBASE_T_USBDI_0488(TBool aHostRole)
sl@0
    41
:	CBaseTestCase(KTestCaseId,aHostRole),
sl@0
    42
	iCaseStep(EInProgress)
sl@0
    43
	{
sl@0
    44
	} 
sl@0
    45
sl@0
    46
sl@0
    47
void CUT_PBASE_T_USBDI_0488::ConstructL()
sl@0
    48
	{
sl@0
    49
	iTestDevice = new RUsbDeviceA(this);
sl@0
    50
	BaseConstructL();
sl@0
    51
	}
sl@0
    52
sl@0
    53
sl@0
    54
CUT_PBASE_T_USBDI_0488::~CUT_PBASE_T_USBDI_0488()
sl@0
    55
	{
sl@0
    56
	LOG_FUNC
sl@0
    57
	
sl@0
    58
	Cancel();
sl@0
    59
	
sl@0
    60
	// Close the interface
sl@0
    61
	iUsbInterface0.Close();
sl@0
    62
	
sl@0
    63
	delete iControlEp0;
sl@0
    64
	delete iActorFDF;
sl@0
    65
	if(!IsHost() && iTestDevice)
sl@0
    66
		{
sl@0
    67
		iTestDevice->Close();
sl@0
    68
		}		
sl@0
    69
	delete iTestDevice;
sl@0
    70
	}
sl@0
    71
	
sl@0
    72
	
sl@0
    73
void CUT_PBASE_T_USBDI_0488::ExecuteHostTestCaseL()	
sl@0
    74
	{
sl@0
    75
	LOG_FUNC
sl@0
    76
		
sl@0
    77
	iActorFDF = CActorFDF::NewL(*this);
sl@0
    78
	iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
sl@0
    79
	iActorFDF->Monitor();
sl@0
    80
	
sl@0
    81
	TimeoutIn(30);
sl@0
    82
	}
sl@0
    83
	
sl@0
    84
/*static*/ TInt CUT_PBASE_T_USBDI_0488::TestSelectAlternateInterfaceThenPanic(TAny* aTest) 
sl@0
    85
	{
sl@0
    86
	LOG_CFUNC
sl@0
    87
	
sl@0
    88
	CTrapCleanup* trapHandler=CTrapCleanup::New();
sl@0
    89
	if(!trapHandler)
sl@0
    90
		{
sl@0
    91
		return KErrNoMemory;
sl@0
    92
		}		
sl@0
    93
						
sl@0
    94
	CUT_PBASE_T_USBDI_0488* pTest = reinterpret_cast<CUT_PBASE_T_USBDI_0488*>(aTest);
sl@0
    95
	
sl@0
    96
	// change interface setting whilst pipes are opened in another alt. setting, should panic
sl@0
    97
	pTest->iUsbInterface1.SelectAlternateInterface(0); // panic expected
sl@0
    98
	
sl@0
    99
	// Should never get here.*/
sl@0
   100
	return KErrNone;
sl@0
   101
	}
sl@0
   102
	
sl@0
   103
	
sl@0
   104
	
sl@0
   105
void CUT_PBASE_T_USBDI_0488::HostDoCancel()
sl@0
   106
	{
sl@0
   107
	LOG_FUNC	
sl@0
   108
	// Cancel the timeout timer	
sl@0
   109
	CancelTimeout();
sl@0
   110
	}
sl@0
   111
	
sl@0
   112
	
sl@0
   113
void CUT_PBASE_T_USBDI_0488::ExecuteDeviceTestCaseL()	
sl@0
   114
	{
sl@0
   115
	LOG_FUNC	
sl@0
   116
	iTestDevice->OpenL(TestCaseId());
sl@0
   117
	iTestDevice->SubscribeToReports(iStatus);
sl@0
   118
	SetActive();
sl@0
   119
	iTestDevice->SoftwareConnect();
sl@0
   120
	}
sl@0
   121
	
sl@0
   122
void CUT_PBASE_T_USBDI_0488::DeviceDoCancel()
sl@0
   123
	{
sl@0
   124
	LOG_FUNC	
sl@0
   125
	// Cancel the device	
sl@0
   126
	iTestDevice->CancelSubscriptionToReports();
sl@0
   127
	}
sl@0
   128
	
sl@0
   129
	
sl@0
   130
void CUT_PBASE_T_USBDI_0488::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,RUsbDevice::TDeviceState aNewState,
sl@0
   131
		TInt aCompletionCode)
sl@0
   132
	{
sl@0
   133
	LOG_FUNC	
sl@0
   134
	}
sl@0
   135
sl@0
   136
sl@0
   137
void CUT_PBASE_T_USBDI_0488::DeviceInsertedL(TUint aDeviceHandle)
sl@0
   138
	{
sl@0
   139
	LOG_FUNC
sl@0
   140
	Cancel();
sl@0
   141
	TInt err(KErrNone);
sl@0
   142
	
sl@0
   143
	// Validate that device is as expected
sl@0
   144
	CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
sl@0
   145
	if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
sl@0
   146
		{
sl@0
   147
		// Incorrect device for this test case
sl@0
   148
		RDebug::Printf("<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
sl@0
   149
			KErrNotFound,&testDevice.SerialNumber(),&TestCaseId());
sl@0
   150
		// Start the connection timeout again
sl@0
   151
		CancelTimeout();
sl@0
   152
		iTimer.After(iStatus,30000000);
sl@0
   153
		SetActive();
sl@0
   154
		return;
sl@0
   155
		}
sl@0
   156
	
sl@0
   157
	
sl@0
   158
	TUint32 token0,token1;
sl@0
   159
	err = testDevice.Device().GetTokenForInterface(0,token0);
sl@0
   160
	if(err != KErrNone)
sl@0
   161
		{
sl@0
   162
		RDebug::Printf("<Error %d> Token for interface 0 could not be retrieved",err);
sl@0
   163
		return TestFailed(err);
sl@0
   164
		}
sl@0
   165
	err = iUsbInterface0.Open(token0); // Default interface setting 0
sl@0
   166
	if(err != KErrNone)
sl@0
   167
		{
sl@0
   168
		RDebug::Printf("<Error %d> Unable to open interface 0 using token %d",err,token0);
sl@0
   169
		return TestFailed(err);
sl@0
   170
		}
sl@0
   171
		
sl@0
   172
	__UHEAP_MARK;
sl@0
   173
	err = testDevice.Device().GetTokenForInterface(1,token1);
sl@0
   174
	if(err != KErrNone)
sl@0
   175
		{
sl@0
   176
		TBuf<256> msg;
sl@0
   177
		msg.Format(_L("<Error %d> Token for interface 1 could not be retrieved"),err);
sl@0
   178
		RDebug::Print(msg);
sl@0
   179
		iCaseStep = EFailed;
sl@0
   180
		TTestCaseFailed request(err,msg);
sl@0
   181
		return iControlEp0->SendRequest(request,this);
sl@0
   182
		}
sl@0
   183
	err = iUsbInterface1.Open(token1); // Default interface setting 0
sl@0
   184
	if(err != KErrNone)
sl@0
   185
		{
sl@0
   186
		TBuf<256> msg;
sl@0
   187
		msg.Format(_L("<Error %d> Unable to open interface 1 using token %d"),err,token1);
sl@0
   188
		RDebug::Print(msg);
sl@0
   189
		iCaseStep = EFailed;
sl@0
   190
		TTestCaseFailed request(err,msg);
sl@0
   191
		return iControlEp0->SendRequest(request,this);
sl@0
   192
		} 
sl@0
   193
	
sl@0
   194
	// Select alternate interface setting 1	
sl@0
   195
	err = iUsbInterface1.SelectAlternateInterface(1);
sl@0
   196
	if(err != KErrNone)
sl@0
   197
		{
sl@0
   198
		TBuf<256> msg;
sl@0
   199
		msg.Format(_L("<Error %d> Selecting alternate interface setting 1 on interface 1"),err);
sl@0
   200
		RDebug::Print(msg);
sl@0
   201
		iCaseStep = EFailed;
sl@0
   202
		TTestCaseFailed request(err,msg);
sl@0
   203
		iControlEp0->SendRequest(request,this);
sl@0
   204
		return;
sl@0
   205
		}  
sl@0
   206
	
sl@0
   207
	// Open a pipe for endpoint (Int in)	
sl@0
   208
	TInt endpointAddress;
sl@0
   209
	err = GetEndpointAddress(iUsbInterface1,1,KTransferTypeInterrupt,KEpDirectionIn,endpointAddress);
sl@0
   210
	if(err != KErrNone)
sl@0
   211
		{
sl@0
   212
		TBuf<256> msg;
sl@0
   213
		msg.Format(_L("<Error %d> unable to get endpoint address for interrupt in endpoint"),err);
sl@0
   214
		RDebug::Print(msg);
sl@0
   215
		iCaseStep = EFailed;
sl@0
   216
		TTestCaseFailed request(err,msg);
sl@0
   217
		iControlEp0->SendRequest(request,this);
sl@0
   218
		return;
sl@0
   219
		}	
sl@0
   220
	
sl@0
   221
	err = iUsbInterface1.OpenPipeForEndpoint(iInPipe,endpointAddress,EFalse);
sl@0
   222
	if(err != KErrNone)
sl@0
   223
		{
sl@0
   224
		TBuf<256> msg;
sl@0
   225
		msg.Format(_L("<Error %d> Unable to open pipe for endpoint 1"),err);
sl@0
   226
		RDebug::Print(msg);
sl@0
   227
		iCaseStep = EFailed;
sl@0
   228
		TTestCaseFailed request(err,msg);
sl@0
   229
		return iControlEp0->SendRequest(request,this);		
sl@0
   230
		}		
sl@0
   231
sl@0
   232
	RThread rt;
sl@0
   233
	TInt r = rt.Create(_L("PanicThread"), CUT_PBASE_T_USBDI_0488::TestSelectAlternateInterfaceThenPanic, KDefaultStackSize, 0x1000, 0x1000, reinterpret_cast<TAny*>(this));
sl@0
   234
	gtest(r == KErrNone);
sl@0
   235
	TRequestStatus status;
sl@0
   236
	rt.Logon(status);
sl@0
   237
	rt.Resume();
sl@0
   238
	rt.Close();
sl@0
   239
	User::WaitForRequest(status);
sl@0
   240
	gtest(status.Int() == UsbdiPanics::EInterfaceSettingChangeWithPipeOpen);
sl@0
   241
	
sl@0
   242
	iUsbInterface1.Close();	
sl@0
   243
	 	
sl@0
   244
	__UHEAP_MARKEND;
sl@0
   245
	
sl@0
   246
	// ok now, inform client that the test has passed
sl@0
   247
	iCaseStep = EPassed;
sl@0
   248
	TTestCasePassed request;
sl@0
   249
	return iControlEp0->SendRequest(request,this);
sl@0
   250
	}
sl@0
   251
sl@0
   252
sl@0
   253
void CUT_PBASE_T_USBDI_0488::Ep0TransferCompleteL(TInt aCompletionCode)
sl@0
   254
	{
sl@0
   255
	LOG_FUNC
sl@0
   256
	
sl@0
   257
	RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
sl@0
   258
	
sl@0
   259
	if(aCompletionCode != KErrNone)
sl@0
   260
		{	
sl@0
   261
		TBuf<256> msg;
sl@0
   262
		msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
sl@0
   263
		RDebug::Print(msg);
sl@0
   264
		}
sl@0
   265
sl@0
   266
	if(iCaseStep == EPassed)
sl@0
   267
		{	
sl@0
   268
		if(aCompletionCode == KErrNone)
sl@0
   269
			{
sl@0
   270
			return TestPassed();
sl@0
   271
			}
sl@0
   272
		// else error
sl@0
   273
	    iCaseStep = EFailed;
sl@0
   274
		}
sl@0
   275
	
sl@0
   276
	if(iCaseStep == EFailed)
sl@0
   277
		{
sl@0
   278
		return TestFailed(KErrCompletion);
sl@0
   279
		}	
sl@0
   280
	}
sl@0
   281
	
sl@0
   282
sl@0
   283
void CUT_PBASE_T_USBDI_0488::DeviceRemovedL(TUint aDeviceHandle)
sl@0
   284
	{
sl@0
   285
	LOG_FUNC
sl@0
   286
	
sl@0
   287
	// The test device should not be removed until the test case has passed
sl@0
   288
	// so this test case has not completed, and state this event as an error	
sl@0
   289
	TestFailed(KErrDisconnected);
sl@0
   290
	}
sl@0
   291
	
sl@0
   292
	
sl@0
   293
void CUT_PBASE_T_USBDI_0488::BusErrorL(TInt aError)
sl@0
   294
	{
sl@0
   295
	LOG_FUNC
sl@0
   296
	
sl@0
   297
	// This test case handles no failiures on the bus	
sl@0
   298
	TestFailed(KErrCompletion);
sl@0
   299
	}
sl@0
   300
sl@0
   301
void CUT_PBASE_T_USBDI_0488::HostRunL()
sl@0
   302
	{
sl@0
   303
	LOG_FUNC	
sl@0
   304
	// Obtain the completion code
sl@0
   305
	TInt completionCode(iStatus.Int());
sl@0
   306
	
sl@0
   307
	if(completionCode == KErrNone)
sl@0
   308
		{
sl@0
   309
		// Action timeout
sl@0
   310
		RDebug::Printf("<Error> Action timeout");
sl@0
   311
		TestFailed(KErrTimedOut);
sl@0
   312
		}
sl@0
   313
	else
sl@0
   314
		{
sl@0
   315
		RDebug::Printf("<Error %d> Timeout timer could not complete",completionCode);
sl@0
   316
		TestFailed(completionCode);
sl@0
   317
		}
sl@0
   318
	}
sl@0
   319
sl@0
   320
void CUT_PBASE_T_USBDI_0488::DeviceRunL()
sl@0
   321
	{
sl@0
   322
	LOG_FUNC
sl@0
   323
	
sl@0
   324
	// Disconnect the device	
sl@0
   325
	iTestDevice->SoftwareDisconnect();
sl@0
   326
	
sl@0
   327
	// Complete the test case request	
sl@0
   328
	TestPolicy().SignalTestComplete(iStatus.Int());
sl@0
   329
	}
sl@0
   330
sl@0
   331
	
sl@0
   332
	}