Update contrib.
1 // Copyright (c) 2008-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // @file PBASE-T_USBDI-0495.cpp
19 #include "PBASE-T_USBDI-0495.h"
20 #include "testpolicy.h"
21 #include "modelleddevices.h"
22 #include "testliterals.h"
27 namespace NUnitTesting_USBDI
29 const TUint KTotalBytesToTransfer = 2*1024*1024+511; //2MB + 511 bytes
30 const TUint KHostNumWriteBytes = 1024*256;
31 const TInt KBulkMaxTransferSize = KHostNumWriteBytes + 1000;
32 const TInt KDeviceNumReadBytes = 1024;
35 //Make these single bit values ...
36 // ... so that their completion can be easily recorded in a bit mask!
37 const TUint32 KBulkTransferOutId[KMaxNumOutTransfers] = {1<<0, 1<<1};
38 const TUint32 KBulkTransferIdMask = KBulkTransferOutId[0] | KBulkTransferOutId[1];
40 const TInt KUndefinedStep = -102;
41 const TInt KUnexpectedTransferID = -103;
45 _LIT(KTestCaseId,"PBASE-T_USBDI-0495");
46 const TFunctorTestCase<CUT_PBASE_T_USBDI_0495,TBool> CUT_PBASE_T_USBDI_0495::iFunctor(KTestCaseId);
48 CUT_PBASE_T_USBDI_0495* CUT_PBASE_T_USBDI_0495::NewL(TBool aHostRole)
50 CUT_PBASE_T_USBDI_0495* self = new (ELeave) CUT_PBASE_T_USBDI_0495(aHostRole);
51 CleanupStack::PushL(self);
53 CleanupStack::Pop(self);
58 CUT_PBASE_T_USBDI_0495::CUT_PBASE_T_USBDI_0495(TBool aHostRole)
59 : CBaseBulkTestCase(KTestCaseId,aHostRole),
60 iCaseStep(EInProgress),
61 iRequestValidationResultPtr(NULL,0)
66 void CUT_PBASE_T_USBDI_0495::ConstructL()
70 iInBuffer = HBufC8::NewL(KTestBufferLength);
72 //Create buffer to contain sufficient repeats of the payload pattern
73 //..so that we may grab cyclic chunks of said payload pattern for OUT transfers
74 TInt repeats = KHostNumWriteBytes / (KLiteralEnglish5().Length()) + 1 + 1; //1 extra to accommodate start point plus 1 to accomodate remainder in division
75 iOutBuffer = HBufC8::NewL(KLiteralEnglish5().Length() * repeats);
76 iOutBufferPtr.Set(iOutBuffer->Des());
78 for(TInt i=0;i<repeats;i++)
80 iOutBufferPtr.Append(KLiteralEnglish5());
83 RDebug::Printf("CUT_PBASE_T_USBDI_0495::ConstructL(): buffer created");
87 CUT_PBASE_T_USBDI_0495::~CUT_PBASE_T_USBDI_0495()
92 void CUT_PBASE_T_USBDI_0495::KillTransfers()
96 iOutTransfer[0]->Cancel();
97 iOutTransfer[1]->Cancel();
102 void CUT_PBASE_T_USBDI_0495::Ep0TransferCompleteL(TInt aCompletionCode)
106 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d", aCompletionCode);
108 if(aCompletionCode != KErrNone)
110 if(iCaseStep == EFailed)
111 {// ignore error, nad catch the TestFailed method called further down.
112 RDebug::Printf("***Failure sending FAIL message to client on endpoint 0***");
118 _LIT(lit, "<Error %d> Transfer to control endpoint 0 was not successful");
119 msg.Format(lit,aCompletionCode);
122 TTestCaseFailed request(aCompletionCode,msg);
123 iControlEp0->SendRequest(request,this);
137 TestFailed(KErrCompletion);
140 case ERequestRepeatedReadAndValidate:
142 RDebug::Printf("Try to perform ALL transfers");
144 iCaseStep = ETransfer;
146 iTransferComplete |= PerformNextTransfer(KBulkTransferOutId[0]); //should not validate - just perform necessary transfers
147 iTransferComplete |= PerformNextTransfer(KBulkTransferOutId[1]); //should not validate - just perform necessary transfers
148 if((iTransferComplete & KBulkTransferIdMask) == KBulkTransferIdMask)
150 _LIT(lit, "TEST FAILURE: No data to send!!");
154 TTestCaseFailed request(KErrAbort,msg);
155 return iControlEp0->SendRequest(request,this);
160 case ERequestPrepareEndpointValidationResult:
162 RDebug::Printf("Asking client to prepare the result of its continuous validation");
163 iCaseStep = ERequestValidationResult;
164 iRequestValidationResultPtr.Set( iInBuffer->Des());
165 iRequestValidationResultPtr.Zero(); //reset
166 iRequestValidationResultPtr.SetLength(KPassFailStringLength);
167 TInterfaceGetPayloadRequest request(1,iRequestValidationResultPtr);
168 iControlEp0->SendRequest(request,this);
172 case ERequestValidationResult:
174 RDebug::Printf("Collect client's return validation result in a pass or fail string ...");
175 RDebug::RawPrint(*iInBuffer);
176 RDebug::Printf("\n");
177 TPtr8 ptr(iInBuffer->Des());
178 if(ptr.Compare(KClientPassString) == 0)
180 RDebug::Printf("Client Validation Result is a PASS");
181 RDebug::Printf("This is the FINAL check - the whole test has a PASSED");
183 TTestCasePassed request;
184 iControlEp0->SendRequest(request,this);
189 _LIT(lit, "<Error> Bulk data VALIDATION check was NOT successful");
193 TTestCaseFailed request(KErrCorrupt,msg);
194 iControlEp0->SendRequest(request,this);
200 RDebug::Printf("<Error> Unknown test step");
201 TestFailed(KErrUnknown);
206 void CUT_PBASE_T_USBDI_0495::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
213 RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d, test step = %d",aTransferId, aCompletionCode, iCaseStep);
220 if(aCompletionCode != KErrNone)
224 _LIT(lit, "<Error %d> The transfer completed with an error.");
225 msg.Format(lit, aCompletionCode);
229 if(aTransferId != KBulkTransferOutId[0] && aTransferId != KBulkTransferOutId[1])
231 iTransferComplete = 0; //reset
232 err = KUnexpectedTransferID;
233 _LIT(lit, "<Error %d> Unexpected transfer ID, wanted %d or %d, got %d");
234 msg.Format(lit, err, KBulkTransferOutId[0], KBulkTransferOutId[1], aTransferId);
238 RDebug::Printf("Transfer OUT %d completed - num bytes sent = %d", aTransferId, iNumWriteBytesRequested);
240 iTransferComplete |= PerformNextTransfer(aTransferId);
242 if(err==KErrNone && (iTransferComplete & KBulkTransferIdMask) == KBulkTransferIdMask)
245 Transfers all complete - now ask device to validate first interface's transfer OUT
247 RDebug::Printf("All Transfers Completed Successfully: Transfer Completion Aggregation Mask 0x%x", iTransferComplete);
250 RDebug::Printf("Asking client to post validation recorded on the endpoint on its interface - ready for collection");
251 iCaseStep = ERequestPrepareEndpointValidationResult;
252 TRecordedValidationResultRequest request(1,1);
253 iControlEp0->SendRequest(request,this);
259 err = KUndefinedStep;
260 _LIT(lit, "<Error %d> Undefined case step %d reached");
261 msg.Format(lit,KUndefinedStep, iCaseStep);
266 if(err == KErrCompletion)
267 //indicates data validation failure
269 _LIT(lit, "<Error %d> Client has posted an error discovered in validation");
270 msg.Format(lit, err);
278 TTestCaseFailed request(err,msg);
279 return iControlEp0->SendRequest(request,this);
283 void CUT_PBASE_T_USBDI_0495::DeviceInsertedL(TUint aDeviceHandle)
288 RDebug::Printf("this - %08x", this);
292 if(BaseBulkDeviceInsertedL(aDeviceHandle, EFalse) == EDeviceConfigurationError)
293 // Prepare for response from control transfer to client
296 _LIT(lit, "Base class DeviceInsertedL failed");
301 if(SetUpInterfaceAndPipesL(aDeviceHandle, 2) == EDeviceConfigurationError)
302 // Prepare for response from control transfer to client
305 _LIT(lit, "Base class SetUpInterfaceAndPipes for Interface 2 failed");
311 iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxTransferSize,*this,KBulkTransferOutId[0]);
312 iOutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxTransferSize,*this,KBulkTransferOutId[1]);
314 // Initialise the descriptors for transfer
315 RDebug::Printf("Initialising the transfer descriptors - interface 1");
316 err = iUsbInterface1.InitialiseTransferDescriptors();
319 _LIT(lit, "<Error %d> Unable to initialise transfer descriptors");
328 TTestCaseFailed request(err,msg);
329 iControlEp0->SendRequest(request,this);
333 RDebug::Printf("Asking client for continuous 'Read' and 'Validate'");
334 iCaseStep = ERequestRepeatedReadAndValidate;
335 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
336 iControlEp0->SendRequest(request,this);
340 TInt CUT_PBASE_T_USBDI_0495::PerformNextTransfer(TInt aTransferId)
342 @param aTransferId - specifies trasnfer to use
343 @return zero UNLESS no more trasnfers have been queued for the specified ID in which case return the transfer ID
344 Note: This return value allows the caller to respond easily if no more transfers are required for the specified
350 if(iNumWriteBytesRequested >= KTotalBytesToTransfer)
352 RDebug::Printf("****ALL DONE for Transfer using ID %d****", aTransferId);
353 RDebug::Printf("Num bytes actually written = %d, num bytes required to be written = %d", iNumWriteBytesRequested, KTotalBytesToTransfer);
354 return aTransferId; //Not writing any more - signal to user that no more transfers are required on this transfer ID
356 TUint bytesToWrite = KTotalBytesToTransfer - iNumWriteBytesRequested;
357 TUint numWriteBytes = bytesToWrite < KHostNumWriteBytes ? bytesToWrite : KHostNumWriteBytes;
359 _LITDBG("PerformNextTransfer: None existant transfer ID requested");
360 __ASSERT_DEBUG(aTransferId==KBulkTransferOutId[0] || aTransferId==KBulkTransferOutId[1], User::Panic(lit, KErrArgument));
361 CBulkTransfer& bulkTransfer = aTransferId==KBulkTransferOutId[0]?*iOutTransfer[0]:*iOutTransfer[1];
362 bulkTransfer.TransferOut(iOutBufferPtr.Mid(iNumWriteBytesRequested%(KLiteralEnglish5().Length()), numWriteBytes), EFalse);
363 iNumWriteBytesRequested += numWriteBytes;
365 return 0; //Signal to the user that another transfer is queued on the specified transfer ID