os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0494.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) 2008-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-0494.cpp
sl@0
    15
// @internalComponent
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include "PBASE-T_USBDI-0494.h"
sl@0
    20
#include "testpolicy.h"
sl@0
    21
#include "modelleddevices.h"
sl@0
    22
#include "testliterals.h"
sl@0
    23
sl@0
    24
sl@0
    25
 
sl@0
    26
sl@0
    27
namespace NUnitTesting_USBDI
sl@0
    28
	{
sl@0
    29
const TUint KBulkTransferSize = 1024*512; //512kB
sl@0
    30
const TUint KBulkNumReadBytes = 1024*600; //600kB
sl@0
    31
const TUint KBulkTransferMaxSize = KBulkNumReadBytes+KBulkTransferSize;
sl@0
    32
const TInt KBulkTranferInId = 1<<0;
sl@0
    33
const TInt KBulkTranferOutId = 1<<1;
sl@0
    34
sl@0
    35
const TInt KUnexpectedTransferID = -101;
sl@0
    36
const TInt KUndefinedStep	 = -102;
sl@0
    37
sl@0
    38
sl@0
    39
_LIT(KTestCaseId,"PBASE-T_USBDI-0494");
sl@0
    40
const TFunctorTestCase<CUT_PBASE_T_USBDI_0494,TBool> CUT_PBASE_T_USBDI_0494::iFunctor(KTestCaseId);	
sl@0
    41
sl@0
    42
CUT_PBASE_T_USBDI_0494* CUT_PBASE_T_USBDI_0494::NewL(TBool aHostRole)
sl@0
    43
	{
sl@0
    44
	CUT_PBASE_T_USBDI_0494* self = new (ELeave) CUT_PBASE_T_USBDI_0494(aHostRole);
sl@0
    45
	CleanupStack::PushL(self);
sl@0
    46
	self->ConstructL();
sl@0
    47
	CleanupStack::Pop(self);
sl@0
    48
	return self;
sl@0
    49
	}
sl@0
    50
	
sl@0
    51
sl@0
    52
CUT_PBASE_T_USBDI_0494::CUT_PBASE_T_USBDI_0494(TBool aHostRole)
sl@0
    53
:	CBaseBulkTestCase(KTestCaseId,aHostRole),
sl@0
    54
	iCaseStep(EInProgress)
sl@0
    55
	{
sl@0
    56
	} 
sl@0
    57
sl@0
    58
sl@0
    59
void CUT_PBASE_T_USBDI_0494::ConstructL()
sl@0
    60
	{
sl@0
    61
	BaseBulkConstructL();
sl@0
    62
	}
sl@0
    63
sl@0
    64
sl@0
    65
CUT_PBASE_T_USBDI_0494::~CUT_PBASE_T_USBDI_0494()
sl@0
    66
	{
sl@0
    67
	LOG_FUNC
sl@0
    68
	}
sl@0
    69
sl@0
    70
void CUT_PBASE_T_USBDI_0494::Ep0TransferCompleteL(TInt aCompletionCode)
sl@0
    71
	{
sl@0
    72
	LOG_FUNC
sl@0
    73
	
sl@0
    74
	RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
sl@0
    75
	
sl@0
    76
	if(aCompletionCode != KErrNone)
sl@0
    77
		{
sl@0
    78
		if(iCaseStep == EFailed)
sl@0
    79
			{// ignore error, nad catch the TestFailed method called further down.
sl@0
    80
			RDebug::Printf("***Failure sending FAIL message to client on endpoint 0***");
sl@0
    81
			}
sl@0
    82
		else
sl@0
    83
			{
sl@0
    84
			TBuf<256> msg;
sl@0
    85
			msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
sl@0
    86
			RDebug::Print(msg);
sl@0
    87
			iCaseStep = EFailed;
sl@0
    88
			TTestCaseFailed request(aCompletionCode,msg);
sl@0
    89
			iControlEp0->SendRequest(request,this);
sl@0
    90
			return;
sl@0
    91
			}
sl@0
    92
		}
sl@0
    93
	
sl@0
    94
	switch(iCaseStep)
sl@0
    95
		{
sl@0
    96
		// Test case passed
sl@0
    97
		case EPassed:
sl@0
    98
			TestPassed();
sl@0
    99
			break;
sl@0
   100
		
sl@0
   101
		// Test case failed	
sl@0
   102
		case EFailed:
sl@0
   103
			TestFailed(KErrCompletion);
sl@0
   104
			break;
sl@0
   105
			
sl@0
   106
		case ETransferOut:
sl@0
   107
			RDebug::Printf("Try to send data");
sl@0
   108
			iOutTransfer[0]->TransferOut(KLiteralEnglish8(), KBulkTransferSize, ETrue);
sl@0
   109
			break;
sl@0
   110
		
sl@0
   111
		case ETransferIn:
sl@0
   112
			RDebug::Printf("Try to receive data");
sl@0
   113
			iInTransfer[0]->TransferIn(KBulkNumReadBytes); //require completion using ZLP
sl@0
   114
			break;
sl@0
   115
	
sl@0
   116
		default:
sl@0
   117
			RDebug::Printf("<Error> Unknown test step");
sl@0
   118
			TestFailed(KErrUnknown);
sl@0
   119
			break;
sl@0
   120
		}
sl@0
   121
	}
sl@0
   122
	
sl@0
   123
void CUT_PBASE_T_USBDI_0494::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
sl@0
   124
	{
sl@0
   125
	LOG_FUNC
sl@0
   126
	Cancel();
sl@0
   127
	
sl@0
   128
	TInt err(KErrNone);
sl@0
   129
	TBuf<256> msg;
sl@0
   130
	RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
sl@0
   131
sl@0
   132
	switch(iCaseStep)
sl@0
   133
		{
sl@0
   134
		case ETransferOut:
sl@0
   135
			{
sl@0
   136
			if(aCompletionCode != KErrNone)
sl@0
   137
				{
sl@0
   138
				err = KErrCorrupt;
sl@0
   139
				msg.Format(_L("<Error %d> No data sent on bulk OUT request"),aCompletionCode);
sl@0
   140
				break;
sl@0
   141
				}
sl@0
   142
sl@0
   143
			if(aTransferId != KBulkTranferOutId)
sl@0
   144
				{
sl@0
   145
				err = KUnexpectedTransferID;
sl@0
   146
				msg.Format(_L("<Error %d> Unexpected tranfer ID, wanted %d, got %d"),
sl@0
   147
						       err, KBulkTranferOutId, aTransferId);
sl@0
   148
				break;
sl@0
   149
				}
sl@0
   150
sl@0
   151
			RDebug::Printf("Try to receive back sent data");
sl@0
   152
			iCaseStep = ETransferIn;
sl@0
   153
			TWriteSynchronousCachedReadDataRequest request(1,1,1);  //Use first read EP and first write EP (on interface 1)
sl@0
   154
			iControlEp0->SendRequest(request,this);
sl@0
   155
			}
sl@0
   156
			break;
sl@0
   157
sl@0
   158
		case ETransferIn:
sl@0
   159
			{
sl@0
   160
			if(aCompletionCode != KErrNone)
sl@0
   161
				{
sl@0
   162
				err = KErrCorrupt;
sl@0
   163
				msg.Format(_L("<Error %d> No data sent on bulk IN request"),aCompletionCode);
sl@0
   164
				break;
sl@0
   165
				}
sl@0
   166
sl@0
   167
			if(aTransferId != KBulkTranferInId)
sl@0
   168
				{
sl@0
   169
				err = KUnexpectedTransferID;
sl@0
   170
				msg.Format(_L("<Error %d> Unexpected tranfer ID, wanted %d, got %d"),
sl@0
   171
						       err, KBulkTranferInId, aTransferId);
sl@0
   172
				break;
sl@0
   173
				}
sl@0
   174
sl@0
   175
			// Compare the data to what is expected
sl@0
   176
			if(ValidateData(iInTransfer[0]->DataPolled(), KLiteralEnglish8(), KBulkTransferSize) == EFalse)
sl@0
   177
				{
sl@0
   178
				err = KErrCompletion; //indicates data validation failure
sl@0
   179
				msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
sl@0
   180
				break;
sl@0
   181
				}
sl@0
   182
sl@0
   183
			if(err == KErrNone)
sl@0
   184
				{
sl@0
   185
				// Comparison is a match
sl@0
   186
				RDebug::Printf("Comparison for IN transfer is a match");
sl@0
   187
				iCaseStep = EPassed;
sl@0
   188
				TTestCasePassed request;
sl@0
   189
				iControlEp0->SendRequest(request,this);
sl@0
   190
				}
sl@0
   191
			}
sl@0
   192
			break;
sl@0
   193
sl@0
   194
		default:
sl@0
   195
			err = KUndefinedStep;
sl@0
   196
			msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep);
sl@0
   197
			break;
sl@0
   198
		}
sl@0
   199
	
sl@0
   200
	if(err!=KErrNone)
sl@0
   201
		{	
sl@0
   202
		RDebug::Print(msg);
sl@0
   203
		iCaseStep = EFailed;
sl@0
   204
		TTestCaseFailed request(err,msg);
sl@0
   205
		return iControlEp0->SendRequest(request,this);
sl@0
   206
		}	
sl@0
   207
	}
sl@0
   208
	
sl@0
   209
void CUT_PBASE_T_USBDI_0494::DeviceInsertedL(TUint aDeviceHandle)
sl@0
   210
	{
sl@0
   211
	LOG_FUNC
sl@0
   212
	Cancel();
sl@0
   213
	
sl@0
   214
	if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
sl@0
   215
		// Prepare for response from control transfer to client
sl@0
   216
		{
sl@0
   217
		iCaseStep = EFailed;
sl@0
   218
		}
sl@0
   219
	
sl@0
   220
	// Create the bulk transfers	
sl@0
   221
	iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTranferInId);
sl@0
   222
	iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTranferOutId);
sl@0
   223
	
sl@0
   224
	// Initialise the descriptors for transfer		
sl@0
   225
	RDebug::Printf("Initialising the transfer descriptors");
sl@0
   226
	TInt err = iUsbInterface1.InitialiseTransferDescriptors();
sl@0
   227
	if(err != KErrNone)
sl@0
   228
		{
sl@0
   229
		TBuf<256> msg;
sl@0
   230
		msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
sl@0
   231
		RDebug::Print(msg);
sl@0
   232
		iCaseStep = EFailed;
sl@0
   233
		TTestCaseFailed request(err,msg);
sl@0
   234
		iControlEp0->SendRequest(request,this);
sl@0
   235
		return;
sl@0
   236
		}
sl@0
   237
sl@0
   238
	iCaseStep = ETransferOut;	
sl@0
   239
	TEndpointReadUntilShortRequest request(1,1,KBulkTransferSize);// EP1 because 1st reader EP ??FIXME
sl@0
   240
	iControlEp0->SendRequest(request,this);
sl@0
   241
	}
sl@0
   242
	
sl@0
   243
	} //end namespace