1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-0493.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,338 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// @file PBASE-T_USBDI-0493.cpp
1.18 +// @internalComponent
1.19 +//
1.20 +//
1.21 +
1.22 +#include "PBASE-T_USBDI-0493.h"
1.23 +#include "testpolicy.h"
1.24 +#include "modelleddevices.h"
1.25 +#include "testliterals.h"
1.26 +
1.27 +
1.28 +
1.29 +
1.30 +namespace NUnitTesting_USBDI
1.31 + {
1.32 +const TInt KLiteralEnglish8Length = KLiteralEnglish8().Length();
1.33 +const TUint KBulkTransferMaxSize = 320;
1.34 +const TUint KHostNumWriteBytes = 256;
1.35 +const TUint KHostNumReadBytes = 256;
1.36 +const TUint KHostFinalNumReadBytes = 300;
1.37 +
1.38 +const TUint KStartNumTransferBytes = 1023;
1.39 +const TUint KFinishNumTransferBytes = 1025;
1.40 +
1.41 +const TUint KClientNumReadBytes = 2000;
1.42 +
1.43 +//Make these single bit values ...
1.44 +// ... so that their completion can be easily recorded in a bit mask!
1.45 +const TInt KBulkTransferInId0 = 1<<0;
1.46 +const TInt KBulkTransferInId1 = 1<<1;
1.47 +const TInt KBulkTransferInId2 = 1<<2;
1.48 +const TInt KBulkTransferInId3 = 1<<3;
1.49 +const TInt KBulkTransferOutId0 = 1<<4;
1.50 +const TInt KBulkTransferOutId1 = 1<<5;
1.51 +const TInt KBulkTransferOutId2 = 1<<6;
1.52 +const TInt KBulkTransferOutId3 = 1<<7;
1.53 +
1.54 +const TInt KUnexpectedTransferID = -101;
1.55 +const TInt KUndefinedStep = -102;
1.56 +
1.57 +
1.58 +_LIT(KTestCaseId,"PBASE-T_USBDI-0493");
1.59 +const TFunctorTestCase<CUT_PBASE_T_USBDI_0493,TBool> CUT_PBASE_T_USBDI_0493::iFunctor(KTestCaseId);
1.60 +
1.61 +CUT_PBASE_T_USBDI_0493* CUT_PBASE_T_USBDI_0493::NewL(TBool aHostRole)
1.62 + {
1.63 + CUT_PBASE_T_USBDI_0493* self = new (ELeave) CUT_PBASE_T_USBDI_0493(aHostRole);
1.64 + CleanupStack::PushL(self);
1.65 + self->ConstructL();
1.66 + CleanupStack::Pop(self);
1.67 + return self;
1.68 + }
1.69 +
1.70 +
1.71 +CUT_PBASE_T_USBDI_0493::CUT_PBASE_T_USBDI_0493(TBool aHostRole)
1.72 +: CBaseBulkTestCase(KTestCaseId,aHostRole),
1.73 + iNumTransferBytes(KStartNumTransferBytes),
1.74 + iCaseStep(EInProgress)
1.75 + {
1.76 + }
1.77 +
1.78 +
1.79 +void CUT_PBASE_T_USBDI_0493::ConstructL()
1.80 + {
1.81 + BaseBulkConstructL();
1.82 + }
1.83 +
1.84 +
1.85 +CUT_PBASE_T_USBDI_0493::~CUT_PBASE_T_USBDI_0493()
1.86 + {
1.87 + LOG_FUNC
1.88 + }
1.89 +
1.90 +void CUT_PBASE_T_USBDI_0493::Ep0TransferCompleteL(TInt aCompletionCode)
1.91 + {
1.92 + LOG_FUNC
1.93 +
1.94 + RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
1.95 +
1.96 + if(aCompletionCode != KErrNone)
1.97 + {
1.98 + if(iCaseStep == EFailed)
1.99 + {// todo, cope with errors
1.100 + }
1.101 + else
1.102 + {
1.103 + TBuf<256> msg;
1.104 + msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
1.105 + RDebug::Print(msg);
1.106 + iCaseStep = EFailed;
1.107 + TTestCaseFailed request(aCompletionCode,msg);
1.108 + iControlEp0->SendRequest(request,this);
1.109 + return;
1.110 + }
1.111 + }
1.112 +
1.113 + switch(iCaseStep)
1.114 + {
1.115 + // Test case passed
1.116 + case EPassed:
1.117 + TestPassed();
1.118 + break;
1.119 +
1.120 + // Test case failed
1.121 + case EFailed:
1.122 + TestFailed(KErrCompletion);
1.123 + break;
1.124 +
1.125 + case ETransferOut:
1.126 + RDebug::Printf("Try to send %d bytes of data", iNumTransferBytes);
1.127 + RDebug::RawPrint(KLiteralEnglish8().Mid(0*KHostNumWriteBytes, KHostNumWriteBytes));
1.128 + iOutTransfer[0]->TransferOut(KLiteralEnglish8().Mid(0*KHostNumWriteBytes, KHostNumWriteBytes), EFalse);
1.129 + iOutTransfer[1]->TransferOut(KLiteralEnglish8().Mid(1*KHostNumWriteBytes, KHostNumWriteBytes), EFalse);
1.130 + iOutTransfer[2]->TransferOut(KLiteralEnglish8().Mid(2*KHostNumWriteBytes, KHostNumWriteBytes), EFalse);
1.131 + iOutTransfer[3]->TransferOut(KLiteralEnglish8().Mid(3*KHostNumWriteBytes, iNumTransferBytes - 3*KHostNumWriteBytes), ETrue);
1.132 + break;
1.133 +
1.134 + case ETransferIn:
1.135 + RDebug::Printf("Try to receive max %d bytes of data", 3*KHostNumReadBytes + KHostFinalNumReadBytes);
1.136 + iInTransfer[0]->TransferIn(KHostNumReadBytes);
1.137 + iInTransfer[1]->TransferIn(KHostNumReadBytes);
1.138 + iInTransfer[2]->TransferIn(KHostNumReadBytes);
1.139 + iInTransfer[3]->TransferIn(KHostFinalNumReadBytes);
1.140 + break;
1.141 +
1.142 + default:
1.143 + RDebug::Printf("<Error> Unknown test step");
1.144 + TestFailed(KErrUnknown);
1.145 + break;
1.146 + }
1.147 + }
1.148 +
1.149 +void CUT_PBASE_T_USBDI_0493::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
1.150 + {
1.151 + LOG_FUNC
1.152 + Cancel();
1.153 +
1.154 + TInt err(KErrNone);
1.155 + TBuf<256> msg;
1.156 + RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
1.157 +
1.158 + switch(iCaseStep)
1.159 + {
1.160 + case ETransferOut:
1.161 + if(aCompletionCode != KErrNone)
1.162 + {
1.163 + err = KErrCorrupt;
1.164 + msg.Format(_L("<Error %d> No data sent on bulk OUT request"),aCompletionCode);
1.165 + break; //switch(iCaseStep)
1.166 + }
1.167 +
1.168 + switch(aTransferId)
1.169 + {
1.170 + case KBulkTransferOutId0:
1.171 + case KBulkTransferOutId1:
1.172 + case KBulkTransferOutId2:
1.173 + case KBulkTransferOutId3:
1.174 + iTransferComplete |= aTransferId;
1.175 + RDebug::Printf("Transfer %d completed", aTransferId);
1.176 + break; //switch(aTransferId)
1.177 +
1.178 + default:
1.179 + iTransferComplete = 0; //reset
1.180 + err = KUnexpectedTransferID;
1.181 + msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d or %d or %d, got %d"),
1.182 + err, KBulkTransferOutId0, KBulkTransferOutId1, KBulkTransferOutId2, KBulkTransferOutId3, aTransferId);
1.183 + break; //switch(aTransferId)
1.184 + }
1.185 +
1.186 + if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1 | KBulkTransferOutId2 | KBulkTransferOutId3))
1.187 + {
1.188 + RDebug::Printf("Try to receive back sent data. Transfers Completed %d", iTransferComplete);
1.189 + iCaseStep = ETransferIn;
1.190 + TWriteSynchronousCachedReadDataRequest request(1,1,1); //Use first read EP and first write EP (on interface 1)
1.191 + iControlEp0->SendRequest(request,this);
1.192 + iTransferComplete = 0; //reset
1.193 + }
1.194 + break; //switch(iCaseStep)
1.195 +
1.196 + case ETransferIn:
1.197 + if(aCompletionCode != KErrNone)
1.198 + {
1.199 + err = KErrCorrupt;
1.200 + msg.Format(_L("<Error %d> No data sent on bulk IN request"),aCompletionCode);
1.201 + break; //switch(iCaseStep)
1.202 + }
1.203 + switch(aTransferId)
1.204 + {
1.205 + case KBulkTransferInId0:
1.206 + case KBulkTransferInId1:
1.207 + case KBulkTransferInId2:
1.208 + case KBulkTransferInId3:
1.209 + iTransferComplete |= aTransferId;
1.210 + break; //switch(aTransferId)
1.211 +
1.212 + default:
1.213 + RDebug::Printf("Bad Transfer ID");
1.214 + iTransferComplete = 0; //reset
1.215 + err = KUnexpectedTransferID;
1.216 + msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d or %d or %d, got %d"),
1.217 + err, KBulkTransferInId0, KBulkTransferInId1, KBulkTransferInId2, KBulkTransferInId3, aTransferId);
1.218 + break; //switch(aTransferId)
1.219 + }
1.220 +
1.221 + if(err==KErrNone && iTransferComplete == (KBulkTransferInId0 | KBulkTransferInId1 | KBulkTransferInId2 | KBulkTransferInId3))
1.222 + {
1.223 + // compare data rcvd now
1.224 + TPtrC8 data1(iInTransfer[0]->DataPolled());
1.225 + TPtrC8 data2(iInTransfer[1]->DataPolled());
1.226 + TPtrC8 data3(iInTransfer[2]->DataPolled());
1.227 + TPtrC8 data4(iInTransfer[3]->DataPolled());
1.228 + if(ValidateData(data1, KLiteralEnglish8().Mid(0*KHostNumReadBytes, KHostNumReadBytes)) == EFalse)
1.229 + {
1.230 + err = KErrCompletion; //indicates data validation failure
1.231 + break; //switch(iCaseStep)
1.232 + }
1.233 +
1.234 + if(ValidateData(data2, KLiteralEnglish8().Mid(1*KHostNumReadBytes, KHostNumReadBytes)) == EFalse)
1.235 + {
1.236 + err = KErrCompletion; //indicates data validation failure
1.237 + break; //switch(iCaseStep)
1.238 + }
1.239 +
1.240 + if(ValidateData(data3, KLiteralEnglish8().Mid(2*KHostNumReadBytes, KHostNumReadBytes)) == EFalse)
1.241 + {
1.242 + err = KErrCompletion; //indicates data validation failure
1.243 + break; //switch(iCaseStep)
1.244 + }
1.245 +
1.246 + if(ValidateData(data4, KLiteralEnglish8().Mid(3*KHostNumReadBytes, iNumTransferBytes - 3*KHostNumReadBytes)) == EFalse)
1.247 + {
1.248 + err = KErrCompletion; //indicates data validation failure
1.249 + break; //switch(iCaseStep)
1.250 + }
1.251 +
1.252 + if(err == KErrNone)
1.253 + {
1.254 + // Comparison is a match
1.255 + RDebug::Printf("Comparison for IN transfer is a match - Number of Transfer Bytes %d", iNumTransferBytes);
1.256 + iTransferComplete = 0; //reset
1.257 + if(++iNumTransferBytes<=KFinishNumTransferBytes)
1.258 + /*
1.259 + Loop round again having added one to
1.260 + the number of transfer bytes to be used.
1.261 + In this test there should be three repeats of the underlying
1.262 + "Transfer Out followed by Transfer In" test.
1.263 + The repeats will use
1.264 + KStartNumTransferBytes,
1.265 + KStartNumTransferBytes+1,
1.266 + and finally
1.267 + KFinishNumTransferBytes.
1.268 + */
1.269 + {
1.270 + iCaseStep = ETransferOut;
1.271 + TEndpointReadUntilShortRequest request(1,1,KClientNumReadBytes);// EP1 because 1st reader EP
1.272 + iControlEp0->SendRequest(request,this);
1.273 + break; //switch(iCaseStep)
1.274 + }
1.275 + iCaseStep = EPassed;
1.276 + TTestCasePassed request;
1.277 + iControlEp0->SendRequest(request,this);
1.278 + }
1.279 + }
1.280 + break; //switch(iCaseStep)
1.281 +
1.282 + default:
1.283 + err = KUndefinedStep;
1.284 + msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep);
1.285 + break; //switch(iCaseStep)
1.286 + }
1.287 +
1.288 + if(err!=KErrNone)
1.289 + {
1.290 + RDebug::Print(msg);
1.291 + iCaseStep = EFailed;
1.292 + TTestCaseFailed request(err,msg);
1.293 + iControlEp0->SendRequest(request,this);
1.294 + return;
1.295 + }
1.296 + }
1.297 +
1.298 +
1.299 +void CUT_PBASE_T_USBDI_0493::DeviceInsertedL(TUint aDeviceHandle)
1.300 + {
1.301 + LOG_FUNC
1.302 + Cancel();
1.303 + RDebug::Printf("****** Father William Pattern Length is %d bytes! *********", KLiteralEnglish8Length);
1.304 + if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
1.305 + // Prepare for response from control transfer to client
1.306 + {
1.307 + iCaseStep = EFailed;
1.308 + }
1.309 +
1.310 + // Create the bulk transfers
1.311 + RDebug::Printf("Trying to create the bulk transfers - size 0x%u", KBulkTransferMaxSize);
1.312 + iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferInId0);
1.313 + iInTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferInId1);
1.314 + iInTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferInId2);
1.315 + iInTransfer[3] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferInId3);
1.316 + iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferOutId0);
1.317 + iOutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferOutId1);
1.318 + iOutTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferOutId2);
1.319 + iOutTransfer[3] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkTransferMaxSize,*this,KBulkTransferOutId3);
1.320 +
1.321 + // Initialise the descriptors for transfer
1.322 + RDebug::Printf("Initialising the transfer descriptors");
1.323 + TInt err = iUsbInterface1.InitialiseTransferDescriptors();
1.324 + if(err != KErrNone)
1.325 + {
1.326 + TBuf<256> msg;
1.327 + msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
1.328 + RDebug::Print(msg);
1.329 + iCaseStep = EFailed;
1.330 + TTestCaseFailed request(err,msg);
1.331 + iControlEp0->SendRequest(request,this);
1.332 + return;
1.333 + }
1.334 +
1.335 + RDebug::Printf("Ask client to read %d bytes of data", KClientNumReadBytes);
1.336 + iCaseStep = ETransferOut;
1.337 + TEndpointReadUntilShortRequest request(1,1,KClientNumReadBytes);// EP1 because 1st reader EP
1.338 + iControlEp0->SendRequest(request,this);
1.339 + }
1.340 +
1.341 + } //end namespace