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-0497.cpp
19 #include "PBASE-T_USBDI-0497.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 TUint KHostNumReadBytes1 = 32000;
34 const TUint KHostNumReadBytes2 = 32001; //allow or ZLP
37 //Make these single bit values ...
38 // ... so that their completion can be easily recorded in a bit mask!
39 const TUint32 KIfc1BulkTransferInId1 = 1<<0;
40 const TUint32 KIfc1BulkTransferInId2 = 1<<1;
41 const TUint32 KIfc2BulkTransferInId1 = 1<<2;
42 const TUint32 KIfc2BulkTransferInId2 = 1<<3;
43 const TUint32 KIfc1BulkTransferInIdMask = KIfc1BulkTransferInId1 | KIfc1BulkTransferInId2;
44 const TUint32 KIfc2BulkTransferInIdMask = KIfc2BulkTransferInId1 | KIfc2BulkTransferInId2;
45 const TUint32 KBulkTransferInIdMask = KIfc1BulkTransferInIdMask | KIfc2BulkTransferInIdMask;
46 const TUint32 KIfc1BulkTransferOutId1 = 1<<4;
47 const TUint32 KIfc1BulkTransferOutId2 = 1<<5;
48 const TUint32 KIfc2BulkTransferOutId1 = 1<<6;
49 const TUint32 KIfc2BulkTransferOutId2 = 1<<7;
50 const TUint32 KIfc1BulkTransferOutIdMask = KIfc1BulkTransferOutId1 | KIfc1BulkTransferOutId2;
51 const TUint32 KIfc2BulkTransferOutIdMask = KIfc2BulkTransferOutId1 | KIfc2BulkTransferOutId2;
52 const TUint32 KBulkTransferOutIdMask = KIfc1BulkTransferOutIdMask | KIfc2BulkTransferOutIdMask;
54 const TInt KUnexpectedTransferID = -101;
55 const TInt KUndefinedStep = -102;
57 const TInt KMaxTimeDiffPercentage = 60;
61 _LIT(KTestCaseId,"PBASE-T_USBDI-0497");
62 const TFunctorTestCase<CUT_PBASE_T_USBDI_0497,TBool> CUT_PBASE_T_USBDI_0497::iFunctor(KTestCaseId);
64 CUT_PBASE_T_USBDI_0497* CUT_PBASE_T_USBDI_0497::NewL(TBool aHostRole)
66 CUT_PBASE_T_USBDI_0497* self = new (ELeave) CUT_PBASE_T_USBDI_0497(aHostRole);
67 CleanupStack::PushL(self);
69 CleanupStack::Pop(self);
74 CUT_PBASE_T_USBDI_0497::CUT_PBASE_T_USBDI_0497(TBool aHostRole)
75 : CBaseBulkTestCase(KTestCaseId,aHostRole),
76 iCaseStep(EInProgress)
81 void CUT_PBASE_T_USBDI_0497::ConstructL()
87 CUT_PBASE_T_USBDI_0497::~CUT_PBASE_T_USBDI_0497()
89 The transfer objects have test specific names - so perform transfer specific clean up here.
96 //Do this before deleting the transfer objects
97 CloseInterfaceAndPipes();
100 for(count=0;count<KNumOutTransfersPerInterface;count++)
102 delete iIfc1OutTransfer[count];
103 iIfc1OutTransfer[count] = NULL;
104 delete iIfc2OutTransfer[count];
105 iIfc2OutTransfer[count] = NULL;
107 for(count=0;count<KNumInTransfersPerInterface;count++)
109 delete iIfc1InTransfer[count];
110 iIfc1InTransfer[count] = NULL;
111 delete iIfc2InTransfer[count];
112 iIfc2InTransfer[count] = NULL;
117 void CUT_PBASE_T_USBDI_0497::Ep0TransferCompleteL(TInt aCompletionCode)
121 RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
123 if(aCompletionCode != KErrNone)
125 if(iCaseStep == EFailed)
126 {// ignore error, nad catch the TestFailed method called further down.
127 RDebug::Printf("***Failure sending FAIL message to client on endpoint 0***");
132 msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
135 TTestCaseFailed request(aCompletionCode,msg);
136 iControlEp0->SendRequest(request,this);
150 TestFailed(KErrCompletion);
153 case ERequestDeviceRead:
155 RDebug::Printf("Asking client for 'Read' on interface 2");
156 iCaseStep = ETransferOut;
157 TEndpointReadRequest request(2,1,KDeviceNumReadBytes);// EP1 means endpoint index 1 not the actual endpoint number
158 iControlEp0->SendRequest(request,this);
163 RDebug::Printf("Try to write data on BOTH interfaces");
165 iStartTime[0].HomeTime();
166 iStartTime[1].HomeTime();
168 iIfc1OutTransfer[0]->TransferOut(KLiteralFrench4(), KHostNumWriteBytes1, EFalse);
169 iIfc1OutTransfer[1]->TransferOut(KLiteralFrench4(), KHostNumWriteBytes1, KHostNumWriteBytes2, EFalse);
170 iIfc2OutTransfer[0]->TransferOut(KLiteralEnglish8(), KHostNumWriteBytes1, EFalse);
171 iIfc2OutTransfer[1]->TransferOut(KLiteralEnglish8(), KHostNumWriteBytes1, KHostNumWriteBytes2, EFalse);
174 case ERequestDeviceWriteBack:
176 RDebug::Printf("Asking client for 'Write' back on interface 2");
177 iCaseStep = ETransferIn;
178 TWriteCachedReadDataRequest request(2,1,1);// EP1 means endpoint index 1 not the actual endpoint number
179 iControlEp0->SendRequest(request,this);
184 RDebug::Printf("Try to receive data on BOTH interfaces");
186 iStartTime[0].HomeTime();
187 iStartTime[1].HomeTime();
189 iIfc1InTransfer[0]->TransferIn(KHostNumReadBytes1);
190 iIfc1InTransfer[1]->TransferIn(KHostNumReadBytes2);
191 iIfc2InTransfer[0]->TransferIn(KHostNumReadBytes1);
192 iIfc2InTransfer[1]->TransferIn(KHostNumReadBytes2);
196 RDebug::Printf("<Error> Unknown test step");
197 TestFailed(KErrUnknown);
202 void CUT_PBASE_T_USBDI_0497::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
209 RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d, test step = %d",aTransferId, aCompletionCode, iCaseStep);
214 if(aCompletionCode != KErrNone)
216 iIfc1OutTransfer[0]->Cancel();
217 iIfc1OutTransfer[1]->Cancel();
218 iIfc2OutTransfer[0]->Cancel();
219 iIfc2OutTransfer[1]->Cancel();
221 msg.Format(_L("<Error %d> The transfer completed with an error."), aCompletionCode);
222 break; //switch(iCaseStep)
227 case KIfc1BulkTransferOutId1:
228 case KIfc1BulkTransferOutId2:
229 case KIfc2BulkTransferOutId1:
230 case KIfc2BulkTransferOutId2:
231 iTransferComplete |= aTransferId;
232 RDebug::Printf("Transfer OUT %d completed (Transfer Completion Aggregation Mask 0x%x)", aTransferId, iTransferComplete);
233 break; //switch(aTransferId)
235 iTransferComplete = 0; //reset
236 err = KUnexpectedTransferID;
237 msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d, got %d"),
238 err, KIfc1BulkTransferInId1, KIfc1BulkTransferInId2, aTransferId);
239 break; //switch(aTransferId)
242 if(err==KErrNone && iTimeElapsed[0] == 0 && (iTransferComplete & KIfc1BulkTransferOutIdMask) == KIfc1BulkTransferOutIdMask)
243 //Record time elapsed for Interface 1 if not yet recorded.
248 if(err==KErrNone && iTimeElapsed[1] == 0 && (iTransferComplete & KIfc2BulkTransferOutIdMask) == KIfc2BulkTransferOutIdMask)
249 //Record time elapsed for Interface 2 if not yet recorded.
254 if(err==KErrNone && (iTransferComplete & KBulkTransferOutIdMask) == KBulkTransferOutIdMask)
256 RDebug::Printf("All OUT Transfers Completed Successfully: Transfer Completion Aggregation Mask 0x%x", iTransferComplete);
257 iTransferComplete = 0; //reset
258 err = CheckAndResetTimes(0, 1, KMaxTimeDiffPercentage);
261 break; //switch(iCaseStep)
264 RDebug::Printf("Asking client for 'Write' back on interface 1");
265 iCaseStep = ERequestDeviceWriteBack;
266 TWriteCachedReadDataRequest request(1,1,1);// EP1 means endpoint index 1 not the actual endpoint number
267 iControlEp0->SendRequest(request,this);
269 break; //switch(iCaseStep)
272 if(aCompletionCode != KErrNone)
274 iIfc1InTransfer[0]->Cancel();
275 iIfc1InTransfer[1]->Cancel();
276 iIfc2InTransfer[0]->Cancel();
277 iIfc2InTransfer[1]->Cancel();
280 msg.Format(_L("<Error %d> No data sent on bulk IN request"),aCompletionCode);
281 break; //switch(iCaseStep)
286 case KIfc1BulkTransferInId1:
287 case KIfc1BulkTransferInId2:
288 case KIfc2BulkTransferInId1:
289 case KIfc2BulkTransferInId2:
290 iTransferComplete |= aTransferId;
291 RDebug::Printf("Transfer OUT %d completed (Transfer Completion Aggregation Mask 0x%x)", aTransferId, iTransferComplete);
292 break; //switch(aTransferId)
295 iTransferComplete = 0; //reset
296 err = KUnexpectedTransferID;
297 msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d, got %d"),
298 err, KIfc1BulkTransferInId1, KIfc1BulkTransferInId2, aTransferId);
299 break; //switch(aTransferId)
302 if(err==KErrNone && iTimeElapsed[0] == 0 && (iTransferComplete & KIfc1BulkTransferInIdMask) == KIfc1BulkTransferInIdMask)
303 //Record time elapsed for Interface 1 if not yet recorded.
308 if(err==KErrNone && iTimeElapsed[1] == 0 && (iTransferComplete & KIfc2BulkTransferInIdMask) == KIfc2BulkTransferInIdMask)
309 //Record time elapsed for Interface 2 if not yet recorded.
314 if(err==KErrNone && (iTransferComplete & KBulkTransferInIdMask) == KBulkTransferInIdMask)
316 // ok, compare data rcvd now
317 RDebug::Printf("All IN Transfers Completed Successfully: Transfer Completion Aggregation Mask 0x%x", iTransferComplete);
318 iTransferComplete = 0; //reset
319 err = CheckAndResetTimes(0, 1, KMaxTimeDiffPercentage);
322 break; //switch(iCaseStep)
325 TPtrC8 data1(iIfc1InTransfer[0]->DataPolled());
326 TPtrC8 data2(iIfc1InTransfer[1]->DataPolled());
327 TPtrC8 data3(iIfc2InTransfer[0]->DataPolled());
328 TPtrC8 data4(iIfc2InTransfer[1]->DataPolled());
329 //Validate first transfer on Interface 1 for number of bytes originally written.
330 if(ValidateData(data1, KLiteralFrench4(), KHostNumWriteBytes1) == EFalse)
332 RDebug::Printf("Validation failure 1st transfer, Interface 1");
333 err = KErrCompletion; //indicates data validation failure
334 break; //switch(iCaseStep)
337 //Validate second transfer on Interface 1 for number of bytes originally written.
338 if(ValidateData(data2, KLiteralFrench4(), KHostNumWriteBytes1, KHostNumWriteBytes2) == EFalse)
340 RDebug::Printf("Validation failure 2nd transfer, Interface 1");
341 err = KErrCompletion; //indicates data validation failure
342 break; //switch(iCaseStep)
345 //Validate first transfer on Interface 2 for number of bytes originally written.
346 if(ValidateData(data3, KLiteralEnglish8(), KHostNumWriteBytes1) == EFalse)
348 RDebug::Printf("Validation failure 1st transfer, Interface 2");
349 err = KErrCompletion; //indicates data validation failure
350 break; //switch(iCaseStep)
353 //Validate second transfer on Interface 2 for number of bytes originally written.
354 if(ValidateData(data4, KLiteralEnglish8(), KHostNumWriteBytes1, KHostNumWriteBytes2) == EFalse)
356 RDebug::Printf("Validation failure 2nd transfer, Interface 2");
357 err = KErrCompletion; //indicates data validation failure
358 break; //switch(iCaseStep)
361 // Comparison is a match
362 RDebug::Printf("Comparison for IN transfer is a match");
364 TTestCasePassed request;
365 iControlEp0->SendRequest(request,this);
367 break; //switch(iCaseStep)
370 err = KUndefinedStep;
371 msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep);
372 break; //switch(iCaseStep)
375 if(err == KErrCompletion)
376 //indicates data validation failure
378 msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
381 if(err == KErrTooBig)
382 //indicates timing validation failure
384 msg.Format(_L("<Error %d> Timer comparison showed too great a difference in transfer times between the two interfaces"), err);
391 TTestCaseFailed request(err,msg);
392 return iControlEp0->SendRequest(request,this);
396 void CUT_PBASE_T_USBDI_0497::DeviceInsertedL(TUint aDeviceHandle)
401 RDebug::Printf("this - %08x", this);
405 if(BaseBulkDeviceInsertedL(aDeviceHandle, EFalse) == EDeviceConfigurationError)
406 // Prepare for response from control transfer to client
409 msg.Format(_L("Base class DeviceInsertedL failed"));
413 if(SetUpInterfaceAndPipesL(aDeviceHandle, 2) == EDeviceConfigurationError)
414 // Prepare for response from control transfer to client
417 msg.Format(_L("Base class SetUpInterfaceAndPipes for Interface 2 failed"));
422 iIfc1InTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxTransferSize,*this,KIfc1BulkTransferInId1);
423 iIfc1InTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxTransferSize,*this,KIfc1BulkTransferInId2);
424 iIfc1OutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxTransferSize,*this,KIfc1BulkTransferOutId1);
425 iIfc1OutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxTransferSize,*this,KIfc1BulkTransferOutId2);
427 iIfc2InTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface2BulkIn,iUsbInterface2,KBulkMaxTransferSize,*this,KIfc2BulkTransferInId1);
428 iIfc2InTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface2BulkIn,iUsbInterface2,KBulkMaxTransferSize,*this,KIfc2BulkTransferInId2);
429 iIfc2OutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface2BulkOut1,iUsbInterface2,KBulkMaxTransferSize,*this,KIfc2BulkTransferOutId1);
430 iIfc2OutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface2BulkOut1,iUsbInterface2,KBulkMaxTransferSize,*this,KIfc2BulkTransferOutId2);
432 // Initialise the descriptors for transfer
433 RDebug::Printf("Initialising the transfer descriptors - interface 1");
434 err = iUsbInterface1.InitialiseTransferDescriptors();
437 msg.Format(_L("<Error %d> Unable to initialise transfer descriptors (Interface 1)"),err);
441 // Initialise the descriptors for transfer
442 RDebug::Printf("Initialising the transfer descriptors (Interface 2)");
443 err = iUsbInterface2.InitialiseTransferDescriptors();
446 msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
455 TTestCaseFailed request(err,msg);
456 iControlEp0->SendRequest(request,this);
460 RDebug::Printf("Asking client for 'Read' on interface 1");
461 iCaseStep = ERequestDeviceRead;
462 TEndpointReadRequest request(1,1,KDeviceNumReadBytes);// EP1 means endpoint index 1 not the actual endpoint number
463 iControlEp0->SendRequest(request,this);