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-0499.cpp sl@0: // @internalComponent sl@0: // sl@0: // sl@0: sl@0: #include "PBASE-T_USBDI-0499.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 KBulkMaxINTransferSize = 1200; sl@0: const TInt KBulkMaxOUTTransferSize = 150000; sl@0: const TUint KHostNumWriteBytesPreHalt1 = 128000; sl@0: const TUint KHostNumWriteBytesPreHalt2 = 128000; sl@0: const TUint KHostNumWriteBytesPostHalt1 = 512; sl@0: const TUint KHostNumWriteBytesPostHalt2 = 512; sl@0: const TInt KDeviceNumWrittenBytesPreHalt = KHostNumWriteBytesPreHalt1+KHostNumWriteBytesPreHalt2; sl@0: const TInt KDeviceNumReadBytesPostHalt = KHostNumWriteBytesPostHalt1+KHostNumWriteBytesPostHalt2; sl@0: const TInt KDeviceNumReadBytesPreHalt = 128; sl@0: const TInt KHostNumReadBytesPostHalt = KDeviceNumReadBytesPostHalt+1; //read cached data, allow 1 for 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 TInt KBulkTransferInId0 = 1<<0; sl@0: const TInt KBulkTransferOutId0 = 1<<3; sl@0: const TInt KBulkTransferOutId1 = 1<<4; sl@0: sl@0: const TInt KUnexpectedTransferID = -101; sl@0: const TInt KUndefinedStep = -102; sl@0: sl@0: sl@0: _LIT(KTestCaseId,"PBASE-T_USBDI-0499"); sl@0: const TFunctorTestCase CUT_PBASE_T_USBDI_0499::iFunctor(KTestCaseId); sl@0: sl@0: CUT_PBASE_T_USBDI_0499* CUT_PBASE_T_USBDI_0499::NewL(TBool aHostRole) sl@0: { sl@0: CUT_PBASE_T_USBDI_0499* self = new (ELeave) CUT_PBASE_T_USBDI_0499(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_0499::CUT_PBASE_T_USBDI_0499(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_0499::ConstructL() sl@0: { sl@0: BaseBulkConstructL(); sl@0: } sl@0: sl@0: sl@0: CUT_PBASE_T_USBDI_0499::~CUT_PBASE_T_USBDI_0499() sl@0: { sl@0: LOG_FUNC sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0499::Ep0TransferCompleteL(TInt aCompletionCode) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode); sl@0: sl@0: if(aCompletionCode != KErrNone) sl@0: { sl@0: if(iCaseStep == EFailed) sl@0: {// ignore error, nad catch the TestFailed method called further down. sl@0: RDebug::Printf("***Failure sending FAIL message to client on endpoint 0***"); sl@0: } sl@0: else sl@0: { sl@0: TBuf<256> 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 ETransferOutHalt: sl@0: iOutTransfer[0]->TransferOut(KLiteralFrench4(), KHostNumWriteBytesPreHalt1, EFalse); sl@0: iOutTransfer[1]->TransferOut(KLiteralFrench4(), KHostNumWriteBytesPreHalt2, EFalse); sl@0: break; sl@0: sl@0: case EAwaitClearPreHalt: sl@0: { sl@0: RDebug::Printf("Client has been asked to clear endpoint buffer"); sl@0: User::After(1000000); //Give client time to clear buffer sl@0: TEndpointCancelReadRequest request(1,1); sl@0: iControlEp0->SendRequest(request,this); sl@0: iCaseStep = EAwaitCancelRead; sl@0: } sl@0: break; sl@0: sl@0: case EAwaitCancelRead: sl@0: { sl@0: TEndpointReadRequest request(1,1, KDeviceNumReadBytesPostHalt);// EP1 because 1st writter EP sl@0: iControlEp0->SendRequest(request,this); sl@0: iCaseStep = ETransferOut; sl@0: } sl@0: break; sl@0: sl@0: case ETransferOut: sl@0: RDebug::Printf("Try to send data (post halt)"); sl@0: iOutTransfer[0]->TransferOut(KLiteralEnglish8().Mid(0, KHostNumWriteBytesPostHalt1), EFalse); sl@0: iOutTransfer[1]->TransferOut(KLiteralEnglish8().Mid(KHostNumWriteBytesPostHalt1, KHostNumWriteBytesPostHalt2), EFalse); sl@0: break; sl@0: sl@0: case ETransferIn: sl@0: RDebug::Printf("Try to receive data"); sl@0: iInTransfer[0]->TransferIn(KHostNumReadBytesPostHalt); 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_0499::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",aTransferId, aCompletionCode); sl@0: sl@0: switch(iCaseStep) sl@0: { sl@0: case ETransferOutHalt: sl@0: { sl@0: if(aCompletionCode != KErrUsbStalled) sl@0: { sl@0: iOutTransfer[0]->Cancel(); sl@0: iOutTransfer[1]->Cancel(); sl@0: err = KErrCorrupt; sl@0: msg.Format(_L(" The transfer completed with no errors but the endpoint should have halted"),aCompletionCode); sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: switch(aTransferId) sl@0: { sl@0: case KBulkTransferOutId0: sl@0: case KBulkTransferOutId1: sl@0: iTransferComplete |= aTransferId; sl@0: RDebug::Printf("Transfer %d stalled", aTransferId); 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, KBulkTransferOutId0, KBulkTransferOutId1, aTransferId); sl@0: break; //switch(aTransferId) sl@0: } sl@0: sl@0: if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1)) sl@0: { sl@0: RDebug::Printf("Clear halt and try to send data again. Transfers Completed %d", iTransferComplete); sl@0: // Acknowledge the stall and clear sl@0: err = iTestPipeInterface1BulkOut.ClearRemoteStall(); sl@0: if(err != KErrNone) sl@0: { sl@0: msg.Format(_L(" The remote stall cannot be cleared"),err); sl@0: break; //switch(iCaseStep) sl@0: } sl@0: iCaseStep = EAwaitClearPreHalt; sl@0: TEndpointReadRequest request(1,1, KDeviceNumWrittenBytesPreHalt);// EP1 because 1st writter EP sl@0: iControlEp0->SendRequest(request,this); sl@0: iTransferComplete = 0; //reset sl@0: } sl@0: } sl@0: break; //switch(iCaseStep) sl@0: sl@0: case ETransferOut: sl@0: { sl@0: if(aCompletionCode != KErrNone) sl@0: { sl@0: iOutTransfer[0]->Cancel(); sl@0: iOutTransfer[1]->Cancel(); sl@0: err = KErrCorrupt; sl@0: msg.Format(_L(" No data sent on bulk OUT request"),aCompletionCode); sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: switch(aTransferId) sl@0: { sl@0: case KBulkTransferOutId0: sl@0: case KBulkTransferOutId1: sl@0: iTransferComplete |= aTransferId; sl@0: RDebug::Printf("Transfer %d completed", aTransferId); 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, KBulkTransferOutId0, KBulkTransferOutId1, aTransferId); sl@0: break; //switch(aTransferId) sl@0: } sl@0: sl@0: if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1)) sl@0: { sl@0: RDebug::Printf("Try to receive back sent data. Transfers Completed %d", iTransferComplete); sl@0: iCaseStep = ETransferIn; sl@0: TWriteSynchronousCachedReadDataRequest request(1,1,1); sl@0: iControlEp0->SendRequest(request,this); sl@0: iTransferComplete = 0; //reset sl@0: } sl@0: break; //switch(iCaseStep) sl@0: sl@0: case ETransferIn: sl@0: if(aCompletionCode != KErrNone) sl@0: { sl@0: err = KErrCorrupt; sl@0: msg.Format(_L(" No data sent on bulk IN request"),aCompletionCode); sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: if(aTransferId != KBulkTransferInId0) sl@0: { sl@0: iTransferComplete = 0; //reset sl@0: err = KUnexpectedTransferID; sl@0: msg.Format(_L(" Unexpected transfer ID, wanted %d , got %d"), sl@0: err, KBulkTransferInId0, aTransferId); sl@0: break; //switch(iCaseStep) sl@0: } sl@0: sl@0: // else ok, compare data rcvd now sl@0: TPtrC8 data1(iInTransfer[0]->DataPolled()); sl@0: if(ValidateData(data1, KLiteralEnglish8().Mid(0, KDeviceNumReadBytesPostHalt)) == EFalse) sl@0: { sl@0: err = KErrCompletion; //indicates data validation failure sl@0: msg.Format(_L(" Bulk transfer IN data received does not match Bulk Transfer OUT data"), err); 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: iTransferComplete = 0; //reset 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!=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_0499::DeviceInsertedL(TUint aDeviceHandle) sl@0: { sl@0: LOG_FUNC sl@0: sl@0: Cancel(); sl@0: sl@0: if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError) sl@0: // Prepare for response from control transfer to client sl@0: { sl@0: iCaseStep = EFailed; sl@0: } sl@0: sl@0: // Create the bulk transfers sl@0: iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxINTransferSize,*this,KBulkTransferInId0); sl@0: iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxOUTTransferSize,*this,KBulkTransferOutId0); sl@0: iOutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxOUTTransferSize,*this,KBulkTransferOutId1); sl@0: sl@0: // Initialise the descriptors for transfer sl@0: RDebug::Printf("Initialising the transfer descriptors"); sl@0: TInt err = iUsbInterface1.InitialiseTransferDescriptors(); sl@0: if(err != KErrNone) sl@0: { sl@0: TBuf<256> msg; sl@0: msg.Format(_L(" Unable to initialise transfer descriptors"),err); sl@0: RDebug::Print(msg); sl@0: iCaseStep = EFailed; sl@0: TTestCaseFailed request(err,msg); sl@0: iControlEp0->SendRequest(request,this); sl@0: return; sl@0: } sl@0: sl@0: iCaseStep = ETransferOutHalt; sl@0: TEndpointReadAndHaltRequest request(1,1,KDeviceNumReadBytesPreHalt);// EP1 means endpoint index 1 not the actual endpoint number sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: sl@0: } //end namespace