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