Update contrib.
1 // Copyright (c) 1996-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\device\t_loop.cpp
18 //#define _DEBUG_DEVCOMM
21 #include <e32base_private.h>
28 #if defined (__WINS__)
29 #define __COMM_LDD _L("ECOMM")
30 #define __COMM_PDD1 _L("ECDRV")
32 #define __COMM_LDD _L("ECOMM")
33 #define __COMM_PDD1 _L("EUART1")
34 #define __COMM_PDD2 _L("EUART2")
37 const char KSpinner[]={'|','/','-','\\',};
39 const TInt KKeyboardPriority = 4;
40 const TInt KTimerPriority = 3;
41 const TInt KWriterPriority = 2;
42 const TInt KReaderPriority = 1;
44 ////////////////////////////////////////////////////////////////////////////////
46 RTest Test(_L("T_LOOP"));
48 #define TEST(a) __DoTest((a), __FILE__, __LINE__, 0)
49 #define TESTERR(a,b) __DoTest((a), __FILE__, __LINE__, b)
51 void __DoTest(TBool aCondition, char* aFile, TInt aLine, TInt aErr)
57 Test.Printf(_L("\r\nCheckpoint Fail at %s:%d\r\n"), aFile, aLine);
59 Test.Printf(_L("\r\nCheckpoint Fail at %s:%d: Return code = %d (0x%x)\r\n"), aFile, aLine, aErr, aErr);
65 ////////////////////////////////////////////////////////////////////////////////
67 class CDevCommTestBase;
70 // inline void Read(TRequestStatus &aStatus) { iConsole->Read(aStatus); }
71 // inline void ReadCancel() { iConsole->ReadCancel(); }
72 // inline void TKeyCode KeyCode() { return iConsole->KeyCode(); }
75 class CKeyReader : public CActive
78 CKeyReader(CDevCommTestBase* aTester, RTest& aTest);
87 CDevCommTestBase* iTester;
90 class CDevCommIOBase : public CActive
93 CDevCommIOBase(CDevCommTestBase* aTester, TInt aPriority);
95 void CreateL(TInt aBufferSize);
99 CDevCommTestBase* iTester;
107 class CDevCommWriterBase : public CDevCommIOBase
110 CDevCommWriterBase(CDevCommTestBase* aTester);
111 ~CDevCommWriterBase();
119 class CDevCommReaderBase : public CDevCommIOBase
122 CDevCommReaderBase(CDevCommTestBase* aTester);
123 ~CDevCommReaderBase();
131 class CDevCommTimerBase : public CTimer
134 CDevCommTimerBase(CDevCommTestBase* aTester);
139 CDevCommTestBase* iTester;
149 class CDevCommTestBase : public CAsyncOneShot
154 void CreateL(TInt aBufferSize);
155 TInt Open(TInt aPort);
158 TInt SetHandshaking(THandshakeMode aMode);
161 TInt ZeroTerminate();
162 void ShowLoopSignals(TUint aOutState, TUint aInState);
163 virtual void ReadComplete(TInt aStatus);
164 virtual void WriteComplete(TInt aStatus);
165 virtual void TimeComplete(TInt aStatus);
166 virtual void KeyComplete(TKeyCode aKey);
170 CDevCommWriterBase* iWriter;
171 CDevCommReaderBase* iReader;
172 CDevCommTimerBase* iTimer;
173 CKeyReader* iKeyboard;
178 CKeyReader::CKeyReader(CDevCommTestBase* aTester, RTest& aTest)
179 : CActive(KKeyboardPriority), iTest(aTest), iTester(aTester)
181 __DECLARE_NAME(_S("CKeyReader"));
182 CActiveScheduler::Add(this);
185 CKeyReader::~CKeyReader()
190 void CKeyReader::Start()
195 iTest.Console()->Read(iStatus);
198 void CKeyReader::RunL()
200 iKey = iTest.Console()->KeyCode();
201 iTester->KeyComplete(iKey);
205 void CKeyReader::DoCancel()
207 iTest.Console()->ReadCancel();
212 CDevCommIOBase::CDevCommIOBase(CDevCommTestBase* aTester, TInt aPriority)
213 : CActive(aPriority), iTester(aTester), iDes(NULL, 0)
215 __DECLARE_NAME(_S("CDevCommIOBase"));
216 CActiveScheduler::Add(this);
219 CDevCommIOBase::~CDevCommIOBase()
225 void CDevCommIOBase::CreateL(TInt aSize)
229 iBuffer = (TUint8*)User::AllocL(iSize);
230 iDes.Set(iBuffer, iSize, iSize);
233 void CDevCommIOBase::UpdateCount()
235 iCount += iDes.Length();
236 iTotal += iDes.Length();
239 void CDevCommIOBase::ResetCount()
244 CDevCommWriterBase::CDevCommWriterBase(CDevCommTestBase* aTester)
245 : CDevCommIOBase(aTester, KWriterPriority)
247 __DECLARE_NAME(_S("CDevCommWriterBase"));
250 CDevCommWriterBase::~CDevCommWriterBase()
255 void CDevCommWriterBase::Start()
257 __ASSERT_ALWAYS(iBuffer!=NULL, User::Panic(_L("No Buffer"), 0));
261 iTester->iComm.Write(iStatus, iDes);
264 void CDevCommWriterBase::Ready()
269 iTester->iComm.Write(iStatus, TPtr8(NULL, 0));
272 void CDevCommWriterBase::RunL()
275 iTester->WriteComplete(iStatus.Int());
278 void CDevCommWriterBase::DoCancel()
280 iTester->iComm.WriteCancel();
284 CDevCommReaderBase::CDevCommReaderBase(CDevCommTestBase* aTester)
285 : CDevCommIOBase(aTester, KReaderPriority)
287 __DECLARE_NAME(_S("CDevCommReaderBase"));
290 CDevCommReaderBase::~CDevCommReaderBase()
295 void CDevCommReaderBase::Start()
297 __ASSERT_ALWAYS(iBuffer!=NULL, User::Panic(_L("No Buffer"), 0));
301 iDes.SetLength(iDes.MaxLength()-iCount);
302 iTester->iComm.Read(iStatus, iDes);
305 void CDevCommReaderBase::Ready()
311 iTester->iComm.Read(iStatus, ptr);
314 void CDevCommReaderBase::RunL()
317 iTester->ReadComplete(iStatus.Int());
320 void CDevCommReaderBase::DoCancel()
322 iTester->iComm.ReadCancel();
325 CDevCommTimerBase::CDevCommTimerBase(CDevCommTestBase* aTester)
326 : CTimer(KTimerPriority), iTester(aTester)
328 __DECLARE_NAME(_S("CDevCommTestTimerBase"));
329 CActiveScheduler::Add(this);
332 void CDevCommTimerBase::CreateL()
337 void CDevCommTimerBase::RunL()
339 iTester->TimeComplete(iStatus.Int());
342 CDevCommTestBase::CDevCommTestBase()
345 __DECLARE_NAME(_S("CDevCommTestBase"));
348 CDevCommTestBase::~CDevCommTestBase()
357 void CDevCommTestBase::CreateL(TInt aBufferSize)
359 iBufferSize = aBufferSize;
360 iKeyboard = new (ELeave) CKeyReader(this, Test);
361 iTimer = new (ELeave) CDevCommTimerBase(this);
362 iWriter = new (ELeave) CDevCommWriterBase(this);
363 iReader = new (ELeave) CDevCommReaderBase(this);
365 iWriter->CreateL(iBufferSize);
367 iReader->CreateL(iBufferSize/16);
370 void CDevCommTestBase::Start()
375 TInt CDevCommTestBase::Open(TInt aPort)
378 if (err = iComm.Open(aPort), err!=KErrNone)
382 TCommConfigV01 &c=cBuf();
385 c.iStopBits = EStop1;
386 c.iDataBits = EData8;
387 c.iParity = EParityNone;
400 c.iRate = EBps115200;
401 c.iFifo = EFifoEnable;
402 c.iTerminatorCount = 0;
403 c.iTerminator[0] = 0x00;
405 if (err = iComm.SetConfig(cBuf), err!=KErrNone)
414 TInt CDevCommTestBase::ZeroTerminate()
417 TCommConfigV01 &c=cBuf();
420 c.iTerminatorCount = 1;
421 c.iTerminator[0] = 0x00;
423 return iComm.SetConfig(cBuf);
426 void CDevCommTestBase::Close()
434 TInt CDevCommTestBase::SetHandshaking(THandshakeMode aMode)
437 TCommConfigV01 &c=cBuf();
456 case EHandshakeSoftware:
472 case EHandshakeHardware:
487 return iComm.SetConfig(cBuf);
490 TInt CDevCommTestBase::LineFailOn()
493 TCommConfigV01 &c=cBuf();
495 c.iHandshake |= (KConfigFailDSR|KConfigFailDCD);
496 return iComm.SetConfig(cBuf);
499 TInt CDevCommTestBase::LineFailOff()
502 TCommConfigV01 &c=cBuf();
504 c.iHandshake &= ~(KConfigFailDSR|KConfigFailDCD);
505 return iComm.SetConfig(cBuf);
508 void CDevCommTestBase::ShowLoopSignals(TUint aOutState, TUint aInState)
512 rts.Set(aOutState & KSignalRTS ? _L("RTS On ") : _L("RTS Off"));
513 dtr.Set(aOutState & KSignalDTR ? _L("DTR On ") : _L("DTR Off"));
514 Test.Printf(_L("%S, %S : "), &rts, &dtr);
515 cts.Set(aInState & KSignalCTS ? _L("CTS On ") : _L("CTS Off"));
516 dsr.Set(aInState & KSignalDSR ? _L("DSR On ") : _L("DSR Off"));
517 dcd.Set(aInState & KSignalDCD ? _L("DCD On ") : _L("DCD Off"));
518 Test.Printf(_L("%S, %S, %S "), &cts, &dsr, &dcd);
519 rts.Set(aInState & KSignalRTS ? _L("RTS On ") : _L("RTS Off"));
520 dtr.Set(aInState & KSignalDTR ? _L("DTR On ") : _L("DTR Off"));
521 Test.Printf(_L("[%S, %S]\r\n"), &rts, &dtr);
524 #ifdef _DEBUG_DEVCOMM
525 void CDevCommTestBase::Debug()
527 TCommDebugInfoPckg infopckg;
528 TCommDebugInfo& info = infopckg();
529 iComm.DebugInfo(infopckg);
531 Test.Printf(_L(" LDD State : TX RX \r\n"));
532 Test.Printf(_L(" Busy : %10d %10d\r\n"), info.iTxBusy, info.iRxBusy);
533 Test.Printf(_L(" Held : %10d %10d\r\n"), info.iTxHeld, info.iRxHeld);
534 Test.Printf(_L(" Length : %10d %10d\r\n"), info.iTxLength, info.iRxLength);
535 Test.Printf(_L(" Offset : %10d %10d\r\n"), info.iTxOffset, info.iRxOffset);
536 Test.Printf(_L(" Int Count : %10d %10d\r\n"), info.iTxIntCount, info.iRxIntCount);
537 Test.Printf(_L(" Err Count : %10d %10d\r\n"), info.iTxErrCount, info.iRxErrCount);
538 Test.Printf(_L(" Buf Count : %10d %10d\r\n"), info.iTxBufCount, info.iRxBufCount);
539 Test.Printf(_L(" Fill/Drain : %10d %10d\r\n"), info.iFillingTxBuf, info.iFillingTxBuf);
540 Test.Printf(_L(" XON : %10d %10d\r\n"), info.iTxXon, info.iRxXon);
541 Test.Printf(_L(" XOFF : %10d %10d\r\n"), info.iTxXoff, info.iRxXoff);
542 Test.Printf(_L(" Chars : %10d %10d\r\n"), info.iTxChars, info.iRxChars);
543 // Test.Printf(_L(" DFC Pending : %10d %10d\r\n"), info.iTxDfcPend, info.iTxDfcPend);
544 // Test.Printf(_L(" DFC Run/Count : %10d %10d\r\n"), info.iRunningDfc, info.iDfcCount);
545 // Test.Printf(_L(" DFC Req/Do/Drain : %10d %10d %10d\r\n"), info.iDfcReqSeq, info.iDfcHandlerSeq, info.iDoDrainSeq);
548 void CDevCommTestBase::Debug()
550 Test.Printf(_L("Debug Dump not available\r\n"));
554 void CDevCommTestBase::ReadComplete(TInt /*aStatus*/)
557 void CDevCommTestBase::WriteComplete(TInt /*aStatus*/)
560 void CDevCommTestBase::TimeComplete(TInt /*aStatus*/)
563 void CDevCommTestBase::KeyComplete(TKeyCode /*aKey*/)
566 ////////////////////////////////////////////////////////////////////////////////
568 void StripeMem(TUint8 *aBuf, TInt aStartPos, TInt anEndPos, TUint aStartChar, TUint anEndChar, TInt aOffset=0)
570 // Mark a buffer with repeating byte pattern
573 TUint character=aStartChar+(aOffset%((anEndChar+1)-aStartChar));
575 for (TInt i=aStartPos;i<anEndPos;i++)
577 aBuf[i]=(TText8)character;
578 if(++character>anEndChar)
579 character=aStartChar;
583 inline void StripeDes(TDes8 &aBuf, TInt aStartPos, TInt anEndPos, TUint aStartChar, TUint anEndChar, TInt aOffset=0)
585 StripeMem((TUint8 *)aBuf.Ptr(), aStartPos, anEndPos, aStartChar, anEndChar, aOffset);
588 TBool CheckMem(TUint8 *aBuf, TInt aStartPos, TInt anEndPos, TUint aStartChar, TUint anEndChar, TInt aOffset=0)
590 // Mark a buffer with repeating byte pattern
593 TUint character=aStartChar+(aOffset%((anEndChar+1)-aStartChar));
595 for (TInt i=aStartPos;i<anEndPos;i++)
597 if (aBuf[i]!=(TText8)character)
599 if(++character>anEndChar)
600 character=aStartChar;
605 inline TBool CheckDes(TDes8 &aBuf, TInt aStartPos, TInt anEndPos, TUint aStartChar, TUint anEndChar, TInt aOffset=0)
607 return CheckMem((TUint8 *)aBuf.Ptr(), aStartPos, anEndPos, aStartChar, anEndChar, aOffset);
610 ////////////////////////////////////////////////////////////////////////////////
615 Test.Printf(_L("Loading Drivers\r\n"));
616 ret = User::LoadPhysicalDevice(__COMM_PDD1);
617 TESTERR(ret==KErrNone || ret==KErrAlreadyExists, ret);
618 // ret = User::LoadPhysicalDevice(__COMM_PDD2);
619 // TESTERR(ret==KErrNone || ret==KErrAlreadyExists, ret);
620 ret = User::LoadLogicalDevice(__COMM_LDD);
621 TESTERR(ret==KErrNone || ret==KErrAlreadyExists, ret);
622 Test.Printf(_L("OK\r\n"));
625 ////////////////////////////////////////////////////////////////////////////////
627 class CTestRandTerm : public CDevCommTestBase
630 enum TTestRandTermState { EIdle, EWaitReady, EWaitReset, EWaitIO };
631 enum TTestFailType { ETestFailBoth, ETestFailRead, ETestFailWrite, ETestBadData };
633 static CTestRandTerm* NewL(TInt aPort);
636 virtual void ReadComplete(TInt aStatus);
637 virtual void WriteComplete(TInt aStatus);
638 virtual void TimeComplete(TInt aStatus);
639 virtual void KeyComplete(TKeyCode aKey);
645 void Fail(TTestFailType aType, TInt aError);
649 TTestRandTermState iState;
659 CTestRandTerm::CTestRandTerm()
663 CTestRandTerm::~CTestRandTerm()
667 CTestRandTerm* CTestRandTerm::NewL(TInt aPort)
669 CTestRandTerm* tester = new (ELeave) CTestRandTerm;
670 CleanupStack::PushL(tester);
671 tester->CreateL(1000);
672 User::LeaveIfError(tester->Open(aPort));
677 void CTestRandTerm::Reset()
679 Test.Printf(_L("Resetting Port\r\n"));
684 iComm.ResetBuffers();
685 iTimer->After(1000000);
689 void CTestRandTerm::RunL()
694 Test.Printf(_L("Waiting for Port\r\n"));
697 iTimer->After(1000000);
701 void CTestRandTerm::ReadComplete(TInt aStatus)
704 Test.Printf(_L("CTestRandTerm::ReadComplete(%d) len = %d/%d\r\n"), aStatus, iWriter->iDes.Length(), iWriter->iDes.MaxLength());
706 if (aStatus!=KErrNone)
708 Fail(ETestFailRead, aStatus);
720 if (iReader->iCount==iWriter->iCount)
722 iCount += iWriter->iCount;
723 Test.Printf(_L("%c %6d %d\r"), KSpinner[iSpin++ & 3], iPackets, iCount);
729 iOffset = iReader->iCount;
730 Test.Printf(_L("%c\r"), KSpinner[iSpin++ & 3]);
736 Fail(ETestBadData, KErrNone);
744 void CTestRandTerm::WriteComplete(TInt aStatus)
748 Test.Printf(_L("CTestRandTerm::WriteComplete(%d) len = %d/%d\r\n"), aStatus, iWriter->iDes.Length(), iWriter->iDes.MaxLength());
751 if (aStatus!=KErrNone)
753 Fail(ETestFailWrite, aStatus);
763 Test.Printf(_L("Port Ready\r\n"));
770 if (iReader->iCount==iWriter->iCount)
781 void CTestRandTerm::TimeComplete(TInt aStatus)
784 Test.Printf(_L("CTestRandTerm::TimeComplete(%d)\r\n"), aStatus);
786 if (aStatus!=KErrNone)
795 Test.Printf(_L("Waiting for Port\r\n"));
797 iTimer->After(1000000);
803 Test.Printf(_L("Too many retries\r\n"));
808 Test.Printf(_L("%c\r"), KSpinner[iSpin++ & 3]);
810 iTimer->After(1000000);
814 Fail(ETestFailBoth, KErrTimedOut);
823 void CTestRandTerm::KeyComplete(TKeyCode aKey)
826 Test.Printf(_L("CTestRandTerm::KeyComplete(%d)\r\n"), aKey);
851 void CTestRandTerm::Fail(TTestFailType aType, TInt aError)
856 Test.Printf(_L("Timeout at offset %d\r\n"), iOffset);
859 Test.Printf(_L("Read fail (%d) at offset %d\r\n"), aError, iOffset);
862 Test.Printf(_L("Write fail (%d) at offset %d\r\n"), aError, iOffset);
865 Test.Printf(_L("Data verify failure at offset %d\r\n"), iOffset);
873 void CTestRandTerm::Write()
876 iWriter->ResetCount();
877 iReader->ResetCount();
881 StripeDes(iWriter->iDes, 0, iBufferSize, '@', 'Z');
882 while (j<iBufferSize)
884 i = Math::Rand(iSeed) % (iBufferSize/4);
886 iWriter->iDes[j+i] = '\0';
894 void CTestRandTerm::Read()
897 iTimer->After(5000000);
901 TBool CTestRandTerm::CheckRead()
904 ref.Set(iWriter->iDes.Ptr()+iOffset, iReader->iDes.Length());
905 return ref.Compare(iReader->iDes)==0;
908 void CTestRandTerm::Halt()
913 CActiveScheduler::Stop();
916 ////////////////////////////////////////////////////////////////////////////////
919 class CTestSignals : public CDevCommTestBase
922 enum TTestState { EAllOff, ERtsOn, EDtrOn, EAllOn, EMonitor };
924 static CTestSignals* NewL(TInt aPort);
927 virtual void KeyComplete(TKeyCode aKey);
928 virtual void ReadComplete(TInt aStatus);
930 void DoSignals(TTestState aState);
937 CTestSignals::CTestSignals()
941 CTestSignals::~CTestSignals()
945 CTestSignals* CTestSignals::NewL(TInt aPort)
947 CTestSignals* tester = new (ELeave) CTestSignals;
948 CleanupStack::PushL(tester);
950 User::LeaveIfError(tester->Open(aPort));
955 void CTestSignals::RunL()
958 TCommConfigV01 &c=cBuf();
960 c.iHandshake = KConfigFreeRTS | KConfigFreeDTR;
961 iComm.SetConfig(cBuf);
966 void CTestSignals::Halt()
968 Test.Printf(_L(" \r"));
969 CActiveScheduler::Stop();
972 void CTestSignals::ReadComplete(TInt /*aStatus*/)
977 void CTestSignals::KeyComplete(TKeyCode aKey)
1005 void CTestSignals::DoSignals(TTestState aState)
1013 clr = KSignalRTS | KSignalDTR;
1024 set = KSignalRTS | KSignalDTR;
1031 iComm.SetSignals(set, clr);
1032 TUint sig = iComm.Signals();
1033 ShowLoopSignals(set, sig);
1035 Test.Printf(_L("Press key for next state\r"));
1038 ////////////////////////////////////////////////////////////////////////////////
1040 class CTestPerf : public CDevCommTestBase
1043 enum TTestRandTermState { EIdle, EWaitReady, EWaitReset, EWaitIO };
1044 enum TTestFailType { ETestFailBoth, ETestFailRead, ETestFailWrite, ETestBadData };
1046 static CTestPerf* NewL(TInt aPort);
1049 virtual void ReadComplete(TInt aStatus);
1050 virtual void WriteComplete(TInt aStatus);
1051 virtual void TimeComplete(TInt aStatus);
1052 virtual void KeyComplete(TKeyCode aKey);
1058 void Fail(TTestFailType aType, TInt aError);
1060 virtual void RunL();
1062 TTestRandTermState iState;
1075 CTestPerf::CTestPerf()
1079 CTestPerf::~CTestPerf()
1083 CTestPerf* CTestPerf::NewL(TInt aPort)
1085 CTestPerf* tester = new (ELeave) CTestPerf;
1086 CleanupStack::PushL(tester);
1087 tester->CreateL(250);
1088 User::LeaveIfError(tester->Open(aPort));
1089 CleanupStack::Pop();
1090 StripeDes(tester->iWriter->iDes, 0, tester->iBufferSize, '@', 'Z');
1094 void CTestPerf::Reset()
1096 Test.Printf(_L("Resetting Port\r\n"));
1101 iComm.ResetBuffers();
1102 iTimer->After(1000000);
1103 iState = EWaitReset;
1106 void CTestPerf::RunL()
1111 Test.Printf(_L("Waiting for Port\r\n"));
1114 iTimer->After(1000000);
1115 iState = EWaitReady;
1118 void CTestPerf::ReadComplete(TInt aStatus)
1121 Test.Printf(_L("CTestPerf::ReadComplete(%d) len = %d/%d\r\n"), aStatus, iWriter->iDes.Length(), iWriter->iDes.MaxLength());
1123 if (aStatus!=KErrNone)
1125 Fail(ETestFailRead, aStatus);
1134 iCount += iReader->iCount;
1138 end.UniversalTime();
1139 TInt64 difftime = (end.MicroSecondsFrom(iStartTime).Int64()+TInt64(500000))/TInt64(1000000);
1142 TInt64 cps = MAKE_TINT64(0,iCount)/difftime;
1143 TInt rate = (I64INT(cps)*10000)/11520;
1146 iSpeed += I64INT(cps);
1148 Test.Printf(_L("%c %6d %d (%dbps=%d.%02d%%)\r"), KSpinner[iSpin++ & 3], iPackets, iCount, iSpeed/iPackets, (iRate/iPackets)/100, (iRate/iPackets)%100);
1157 void CTestPerf::WriteComplete(TInt aStatus)
1161 Test.Printf(_L("CTestPerf::WriteComplete(%d) len = %d/%d\r\n"), aStatus, iWriter->iDes.Length(), iWriter->iDes.MaxLength());
1164 if (aStatus!=KErrNone)
1166 Fail(ETestFailWrite, aStatus);
1176 Test.Printf(_L("Port Ready\r\n"));
1178 iStartTime.UniversalTime();;
1191 void CTestPerf::TimeComplete(TInt aStatus)
1194 Test.Printf(_L("CTestPerf::TimeComplete(%d)\r\n"), aStatus);
1196 if (aStatus!=KErrNone)
1205 Test.Printf(_L("Waiting for Port\r\n"));
1207 iTimer->After(1000000);
1208 iState = EWaitReady;
1213 Test.Printf(_L("Too many retries\r\n"));
1218 Test.Printf(_L("%c\r"), KSpinner[iSpin++ & 3]);
1220 iTimer->After(1000000);
1224 Fail(ETestFailBoth, KErrTimedOut);
1233 void CTestPerf::KeyComplete(TKeyCode aKey)
1236 Test.Printf(_L("CTestPerf::KeyComplete(%d)\r\n"), aKey);
1245 Test.Printf(_L("\r\n"));
1258 Test.Printf(_L("\r\n"));
1259 Test.Printf(_L("Keyboard : %08x, %d\r\n"), iKeyboard->iStatus.Int(), iKeyboard->IsActive());
1260 Test.Printf(_L("Timer : %08x, %d\r\n"), iTimer->iStatus.Int(), iTimer->IsActive());
1261 Test.Printf(_L("Reader : %08x, %d\r\n"), iReader->iStatus.Int(), iReader->IsActive());
1262 Test.Printf(_L("Writer : %08x, %d\r\n"), iWriter->iStatus.Int(), iWriter->IsActive());
1270 void CTestPerf::Fail(TTestFailType aType, TInt aError)
1275 Test.Printf(_L("\r\nTimeout at offset %d\r\n"), iOffset);
1278 Test.Printf(_L("\r\nRead fail (%d) at offset %d\r\n"), aError, iOffset);
1280 case ETestFailWrite:
1281 Test.Printf(_L("\r\nWrite fail (%d) at offset %d\r\n"), aError, iOffset);
1284 Test.Printf(_L("\r\nData verify failure at offset %d\r\n"), iOffset);
1292 void CTestPerf::Write()
1295 iWriter->ResetCount();
1299 void CTestPerf::Read()
1301 iReader->ResetCount();
1303 iTimer->After(5000000);
1306 TBool CTestPerf::CheckRead()
1309 ref.Set(iWriter->iDes.Ptr()+iOffset, iReader->iDes.Length());
1310 return ref.Compare(iReader->iDes)==0;
1313 void CTestPerf::Halt()
1318 CActiveScheduler::Stop();
1321 ////////////////////////////////////////////////////////////////////////////////
1323 class CTestXonXoff : public CDevCommTestBase
1326 enum TTestRandTermState { EIdle, EWaitReady, EWaitReset, EWaitIO };
1327 enum TTestFailType { ETestFailBoth, ETestFailRead, ETestFailWrite, ETestBadData };
1329 static CTestXonXoff* NewL(TInt aPort);
1332 virtual void ReadComplete(TInt aStatus);
1333 virtual void WriteComplete(TInt aStatus);
1334 virtual void TimeComplete(TInt aStatus);
1335 virtual void KeyComplete(TKeyCode aKey);
1341 void Fail(TTestFailType aType, TInt aError);
1343 virtual void RunL();
1345 TTestRandTermState iState;
1358 CTestXonXoff::CTestXonXoff()
1362 CTestXonXoff::~CTestXonXoff()
1366 CTestXonXoff* CTestXonXoff::NewL(TInt aPort)
1368 CTestXonXoff* tester = new (ELeave) CTestXonXoff;
1369 CleanupStack::PushL(tester);
1370 tester->CreateL(16384);
1371 User::LeaveIfError(tester->Open(aPort));
1372 User::LeaveIfError(tester->SetHandshaking(EHandshakeSoftware));
1373 CleanupStack::Pop();
1374 StripeDes(tester->iWriter->iDes, 0, tester->iBufferSize, '@', 'Z');
1378 void CTestXonXoff::Reset()
1380 Test.Printf(_L("Resetting Port\r\n"));
1385 iComm.ResetBuffers();
1386 iTimer->After(1000000);
1387 iState = EWaitReset;
1390 void CTestXonXoff::RunL()
1395 Test.Printf(_L("Waiting for Port\r\n"));
1399 iTimer->After(1000000);
1401 // iState = EWaitReady;
1402 // WriteComplete(0);
1405 void CTestXonXoff::ReadComplete(TInt aStatus)
1408 Test.Printf(_L("CTestXonXoff::ReadComplete(%d) len = %d/%d (%d)\r\n"), aStatus, iReader->iDes.Length(), iReader->iDes.MaxLength(), iReader->iTotal);
1410 if (aStatus!=KErrNone)
1412 Fail(ETestFailRead, aStatus);
1421 if (!CheckDes(iReader->iDes, 0, iReader->iDes.Length(), '@', 'Z', iCount & 0x3fff))
1423 Fail(ETestBadData, aStatus);
1426 iCount += iReader->iCount;
1430 end.UniversalTime();
1431 TInt64 difftime = (end.MicroSecondsFrom(iStartTime).Int64()+TInt64(500000))/TInt64(1000000);
1434 TInt64 cps = MAKE_TINT64(0,iCount)/difftime;
1435 TInt rate = (I64INT(cps)*10000)/11520;
1437 iSpeed += I64INT(cps);
1438 Test.Printf(_L("%c %6d %d (%dbps=%d.%02d%%)\r"), KSpinner[iSpin++ & 3], iPackets, iCount, iSpeed/iPackets, (iRate/iPackets)/100, (iRate/iPackets)%100);
1447 void CTestXonXoff::WriteComplete(TInt aStatus)
1451 Test.Printf(_L("CTestXonXoff::WriteComplete(%d) len = %d/%d (%d)\r\n"), aStatus, iWriter->iDes.Length(), iWriter->iDes.MaxLength(), iWriter->iTotal);
1454 if (aStatus!=KErrNone)
1456 Fail(ETestFailWrite, aStatus);
1466 Test.Printf(_L("Port Ready\r\n"));
1468 iStartTime.UniversalTime();;
1481 void CTestXonXoff::TimeComplete(TInt aStatus)
1484 Test.Printf(_L("CTestXonXoff::TimeComplete(%d)\r\n"), aStatus);
1486 if (aStatus!=KErrNone)
1495 Test.Printf(_L("Waiting for Port\r\n"));
1497 iTimer->After(1000000);
1498 iState = EWaitReady;
1503 Test.Printf(_L("Too many retries\r\n"));
1508 Test.Printf(_L("%c\r"), KSpinner[iSpin++ & 3]);
1510 iTimer->After(1000000);
1514 Fail(ETestFailBoth, KErrTimedOut);
1523 void CTestXonXoff::KeyComplete(TKeyCode aKey)
1526 Test.Printf(_L("CTestXonXoff::KeyComplete(%d)\r\n"), aKey);
1535 Test.Printf(_L("\r\n"));
1548 Test.Printf(_L("\r\n"));
1549 Test.Printf(_L("Keyboard : %08x, %d\r\n"), iKeyboard->iStatus.Int(), iKeyboard->IsActive());
1550 Test.Printf(_L("Timer : %08x, %d\r\n"), iTimer->iStatus.Int(), iTimer->IsActive());
1551 Test.Printf(_L("Reader : %08x, %d\r\n"), iReader->iStatus.Int(), iReader->IsActive());
1552 Test.Printf(_L("Writer : %08x, %d\r\n"), iWriter->iStatus.Int(), iWriter->IsActive());
1560 void CTestXonXoff::Fail(TTestFailType aType, TInt aError)
1565 Test.Printf(_L("\r\nTimeout at offset %d\r\n"), iOffset);
1568 Test.Printf(_L("\r\nRead fail (%d) at offset %d\r\n"), aError, iOffset);
1570 case ETestFailWrite:
1571 Test.Printf(_L("\r\nWrite fail (%d) at offset %d\r\n"), aError, iOffset);
1574 Test.Printf(_L("\r\nData verify failure at offset %d\r\n"), iOffset);
1582 void CTestXonXoff::Write()
1585 iWriter->ResetCount();
1586 StripeDes(iWriter->iDes, 0, iWriter->iDes.Length(), '@', 'Z');
1590 void CTestXonXoff::Read()
1592 User::After(1000000);
1593 iReader->ResetCount();
1595 iTimer->After(5000000);
1598 TBool CTestXonXoff::CheckRead()
1601 ref.Set(iWriter->iDes.Ptr()+iOffset, iReader->iDes.Length());
1602 return ref.Compare(iReader->iDes)==0;
1605 void CTestXonXoff::Halt()
1610 CActiveScheduler::Stop();
1614 ////////////////////////////////////////////////////////////////////////////////
1620 Test.Start(_L("Comm Driver Tests"));
1622 Test.Printf(_L("Insert plug in then press a key\r\n"));
1625 TEST(CTrapCleanup::New()!=NULL);
1626 CActiveScheduler* Scheduler = new CActiveScheduler;
1627 TEST(Scheduler!=NULL);
1628 CActiveScheduler::Install(Scheduler);
1630 CTestSignals* testsignals = NULL;
1631 TRAP(err, testsignals = CTestSignals::NewL(0));
1632 TEST(err==KErrNone);
1633 testsignals->Start();
1637 CTestRandTerm* testrandterm = NULL;
1638 TRAP(err, testrandterm = CTestRandTerm::NewL(0));
1639 TEST(err==KErrNone);
1640 testrandterm->Start();
1642 delete testrandterm;
1644 CTestPerf* testperf = NULL;
1645 TRAP(err, testperf = CTestPerf::NewL(0));
1646 TEST(err==KErrNone);
1652 CTestXonXoff* testx = NULL;
1653 TRAP(err, testx = CTestXonXoff::NewL(0));
1654 TEST(err==KErrNone);
1660 CTestXonXoff* testx1 = NULL;
1661 TRAP(err, testx1 = CTestXonXoff::NewL(0));
1662 TEST(err==KErrNone);
1665 CTestXonXoff* testx2 = NULL;
1666 TRAP(err, testx2 = CTestXonXoff::NewL(1));
1667 TEST(err==KErrNone);