First public contribution.
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-0498.cpp
19 #include "PBASE-T_USBDI-0498.h"
20 #include "testpolicy.h"
21 #include "modelleddevices.h"
22 #include "testliterals.h"
27 namespace NUnitTesting_USBDI
29 const TInt KBulkMaxTransferSize = 40000;
30 const TUint KHostNumWriteBytes1 = 32000;
31 const TUint KHostNumWriteBytes2 = 32000;
32 const TInt KDeviceNumReadBytes = 64000;
33 const TInt KDeviceNumWriteBytes = 64000;
34 const TUint KHostNumReadBytes1 = 32000;
35 const TUint KHostNumReadBytes2 = 32001; //allow or ZLP
38 //Make these single bit values ...
39 // ... so that their completion can be easily recorded in a bit mask!
40 const TUint32 KIfc1BulkTransferInId1 = 1<<0;
41 const TUint32 KIfc1BulkTransferInId2 = 1<<1;
42 const TUint32 KIfc2BulkTransferInId1 = 1<<2;
43 const TUint32 KIfc2BulkTransferInId2 = 1<<3;
44 const TUint32 KIfc1BulkTransferInIdMask = KIfc1BulkTransferInId1 | KIfc1BulkTransferInId2;
45 const TUint32 KIfc2BulkTransferInIdMask = KIfc2BulkTransferInId1 | KIfc2BulkTransferInId2;
46 const TUint32 KBulkTransferInIdMask = KIfc1BulkTransferInIdMask | KIfc2BulkTransferInIdMask;
47 const TUint32 KIfc1BulkTransferOutId1 = 1<<4;
48 const TUint32 KIfc1BulkTransferOutId2 = 1<<5;
49 const TUint32 KIfc2BulkTransferOutId1 = 1<<6;
50 const TUint32 KIfc2BulkTransferOutId2 = 1<<7;
51 const TUint32 KIfc1BulkTransferOutIdMask = KIfc1BulkTransferOutId1 | KIfc1BulkTransferOutId2;
52 const TUint32 KIfc2BulkTransferOutIdMask = KIfc2BulkTransferOutId1 | KIfc2BulkTransferOutId2;
53 const TUint32 KBulkTransferOutIdMask = KIfc1BulkTransferOutIdMask | KIfc2BulkTransferOutIdMask;
54 const TUint32 KBulkTransferIdMask = KBulkTransferInIdMask | KBulkTransferOutIdMask;
56 const TInt KUnexpectedTransferID = -101;
57 const TInt KUndefinedStep = -102;
59 const TInt KMaxTimeDiffPercentage = 25;
63 _LIT(KTestCaseId,"PBASE-T_USBDI-0498");
64 const TFunctorTestCase<CUT_PBASE_T_USBDI_0498,TBool> CUT_PBASE_T_USBDI_0498::iFunctor(KTestCaseId);
66 CUT_PBASE_T_USBDI_0498* CUT_PBASE_T_USBDI_0498::NewL(TBool aHostRole)
68 CUT_PBASE_T_USBDI_0498* self = new (ELeave) CUT_PBASE_T_USBDI_0498(aHostRole);
69 CleanupStack::PushL(self);
71 CleanupStack::Pop(self);
76 CUT_PBASE_T_USBDI_0498::CUT_PBASE_T_USBDI_0498(TBool aHostRole)
77 : CBaseBulkTestCase(KTestCaseId,aHostRole),
78 iCaseStep(EInProgress),
79 iRequestDeviceValidationResultPtr(NULL,0)
84 void CUT_PBASE_T_USBDI_0498::ConstructL()
88 iInBuffer = HBufC8::NewL(KTestBufferLength);
89 RDebug::Printf("CUT_PBASE_T_USBDI_0491::ConstructL(): buffer created");
93 CUT_PBASE_T_USBDI_0498::~CUT_PBASE_T_USBDI_0498()
95 The transfer objects have test specific names - so perform transfer specific clean up here.
102 //Do this before deleting the transfer objects
103 CloseInterfaceAndPipes();
106 for(count=0;count<KNumOutTransfersPerInterface;count++)
108 delete iIfc1OutTransfer[count];
109 iIfc1OutTransfer[count] = NULL;
110 delete iIfc2OutTransfer[count];
111 iIfc2OutTransfer[count] = NULL;
113 for(count=0;count<KNumInTransfersPerInterface;count++)
115 delete iIfc1InTransfer[count];
116 iIfc1InTransfer[count] = NULL;
117 delete iIfc2InTransfer[count];
118 iIfc2InTransfer[count] = NULL;
123 void CUT_PBASE_T_USBDI_0498::Ep0TransferCompleteL(TInt aCompletionCode)
127 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
129 if(aCompletionCode != KErrNone)
131 if(iCaseStep == EFailed)
132 {// ignore error, nad catch the TestFailed method called further down.
133 RDebug::Printf("***Failure sending FAIL message to client on endpoint 0***");
138 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
141 TTestCaseFailed request(aCompletionCode,msg);
142 iControlEp0->SendRequest(request,this);
156 TestFailed(KErrCompletion);
159 case ERequestDeviceIFC1Read:
161 RDebug::Printf("Asking client for 'Read' on interface 2");
162 iCaseStep = ERequestDeviceIFC2Read;
163 TEndpointReadRequest request(2,1,KDeviceNumReadBytes);// EP1 means endpoint index 1 not the actual endpoint number
164 iControlEp0->SendRequest(request,this);
168 case ERequestDeviceIFC2Read:
170 RDebug::Printf("Asking client to 'Write' on interface 1");
171 iCaseStep = ERequestDeviceIFC1Write;
172 TEndpointPatternWriteRequest request(1,1,KLiteralFrench4(),KDeviceNumWriteBytes);
173 iControlEp0->SendRequest(request,this);
177 case ERequestDeviceIFC1Write:
179 RDebug::Printf("Asking client to 'Write' on interface 2");
180 iCaseStep = ERequestDeviceIFC2Write;
181 TEndpointPatternWriteRequest request(2,1,KLiteralEnglish2(),KDeviceNumWriteBytes);
182 iControlEp0->SendRequest(request,this);
186 case ERequestDeviceIFC2Write:
188 RDebug::Printf("Try to perform ALL transfers on BOTH interfaces");
190 iCaseStep = ETransfer;
192 iStartTime[0].HomeTime();
193 iStartTime[1].HomeTime();
194 iStartTime[2].HomeTime();
195 iStartTime[3].HomeTime();
197 iIfc1OutTransfer[0]->TransferOut(KLiteralFrench4(), KHostNumWriteBytes1, EFalse);
198 iIfc1OutTransfer[1]->TransferOut(KLiteralFrench4(), KHostNumWriteBytes1, KHostNumWriteBytes2, EFalse);
199 iIfc2OutTransfer[0]->TransferOut(KLiteralEnglish2(), KHostNumWriteBytes1, EFalse);
200 iIfc2OutTransfer[1]->TransferOut(KLiteralEnglish2(), KHostNumWriteBytes1, KHostNumWriteBytes2, EFalse);
202 iIfc1InTransfer[0]->TransferIn(KHostNumReadBytes1);
203 iIfc1InTransfer[1]->TransferIn(KHostNumReadBytes2);
204 iIfc2InTransfer[0]->TransferIn(KHostNumReadBytes1);
205 iIfc2InTransfer[1]->TransferIn(KHostNumReadBytes2);
209 case ERequestDeviceValidateIFC1:
211 iCaseStep = ERequestDeviceValidationResultIFC1;
212 RDebug::Printf("Interface 1: Request Client Validation Result");
213 iRequestDeviceValidationResultPtr.Set(iInBuffer->Des());
214 iRequestDeviceValidationResultPtr.Zero(); //reset
215 iRequestDeviceValidationResultPtr.SetLength(KPassFailStringLength);
216 TInterfaceGetPayloadRequest request(1,iRequestDeviceValidationResultPtr);
217 iControlEp0->SendRequest(request,this);
221 case ERequestDeviceValidationResultIFC1:
223 RDebug::Printf("Interface 1: Client Validation Result string ...");
224 RDebug::RawPrint(*iInBuffer);
225 RDebug::Printf("\n");
226 TPtr8 ptr(iInBuffer->Des());
227 if(ptr.Compare(KClientPassString) == 0)
229 RDebug::Printf("Client Validation Interface 1 Result is a PASS");
230 RDebug::Printf("Now performing Client Validation for Interface 2");
231 iCaseStep = ERequestDeviceValidateIFC2;
232 TEndpointStringValidationRequest request(2,1,KLiteralEnglish2(),KDeviceNumReadBytes);
233 iControlEp0->SendRequest(request,this);
238 msg.Format(_L("<Error> Bulk data VALIDATION check was NOT successful"));
241 TTestCaseFailed request(KErrCorrupt,msg);
242 iControlEp0->SendRequest(request,this);
247 case ERequestDeviceValidateIFC2:
249 iCaseStep = ERequestDeviceValidationResultIFC2;
250 RDebug::Printf("Interface 2: Request Client Validation Result");
251 iRequestDeviceValidationResultPtr.Set(iInBuffer->Des());
252 iRequestDeviceValidationResultPtr.Zero(); //reset
253 iRequestDeviceValidationResultPtr.SetLength(KPassFailStringLength);
254 TInterfaceGetPayloadRequest request(2,iRequestDeviceValidationResultPtr);
255 iControlEp0->SendRequest(request,this);
259 case ERequestDeviceValidationResultIFC2:
261 RDebug::Printf("Interface 1: Client Validation Result string ...");
262 RDebug::RawPrint(*iInBuffer);
263 RDebug::Printf("\n");
264 TPtr8 ptr(iInBuffer->Des());
265 if(ptr.Compare(KClientPassString) == 0)
267 RDebug::Printf("Client Validation Interface 2 Result is a PASS");
268 RDebug::Printf("This is the FINAL check - the whole test has a PASSED");
270 TTestCasePassed request;
271 iControlEp0->SendRequest(request,this);
276 msg.Format(_L("<Error> Bulk data VALIDATION check was NOT successful"));
279 TTestCaseFailed request(KErrCorrupt,msg);
280 iControlEp0->SendRequest(request,this);
286 RDebug::Printf("<Error> Unknown test step");
287 TestFailed(KErrUnknown);
292 void CUT_PBASE_T_USBDI_0498::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
299 RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d, test step = %d",aTransferId, aCompletionCode, iCaseStep);
305 if(aCompletionCode != KErrNone)
307 iIfc1OutTransfer[0]->Cancel();
308 iIfc1OutTransfer[1]->Cancel();
309 iIfc2OutTransfer[0]->Cancel();
310 iIfc2OutTransfer[1]->Cancel();
311 iIfc1InTransfer[0]->Cancel();
312 iIfc1InTransfer[1]->Cancel();
313 iIfc2InTransfer[0]->Cancel();
314 iIfc2InTransfer[1]->Cancel();
316 msg.Format(_L("<Error %d> The transfer completed with an error."), aCompletionCode);
317 break; //switch(iCaseStep)
322 case KIfc1BulkTransferOutId1:
323 case KIfc1BulkTransferOutId2:
324 case KIfc2BulkTransferOutId1:
325 case KIfc2BulkTransferOutId2:
326 iTransferComplete |= aTransferId;
327 RDebug::Printf("Transfer OUT %d completed (Transfer Completion Aggregation Mask 0x%x)", aTransferId, iTransferComplete);
328 break; //switch(aTransferId)
330 case KIfc1BulkTransferInId1:
331 case KIfc1BulkTransferInId2:
332 case KIfc2BulkTransferInId1:
333 case KIfc2BulkTransferInId2:
334 iTransferComplete |= aTransferId;
335 RDebug::Printf("Transfer OUT %d completed (Transfer Completion Aggregation Mask 0x%x)", aTransferId, iTransferComplete);
336 break; //switch(aTransferId)
339 iTransferComplete = 0; //reset
340 err = KUnexpectedTransferID;
341 msg.Format(_L("<Error %d> Unexpected transfer ID, GOT %d, (wanted one of:- %d, %d, %d, %d, %d, %d, %d, or%d)"),
343 KIfc1BulkTransferInId1,
344 KIfc1BulkTransferInId2,
345 KIfc2BulkTransferInId1,
346 KIfc2BulkTransferInId2,
347 KIfc1BulkTransferOutId1,
348 KIfc1BulkTransferOutId2,
349 KIfc2BulkTransferOutId1,
350 KIfc2BulkTransferOutId2
352 break; //switch(aTransferId)
355 // Transfer Out Response
356 if(err==KErrNone && iTimeElapsed[0] == 0 && (iTransferComplete & KIfc1BulkTransferOutIdMask) == KIfc1BulkTransferOutIdMask)
357 //Record time elapsed for Interface 1 if not yet recorded.
361 if(err==KErrNone && iTimeElapsed[1] == 0 && (iTransferComplete & KIfc2BulkTransferOutIdMask) == KIfc2BulkTransferOutIdMask)
362 //Record time elapsed for Interface 2 if not yet recorded.
366 if(err==KErrNone && (iTransferComplete & KBulkTransferOutIdMask) == KBulkTransferOutIdMask)
368 RDebug::Printf("All OUT Transfers Completed Successfully: Transfer Completion Aggregation Mask 0x%x", iTransferComplete);
369 //Leave validation to the point at which all transfers have completed.
372 // Transfer In Response
373 if(err==KErrNone && iTimeElapsed[2] == 0 && (iTransferComplete & KIfc1BulkTransferInIdMask) == KIfc1BulkTransferInIdMask)
374 //Record time elapsed for Interface 1 if not yet recorded.
378 if(err==KErrNone && iTimeElapsed[3] == 0 && (iTransferComplete & KIfc2BulkTransferInIdMask) == KIfc2BulkTransferInIdMask)
379 //Record time elapsed for Interface 2 if not yet recorded.
383 if(err==KErrNone && (iTransferComplete & KBulkTransferInIdMask) == KBulkTransferInIdMask)
385 // ok, compare data rcvd now
386 RDebug::Printf("All IN Transfers Completed Successfully: Transfer Completion Aggregation Mask 0x%x", iTransferComplete);
388 TPtrC8 data1(iIfc1InTransfer[0]->DataPolled());
389 TPtrC8 data2(iIfc1InTransfer[1]->DataPolled());
390 TPtrC8 data3(iIfc2InTransfer[0]->DataPolled());
391 TPtrC8 data4(iIfc2InTransfer[1]->DataPolled());
392 //Validate first transfer on Interface 1 for number of bytes originally written.
393 if(ValidateData(data1, KLiteralFrench4(), KHostNumWriteBytes1) == EFalse)
395 RDebug::Printf("Validation failure 1st transfer, Interface 1");
396 err = KErrCompletion; //indicates data validation failure
397 break; //switch(iCaseStep)
400 //Validate second transfer on Interface 1 for number of bytes originally written.
401 if(ValidateData(data2, KLiteralFrench4(), KHostNumWriteBytes1, KHostNumWriteBytes2) == EFalse)
403 RDebug::Printf("Validation failure 2nd transfer, Interface 1");
404 err = KErrCompletion; //indicates data validation failure
405 break; //switch(iCaseStep)
408 //Validate first transfer on Interface 2 for number of bytes originally written.
409 if(ValidateData(data3, KLiteralEnglish2(), KHostNumWriteBytes1) == EFalse)
411 RDebug::Printf("Validation failure 1st transfer, Interface 2");
412 err = KErrCompletion; //indicates data validation failure
413 break; //switch(iCaseStep)
416 //Validate second transfer on Interface 2 for number of bytes originally written.
417 if(ValidateData(data4, KLiteralEnglish2(), KHostNumWriteBytes1, KHostNumWriteBytes2) == EFalse)
419 RDebug::Printf("Validation failure 2nd transfer, Interface 2");
420 err = KErrCompletion; //indicates data validation failure
421 break; //switch(iCaseStep)
424 // Comparison is a match
425 RDebug::Printf("Comparison for IN transfer is a match");
427 break; //switch(iCaseStep)
430 err = KUndefinedStep;
431 msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep);
432 break; //switch(iCaseStep)
435 if(err == KErrNone && iTransferComplete == KBulkTransferIdMask)
437 Transfers all complete - now ask device to validate first interface's transfer OUT
440 RDebug::Printf("Checking all times against each other");
441 err = CheckTimes(0, 1, KMaxTimeDiffPercentage);
442 err = err?err:CheckTimes(0, 2, KMaxTimeDiffPercentage);
443 err = err?err:CheckTimes(0, 3, KMaxTimeDiffPercentage);
444 err = err?err:CheckTimes(1, 2, KMaxTimeDiffPercentage);
445 err = err?err:CheckTimes(1, 3, KMaxTimeDiffPercentage);
446 err = err?err:CheckTimes(2, 3, KMaxTimeDiffPercentage);
454 RDebug::Printf("Asking client for 'Validate' data written on interface 1");
455 iCaseStep = ERequestDeviceValidateIFC1;
456 TEndpointStringValidationRequest request(1,1,KLiteralFrench4(),KDeviceNumReadBytes);
457 iControlEp0->SendRequest(request,this);
461 if(err == KErrCompletion)
462 //indicates data validation failure
464 msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
467 if(err == KErrTooBig)
468 //indicates timing validation failure
470 msg.Format(_L("<Error %d> Timer comparison showed too great a difference in transfer times between the two interfaces"), err);
477 TTestCaseFailed request(err,msg);
478 return iControlEp0->SendRequest(request,this);
482 void CUT_PBASE_T_USBDI_0498::DeviceInsertedL(TUint aDeviceHandle)
487 RDebug::Printf("this - %08x", this);
491 if(BaseBulkDeviceInsertedL(aDeviceHandle, EFalse) == EDeviceConfigurationError)
492 // Prepare for response from control transfer to client
495 msg.Format(_L("Base class DeviceInsertedL failed"));
499 if(SetUpInterfaceAndPipesL(aDeviceHandle, 2) == EDeviceConfigurationError)
500 // Prepare for response from control transfer to client
503 msg.Format(_L("Base class SetUpInterfaceAndPipes for Interface 2 failed"));
508 iIfc1InTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxTransferSize,*this,KIfc1BulkTransferInId1);
509 iIfc1InTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxTransferSize,*this,KIfc1BulkTransferInId2);
510 iIfc1OutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxTransferSize,*this,KIfc1BulkTransferOutId1);
511 iIfc1OutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxTransferSize,*this,KIfc1BulkTransferOutId2);
513 iIfc2InTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface2BulkIn,iUsbInterface2,KBulkMaxTransferSize,*this,KIfc2BulkTransferInId1);
514 iIfc2InTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface2BulkIn,iUsbInterface2,KBulkMaxTransferSize,*this,KIfc2BulkTransferInId2);
515 iIfc2OutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface2BulkOut1,iUsbInterface2,KBulkMaxTransferSize,*this,KIfc2BulkTransferOutId1);
516 iIfc2OutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface2BulkOut1,iUsbInterface2,KBulkMaxTransferSize,*this,KIfc2BulkTransferOutId2);
518 // Initialise the descriptors for transfer
519 RDebug::Printf("Initialising the transfer descriptors - interface 1");
520 err = iUsbInterface1.InitialiseTransferDescriptors();
523 msg.Format(_L("<Error %d> Unable to initialise transfer descriptors (Interface 1)"),err);
527 // Initialise the descriptors for transfer
528 RDebug::Printf("Initialising the transfer descriptors (Interface 2)");
529 err = iUsbInterface2.InitialiseTransferDescriptors();
532 msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
541 TTestCaseFailed request(err,msg);
542 iControlEp0->SendRequest(request,this);
546 RDebug::Printf("Asking client for 'Read' on interface 1");
547 iCaseStep = ERequestDeviceIFC1Read;
548 TEndpointReadRequest request(1,1,KDeviceNumReadBytes);// EP1 means endpoint index 1 not the actual endpoint number
549 iControlEp0->SendRequest(request,this);