Update contrib.
1 // Copyright (c) 2000-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 // e32test/usb/t_usb_device/src/activerw.cpp
15 // USB Test Program T_USB_DEVICE, functional part.
16 // Device-side part, to work against T_USB_HOST running on the host.
20 #include "general.h" // CActiveControl, CActiveRW
23 #include "activetimer.h"
24 #include "usblib.h" // Helpers
26 _LIT(KFileName, "\\T_USBFILE.BIN");
29 extern TBool gVerbose;
31 extern TBool gStopOnFail;
32 extern TBool gAltSettingOnNotify;
33 extern TInt8 gSettingNumber [128];
34 extern TInt gSoakCount;
35 extern CActiveRW* gRW[KMaxConcurrentTests]; // the USB read/write active object
36 extern IFConfigPtr gInterfaceConfig [128] [KMaxInterfaceSettings];
37 extern TInt gActiveTestCount;
39 static TInt gYieldRepeat = 0;
40 static const TInt KYieldRepeat = 100;
43 // --- class CActiveRW ---------------------------------------------------------
46 CActiveRW::CActiveRW(CConsoleBase* aConsole, RDEVCLIENT* aPort, RFs aFs, TUint16 aIndex, TBool aLastSetting)
47 : CActive(EPriorityNormal),
49 iWriteBuf((TUint8 *)NULL,0,0), // temporary initialisation
50 iReadBuf((TUint8 *)NULL,0,0), // temporary initialisation
56 iCurrentXfer(ETxferNone),
65 iLastSetting (aLastSetting)
68 TUSB_VERBOSE_PRINT("CActiveRW::CActiveRW()");
72 CActiveRW* CActiveRW::NewL(CConsoleBase* aConsole, RDEVCLIENT* aPort, RFs aFs, TUint16 aIndex, TBool aLastSetting)
74 TUSB_VERBOSE_APRINT("CActiveRW::NewL()");
76 CActiveRW* self = new (ELeave) CActiveRW(aConsole, aPort, aFs, aIndex, aLastSetting);
77 CleanupStack::PushL(self);
79 CActiveScheduler::Add(self);
80 CleanupStack::Pop(); // self
85 void CActiveRW::ConstructL()
87 TUSB_VERBOSE_PRINT("CActiveRW::ConstructL()");
89 // Create read timeout timer active object (but don't activate it yet)
90 iTimeoutTimer = CActiveTimer::NewL(iConsole, iPort);
93 TUSB_PRINT("Failed to create timeout timer");
98 CActiveRW::~CActiveRW()
100 TUSB_VERBOSE_PRINT("CActiveRW::~CActiveRW()");
101 Cancel(); // base class
102 delete iTimeoutTimer;
104 if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
108 if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
113 User::Free((TAny *)iReadBuf.Ptr());
114 User::Free((TAny *)iWriteBuf.Ptr());
122 void CActiveRW::SetTestParams(TestParamPtr aTpPtr)
124 iBufSz = aTpPtr->minSize;
125 iPktNum = aTpPtr->packetNumber;
127 iTestParams = *aTpPtr;
129 gYieldRepeat = ((iTestParams.settingRepeat != 0) || (iIndex == 0))? 0 : KYieldRepeat;
131 if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
134 TAny * newBuffer = User::Alloc(aTpPtr->maxSize);
135 if (newBuffer == NULL)
137 TUSB_PRINT ("Failure to allocate heap memory");
140 iReadBuf.Set((TUint8 *)newBuffer,0,(TInt)aTpPtr->maxSize);
142 TBuf8<KUsbDescSize_Endpoint> descriptor;
143 TUSB_VERBOSE_PRINT2 ("GetEndpointDescriptor Alt Setting %d Endpoint %d",iTestParams.alternateSetting, iTestParams.outPipe);
144 TInt r = iPort->GetEndpointDescriptor(iTestParams.alternateSetting, (TENDPOINTNUMBER)iTestParams.outPipe, descriptor);
145 if ((TUint)r != iReadSize)
147 TUSB_PRINT("Failed to get endpoint descriptor");
152 iMaxPktSz = EpSize(descriptor[KEpDesc_PacketSizeOffset],descriptor[KEpDesc_PacketSizeOffset+1]);
153 TUSB_VERBOSE_PRINT5 ("Out Endpoint 0x%x attributes 0x%x interface %d setting %d max packet size %d",
154 descriptor[KEpDesc_AddressOffset],descriptor[KEpDesc_AttributesOffset],iTestParams.interfaceNumber,iTestParams.alternateSetting,iMaxPktSz);
155 if (!gSkip && iMaxPktSz != (TUint)gInterfaceConfig[iTestParams.interfaceNumber][iTestParams.alternateSetting]->iInfoPtr->iEndpointData[iTestParams.outPipe-1].iSize)
157 TUSB_PRINT4("Error - Interface %d Setting %d Endpoint %d Max Packet Size %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe,iMaxPktSz);
162 if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
165 TAny * newBuffer = User::Alloc(aTpPtr->maxSize);
166 if (newBuffer == NULL)
168 TUSB_PRINT ("Failure to allocate heap memory");
171 iWriteBuf.Set((TUint8 *)newBuffer,0,(TInt)aTpPtr->maxSize);
173 TBuf8<KUsbDescSize_Endpoint> descriptor;
174 TUSB_VERBOSE_PRINT2 ("GetEndpointDescriptor Alt Setting %d Endpoint %d",iTestParams.alternateSetting, iTestParams.inPipe);
175 TInt r = iPort->GetEndpointDescriptor(iTestParams.alternateSetting, (TENDPOINTNUMBER)iTestParams.inPipe, descriptor);
178 TUSB_PRINT("Failed to get endpoint descriptor");
183 TInt maxPktSz = EpSize(descriptor[KEpDesc_PacketSizeOffset],descriptor[KEpDesc_PacketSizeOffset+1]);
184 TUSB_VERBOSE_PRINT5 ("In Endpoint 0x%x attributes 0x%x interface %d setting %d max packet size %d",
185 descriptor[KEpDesc_AddressOffset],descriptor[KEpDesc_AttributesOffset],iTestParams.interfaceNumber,iTestParams.alternateSetting,maxPktSz);
186 if (!gSkip && maxPktSz != gInterfaceConfig[iTestParams.interfaceNumber][iTestParams.alternateSetting]->iInfoPtr->iEndpointData[iTestParams.inPipe-1].iSize)
188 TUSB_PRINT4("Error - Interface %d Setting %d Endpoint %d Max Packet Size %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.inPipe,maxPktSz);
197 void CActiveRW::SetTransferMode(TXferMode aMode)
200 if (aMode == EReceiveOnly || aMode == ETransmitOnly)
202 // For streaming transfers we do this only once.
203 iBufSz = iTestParams.maxSize;
207 void CActiveRW::Suspend(TXferType aType)
209 if (aType == ESuspend)
210 TUSB_VERBOSE_PRINT1("Index %d Suspend",iIndex);
211 if (aType == EAltSetting)
212 TUSB_VERBOSE_PRINT3("Index %d Suspend for Alternate Setting - interface %d setting %d",iIndex,iTestParams.interfaceNumber,iTestParams.alternateSetting);
213 iStatus = KRequestPending;
214 iCurrentXfer = aType;
221 void CActiveRW::Resume()
223 TUSB_VERBOSE_PRINT3("Index %d Resume interface %d setting %d",iIndex,iTestParams.interfaceNumber,iTestParams.alternateSetting);
224 TRequestStatus* status = &iStatus;
225 User::RequestComplete(status,KErrNone);
232 void CActiveRW::Yield()
234 TUSB_VERBOSE_PRINT1("Index %d Scheduler Yield",iIndex);
235 // removes the active object from the scheduler queue then adds it back in again
237 CActiveScheduler::Add(this);
240 void CActiveRW::ResumeAltSetting(TUint aAltSetting)
242 if (iCurrentXfer == EAltSetting && iTestParams.alternateSetting == aAltSetting)
248 void CActiveRW::StartOrSuspend()
252 iPort->GetAlternateSetting (altSetting);
253 if (iTestParams.alternateSetting != altSetting)
255 Suspend(EAltSetting);
261 if (iTestParams.alternateSetting != gSettingNumber[iTestParams.interfaceNumber])
263 gSettingNumber[iTestParams.interfaceNumber] = iTestParams.alternateSetting;
264 r = iPort->StartNextOutAlternateSetting(ETrue);
265 TUSB_VERBOSE_PRINT1("StartNextOutAlternateSetting retValue %d",r);
266 test_Value(r, (r >= KErrNone) || (r == KErrNotReady) || (r == KErrGeneral));
268 TUSB_VERBOSE_PRINT4 ("CActiveRW::StartOrSuspend() interface %d setting %d Out %d In %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe,iTestParams.inPipe);
269 if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
271 r = iPort->OpenEndpoint(iSCReadBuf,iTestParams.outPipe);
274 if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
276 r = iPort->OpenEndpoint(iSCWriteBuf,iTestParams.inPipe);
280 if (iXferMode == EReceiveOnly)
282 // read data and process any available
283 iReadSize = ReadData();
291 SendData(); // or we send data
292 if (iXferMode == ETransmitOnly)
301 void CActiveRW::RunL()
309 TUSB_VERBOSE_PRINT("CActiveRW::RunL()");
311 if ((iStatus != KErrNone) && (iStatus != KErrEof))
313 TUSB_PRINT1("Error %d in RunL", iStatus.Int());
317 TUSB_PRINT("Stopped");
321 switch (iCurrentXfer)
325 if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
327 r = iSCReadBuf.Close();
330 if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
332 r = iSCWriteBuf.Close();
336 if (iTestParams.settingRepeat && ((iRepeat < iTestParams.repeat) || !iLastSetting))
338 gRW[iTestParams.afterIndex]->Resume();
345 TUSB_VERBOSE_PRINT3("Index %d Resumed interface %d setting test=%d",iIndex,iTestParams.interfaceNumber,iTestParams.alternateSetting);
346 if (iTestParams.alternateSetting != gSettingNumber[iTestParams.interfaceNumber])
348 r = iPort->StartNextOutAlternateSetting(ETrue);
349 TUSB_VERBOSE_PRINT1("StartNextOutAlternateSetting retValue %d",r);
350 test_Value(r, (r >= KErrNone) || (r == KErrNotReady) || (r == KErrGeneral));
351 if (r != KErrNotReady)
353 gSettingNumber[iTestParams.interfaceNumber] = r;
355 if (iTestParams.alternateSetting != gSettingNumber[iTestParams.interfaceNumber])
357 Suspend(EAltSetting);
362 iPort->GetAlternateSetting (altSetting);
363 TUSB_VERBOSE_PRINT4("Index %d Resumed interface %d setting test=%d actual=%d",iIndex,iTestParams.interfaceNumber,iTestParams.alternateSetting,altSetting);
364 if (gAltSettingOnNotify)
366 if (iTestParams.alternateSetting != altSetting)
368 Suspend(EAltSetting);
374 // If alternate setting is ok drops through to EAltSetting to start next read or write
375 iCurrentXfer = EAltSetting;
379 if (iTestParams.alternateSetting != gSettingNumber[iTestParams.interfaceNumber])
381 r = iPort->StartNextOutAlternateSetting(ETrue);
382 TUSB_VERBOSE_PRINT1("StartNextOutAlternateSetting retValue %d",r);
383 test_Value(r, (r >= KErrNone) || (r == KErrNotReady) || (r == KErrGeneral));
384 if (r != KErrNotReady)
386 gSettingNumber[iTestParams.interfaceNumber] = r;
388 if (iTestParams.alternateSetting != gSettingNumber[iTestParams.interfaceNumber])
390 Suspend(EAltSetting);
394 TUSB_VERBOSE_PRINT4 ("CActiveRW::Runl() EAltSetting interface %d setting %d Out %d In %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe,iTestParams.inPipe);
395 if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
397 r = iPort->OpenEndpoint(iSCReadBuf,iTestParams.outPipe);
400 if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
402 r = iPort->OpenEndpoint(iSCWriteBuf,iTestParams.inPipe);
406 if (iXferMode == EReceiveOnly)
408 // read data and process any available
409 iReadSize = ReadData();
417 SendData(); // or we send data
418 if (iXferMode == ETransmitOnly)
432 iReadSize = ReadData();
438 iReadSize = iReadBuf.Length();
444 TUSB_PRINT("Oops. (Shouldn't end up here...)");
450 void CActiveRW::ProcessWriteXfer()
452 if (iXferMode == ETransmitOnly)
454 if (iTestParams.settingRepeat && iRepeat)
456 if (((iRepeat % iTestParams.settingRepeat) == 0) || (iRepeat >= iTestParams.repeat))
458 if ((iRepeat < iTestParams.repeat) || !iLastSetting)
461 if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
463 test_KErrNone(iSCWriteBuf.Close());
466 gRW[iTestParams.afterIndex]->Resume();
468 if (iRepeat < iTestParams.repeat)
476 if ((iTestParams.repeat == 0) || (iRepeat < iTestParams.repeat))
478 // Yield the scheduler to ensure other activeObjects can run
479 if (iRepeat && gYieldRepeat)
481 if ((iRepeat % gYieldRepeat) == 0)
486 SendData(); // next we send data
497 // read data and process any available
498 iReadSize = ReadData();
508 void CActiveRW::ProcessReadXfer()
510 if ((iReadOffset + iReadSize) > iBufSz)
512 TUSB_PRINT2("*** rcv'd too much data: 0x%x (expected: 0x%x)", iReadOffset + iReadSize, iBufSz);
516 if (iXferMode == EReceiveOnly)
518 if (iReadOffset == 0)
521 const TUint32 num = *reinterpret_cast<const TUint32*>(iSCReadData);
523 const TUint32 num = *reinterpret_cast<const TUint32*>(iReadBuf.Ptr());
527 TUSB_PRINT3("*** Repeat %d rcv'd wrong pkt number: 0x%x (expected: 0x%x)", iRepeat, num, iPktNum);
532 if (iDiskAccessEnabled)
534 // Write out to disk previous completed Read
536 TPtr8 readBuf((TUint8 *)iSCReadData,iReadSize,iReadSize);
537 WriteBufferToDisk(readBuf, iReadSize);
539 TUSB_VERBOSE_PRINT2("Max Buffer Size = %d (iReadBuf.Size(): %d)", iTestParams.maxSize, iReadBuf.Size());
540 WriteBufferToDisk(iReadBuf, iTestParams.maxSize);
543 iReadOffset += iReadSize;
544 if (iReadOffset >= iBufSz)
551 iReadSize = ReadData();
562 if (iTestParams.settingRepeat)
564 if (((iRepeat % iTestParams.settingRepeat) == 0) || (iRepeat >= iTestParams.repeat))
567 if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
569 test_KErrNone(iSCReadBuf.Close());
572 if ((iRepeat < iTestParams.repeat) || !iLastSetting)
574 gRW[iTestParams.afterIndex]->Resume();
576 if (iRepeat < iTestParams.repeat)
583 if ((iTestParams.repeat == 0) || (iRepeat < iTestParams.repeat))
585 // Yield the scheduler to ensure other activeObjects can run
586 if (iRepeat && gYieldRepeat)
588 if ((iRepeat % gYieldRepeat) == 0)
594 TRequestStatus* status = &iStatus;
595 User::RequestComplete(status,KErrNone);
601 iReadSize = ReadData();
611 if (iXferMode == ELoopComp)
613 test(CompareBuffers());
617 if (iReadOffset == 0)
620 const TUint32 num = *reinterpret_cast<const TUint32*>(iSCReadData);
622 const TUint32 num = *reinterpret_cast<const TUint32*>(iReadBuf.Ptr());
626 TUSB_PRINT2("*** rcv'd wrong pkt number: 0x%x (expected: 0x%x)", num, iPktNum);
630 iReadOffset += iReadSize;
631 if (iReadOffset >= iBufSz)
637 iReadSize = ReadData();
644 if ((TUint)iBufSz == iTestParams.maxSize)
646 iBufSz = iTestParams.minSize;
655 if (iTestParams.settingRepeat)
657 if (((iRepeat % iTestParams.settingRepeat) == 0) || (iRepeat >= iTestParams.repeat))
659 if (iRepeat < iTestParams.repeat)
667 if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
669 test_KErrNone(iSCReadBuf.Close());
671 if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
673 test_KErrNone(iSCWriteBuf.Close());
678 gRW[iTestParams.afterIndex]->Resume();
684 if ((iTestParams.repeat == 0) || (iRepeat < iTestParams.repeat))
686 // Yield the scheduler to ensure other activeObjects can run
687 if (iRepeat && gYieldRepeat)
689 if ((iRepeat % gYieldRepeat) == 0)
705 void CActiveRW::SendWaitSetting()
707 __ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 662));
711 test_KErrNone(iSCWriteBuf.GetInBufferRange(inBuffer, inBufLength));
712 test_KErrNone(iSCWriteBuf.WriteBuffer(inBuffer,KWaitSettingSize,FALSE,iStatus));
714 iWriteBuf.SetLength(KWaitSettingSize);
715 iPort->Write(iStatus, (TENDPOINTNUMBER)iTestParams.inPipe, iWriteBuf, KWaitSettingSize);
717 iCurrentXfer = EWaitSetting;
725 void CActiveRW::SendData()
727 __ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 663));
731 test_KErrNone(iSCWriteBuf.GetInBufferRange((TAny*&)inBuffer, inBufLength));
732 if (iDiskAccessEnabled)
734 TPtr8 writeBuf((TUint8 *)inBuffer,iBufSz,iBufSz);
735 ReadBufferFromDisk(writeBuf, iBufSz);
738 *reinterpret_cast<TUint32*>(inBuffer) = iPktNum;
740 if (iXferMode == ELoopComp)
742 for (TUint i = 4; i < iBufSz; i++)
744 *(inBuffer+i) = static_cast<TUint8>((iPktNum+i) & 0x000000ff);
747 TUSB_VERBOSE_PRINT3("SendData interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.inPipe);
748 iCurrentXfer = EWriteXfer;
749 TInt r = iSCWriteBuf.WriteBuffer(inBuffer, iBufSz, FALSE, iStatus);
752 if (iDiskAccessEnabled)
754 ReadBufferFromDisk(iWriteBuf, iBufSz);
756 iWriteBuf.SetLength(iBufSz);
758 *reinterpret_cast<TUint32*>(const_cast<TUint8*>(iWriteBuf.Ptr())) = iPktNum;
759 if (iXferMode == ELoopComp)
761 for (TUint i = 4; i < iBufSz; i++)
763 iWriteBuf[i] = static_cast<TUint8>((iPktNum+i) & 0x000000ff);
767 TUSB_VERBOSE_PRINT3("SendData interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.inPipe);
768 iCurrentXfer = EWriteXfer;
769 iPort->Write(iStatus, (TENDPOINTNUMBER)iTestParams.inPipe, iWriteBuf, iBufSz);
777 TInt CActiveRW::WriteToDisk(TChar aDriveLetter)
779 iDiskAccessEnabled = ETrue;
782 iFileName.Format(_L("%c:"), aDriveLetter.operator TUint());
783 iFileName.Append(KFileName);
784 TUSB_PRINT1("\nFilename = %S", &iFileName);
786 // open the record file
787 r = iFile.Replace(iFs, iFileName, EFileWrite);
791 TUSB_PRINT1("RFile::Replace() returned %d", r);
792 iDiskAccessEnabled = EFalse;
800 TInt CActiveRW::ReadFromDisk(TChar aDriveLetter, TInt aMaxFileSize)
802 iDiskAccessEnabled = ETrue;
805 iFileName.Format(_L("%c:"), aDriveLetter.operator TUint());
806 iFileName.Append(KFileName);
807 TUSB_PRINT1("\nFilename = %S", &iFileName);
808 TUSB_PRINT1("File size: %d", aMaxFileSize);
810 // First create the file & fill it
811 r = iFile.Replace(iFs, iFileName, EFileWrite);
814 TUSB_PRINT1("RFile::Replace() returned %d", r);
815 iDiskAccessEnabled = EFalse;
818 const TInt KBufferSize = 4 * 1024;
819 TBuf8<KBufferSize> buffer;
820 buffer.SetLength(KBufferSize);
821 for (TInt n = 0; n < KBufferSize; n++)
823 buffer[n] = static_cast<TUint8>(n & 0x000000ff);
825 TUSB_PRINT("Writing data to file (this may take some minutes...)");
826 for (TInt n = 0; n < aMaxFileSize; n += KBufferSize)
828 r = iFile.Write(buffer, KBufferSize);
831 TUSB_PRINT1("RFile::Write() returned %d (disk full?)", r);
833 iDiskAccessEnabled = EFalse;
839 // Now open the file for reading
840 r = iFile.Open(iFs, iFileName, EFileRead);
843 TUSB_PRINT1("RFile::Open() returned %d", r);
844 iDiskAccessEnabled = EFalse;
853 void CActiveRW::WriteBufferToDisk(TDes8& aBuffer, TInt aLen)
855 TUSB_VERBOSE_PRINT1("CActiveRW::WriteBufferToDisk(), len = %d", aLen);
856 TInt r = iFile.Write(aBuffer, aLen);
859 TUSB_PRINT2("Error writing to %S (%d)", &iFileName, r);
860 iDiskAccessEnabled = EFalse;
867 void CActiveRW::ReadBufferFromDisk(TDes8& aBuffer, TInt aLen)
869 const TInt r = iFile.Read(aBuffer, aLen);
872 TUSB_PRINT2("Error reading from %S (%d)", &iFileName, r);
873 iDiskAccessEnabled = EFalse;
876 TInt readLen = aBuffer.Length();
877 TUSB_VERBOSE_PRINT1("CActiveRW::ReadBufferFromDisk(), len = %d\n", readLen);
880 TUSB_PRINT3("Only %d bytes of %d read from file %S)",
881 readLen, aLen, &iFileName);
882 iDiskAccessEnabled = EFalse;
889 TUint CActiveRW::ReadData()
891 __ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 664));
892 iCurrentXfer = EReadXfer;
894 TUint readSize = 0; // note that this returns zero when asynchronous read is pending
898 r = iSCReadBuf.GetBuffer (iSCReadData,readSize,iReadZlp,iStatus);
899 test_Value(r, (r == KErrNone) || (r == KErrCompletion) || (r == KErrEof));
900 TUSB_VERBOSE_PRINT4("Get Buffer Return code %d Status %d DataPtr 0x%x Size %d", r, iStatus.Int(),iSCReadData,readSize);
902 while ((r == KErrCompletion && readSize == 0) || (r == KErrEof));
903 if (r == KErrCompletion)
916 iReadBuf.SetLength (0);
917 if (iBufSz <= iMaxPktSz)
919 // Testing the packet version of Read()
920 TUSB_VERBOSE_PRINT3("ReadData (single packet) interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe);
921 iPort->ReadPacket(iStatus, (TENDPOINTNUMBER)iTestParams.outPipe, iReadBuf, iBufSz);
923 else if ((TUint)iBufSz == iTestParams.maxSize)
925 // Testing the two-parameter version
926 TUSB_VERBOSE_PRINT3("ReadData (w/o length) interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe);
927 iPort->Read(iStatus, (TENDPOINTNUMBER)iTestParams.outPipe, iReadBuf);
931 // otherwise, we use the universal default version
932 // Testing the three-parameter version
933 TUSB_VERBOSE_PRINT3("ReadData (normal) interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe);
934 iPort->Read(iStatus, (TENDPOINTNUMBER)iTestParams.outPipe, iReadBuf, iBufSz);
945 void CActiveRW::Stop()
949 TUSB_PRINT("CActiveRW::Stop(): Not active");
952 TUSB_PRINT("Cancelling outstanding transfer requests\n");
956 iCurrentXfer = ETxferNone;
961 void CActiveRW::DoCancel()
963 TUSB_VERBOSE_PRINT("CActiveRW::DoCancel()");
964 // Canceling the transfer requests can be done explicitly
965 // for every transfer...
966 iPort->WriteCancel((TENDPOINTNUMBER)iTestParams.inPipe);
967 iPort->ReadCancel((TENDPOINTNUMBER)iTestParams.outPipe);
969 // iPort->EndpointTransferCancel(~0);
973 TBool CActiveRW::CompareBuffers()
975 TUSB_VERBOSE_PRINT2("CActiveRW::CompareBuffers() ReadOffset %d ReadSize %d",iReadOffset,iReadSize);
977 TUint8 *readPtr = reinterpret_cast<TUint8*>(iSCReadData);
980 test_KErrNone(iSCWriteBuf.GetInBufferRange((TAny*&)writePtr, inBufLength));
981 writePtr += iReadOffset;
983 for (TUint i = 0; i < iReadSize; i++)
986 if (*readPtr != *writePtr)
988 TUSB_PRINT3 ("*** Error while comparing tx & rx buffers packet 0x%x length %d index %d",iPktNum, iReadSize,i + iReadOffset);
989 TUSB_PRINT2 ("*** Read byte 0x%x Write byte 0x%x",*readPtr,*writePtr);
995 if (iReadBuf[i] != iWriteBuf[i + iReadOffset])
997 TUSB_PRINT3 ("*** Error while comparing tx & rx buffers packet 0x%x length %d index %d",iPktNum, iReadSize,i + iReadOffset);
998 TUSB_PRINT5 ("WriteBuf Start 0x%x 0x%x 0x%x 0x%x 0x%x",
999 iWriteBuf[i], iWriteBuf[i+1], iWriteBuf[i+2], iWriteBuf[i+3], iWriteBuf[i+4]);
1000 TUSB_PRINT5 ("ReadBuf Start 0x%x 0x%x 0x%x 0x%x 0x%x",
1001 iReadBuf[i], iReadBuf[i+1], iReadBuf[i+2], iReadBuf[i+3], iReadBuf[i+4]);
1002 if (iReadSize >= 10)
1004 TUSB_PRINT5 ("WriteBuf End 0x%x 0x%x 0x%x 0x%x 0x%x",
1005 iWriteBuf[iReadSize-5], iWriteBuf[iReadSize-4], iWriteBuf[iReadSize-3], iWriteBuf[iReadSize-2], iWriteBuf[iReadSize-1]);
1006 TUSB_PRINT5 ("ReadBuf End 0x%x 0x%x 0x%x 0x%x 0x%x",
1007 iReadBuf[iReadSize-5], iReadBuf[iReadSize-4], iReadBuf[iReadSize-3], iReadBuf[iReadSize-2], iReadBuf[iReadSize-1]);
1016 void CActiveRW::TestComplete(TBool aResult)
1018 TUSB_VERBOSE_PRINT("CActiveRW::TestComplete()");
1022 if (iComplete || !iResult || iTestParams.repeat == 0)