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-0484.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,286 @@
1.4 +// Copyright (c) 2007-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-0484.cpp
1.18 +// @internalComponent
1.19 +//
1.20 +//
1.21 +
1.22 +#include "PBASE-T_USBDI-0484.h"
1.23 +#include "testpolicy.h"
1.24 +#include "modelleddevices.h"
1.25 +
1.26 +
1.27 +
1.28 +
1.29 +namespace NUnitTesting_USBDI
1.30 + {
1.31 +_LIT8(KDataPayload1,"opqrstuvwxyzabcdefghijklmnopqrstuvwxyz12345abcdefghijklmnopqrstuvwxyz");
1.32 +_LIT8(KDataPayload2,"12345opqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
1.33 +_LIT8(KDataPayload3,"abcdefghijklmnopqrstuvwxyzopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); // 64bytes
1.34 +
1.35 +const TInt KBulkTransferId1 = 0x01;
1.36 +const TInt KBulkTransferId2 = 0x02;
1.37 +const TInt KBulkTransferId3 = 0x03;
1.38 +_LIT(KTestCaseId,"PBASE-T_USBDI-0484");
1.39 +const TFunctorTestCase<CUT_PBASE_T_USBDI_0484,TBool> CUT_PBASE_T_USBDI_0484::iFunctor(KTestCaseId);
1.40 +
1.41 +CUT_PBASE_T_USBDI_0484* CUT_PBASE_T_USBDI_0484::NewL(TBool aHostRole)
1.42 + {
1.43 + CUT_PBASE_T_USBDI_0484* self = new (ELeave) CUT_PBASE_T_USBDI_0484(aHostRole);
1.44 + CleanupStack::PushL(self);
1.45 + self->ConstructL();
1.46 + CleanupStack::Pop(self);
1.47 + return self;
1.48 + }
1.49 +
1.50 +
1.51 +CUT_PBASE_T_USBDI_0484::CUT_PBASE_T_USBDI_0484(TBool aHostRole)
1.52 +: CBaseBulkTestCase(KTestCaseId,aHostRole),
1.53 + iCaseStep(EInProgress)
1.54 + {
1.55 + }
1.56 +
1.57 +
1.58 +void CUT_PBASE_T_USBDI_0484::ConstructL()
1.59 + {
1.60 + BaseBulkConstructL();
1.61 + }
1.62 +
1.63 +
1.64 +CUT_PBASE_T_USBDI_0484::~CUT_PBASE_T_USBDI_0484()
1.65 + {
1.66 + LOG_FUNC
1.67 + }
1.68 +
1.69 +void CUT_PBASE_T_USBDI_0484::Ep0TransferCompleteL(TInt aCompletionCode)
1.70 + {
1.71 + LOG_FUNC
1.72 + Cancel();
1.73 +
1.74 + RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
1.75 +
1.76 + if(aCompletionCode != KErrNone)
1.77 + {
1.78 + TBuf<256> msg;
1.79 + msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
1.80 + RDebug::Print(msg);
1.81 + }
1.82 +
1.83 + if(iCaseStep == EPassed)
1.84 + {
1.85 + if(aCompletionCode == KErrNone)
1.86 + {
1.87 + return TestPassed();
1.88 + }
1.89 + // else error
1.90 + iCaseStep = EFailed;
1.91 + }
1.92 +
1.93 + if(iCaseStep == EFailed)
1.94 + {
1.95 + return TestFailed(KErrCompletion);
1.96 + }
1.97 + }
1.98 +
1.99 +
1.100 +void CUT_PBASE_T_USBDI_0484::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
1.101 + {
1.102 + Cancel();
1.103 + TInt err(KErrNone);
1.104 + RDebug::Printf("Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
1.105 +
1.106 + if(aTransferId == KBulkTransferId1)
1.107 + {
1.108 + if(iCaseStep == EStalled)
1.109 + {
1.110 + if(aCompletionCode != KErrUsbStalled)
1.111 + {
1.112 + TBuf<256> msg;
1.113 + msg.Format(_L("<Error %d> The transfer completed with no errors but should have stalled"),aCompletionCode);
1.114 + RDebug::Print(msg);
1.115 + TTestCaseFailed request(KErrCorrupt,msg);
1.116 + return iControlEp0->SendRequest(request,this);
1.117 + }
1.118 + else
1.119 + {
1.120 + // Acknowledge the stall and clear
1.121 + err = iTestPipeInterface1BulkIn.ClearRemoteStall();
1.122 + if(err != KErrNone)
1.123 + {
1.124 + TBuf<256> msg;
1.125 + msg.Format(_L("<Error %d> The remote stall cannot be cleared"),err);
1.126 + RDebug::Print(msg);
1.127 + iCaseStep = EFailed;
1.128 + TTestCaseFailed request(err,msg);
1.129 + return iControlEp0->SendRequest(request,this);
1.130 + }
1.131 +
1.132 + // try to get data now, after EP has been stalled
1.133 + RDebug::Printf("try to get data now, after EP has been stalled");
1.134 + iInTransfer[0]->TransferIn(KDataPayload1().Length());
1.135 + iInTransfer[1]->TransferIn(KDataPayload2().Length());
1.136 + iInTransfer[2]->TransferIn(KDataPayload3().Length());
1.137 +
1.138 + iCaseStep = ETransferAfterStall;
1.139 + TEndpointWriteRequest request(1,1,KDataPayload1);// EP1 because 1st writter EP
1.140 + iControlEp0->SendRequest(request,this);
1.141 + return;
1.142 + }
1.143 + }
1.144 + if(iCaseStep == ETransferAfterStall)
1.145 + {
1.146 + if(aCompletionCode != KErrNone)
1.147 + {
1.148 + TBuf<256> msg;
1.149 + msg.Format(_L("<Error %d> No data got after EP2 being stalled"),aCompletionCode);
1.150 + RDebug::Print(msg);
1.151 + iCaseStep = EFailed;
1.152 + TTestCaseFailed request(err,msg);
1.153 + return iControlEp0->SendRequest(request,this);
1.154 + }
1.155 +
1.156 + // else ok, compare data rcvd now
1.157 + TPtrC8 data(iInTransfer[0]->DataPolled());
1.158 + // Compare the data to what is expected
1.159 + if(data.Compare(KDataPayload1) != 0)
1.160 + {
1.161 + TBuf<256> msg;
1.162 + msg.Format(_L("<Error %d> Interrupt data received does not match data sent"),KErrCompletion);
1.163 + RDebug::Print(msg);
1.164 + iCaseStep = EFailed;
1.165 + TTestCaseFailed request(KErrCompletion,msg);
1.166 + return iControlEp0->SendRequest(request,this);
1.167 + }
1.168 + // Comparison is a match, wait for next transfer
1.169 + RDebug::Printf("Comparison is a match, wait for transfer 2");
1.170 + User::After(500000);
1.171 + TEndpointWriteRequest request(1,1,KDataPayload2);// EP1 because 1st writter EP
1.172 + iControlEp0->SendRequest(request,this);
1.173 + }
1.174 + }
1.175 + else if(aTransferId == KBulkTransferId2)
1.176 + {
1.177 + if(aCompletionCode != KErrNone)
1.178 + {
1.179 + TBuf<256> msg;
1.180 + msg.Format(_L("<Error %d> No data got after EP2 being stalled"),aCompletionCode);
1.181 + RDebug::Print(msg);
1.182 + iCaseStep = EFailed;
1.183 + TTestCaseFailed request(err,msg);
1.184 + return iControlEp0->SendRequest(request,this);
1.185 + }
1.186 +
1.187 + // else ok, compare data rcvd now
1.188 + TPtrC8 data(iInTransfer[1]->DataPolled());
1.189 + // Compare the data to what is expected
1.190 + if(data.Compare(KDataPayload2) != 0)
1.191 + {
1.192 + TBuf<256> msg;
1.193 + msg.Format(_L("<Error %d> Interrupt data received does not match data sent"),KErrCompletion);
1.194 + RDebug::Print(msg);
1.195 + iCaseStep = EFailed;
1.196 + TTestCaseFailed request(KErrCompletion,msg);
1.197 + return iControlEp0->SendRequest(request,this);
1.198 + }
1.199 + // Comparison is a match, wait for next transfer
1.200 + RDebug::Printf("Comparison is a match, wait for transfer 3");
1.201 + User::After(500000);
1.202 + TEndpointWriteRequest request(1,1,KDataPayload3);// EP1 because 1st writter EP
1.203 + iControlEp0->SendRequest(request,this);
1.204 + }
1.205 + else if(aTransferId == KBulkTransferId3)
1.206 + {
1.207 + if(aCompletionCode != KErrNone)
1.208 + {
1.209 + TBuf<256> msg;
1.210 + msg.Format(_L("<Error %d> No data got after EP2 being stalled"),aCompletionCode);
1.211 + RDebug::Print(msg);
1.212 + iCaseStep = EFailed;
1.213 + TTestCaseFailed request(err,msg);
1.214 + return iControlEp0->SendRequest(request,this);
1.215 + }
1.216 + // else ok, compare data rcvd now
1.217 + TPtrC8 data(iInTransfer[2]->DataPolled());
1.218 + // Compare the data to what is expected
1.219 + if(data.Compare(KDataPayload3) != 0)
1.220 + {
1.221 + TBuf<256> msg;
1.222 + msg.Format(_L("<Error %d> Interrupt data received does not match data sent"),KErrCompletion);
1.223 + RDebug::Print(msg);
1.224 + iCaseStep = EFailed;
1.225 + TTestCaseFailed request(KErrCompletion,msg);
1.226 + return iControlEp0->SendRequest(request,this);
1.227 + }
1.228 + // Comparison is a match, test passes
1.229 + iCaseStep = EPassed;
1.230 + TTestCasePassed request;
1.231 + return iControlEp0->SendRequest(request,this);
1.232 + }
1.233 + else
1.234 + {
1.235 + RDebug::Printf("<Error> a transfer completed (id=%d) that was not expected",aTransferId);
1.236 + return TestFailed(KErrCorrupt);
1.237 + }
1.238 + }
1.239 +
1.240 +
1.241 +void CUT_PBASE_T_USBDI_0484::DeviceInsertedL(TUint aDeviceHandle)
1.242 + {
1.243 + LOG_FUNC
1.244 +
1.245 + Cancel();
1.246 + RDebug::Printf("this - %08x", this);
1.247 +
1.248 + TBuf<256> msg;
1.249 + TInt err = KErrNone;
1.250 + if(BaseBulkDeviceInsertedL(aDeviceHandle, EFalse) == EDeviceConfigurationError)
1.251 + // Prepare for response from control transfer to client
1.252 + {
1.253 + err = KErrGeneral;
1.254 + msg.Format(_L("Base class DeviceInsertedL failed"));
1.255 + }
1.256 + else
1.257 + {
1.258 + // Create the bulk transfers
1.259 + iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,256,*this,KBulkTransferId1);
1.260 + iInTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,256,*this,KBulkTransferId2);
1.261 + iInTransfer[2] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,256,*this,KBulkTransferId3);
1.262 +
1.263 + // Initialise the descriptors for transfer
1.264 + RDebug::Printf("Initialising the transfer descriptors - interface 1");
1.265 + err = iUsbInterface1.InitialiseTransferDescriptors();
1.266 + if(err != KErrNone)
1.267 + {
1.268 + _LIT(lit, "<Error %d> Unable to initialise transfer descriptors");
1.269 + msg.Format(lit,err);
1.270 + }
1.271 + }
1.272 + if(err != KErrNone)
1.273 + {
1.274 + RDebug::Print(msg);
1.275 + iCaseStep = EFailed;
1.276 + TTestCaseFailed request(err,msg);
1.277 + iControlEp0->SendRequest(request,this);
1.278 + }
1.279 + else
1.280 + {
1.281 + iCaseStep = EStalled;
1.282 + iInTransfer[0]->TransferIn(KDataPayload1().Length());
1.283 +
1.284 + TStallEndpointRequest r2(2,1); // Stall endpoint 2 interface 1
1.285 + iControlEp0->SendRequest(r2,this);
1.286 + }
1.287 + }
1.288 +
1.289 + }