os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/testinterfacesettingbase.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 testinterfacesettingbase.h
sl@0
    15
// @internalComponent
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include "testinterfacesettingbase.h"
sl@0
    20
#include "testinterfacebase.h"
sl@0
    21
#include "controltransferrequests.h"
sl@0
    22
 
sl@0
    23
 
sl@0
    24
namespace NUnitTesting_USBDI
sl@0
    25
	{	
sl@0
    26
	
sl@0
    27
CInterfaceSettingBase::CInterfaceSettingBase(const TDesC& aString)
sl@0
    28
:	iHashEndpointFunction(EndpointNumberHash),
sl@0
    29
	iIdRelEndpoint(EndpointIdentityRelationship),
sl@0
    30
	iEndpoints(iHashEndpointFunction,iIdRelEndpoint)
sl@0
    31
	{	
sl@0
    32
	// Set the name of this interface setting
sl@0
    33
	iSettingString.Copy(aString);
sl@0
    34
	iInterfaceInfo().iString = &iSettingString;
sl@0
    35
	
sl@0
    36
	// Zero count the number of endpoints used for this setting
sl@0
    37
	iInterfaceInfo().iTotalEndpointsUsed = 0;
sl@0
    38
	}
sl@0
    39
sl@0
    40
	
sl@0
    41
CInterfaceSettingBase::~CInterfaceSettingBase()
sl@0
    42
	{
sl@0
    43
	LOG_FUNC
sl@0
    44
	
sl@0
    45
	iEndpointReaders.ResetAndDestroy();
sl@0
    46
	iEndpointWriters.ResetAndDestroy();
sl@0
    47
	}
sl@0
    48
	
sl@0
    49
sl@0
    50
const TDesC& CInterfaceSettingBase::Name() const
sl@0
    51
	{
sl@0
    52
	return iSettingString;
sl@0
    53
	}
sl@0
    54
sl@0
    55
sl@0
    56
void CInterfaceSettingBase::SetClassCodeL(TUint8 aClassCode,TUint8 aSubClassCode,TUint8 aDeviceProtocol)
sl@0
    57
	{
sl@0
    58
	// Set class specific information
sl@0
    59
	iInterfaceInfo().iClass = TUsbcClassInfo(aClassCode,aSubClassCode,aDeviceProtocol);
sl@0
    60
	}
sl@0
    61
sl@0
    62
sl@0
    63
TInt CInterfaceSettingBase::AddEndpoint(TEndpoint& aEndpoint)
sl@0
    64
	{
sl@0
    65
	LOG_FUNC
sl@0
    66
	
sl@0
    67
	if(aEndpoint.iEndpointNumber == EEndpoint0)
sl@0
    68
		{
sl@0
    69
		return KErrInUse;
sl@0
    70
		}
sl@0
    71
	
sl@0
    72
	if(iEndpoints.Count() < KMaxEndpointsPerClient)
sl@0
    73
		{
sl@0
    74
		// Set EEndpoint1, EEndpoint2, EEndpoint3, EEndpoint4 or EEndpoint5
sl@0
    75
		iInterfaceInfo().iEndpointData[iEndpoints.Count()] = aEndpoint.iEndpointInfo;
sl@0
    76
		iEndpoints.Insert(aEndpoint.iEndpointNumber,aEndpoint);
sl@0
    77
		
sl@0
    78
		// Update the total endpoints used on this interface
sl@0
    79
		iInterfaceInfo().iTotalEndpointsUsed = iEndpoints.Count();
sl@0
    80
		
sl@0
    81
		return KErrNone;
sl@0
    82
		}
sl@0
    83
	else
sl@0
    84
		{
sl@0
    85
		return KErrOverflow;
sl@0
    86
		}
sl@0
    87
	}
sl@0
    88
sl@0
    89
sl@0
    90
void CInterfaceSettingBase::CreateEndpointReaderL(RDevUsbcClient& aClientDriver,TUint aEndpoint)
sl@0
    91
	{
sl@0
    92
	LOG_FUNC	
sl@0
    93
	// Create the reader for this endpoint and store in the container	
sl@0
    94
	CEndpointReader* epReader = new (ELeave) CEndpointReader(aClientDriver,
sl@0
    95
	iEndpoints.Find(static_cast<TEndpointNumber>(aEndpoint))->iEndpointNumber);
sl@0
    96
	CleanupStack::PushL(epReader);
sl@0
    97
	iEndpointReaders.AppendL(epReader);
sl@0
    98
	CleanupStack::Pop(epReader);
sl@0
    99
	}
sl@0
   100
sl@0
   101
sl@0
   102
void CInterfaceSettingBase::CreateEndpointWriterL(RDevUsbcClient& aClientDriver,TUint aEndpoint)
sl@0
   103
	{
sl@0
   104
	LOG_FUNC	
sl@0
   105
	// Create the writer for this endpoint and store in the container	
sl@0
   106
	CEndpointWriter* epWriter = new (ELeave) CEndpointWriter(aClientDriver,
sl@0
   107
	iEndpoints.Find(static_cast<TEndpointNumber>(aEndpoint))->iEndpointNumber);
sl@0
   108
	CleanupStack::PushL(epWriter);
sl@0
   109
	iEndpointWriters.AppendL(epWriter);
sl@0
   110
	CleanupStack::Pop(epWriter);
sl@0
   111
	}
sl@0
   112
sl@0
   113
void CInterfaceSettingBase::WriteSpecifiedDataToEndpointL(const TDesC8& aData,TUint16 aEndpointNumber)
sl@0
   114
	{
sl@0
   115
	LOG_FUNC	
sl@0
   116
	// Access the correct writer for the given endpoint
sl@0
   117
	// and write the data to the host			
sl@0
   118
	iEndpointWriters[aEndpointNumber-1]->Write(aData, ETrue);
sl@0
   119
	}
sl@0
   120
sl@0
   121
void CInterfaceSettingBase::WriteSpecifiedDataToEndpointL(const TDesC8& aDataPattern, const TUint aNumBytes, TUint16 aEndpointNumber)
sl@0
   122
	{
sl@0
   123
	LOG_FUNC	
sl@0
   124
	// Access the correct writer for the given endpoint
sl@0
   125
	// and write the data to the host
sl@0
   126
	iEndpointWriters[aEndpointNumber-1]->WriteUsingPatternL(aDataPattern,aNumBytes,ETrue);
sl@0
   127
	}
sl@0
   128
sl@0
   129
void CInterfaceSettingBase::RepeatedWriteSpecifiedDataToEndpointL(const TDesC8& aDataPattern, TUint aNumBytesPerWrite, TUint aTotalNumBytes, TUint16 aEndpointNumber)
sl@0
   130
	{
sl@0
   131
	LOG_FUNC	
sl@0
   132
	// Access the correct writer for the given endpoint
sl@0
   133
	// and write the data to the host
sl@0
   134
	iEndpointWriters[aEndpointNumber-1]->WriteInPartsUsingPatternL(aDataPattern,aNumBytesPerWrite,aTotalNumBytes,ETrue);
sl@0
   135
	}
sl@0
   136
sl@0
   137
void CInterfaceSettingBase::WriteCachedEndpointDataToEndpointL(const TUint16 aReadEndpointNumber,TUint16 aWriteEndpointNumber)
sl@0
   138
	{
sl@0
   139
	LOG_FUNC
sl@0
   140
	
sl@0
   141
	iEndpointWriters[aWriteEndpointNumber-1]->Write(iEndpointReaders[aReadEndpointNumber-1]->Buffer(), ETrue);
sl@0
   142
	}
sl@0
   143
sl@0
   144
void CInterfaceSettingBase::CancelWriteDataToEndpointL(TUint16 aEndpointNumber)
sl@0
   145
	{
sl@0
   146
	LOG_FUNC	
sl@0
   147
	// Access the correct writer for the given endpoint
sl@0
   148
	// and cancel any outstanding write. This will not of course work for 'synchronous' writes.			
sl@0
   149
	iEndpointWriters[aEndpointNumber-1]->Cancel();
sl@0
   150
	}
sl@0
   151
sl@0
   152
void CInterfaceSettingBase::WriteSynchronousSpecifiedDataToEndpointL(const TDesC8& aDataPattern, const TUint aNumBytes, TUint16 aEndpointNumber)
sl@0
   153
	{
sl@0
   154
	LOG_FUNC	
sl@0
   155
	// Access the correct writer for the given endpoint
sl@0
   156
	// and write the data to the host
sl@0
   157
	iEndpointWriters[aEndpointNumber-1]->WriteSynchronousUsingPatternL(aDataPattern,aNumBytes,ETrue);
sl@0
   158
	}
sl@0
   159
sl@0
   160
void CInterfaceSettingBase::WriteSynchronousSpecifiedDataToAndHaltEndpointL(const TDesC8& aDataPattern, const TUint aNumBytes, TUint16 aEndpointNumber)
sl@0
   161
	{
sl@0
   162
	LOG_FUNC	
sl@0
   163
	// Access the correct writer for the given endpoint
sl@0
   164
	// and write the data to the host
sl@0
   165
	iEndpointWriters[aEndpointNumber-1]->WriteSynchronousUsingPatternAndHaltL(aDataPattern,aNumBytes);
sl@0
   166
	}
sl@0
   167
sl@0
   168
void CInterfaceSettingBase::WriteSynchronousCachedEndpointDataToEndpointL(const TUint16 aReadEndpointNumber,TUint16 aWriteEndpointNumber)
sl@0
   169
	{
sl@0
   170
	LOG_FUNC
sl@0
   171
	
sl@0
   172
	//Attempt to write the complete cached buffer by starting at zero and choosing the max length posible
sl@0
   173
	WriteSynchronousCachedEndpointDataToEndpointL(aReadEndpointNumber, aWriteEndpointNumber, 0, KMaxTInt);
sl@0
   174
	}
sl@0
   175
sl@0
   176
void CInterfaceSettingBase::WriteSynchronousCachedEndpointDataToEndpointL(const TUint16 aReadEndpointNumber,TUint16 aWriteEndpointNumber, TUint aStartPoint, TUint aLength)
sl@0
   177
	{
sl@0
   178
	LOG_FUNC	
sl@0
   179
	// Access the correct writer for the given endpoint
sl@0
   180
	// Access the 'source' endpoint buffer. This contains data from that endpoint's last read.
sl@0
   181
	// Write this data to the host using 'write' endpoint.
sl@0
   182
	
sl@0
   183
	// Check data
sl@0
   184
	TPtr8 dataPtr(iEndpointReaders[aReadEndpointNumber-1]->Buffer());
sl@0
   185
	User::LeaveIfError(dataPtr.MaxLength() == 0);
sl@0
   186
	if(aStartPoint+aLength>dataPtr.Length())
sl@0
   187
		//allow use of excessive length to imply a write of all the rest of the buffer...
sl@0
   188
		//..otherwise 'Mid' would panic!
sl@0
   189
		{
sl@0
   190
		aLength = dataPtr.Length() - aStartPoint;
sl@0
   191
		}
sl@0
   192
	
sl@0
   193
	// Do the 'Write'
sl@0
   194
	// Note we need a synchronous 'Write' here
sl@0
   195
	iEndpointWriters[aWriteEndpointNumber-1]->WriteSynchronous(iEndpointReaders[aReadEndpointNumber-1]->Buffer().Mid(aStartPoint, aLength), ETrue);
sl@0
   196
	}
sl@0
   197
sl@0
   198
TBool CInterfaceSettingBase::CachedEndpointResultL(const TUint16 aEndpointNumber)
sl@0
   199
	{
sl@0
   200
	LOG_FUNC	
sl@0
   201
	// Access endpoint buffer containing data from the endpoint's last read
sl@0
   202
	// and validate with the supplied data pattern
sl@0
   203
sl@0
   204
	return iEndpointReaders[aEndpointNumber-1]->IsValid();
sl@0
   205
	}
sl@0
   206
sl@0
   207
TInt CInterfaceSettingBase::NumBytesReadSoFarL(const TUint16 aEndpointNumber)
sl@0
   208
	{
sl@0
   209
	LOG_FUNC	
sl@0
   210
	// Access endpoint buffer containing data from the endpoint's last read
sl@0
   211
	// and validate with the supplied data pattern
sl@0
   212
sl@0
   213
	return iEndpointReaders[aEndpointNumber-1]->NumBytesReadSoFar();
sl@0
   214
	}
sl@0
   215
sl@0
   216
TInt CInterfaceSettingBase::NumBytesWrittenSoFarL(const TUint16 aEndpointNumber)
sl@0
   217
	{
sl@0
   218
	LOG_FUNC	
sl@0
   219
	// Access endpoint buffer containing data from the endpoint's last read
sl@0
   220
	// and validate with the supplied data pattern
sl@0
   221
sl@0
   222
	return iEndpointWriters[aEndpointNumber-1]->NumBytesWrittenSoFar();
sl@0
   223
	}
sl@0
   224
sl@0
   225
TBool CInterfaceSettingBase::ValidateCachedEndpointDataL(const TDesC8& aDataPattern, const TUint aNumBytes, const TUint16 aEndpointNumber)
sl@0
   226
	{
sl@0
   227
	LOG_FUNC	
sl@0
   228
	// Access endpoint buffer containing data from the endpoint's last read
sl@0
   229
	// and validate with the supplied data pattern
sl@0
   230
sl@0
   231
	return ValidateCachedEndpointDataL(aDataPattern, 0, aNumBytes, aEndpointNumber);
sl@0
   232
	}
sl@0
   233
sl@0
   234
TBool CInterfaceSettingBase::ValidateCachedEndpointDataL(const TDesC8& aDataPattern, const TUint aStartPoint, const TUint aNumBytes, const TUint16 aEndpointNumber)
sl@0
   235
	{
sl@0
   236
	LOG_FUNC	
sl@0
   237
	__ASSERT_DEBUG(aDataPattern.Length()!=0, User::Panic(_L("Trying to validate with ZERO LENGTH STRING"), KErrArgument));
sl@0
   238
sl@0
   239
	//Check data in endpoint buffer
sl@0
   240
	TPtr8 dataToValidate(iEndpointReaders[aEndpointNumber-1]->Buffer());
sl@0
   241
	User::LeaveIfError(dataToValidate.MaxLength() == 0);
sl@0
   242
sl@0
   243
	TUint startPoint = aStartPoint%aDataPattern.Length();
sl@0
   244
	TUint numStartBytes = (aDataPattern.Length() - startPoint)%aDataPattern.Length();
sl@0
   245
	numStartBytes = aNumBytes<numStartBytes?aNumBytes:numStartBytes; //never test for more than aNumBytes
sl@0
   246
	TUint fullRepeats = (aNumBytes-numStartBytes)/aDataPattern.Length();
sl@0
   247
	TUint startEndPoint = (fullRepeats*aDataPattern.Length()) + numStartBytes;
sl@0
   248
	TUint numEndBytes = aNumBytes - startEndPoint;//fullRepeats*aDataPattern.Length() - numStartBytes;
sl@0
   249
	if(numStartBytes)
sl@0
   250
		{
sl@0
   251
		if(dataToValidate.Left(numStartBytes).Compare(aDataPattern.Mid(startPoint, numStartBytes)) != 0)
sl@0
   252
			{
sl@0
   253
			RDebug::Printf("ROUND TRIP VALIDATION: Start Bytes Match Failure");
sl@0
   254
			RDebug::Printf("ROUND TRIP VALIDATION: numStartBytes = %d", numStartBytes);
sl@0
   255
			RDebug::Printf("Start of sent data ...");
sl@0
   256
			RDebug::RawPrint(aDataPattern.Mid(startPoint, numStartBytes));
sl@0
   257
			RDebug::Printf("\n");
sl@0
   258
			RDebug::Printf("ROUND TRIP VALIDATION: Start of returned data ...");				
sl@0
   259
			RDebug::RawPrint(dataToValidate.Left(numStartBytes));
sl@0
   260
			RDebug::Printf("\n");
sl@0
   261
			return EFalse;
sl@0
   262
			}
sl@0
   263
		}
sl@0
   264
	if(numEndBytes)
sl@0
   265
		{
sl@0
   266
		if(dataToValidate.Mid(startEndPoint,numEndBytes).Compare(aDataPattern.Left(numEndBytes)) != 0)
sl@0
   267
			{
sl@0
   268
			RDebug::Printf("ROUND TRIP VALIDATION: End Bytes Match Failure");
sl@0
   269
			RDebug::Printf("ROUND TRIP VALIDATION: startEndPoint = %d, numEndBytes = %d", startEndPoint, numEndBytes);
sl@0
   270
			RDebug::Printf("End of sent data ...");
sl@0
   271
			RDebug::RawPrint(aDataPattern.Left(numEndBytes));
sl@0
   272
			RDebug::Printf("\n");
sl@0
   273
			RDebug::Printf("ROUND TRIP VALIDATION: End of returned data ...");				
sl@0
   274
			RDebug::RawPrint(dataToValidate.Mid(startEndPoint,numEndBytes));
sl@0
   275
			RDebug::Printf("\n");
sl@0
   276
			return EFalse;
sl@0
   277
			}
sl@0
   278
		}
sl@0
   279
	for(TInt i=0; i<fullRepeats; i++)
sl@0
   280
		{
sl@0
   281
		if(dataToValidate.Mid(numStartBytes + i*aDataPattern.Length(),aDataPattern.Length()).Compare(aDataPattern) != 0)
sl@0
   282
			{
sl@0
   283
			RDebug::Printf("ROUND TRIP VALIDATION: Repeated Bytes Match Failure, Repeat %d",i);
sl@0
   284
			RDebug::Printf("sent data middle block ...");
sl@0
   285
			RDebug::RawPrint(aDataPattern);
sl@0
   286
			RDebug::Printf("\n");
sl@0
   287
			RDebug::Printf("ROUND TRIP VALIDATION: Middle block of returned data ...");
sl@0
   288
			RDebug::RawPrint(dataToValidate.Mid(numStartBytes + i*aDataPattern.Length(),aDataPattern.Length()));
sl@0
   289
			RDebug::Printf("\n");
sl@0
   290
			return EFalse; //from 'for' loop
sl@0
   291
			}
sl@0
   292
		}
sl@0
   293
	return ETrue;
sl@0
   294
	}
sl@0
   295
sl@0
   296
sl@0
   297
void CInterfaceSettingBase::ReadDataFromEndpointL(TUint aNumBytes, TUint16 aEndpointNumber)	
sl@0
   298
	{
sl@0
   299
	LOG_FUNC	
sl@0
   300
	// Access the correct readerer for the given endpoint
sl@0
   301
	// and prepare to read the data to be sent by the host			
sl@0
   302
	iEndpointReaders[aEndpointNumber-1]->ReadL(aNumBytes);
sl@0
   303
	}
sl@0
   304
sl@0
   305
void CInterfaceSettingBase::CancelAnyReadDataFromEndpointL(TUint16 aEndpointNumber)
sl@0
   306
	{
sl@0
   307
	LOG_FUNC	
sl@0
   308
	// Access the correct writer for the given endpoint
sl@0
   309
	// and cancel any outstanding write. This will not of course work for 'synchronous' writes.			
sl@0
   310
	iEndpointReaders[aEndpointNumber-1]->Cancel();
sl@0
   311
	}
sl@0
   312
sl@0
   313
void CInterfaceSettingBase::ReadDataFromAndHaltEndpointL(TUint aNumBytes, TUint16 aEndpointNumber)	
sl@0
   314
	{
sl@0
   315
	LOG_FUNC	
sl@0
   316
	// Access the correct reader for the given endpoint
sl@0
   317
	// and prepare to read the data to be sent by the host			
sl@0
   318
	iEndpointReaders[aEndpointNumber-1]->ReadAndHaltL(aNumBytes);
sl@0
   319
	}
sl@0
   320
sl@0
   321
void CInterfaceSettingBase::RepeatedReadAndValidateFromEndpointL(const TDesC8& aDataPattern, TUint aNumBytesPerRead, TUint aTotalNumBytes, TUint16 aEndpointNumber)
sl@0
   322
	{
sl@0
   323
	LOG_FUNC	
sl@0
   324
	// Access the correct reader for the given endpoint
sl@0
   325
	// and prepare to read the data to be sent by the host
sl@0
   326
	// using multiple 'Reads'
sl@0
   327
	iEndpointReaders[aEndpointNumber-1]->RepeatedReadAndValidateL(aDataPattern, aNumBytesPerRead, aTotalNumBytes);
sl@0
   328
	}
sl@0
   329
sl@0
   330
void CInterfaceSettingBase::ReadDataUntilShortFromEndpointL(TUint aNumBytes, TUint16 aEndpointNumber)	
sl@0
   331
	{
sl@0
   332
	LOG_FUNC	
sl@0
   333
	// Access the correct reader for the given endpoint
sl@0
   334
	// and prepare to read the data to be sent by the host			
sl@0
   335
	iEndpointReaders[aEndpointNumber-1]->ReadUntilShortL(aNumBytes);
sl@0
   336
	}
sl@0
   337
	}
sl@0
   338
sl@0
   339