sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // @file PBASE-T_USBDI-0497.cpp sl@0: // @internalComponent sl@0: // sl@0: // sl@0: sl@0: #include "PBASE-T_USBDI-0497.h" sl@0: #include "testpolicy.h" sl@0: #include "modelleddevices.h" sl@0: #include "testliterals.h" sl@0: sl@0: sl@0: sl@0: sl@0: namespace NUnitTesting_USBDI sl@0: { sl@0: const TInt KBulkMaxTransferSize = 40000; sl@0: const TUint KHostNumWriteBytes1 = 32000; sl@0: const TUint KHostNumWriteBytes2 = 32000; sl@0: const TInt KDeviceNumReadBytes = 64000; sl@0: const TUint KHostNumReadBytes1 = 32000; sl@0: const TUint KHostNumReadBytes2 = 32001; //allow or ZLP sl@0: sl@0: sl@0: //Make these single bit values ... sl@0: // ... so that their completion can be easily recorded in a bit mask! sl@0: const TUint32 KIfc1BulkTransferInId1 = 1<<0; sl@0: const TUint32 KIfc1BulkTransferInId2 = 1<<1; sl@0: const TUint32 KIfc2BulkTransferInId1 = 1<<2; sl@0: const TUint32 KIfc2BulkTransferInId2 = 1<<3; sl@0: const TUint32 KIfc1BulkTransferInIdMask = KIfc1BulkTransferInId1 | KIfc1BulkTransferInId2; sl@0: const TUint32 KIfc2BulkTransferInIdMask = KIfc2BulkTransferInId1 | KIfc2BulkTransferInId2; sl@0: const TUint32 KBulkTransferInIdMask = KIfc1BulkTransferInIdMask | KIfc2BulkTransferInIdMask; sl@0: const TUint32 KIfc1BulkTransferOutId1 = 1<<4; sl@0: const TUint32 KIfc1BulkTransferOutId2 = 1<<5; sl@0: const TUint32 KIfc2BulkTransferOutId1 = 1<<6; sl@0: const TUint32 KIfc2BulkTransferOutId2 = 1<<7; sl@0: const TUint32 KIfc1BulkTransferOutIdMask = KIfc1BulkTransferOutId1 | KIfc1BulkTransferOutId2; sl@0: const TUint32 KIfc2BulkTransferOutIdMask = KIfc2BulkTransferOutId1 | KIfc2BulkTransferOutId2; sl@0: const TUint32 KBulkTransferOutIdMask = KIfc1BulkTransferOutIdMask | KIfc2BulkTransferOutIdMask; sl@0: sl@0: const TInt KUnexpectedTransferID = -101; sl@0: const TInt KUndefinedStep = -102; sl@0: sl@0: const TInt KMaxTimeDiffPercentage = 60; sl@0: sl@0: sl@0: sl@0: _LIT(KTestCaseId,"PBASE-T_USBDI-0497"); sl@0: const TFunctorTestCase CUT_PBASE_T_USBDI_0497::iFunctor(KTestCaseId); sl@0: sl@0: CUT_PBASE_T_USBDI_0497* CUT_PBASE_T_USBDI_0497::NewL(TBool aHostRole) sl@0: { sl@0: CUT_PBASE_T_USBDI_0497* self = new (ELeave) CUT_PBASE_T_USBDI_0497(aHostRole); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: CUT_PBASE_T_USBDI_0497::CUT_PBASE_T_USBDI_0497(TBool aHostRole) sl@0: : CBaseBulkTestCase(KTestCaseId,aHostRole), sl@0: iCaseStep(EInProgress) sl@0: { sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0497::ConstructL() sl@0: { sl@0: BaseBulkConstructL(); sl@0: } sl@0: sl@0: sl@0: CUT_PBASE_T_USBDI_0497::~CUT_PBASE_T_USBDI_0497() sl@0: /** sl@0: The transfer objects have test specific names - so perform transfer specific clean up here. sl@0: */ sl@0: { sl@0: LOG_FUNC sl@0: sl@0: Cancel(); sl@0: sl@0: //Do this before deleting the transfer objects sl@0: CloseInterfaceAndPipes(); sl@0: sl@0: TUint8 count; sl@0: for(count=0;count msg; sl@0: msg.Format(_L(" Transfer to control endpoint 0 was not successful"),aCompletionCode); sl@0: RDebug::Print(msg); sl@0: iCaseStep = EFailed; sl@0: TTestCaseFailed request(aCompletionCode,msg); sl@0: iControlEp0->SendRequest(request,this); sl@0: return; sl@0: } sl@0: } sl@0: sl@0: switch(iCaseStep) sl@0: { sl@0: // Test case passed sl@0: case EPassed: sl@0: TestPassed(); sl@0: break; sl@0: sl@0: // Test case failed sl@0: case EFailed: sl@0: TestFailed(KErrCompletion); sl@0: break; sl@0: sl@0: case ERequestDeviceRead: sl@0: { sl@0: RDebug::Printf("Asking client for 'Read' on interface 2"); sl@0: iCaseStep = ETransferOut; sl@0: TEndpointReadRequest request(2,1,KDeviceNumReadBytes);// EP1 means endpoint index 1 not the actual endpoint number sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: break; sl@0: sl@0: case ETransferOut: sl@0: RDebug::Printf("Try to write data on BOTH interfaces"); sl@0: sl@0: iStartTime[0].HomeTime(); sl@0: iStartTime[1].HomeTime(); sl@0: sl@0: iIfc1OutTransfer[0]->TransferOut(KLiteralFrench4(), KHostNumWriteBytes1, EFalse); sl@0: iIfc1OutTransfer[1]->TransferOut(KLiteralFrench4(), KHostNumWriteBytes1, KHostNumWriteBytes2, EFalse); sl@0: iIfc2OutTransfer[0]->TransferOut(KLiteralEnglish8(), KHostNumWriteBytes1, EFalse); sl@0: iIfc2OutTransfer[1]->TransferOut(KLiteralEnglish8(), KHostNumWriteBytes1, KHostNumWriteBytes2, EFalse); sl@0: break; sl@0: sl@0: case ERequestDeviceWriteBack: sl@0: { sl@0: RDebug::Printf("Asking client for 'Write' back on interface 2"); sl@0: iCaseStep = ETransferIn; sl@0: TWriteCachedReadDataRequest request(2,1,1);// EP1 means endpoint index 1 not the actual endpoint number sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: break; sl@0: sl@0: case ETransferIn: sl@0: RDebug::Printf("Try to receive data on BOTH interfaces"); sl@0: sl@0: iStartTime[0].HomeTime(); sl@0: iStartTime[1].HomeTime(); sl@0: sl@0: iIfc1InTransfer[0]->TransferIn(KHostNumReadBytes1); sl@0: iIfc1InTransfer[1]->TransferIn(KHostNumReadBytes2); sl@0: iIfc2InTransfer[0]->TransferIn(KHostNumReadBytes1); sl@0: iIfc2InTransfer[1]->TransferIn(KHostNumReadBytes2); sl@0: break; sl@0: sl@0: default: sl@0: RDebug::Printf(" Unknown test step"); sl@0: TestFailed(KErrUnknown); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CUT_PBASE_T_USBDI_0497::TransferCompleteL(TInt aTransferId,TInt aCompletionCode) sl@0: { sl@0: LOG_FUNC sl@0: Cancel(); sl@0: sl@0: TInt err(KErrNone); sl@0: TBuf<256> msg; sl@0: RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d, test step = %d",aTransferId, aCompletionCode, iCaseStep); sl@0: sl@0: switch(iCaseStep) sl@0: { sl@0: case ETransferOut: sl@0: if(aCompletionCode != KErrNone) sl@0: { sl@0: iIfc1OutTransfer[0]->Cancel(); sl@0: iIfc1OutTransfer[1]->Cancel(); sl@0: iIfc2OutTransfer[0]->Cancel(); sl@0: iIfc2OutTransfer[1]->Cancel(); sl@0: err = KErrCorrupt; sl@0: msg.Format(_L(" The transfer completed with an error."), aCompletionCode); sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: switch(aTransferId) sl@0: { sl@0: case KIfc1BulkTransferOutId1: sl@0: case KIfc1BulkTransferOutId2: sl@0: case KIfc2BulkTransferOutId1: sl@0: case KIfc2BulkTransferOutId2: sl@0: iTransferComplete |= aTransferId; sl@0: RDebug::Printf("Transfer OUT %d completed (Transfer Completion Aggregation Mask 0x%x)", aTransferId, iTransferComplete); sl@0: break; //switch(aTransferId) sl@0: default: sl@0: iTransferComplete = 0; //reset sl@0: err = KUnexpectedTransferID; sl@0: msg.Format(_L(" Unexpected transfer ID, wanted %d or %d, got %d"), sl@0: err, KIfc1BulkTransferInId1, KIfc1BulkTransferInId2, aTransferId); sl@0: break; //switch(aTransferId) sl@0: } sl@0: sl@0: if(err==KErrNone && iTimeElapsed[0] == 0 && (iTransferComplete & KIfc1BulkTransferOutIdMask) == KIfc1BulkTransferOutIdMask) sl@0: //Record time elapsed for Interface 1 if not yet recorded. sl@0: { sl@0: RecordTime(0); sl@0: } sl@0: sl@0: if(err==KErrNone && iTimeElapsed[1] == 0 && (iTransferComplete & KIfc2BulkTransferOutIdMask) == KIfc2BulkTransferOutIdMask) sl@0: //Record time elapsed for Interface 2 if not yet recorded. sl@0: { sl@0: RecordTime(1); sl@0: } sl@0: sl@0: if(err==KErrNone && (iTransferComplete & KBulkTransferOutIdMask) == KBulkTransferOutIdMask) sl@0: { sl@0: RDebug::Printf("All OUT Transfers Completed Successfully: Transfer Completion Aggregation Mask 0x%x", iTransferComplete); sl@0: iTransferComplete = 0; //reset sl@0: err = CheckAndResetTimes(0, 1, KMaxTimeDiffPercentage); sl@0: if(err!=KErrNone) sl@0: { sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: RDebug::Printf("Asking client for 'Write' back on interface 1"); sl@0: iCaseStep = ERequestDeviceWriteBack; sl@0: TWriteCachedReadDataRequest request(1,1,1);// EP1 means endpoint index 1 not the actual endpoint number sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: break; //switch(iCaseStep) sl@0: sl@0: case ETransferIn: sl@0: if(aCompletionCode != KErrNone) sl@0: { sl@0: iIfc1InTransfer[0]->Cancel(); sl@0: iIfc1InTransfer[1]->Cancel(); sl@0: iIfc2InTransfer[0]->Cancel(); sl@0: iIfc2InTransfer[1]->Cancel(); sl@0: err = KErrCorrupt; sl@0: sl@0: msg.Format(_L(" No data sent on bulk IN request"),aCompletionCode); sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: switch(aTransferId) sl@0: { sl@0: case KIfc1BulkTransferInId1: sl@0: case KIfc1BulkTransferInId2: sl@0: case KIfc2BulkTransferInId1: sl@0: case KIfc2BulkTransferInId2: sl@0: iTransferComplete |= aTransferId; sl@0: RDebug::Printf("Transfer OUT %d completed (Transfer Completion Aggregation Mask 0x%x)", aTransferId, iTransferComplete); sl@0: break; //switch(aTransferId) sl@0: sl@0: default: sl@0: iTransferComplete = 0; //reset sl@0: err = KUnexpectedTransferID; sl@0: msg.Format(_L(" Unexpected transfer ID, wanted %d or %d, got %d"), sl@0: err, KIfc1BulkTransferInId1, KIfc1BulkTransferInId2, aTransferId); sl@0: break; //switch(aTransferId) sl@0: } sl@0: sl@0: if(err==KErrNone && iTimeElapsed[0] == 0 && (iTransferComplete & KIfc1BulkTransferInIdMask) == KIfc1BulkTransferInIdMask) sl@0: //Record time elapsed for Interface 1 if not yet recorded. sl@0: { sl@0: RecordTime(0); sl@0: } sl@0: sl@0: if(err==KErrNone && iTimeElapsed[1] == 0 && (iTransferComplete & KIfc2BulkTransferInIdMask) == KIfc2BulkTransferInIdMask) sl@0: //Record time elapsed for Interface 2 if not yet recorded. sl@0: { sl@0: RecordTime(1); sl@0: } sl@0: sl@0: if(err==KErrNone && (iTransferComplete & KBulkTransferInIdMask) == KBulkTransferInIdMask) sl@0: { sl@0: // ok, compare data rcvd now sl@0: RDebug::Printf("All IN Transfers Completed Successfully: Transfer Completion Aggregation Mask 0x%x", iTransferComplete); sl@0: iTransferComplete = 0; //reset sl@0: err = CheckAndResetTimes(0, 1, KMaxTimeDiffPercentage); sl@0: if(err!=KErrNone) sl@0: { sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: TPtrC8 data1(iIfc1InTransfer[0]->DataPolled()); sl@0: TPtrC8 data2(iIfc1InTransfer[1]->DataPolled()); sl@0: TPtrC8 data3(iIfc2InTransfer[0]->DataPolled()); sl@0: TPtrC8 data4(iIfc2InTransfer[1]->DataPolled()); sl@0: //Validate first transfer on Interface 1 for number of bytes originally written. sl@0: if(ValidateData(data1, KLiteralFrench4(), KHostNumWriteBytes1) == EFalse) sl@0: { sl@0: RDebug::Printf("Validation failure 1st transfer, Interface 1"); sl@0: err = KErrCompletion; //indicates data validation failure sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: //Validate second transfer on Interface 1 for number of bytes originally written. sl@0: if(ValidateData(data2, KLiteralFrench4(), KHostNumWriteBytes1, KHostNumWriteBytes2) == EFalse) sl@0: { sl@0: RDebug::Printf("Validation failure 2nd transfer, Interface 1"); sl@0: err = KErrCompletion; //indicates data validation failure sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: //Validate first transfer on Interface 2 for number of bytes originally written. sl@0: if(ValidateData(data3, KLiteralEnglish8(), KHostNumWriteBytes1) == EFalse) sl@0: { sl@0: RDebug::Printf("Validation failure 1st transfer, Interface 2"); sl@0: err = KErrCompletion; //indicates data validation failure sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: //Validate second transfer on Interface 2 for number of bytes originally written. sl@0: if(ValidateData(data4, KLiteralEnglish8(), KHostNumWriteBytes1, KHostNumWriteBytes2) == EFalse) sl@0: { sl@0: RDebug::Printf("Validation failure 2nd transfer, Interface 2"); sl@0: err = KErrCompletion; //indicates data validation failure sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: // Comparison is a match sl@0: RDebug::Printf("Comparison for IN transfer is a match"); sl@0: iCaseStep = EPassed; sl@0: TTestCasePassed request; sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: break; //switch(iCaseStep) sl@0: sl@0: default: sl@0: err = KUndefinedStep; sl@0: msg.Format(_L(" Undefined case step %d reached"),KUndefinedStep, iCaseStep); sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: if(err == KErrCompletion) sl@0: //indicates data validation failure sl@0: { sl@0: msg.Format(_L(" Bulk transfer IN data received does not match Bulk Transfer OUT data"), err); sl@0: } sl@0: sl@0: if(err == KErrTooBig) sl@0: //indicates timing validation failure sl@0: { sl@0: msg.Format(_L(" Timer comparison showed too great a difference in transfer times between the two interfaces"), err); sl@0: } sl@0: sl@0: if(err!=KErrNone) sl@0: { sl@0: RDebug::Print(msg); sl@0: iCaseStep = EFailed; sl@0: TTestCaseFailed request(err,msg); sl@0: return iControlEp0->SendRequest(request,this); sl@0: } sl@0: } sl@0: sl@0: void CUT_PBASE_T_USBDI_0497::DeviceInsertedL(TUint aDeviceHandle) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: Cancel(); sl@0: RDebug::Printf("this - %08x", this); sl@0: sl@0: TBuf<256> msg; sl@0: TInt err = KErrNone; sl@0: if(BaseBulkDeviceInsertedL(aDeviceHandle, EFalse) == EDeviceConfigurationError) sl@0: // Prepare for response from control transfer to client sl@0: { sl@0: err = KErrGeneral; sl@0: msg.Format(_L("Base class DeviceInsertedL failed")); sl@0: } sl@0: else sl@0: { sl@0: if(SetUpInterfaceAndPipesL(aDeviceHandle, 2) == EDeviceConfigurationError) sl@0: // Prepare for response from control transfer to client sl@0: { sl@0: err = KErrGeneral; sl@0: msg.Format(_L("Base class SetUpInterfaceAndPipes for Interface 2 failed")); sl@0: } sl@0: else sl@0: { sl@0: sl@0: iIfc1InTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxTransferSize,*this,KIfc1BulkTransferInId1); sl@0: iIfc1InTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxTransferSize,*this,KIfc1BulkTransferInId2); sl@0: iIfc1OutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxTransferSize,*this,KIfc1BulkTransferOutId1); sl@0: iIfc1OutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxTransferSize,*this,KIfc1BulkTransferOutId2); sl@0: sl@0: iIfc2InTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface2BulkIn,iUsbInterface2,KBulkMaxTransferSize,*this,KIfc2BulkTransferInId1); sl@0: iIfc2InTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface2BulkIn,iUsbInterface2,KBulkMaxTransferSize,*this,KIfc2BulkTransferInId2); sl@0: iIfc2OutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface2BulkOut1,iUsbInterface2,KBulkMaxTransferSize,*this,KIfc2BulkTransferOutId1); sl@0: iIfc2OutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface2BulkOut1,iUsbInterface2,KBulkMaxTransferSize,*this,KIfc2BulkTransferOutId2); sl@0: sl@0: // Initialise the descriptors for transfer sl@0: RDebug::Printf("Initialising the transfer descriptors - interface 1"); sl@0: err = iUsbInterface1.InitialiseTransferDescriptors(); sl@0: if(err != KErrNone) sl@0: { sl@0: msg.Format(_L(" Unable to initialise transfer descriptors (Interface 1)"),err); sl@0: } sl@0: else sl@0: { sl@0: // Initialise the descriptors for transfer sl@0: RDebug::Printf("Initialising the transfer descriptors (Interface 2)"); sl@0: err = iUsbInterface2.InitialiseTransferDescriptors(); sl@0: if(err != KErrNone) sl@0: { sl@0: msg.Format(_L(" Unable to initialise transfer descriptors"),err); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: if(err != KErrNone) sl@0: { sl@0: RDebug::Print(msg); sl@0: iCaseStep = EFailed; sl@0: TTestCaseFailed request(err,msg); sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: else sl@0: { sl@0: RDebug::Printf("Asking client for 'Read' on interface 1"); sl@0: iCaseStep = ERequestDeviceRead; sl@0: TEndpointReadRequest request(1,1,KDeviceNumReadBytes);// EP1 means endpoint index 1 not the actual endpoint number sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: } sl@0: sl@0: } //end namespace