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-0495.cpp sl@0: // @internalComponent sl@0: // sl@0: // sl@0: sl@0: #include "PBASE-T_USBDI-0495.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 TUint KTotalBytesToTransfer = 2*1024*1024+511; //2MB + 511 bytes sl@0: const TUint KHostNumWriteBytes = 1024*256; sl@0: const TInt KBulkMaxTransferSize = KHostNumWriteBytes + 1000; sl@0: const TInt KDeviceNumReadBytes = 1024; 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 KBulkTransferOutId[KMaxNumOutTransfers] = {1<<0, 1<<1}; sl@0: const TUint32 KBulkTransferIdMask = KBulkTransferOutId[0] | KBulkTransferOutId[1]; sl@0: sl@0: const TInt KUndefinedStep = -102; sl@0: const TInt KUnexpectedTransferID = -103; sl@0: sl@0: sl@0: sl@0: _LIT(KTestCaseId,"PBASE-T_USBDI-0495"); sl@0: const TFunctorTestCase CUT_PBASE_T_USBDI_0495::iFunctor(KTestCaseId); sl@0: sl@0: CUT_PBASE_T_USBDI_0495* CUT_PBASE_T_USBDI_0495::NewL(TBool aHostRole) sl@0: { sl@0: CUT_PBASE_T_USBDI_0495* self = new (ELeave) CUT_PBASE_T_USBDI_0495(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_0495::CUT_PBASE_T_USBDI_0495(TBool aHostRole) sl@0: : CBaseBulkTestCase(KTestCaseId,aHostRole), sl@0: iCaseStep(EInProgress), sl@0: iRequestValidationResultPtr(NULL,0) sl@0: { sl@0: } sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0495::ConstructL() sl@0: { sl@0: BaseBulkConstructL(); sl@0: sl@0: iInBuffer = HBufC8::NewL(KTestBufferLength); sl@0: sl@0: //Create buffer to contain sufficient repeats of the payload pattern sl@0: //..so that we may grab cyclic chunks of said payload pattern for OUT transfers sl@0: TInt repeats = KHostNumWriteBytes / (KLiteralEnglish5().Length()) + 1 + 1; //1 extra to accommodate start point plus 1 to accomodate remainder in division sl@0: iOutBuffer = HBufC8::NewL(KLiteralEnglish5().Length() * repeats); sl@0: iOutBufferPtr.Set(iOutBuffer->Des()); sl@0: iOutBufferPtr.Zero(); sl@0: for(TInt i=0;iCancel(); sl@0: iOutTransfer[1]->Cancel(); sl@0: } sl@0: sl@0: sl@0: sl@0: void CUT_PBASE_T_USBDI_0495::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: KillTransfers(); sl@0: _LIT(lit, " Transfer to control endpoint 0 was not successful"); sl@0: msg.Format(lit,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 ERequestRepeatedReadAndValidate: sl@0: { sl@0: RDebug::Printf("Try to perform ALL transfers"); sl@0: sl@0: iCaseStep = ETransfer; sl@0: sl@0: iTransferComplete |= PerformNextTransfer(KBulkTransferOutId[0]); //should not validate - just perform necessary transfers sl@0: iTransferComplete |= PerformNextTransfer(KBulkTransferOutId[1]); //should not validate - just perform necessary transfers sl@0: if((iTransferComplete & KBulkTransferIdMask) == KBulkTransferIdMask) sl@0: { sl@0: _LIT(lit, "TEST FAILURE: No data to send!!"); sl@0: TBuf<40> msg(lit); sl@0: RDebug::Print(msg); sl@0: iCaseStep = EFailed; sl@0: TTestCaseFailed request(KErrAbort,msg); sl@0: return iControlEp0->SendRequest(request,this); sl@0: } sl@0: } sl@0: break; sl@0: sl@0: case ERequestPrepareEndpointValidationResult: sl@0: { sl@0: RDebug::Printf("Asking client to prepare the result of its continuous validation"); sl@0: iCaseStep = ERequestValidationResult; sl@0: iRequestValidationResultPtr.Set( iInBuffer->Des()); sl@0: iRequestValidationResultPtr.Zero(); //reset sl@0: iRequestValidationResultPtr.SetLength(KPassFailStringLength); sl@0: TInterfaceGetPayloadRequest request(1,iRequestValidationResultPtr); sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: break; sl@0: sl@0: case ERequestValidationResult: sl@0: { sl@0: RDebug::Printf("Collect client's return validation result in a pass or fail string ..."); sl@0: RDebug::RawPrint(*iInBuffer); sl@0: RDebug::Printf("\n"); sl@0: TPtr8 ptr(iInBuffer->Des()); sl@0: if(ptr.Compare(KClientPassString) == 0) sl@0: { sl@0: RDebug::Printf("Client Validation Result is a PASS"); sl@0: RDebug::Printf("This is the FINAL check - the whole test has a PASSED"); sl@0: iCaseStep = EPassed; sl@0: TTestCasePassed request; sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: else sl@0: { sl@0: TBuf<256> msg; sl@0: _LIT(lit, " Bulk data VALIDATION check was NOT successful"); sl@0: msg.Format(lit); sl@0: RDebug::Print(msg); sl@0: iCaseStep = EFailed; sl@0: TTestCaseFailed request(KErrCorrupt,msg); sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: } 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_0495::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: sl@0: switch(iCaseStep) sl@0: { sl@0: case ETransfer: sl@0: { sl@0: if(aCompletionCode != KErrNone) sl@0: { sl@0: KillTransfers(); sl@0: err = KErrCorrupt; sl@0: _LIT(lit, " The transfer completed with an error."); sl@0: msg.Format(lit, aCompletionCode); sl@0: break; sl@0: } sl@0: sl@0: if(aTransferId != KBulkTransferOutId[0] && aTransferId != KBulkTransferOutId[1]) sl@0: { sl@0: iTransferComplete = 0; //reset sl@0: err = KUnexpectedTransferID; sl@0: _LIT(lit, " Unexpected transfer ID, wanted %d or %d, got %d"); sl@0: msg.Format(lit, err, KBulkTransferOutId[0], KBulkTransferOutId[1], aTransferId); sl@0: break; sl@0: } sl@0: sl@0: RDebug::Printf("Transfer OUT %d completed - num bytes sent = %d", aTransferId, iNumWriteBytesRequested); sl@0: sl@0: iTransferComplete |= PerformNextTransfer(aTransferId); sl@0: sl@0: if(err==KErrNone && (iTransferComplete & KBulkTransferIdMask) == KBulkTransferIdMask) sl@0: { sl@0: /* sl@0: Transfers all complete - now ask device to validate first interface's transfer OUT sl@0: */ sl@0: RDebug::Printf("All Transfers Completed Successfully: Transfer Completion Aggregation Mask 0x%x", iTransferComplete); sl@0: if(err==KErrNone) sl@0: { sl@0: RDebug::Printf("Asking client to post validation recorded on the endpoint on its interface - ready for collection"); sl@0: iCaseStep = ERequestPrepareEndpointValidationResult; sl@0: TRecordedValidationResultRequest request(1,1); sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: } sl@0: } sl@0: break; sl@0: default: sl@0: err = KUndefinedStep; sl@0: _LIT(lit, " Undefined case step %d reached"); sl@0: msg.Format(lit,KUndefinedStep, iCaseStep); sl@0: break; sl@0: } sl@0: sl@0: sl@0: if(err == KErrCompletion) sl@0: //indicates data validation failure sl@0: { sl@0: _LIT(lit, " Client has posted an error discovered in validation"); sl@0: msg.Format(lit, err); sl@0: } sl@0: sl@0: if(err!=KErrNone) sl@0: { sl@0: KillTransfers(); 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_0495::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: _LIT(lit, "Base class DeviceInsertedL failed"); sl@0: msg.Format(lit); 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: _LIT(lit, "Base class SetUpInterfaceAndPipes for Interface 2 failed"); sl@0: msg.Format(lit); sl@0: } sl@0: else sl@0: { sl@0: sl@0: iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxTransferSize,*this,KBulkTransferOutId[0]); sl@0: iOutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxTransferSize,*this,KBulkTransferOutId[1]); 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: _LIT(lit, " Unable to initialise transfer descriptors"); sl@0: msg.Format(lit,err); 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 continuous 'Read' and 'Validate'"); sl@0: iCaseStep = ERequestRepeatedReadAndValidate; sl@0: TRepeatedReadAndValidateDataRequest request(1,1,KLiteralEnglish5,KDeviceNumReadBytes,KTotalBytesToTransfer);// EP2 means endpoint index 2 not the actual endpoint number, here the ep with 32 byte max packet size sl@0: iControlEp0->SendRequest(request,this); sl@0: } sl@0: } sl@0: sl@0: TInt CUT_PBASE_T_USBDI_0495::PerformNextTransfer(TInt aTransferId) sl@0: /** sl@0: @param aTransferId - specifies trasnfer to use sl@0: @return zero UNLESS no more trasnfers have been queued for the specified ID in which case return the transfer ID sl@0: Note: This return value allows the caller to respond easily if no more transfers are required for the specified sl@0: transfer ID. sl@0: */ sl@0: { sl@0: LOG_FUNC sl@0: sl@0: if(iNumWriteBytesRequested >= KTotalBytesToTransfer) sl@0: { sl@0: RDebug::Printf("****ALL DONE for Transfer using ID %d****", aTransferId); sl@0: RDebug::Printf("Num bytes actually written = %d, num bytes required to be written = %d", iNumWriteBytesRequested, KTotalBytesToTransfer); sl@0: return aTransferId; //Not writing any more - signal to user that no more transfers are required on this transfer ID sl@0: } sl@0: TUint bytesToWrite = KTotalBytesToTransfer - iNumWriteBytesRequested; sl@0: TUint numWriteBytes = bytesToWrite < KHostNumWriteBytes ? bytesToWrite : KHostNumWriteBytes; sl@0: sl@0: _LITDBG("PerformNextTransfer: None existant transfer ID requested"); sl@0: __ASSERT_DEBUG(aTransferId==KBulkTransferOutId[0] || aTransferId==KBulkTransferOutId[1], User::Panic(lit, KErrArgument)); sl@0: CBulkTransfer& bulkTransfer = aTransferId==KBulkTransferOutId[0]?*iOutTransfer[0]:*iOutTransfer[1]; sl@0: bulkTransfer.TransferOut(iOutBufferPtr.Mid(iNumWriteBytesRequested%(KLiteralEnglish5().Length()), numWriteBytes), EFalse); sl@0: iNumWriteBytesRequested += numWriteBytes; sl@0: sl@0: return 0; //Signal to the user that another transfer is queued on the specified transfer ID sl@0: } sl@0: sl@0: sl@0: } //end namespace