|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32test\device\t_loop.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 //#define _DEBUG_DEVCOMM |
|
19 |
|
20 #include <e32base.h> |
|
21 #include <e32base_private.h> |
|
22 #include <e32test.h> |
|
23 #include <e32svr.h> |
|
24 #include <d32comm.h> |
|
25 #include <e32math.h> |
|
26 #include <e32uid.h> |
|
27 |
|
28 #if defined (__WINS__) |
|
29 #define __COMM_LDD _L("ECOMM") |
|
30 #define __COMM_PDD1 _L("ECDRV") |
|
31 #else |
|
32 #define __COMM_LDD _L("ECOMM") |
|
33 #define __COMM_PDD1 _L("EUART1") |
|
34 #define __COMM_PDD2 _L("EUART2") |
|
35 #endif |
|
36 |
|
37 const char KSpinner[]={'|','/','-','\\',}; |
|
38 |
|
39 const TInt KKeyboardPriority = 4; |
|
40 const TInt KTimerPriority = 3; |
|
41 const TInt KWriterPriority = 2; |
|
42 const TInt KReaderPriority = 1; |
|
43 |
|
44 //////////////////////////////////////////////////////////////////////////////// |
|
45 |
|
46 RTest Test(_L("T_LOOP")); |
|
47 |
|
48 #define TEST(a) __DoTest((a), __FILE__, __LINE__, 0) |
|
49 #define TESTERR(a,b) __DoTest((a), __FILE__, __LINE__, b) |
|
50 |
|
51 void __DoTest(TBool aCondition, char* aFile, TInt aLine, TInt aErr) |
|
52 { |
|
53 if (aCondition) |
|
54 return; |
|
55 |
|
56 if (aErr==0) |
|
57 Test.Printf(_L("\r\nCheckpoint Fail at %s:%d\r\n"), aFile, aLine); |
|
58 else |
|
59 Test.Printf(_L("\r\nCheckpoint Fail at %s:%d: Return code = %d (0x%x)\r\n"), aFile, aLine, aErr, aErr); |
|
60 __DEBUGGER(); |
|
61 Test.Getch(); |
|
62 User::Exit(aErr); |
|
63 } |
|
64 |
|
65 //////////////////////////////////////////////////////////////////////////////// |
|
66 |
|
67 class CDevCommTestBase; |
|
68 |
|
69 // This needs: |
|
70 // inline void Read(TRequestStatus &aStatus) { iConsole->Read(aStatus); } |
|
71 // inline void ReadCancel() { iConsole->ReadCancel(); } |
|
72 // inline void TKeyCode KeyCode() { return iConsole->KeyCode(); } |
|
73 // adding to RTest |
|
74 |
|
75 class CKeyReader : public CActive |
|
76 { |
|
77 public: |
|
78 CKeyReader(CDevCommTestBase* aTester, RTest& aTest); |
|
79 ~CKeyReader(); |
|
80 void Start(); |
|
81 protected: |
|
82 void RunL(); |
|
83 void DoCancel(); |
|
84 public: |
|
85 RTest& iTest; |
|
86 TKeyCode iKey; |
|
87 CDevCommTestBase* iTester; |
|
88 }; |
|
89 |
|
90 class CDevCommIOBase : public CActive |
|
91 { |
|
92 public: |
|
93 CDevCommIOBase(CDevCommTestBase* aTester, TInt aPriority); |
|
94 ~CDevCommIOBase(); |
|
95 void CreateL(TInt aBufferSize); |
|
96 void UpdateCount(); |
|
97 void ResetCount(); |
|
98 public: |
|
99 CDevCommTestBase* iTester; |
|
100 TPtr8 iDes; |
|
101 TUint8* iBuffer; |
|
102 TInt iSize; |
|
103 TInt iCount; |
|
104 TInt iTotal; |
|
105 }; |
|
106 |
|
107 class CDevCommWriterBase : public CDevCommIOBase |
|
108 { |
|
109 public: |
|
110 CDevCommWriterBase(CDevCommTestBase* aTester); |
|
111 ~CDevCommWriterBase(); |
|
112 void Ready(); |
|
113 void Start(); |
|
114 protected: |
|
115 void RunL(); |
|
116 void DoCancel(); |
|
117 }; |
|
118 |
|
119 class CDevCommReaderBase : public CDevCommIOBase |
|
120 { |
|
121 public: |
|
122 CDevCommReaderBase(CDevCommTestBase* aTester); |
|
123 ~CDevCommReaderBase(); |
|
124 void Ready(); |
|
125 void Start(); |
|
126 protected: |
|
127 void RunL(); |
|
128 void DoCancel(); |
|
129 }; |
|
130 |
|
131 class CDevCommTimerBase : public CTimer |
|
132 { |
|
133 public: |
|
134 CDevCommTimerBase(CDevCommTestBase* aTester); |
|
135 void CreateL(); |
|
136 protected: |
|
137 void RunL(); |
|
138 public: |
|
139 CDevCommTestBase* iTester; |
|
140 }; |
|
141 |
|
142 enum THandshakeMode |
|
143 { |
|
144 EHandshakeNone, |
|
145 EHandshakeHardware, |
|
146 EHandshakeSoftware |
|
147 }; |
|
148 |
|
149 class CDevCommTestBase : public CAsyncOneShot |
|
150 { |
|
151 public: |
|
152 CDevCommTestBase(); |
|
153 ~CDevCommTestBase(); |
|
154 void CreateL(TInt aBufferSize); |
|
155 TInt Open(TInt aPort); |
|
156 void Close(); |
|
157 void Debug(); |
|
158 TInt SetHandshaking(THandshakeMode aMode); |
|
159 TInt LineFailOn(); |
|
160 TInt LineFailOff(); |
|
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); |
|
167 void Start(); |
|
168 public: |
|
169 RBusDevComm iComm; |
|
170 CDevCommWriterBase* iWriter; |
|
171 CDevCommReaderBase* iReader; |
|
172 CDevCommTimerBase* iTimer; |
|
173 CKeyReader* iKeyboard; |
|
174 TInt iBufferSize; |
|
175 }; |
|
176 |
|
177 |
|
178 CKeyReader::CKeyReader(CDevCommTestBase* aTester, RTest& aTest) |
|
179 : CActive(KKeyboardPriority), iTest(aTest), iTester(aTester) |
|
180 { |
|
181 __DECLARE_NAME(_S("CKeyReader")); |
|
182 CActiveScheduler::Add(this); |
|
183 } |
|
184 |
|
185 CKeyReader::~CKeyReader() |
|
186 { |
|
187 Cancel(); |
|
188 } |
|
189 |
|
190 void CKeyReader::Start() |
|
191 { |
|
192 if (IsActive()) |
|
193 return; |
|
194 SetActive(); |
|
195 iTest.Console()->Read(iStatus); |
|
196 } |
|
197 |
|
198 void CKeyReader::RunL() |
|
199 { |
|
200 iKey = iTest.Console()->KeyCode(); |
|
201 iTester->KeyComplete(iKey); |
|
202 Start(); |
|
203 } |
|
204 |
|
205 void CKeyReader::DoCancel() |
|
206 { |
|
207 iTest.Console()->ReadCancel(); |
|
208 } |
|
209 |
|
210 |
|
211 |
|
212 CDevCommIOBase::CDevCommIOBase(CDevCommTestBase* aTester, TInt aPriority) |
|
213 : CActive(aPriority), iTester(aTester), iDes(NULL, 0) |
|
214 { |
|
215 __DECLARE_NAME(_S("CDevCommIOBase")); |
|
216 CActiveScheduler::Add(this); |
|
217 } |
|
218 |
|
219 CDevCommIOBase::~CDevCommIOBase() |
|
220 { |
|
221 if (iBuffer) |
|
222 User::Free(iBuffer); |
|
223 } |
|
224 |
|
225 void CDevCommIOBase::CreateL(TInt aSize) |
|
226 { |
|
227 iSize = aSize; |
|
228 if (iSize>0) |
|
229 iBuffer = (TUint8*)User::AllocL(iSize); |
|
230 iDes.Set(iBuffer, iSize, iSize); |
|
231 } |
|
232 |
|
233 void CDevCommIOBase::UpdateCount() |
|
234 { |
|
235 iCount += iDes.Length(); |
|
236 iTotal += iDes.Length(); |
|
237 } |
|
238 |
|
239 void CDevCommIOBase::ResetCount() |
|
240 { |
|
241 iCount = 0; |
|
242 } |
|
243 |
|
244 CDevCommWriterBase::CDevCommWriterBase(CDevCommTestBase* aTester) |
|
245 : CDevCommIOBase(aTester, KWriterPriority) |
|
246 { |
|
247 __DECLARE_NAME(_S("CDevCommWriterBase")); |
|
248 } |
|
249 |
|
250 CDevCommWriterBase::~CDevCommWriterBase() |
|
251 { |
|
252 Cancel(); |
|
253 } |
|
254 |
|
255 void CDevCommWriterBase::Start() |
|
256 { |
|
257 __ASSERT_ALWAYS(iBuffer!=NULL, User::Panic(_L("No Buffer"), 0)); |
|
258 if (IsActive()) |
|
259 return; |
|
260 SetActive(); |
|
261 iTester->iComm.Write(iStatus, iDes); |
|
262 } |
|
263 |
|
264 void CDevCommWriterBase::Ready() |
|
265 { |
|
266 if (IsActive()) |
|
267 return; |
|
268 SetActive(); |
|
269 iTester->iComm.Write(iStatus, TPtr8(NULL, 0)); |
|
270 } |
|
271 |
|
272 void CDevCommWriterBase::RunL() |
|
273 { |
|
274 UpdateCount(); |
|
275 iTester->WriteComplete(iStatus.Int()); |
|
276 } |
|
277 |
|
278 void CDevCommWriterBase::DoCancel() |
|
279 { |
|
280 iTester->iComm.WriteCancel(); |
|
281 } |
|
282 |
|
283 |
|
284 CDevCommReaderBase::CDevCommReaderBase(CDevCommTestBase* aTester) |
|
285 : CDevCommIOBase(aTester, KReaderPriority) |
|
286 { |
|
287 __DECLARE_NAME(_S("CDevCommReaderBase")); |
|
288 } |
|
289 |
|
290 CDevCommReaderBase::~CDevCommReaderBase() |
|
291 { |
|
292 Cancel(); |
|
293 } |
|
294 |
|
295 void CDevCommReaderBase::Start() |
|
296 { |
|
297 __ASSERT_ALWAYS(iBuffer!=NULL, User::Panic(_L("No Buffer"), 0)); |
|
298 if (IsActive()) |
|
299 return; |
|
300 SetActive(); |
|
301 iDes.SetLength(iDes.MaxLength()-iCount); |
|
302 iTester->iComm.Read(iStatus, iDes); |
|
303 } |
|
304 |
|
305 void CDevCommReaderBase::Ready() |
|
306 { |
|
307 if (IsActive()) |
|
308 return; |
|
309 SetActive(); |
|
310 TPtr8 ptr(NULL, 0); |
|
311 iTester->iComm.Read(iStatus, ptr); |
|
312 } |
|
313 |
|
314 void CDevCommReaderBase::RunL() |
|
315 { |
|
316 UpdateCount(); |
|
317 iTester->ReadComplete(iStatus.Int()); |
|
318 } |
|
319 |
|
320 void CDevCommReaderBase::DoCancel() |
|
321 { |
|
322 iTester->iComm.ReadCancel(); |
|
323 } |
|
324 |
|
325 CDevCommTimerBase::CDevCommTimerBase(CDevCommTestBase* aTester) |
|
326 : CTimer(KTimerPriority), iTester(aTester) |
|
327 { |
|
328 __DECLARE_NAME(_S("CDevCommTestTimerBase")); |
|
329 CActiveScheduler::Add(this); |
|
330 } |
|
331 |
|
332 void CDevCommTimerBase::CreateL() |
|
333 { |
|
334 ConstructL(); |
|
335 } |
|
336 |
|
337 void CDevCommTimerBase::RunL() |
|
338 { |
|
339 iTester->TimeComplete(iStatus.Int()); |
|
340 } |
|
341 |
|
342 CDevCommTestBase::CDevCommTestBase() |
|
343 : CAsyncOneShot(-1) |
|
344 { |
|
345 __DECLARE_NAME(_S("CDevCommTestBase")); |
|
346 } |
|
347 |
|
348 CDevCommTestBase::~CDevCommTestBase() |
|
349 { |
|
350 delete iKeyboard; |
|
351 delete iTimer; |
|
352 delete iWriter; |
|
353 delete iReader; |
|
354 iComm.Close(); |
|
355 } |
|
356 |
|
357 void CDevCommTestBase::CreateL(TInt aBufferSize) |
|
358 { |
|
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); |
|
364 iKeyboard->Start(); |
|
365 iWriter->CreateL(iBufferSize); |
|
366 iTimer->CreateL(); |
|
367 iReader->CreateL(iBufferSize/16); |
|
368 } |
|
369 |
|
370 void CDevCommTestBase::Start() |
|
371 { |
|
372 Call(); |
|
373 } |
|
374 |
|
375 TInt CDevCommTestBase::Open(TInt aPort) |
|
376 { |
|
377 TInt err; |
|
378 if (err = iComm.Open(aPort), err!=KErrNone) |
|
379 return err; |
|
380 |
|
381 TCommConfig cBuf; |
|
382 TCommConfigV01 &c=cBuf(); |
|
383 iComm.Config(cBuf); |
|
384 |
|
385 c.iStopBits = EStop1; |
|
386 c.iDataBits = EData8; |
|
387 c.iParity = EParityNone; |
|
388 c.iHandshake = 0 |
|
389 // | KConfigObeyXoff |
|
390 // | KConfigSendXoff |
|
391 | KConfigObeyCTS |
|
392 // | KConfigFailCTS |
|
393 | KConfigObeyDSR |
|
394 // | KConfigFailDSR |
|
395 // | KConfigObeyDCD |
|
396 // | KConfigFailDCD |
|
397 // | KConfigFreeRTS |
|
398 // | KConfigFreeDTR |
|
399 ; |
|
400 c.iRate = EBps115200; |
|
401 c.iFifo = EFifoEnable; |
|
402 c.iTerminatorCount = 0; |
|
403 c.iTerminator[0] = 0x00; |
|
404 |
|
405 if (err = iComm.SetConfig(cBuf), err!=KErrNone) |
|
406 { |
|
407 iComm.Close(); |
|
408 return err; |
|
409 } |
|
410 return KErrNone; |
|
411 } |
|
412 |
|
413 |
|
414 TInt CDevCommTestBase::ZeroTerminate() |
|
415 { |
|
416 TCommConfig cBuf; |
|
417 TCommConfigV01 &c=cBuf(); |
|
418 iComm.Config(cBuf); |
|
419 |
|
420 c.iTerminatorCount = 1; |
|
421 c.iTerminator[0] = 0x00; |
|
422 |
|
423 return iComm.SetConfig(cBuf); |
|
424 } |
|
425 |
|
426 void CDevCommTestBase::Close() |
|
427 { |
|
428 iTimer->Cancel(); |
|
429 iReader->Cancel(); |
|
430 iWriter->Cancel(); |
|
431 iComm.Close(); |
|
432 } |
|
433 |
|
434 TInt CDevCommTestBase::SetHandshaking(THandshakeMode aMode) |
|
435 { |
|
436 TCommConfig cBuf; |
|
437 TCommConfigV01 &c=cBuf(); |
|
438 iComm.Config(cBuf); |
|
439 |
|
440 switch (aMode) |
|
441 { |
|
442 case EHandshakeNone: |
|
443 c.iHandshake = 0 |
|
444 // | KConfigObeyXoff |
|
445 // | KConfigSendXoff |
|
446 // | KConfigObeyCTS |
|
447 // | KConfigFailCTS |
|
448 // | KConfigObeyDSR |
|
449 // | KConfigFailDSR |
|
450 // | KConfigObeyDCD |
|
451 // | KConfigFailDCD |
|
452 | KConfigFreeRTS |
|
453 | KConfigFreeDTR |
|
454 ; |
|
455 break; |
|
456 case EHandshakeSoftware: |
|
457 c.iXonChar=0x11; |
|
458 c.iXoffChar=0x13; |
|
459 c.iHandshake = 0 |
|
460 | KConfigObeyXoff |
|
461 | KConfigSendXoff |
|
462 // | KConfigObeyCTS |
|
463 // | KConfigFailCTS |
|
464 // | KConfigObeyDSR |
|
465 // | KConfigFailDSR |
|
466 // | KConfigObeyDCD |
|
467 // | KConfigFailDCD |
|
468 | KConfigFreeRTS |
|
469 | KConfigFreeDTR |
|
470 ; |
|
471 break; |
|
472 case EHandshakeHardware: |
|
473 c.iHandshake = 0 |
|
474 // | KConfigObeyXoff |
|
475 // | KConfigSendXoff |
|
476 | KConfigObeyCTS |
|
477 // | KConfigFailCTS |
|
478 | KConfigObeyDSR |
|
479 // | KConfigFailDSR |
|
480 // | KConfigObeyDCD |
|
481 // | KConfigFailDCD |
|
482 // | KConfigFreeRTS |
|
483 // | KConfigFreeDTR |
|
484 ; |
|
485 break; |
|
486 } |
|
487 return iComm.SetConfig(cBuf); |
|
488 } |
|
489 |
|
490 TInt CDevCommTestBase::LineFailOn() |
|
491 { |
|
492 TCommConfig cBuf; |
|
493 TCommConfigV01 &c=cBuf(); |
|
494 iComm.Config(cBuf); |
|
495 c.iHandshake |= (KConfigFailDSR|KConfigFailDCD); |
|
496 return iComm.SetConfig(cBuf); |
|
497 } |
|
498 |
|
499 TInt CDevCommTestBase::LineFailOff() |
|
500 { |
|
501 TCommConfig cBuf; |
|
502 TCommConfigV01 &c=cBuf(); |
|
503 iComm.Config(cBuf); |
|
504 c.iHandshake &= ~(KConfigFailDSR|KConfigFailDCD); |
|
505 return iComm.SetConfig(cBuf); |
|
506 } |
|
507 |
|
508 void CDevCommTestBase::ShowLoopSignals(TUint aOutState, TUint aInState) |
|
509 { |
|
510 TPtrC cts, dsr, dcd; |
|
511 TPtrC rts, dtr; |
|
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); |
|
522 } |
|
523 |
|
524 #ifdef _DEBUG_DEVCOMM |
|
525 void CDevCommTestBase::Debug() |
|
526 { |
|
527 TCommDebugInfoPckg infopckg; |
|
528 TCommDebugInfo& info = infopckg(); |
|
529 iComm.DebugInfo(infopckg); |
|
530 |
|
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); |
|
546 } |
|
547 #else |
|
548 void CDevCommTestBase::Debug() |
|
549 { |
|
550 Test.Printf(_L("Debug Dump not available\r\n")); |
|
551 } |
|
552 #endif |
|
553 |
|
554 void CDevCommTestBase::ReadComplete(TInt /*aStatus*/) |
|
555 {} |
|
556 |
|
557 void CDevCommTestBase::WriteComplete(TInt /*aStatus*/) |
|
558 {} |
|
559 |
|
560 void CDevCommTestBase::TimeComplete(TInt /*aStatus*/) |
|
561 {} |
|
562 |
|
563 void CDevCommTestBase::KeyComplete(TKeyCode /*aKey*/) |
|
564 {} |
|
565 |
|
566 //////////////////////////////////////////////////////////////////////////////// |
|
567 |
|
568 void StripeMem(TUint8 *aBuf, TInt aStartPos, TInt anEndPos, TUint aStartChar, TUint anEndChar, TInt aOffset=0) |
|
569 // |
|
570 // Mark a buffer with repeating byte pattern |
|
571 // |
|
572 { |
|
573 TUint character=aStartChar+(aOffset%((anEndChar+1)-aStartChar)); |
|
574 |
|
575 for (TInt i=aStartPos;i<anEndPos;i++) |
|
576 { |
|
577 aBuf[i]=(TText8)character; |
|
578 if(++character>anEndChar) |
|
579 character=aStartChar; |
|
580 } |
|
581 } |
|
582 |
|
583 inline void StripeDes(TDes8 &aBuf, TInt aStartPos, TInt anEndPos, TUint aStartChar, TUint anEndChar, TInt aOffset=0) |
|
584 { |
|
585 StripeMem((TUint8 *)aBuf.Ptr(), aStartPos, anEndPos, aStartChar, anEndChar, aOffset); |
|
586 } |
|
587 |
|
588 TBool CheckMem(TUint8 *aBuf, TInt aStartPos, TInt anEndPos, TUint aStartChar, TUint anEndChar, TInt aOffset=0) |
|
589 // |
|
590 // Mark a buffer with repeating byte pattern |
|
591 // |
|
592 { |
|
593 TUint character=aStartChar+(aOffset%((anEndChar+1)-aStartChar)); |
|
594 |
|
595 for (TInt i=aStartPos;i<anEndPos;i++) |
|
596 { |
|
597 if (aBuf[i]!=(TText8)character) |
|
598 return EFalse; |
|
599 if(++character>anEndChar) |
|
600 character=aStartChar; |
|
601 } |
|
602 return ETrue; |
|
603 } |
|
604 |
|
605 inline TBool CheckDes(TDes8 &aBuf, TInt aStartPos, TInt anEndPos, TUint aStartChar, TUint anEndChar, TInt aOffset=0) |
|
606 { |
|
607 return CheckMem((TUint8 *)aBuf.Ptr(), aStartPos, anEndPos, aStartChar, anEndChar, aOffset); |
|
608 } |
|
609 |
|
610 //////////////////////////////////////////////////////////////////////////////// |
|
611 |
|
612 void CommStart() |
|
613 { |
|
614 TInt ret; |
|
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")); |
|
623 } |
|
624 |
|
625 //////////////////////////////////////////////////////////////////////////////// |
|
626 |
|
627 class CTestRandTerm : public CDevCommTestBase |
|
628 { |
|
629 public: |
|
630 enum TTestRandTermState { EIdle, EWaitReady, EWaitReset, EWaitIO }; |
|
631 enum TTestFailType { ETestFailBoth, ETestFailRead, ETestFailWrite, ETestBadData }; |
|
632 public: |
|
633 static CTestRandTerm* NewL(TInt aPort); |
|
634 CTestRandTerm(); |
|
635 ~CTestRandTerm(); |
|
636 virtual void ReadComplete(TInt aStatus); |
|
637 virtual void WriteComplete(TInt aStatus); |
|
638 virtual void TimeComplete(TInt aStatus); |
|
639 virtual void KeyComplete(TKeyCode aKey); |
|
640 void Reset(); |
|
641 void Write(); |
|
642 void Read(); |
|
643 TBool CheckRead(); |
|
644 void Halt(); |
|
645 void Fail(TTestFailType aType, TInt aError); |
|
646 protected: |
|
647 virtual void RunL(); |
|
648 public: |
|
649 TTestRandTermState iState; |
|
650 TInt64 iSeed; |
|
651 TInt iCount; |
|
652 TInt iOffset; |
|
653 TInt iRetries; |
|
654 TInt iPackets; |
|
655 TInt iSpin; |
|
656 TBool iTrace; |
|
657 }; |
|
658 |
|
659 CTestRandTerm::CTestRandTerm() |
|
660 { |
|
661 } |
|
662 |
|
663 CTestRandTerm::~CTestRandTerm() |
|
664 { |
|
665 } |
|
666 |
|
667 CTestRandTerm* CTestRandTerm::NewL(TInt aPort) |
|
668 { |
|
669 CTestRandTerm* tester = new (ELeave) CTestRandTerm; |
|
670 CleanupStack::PushL(tester); |
|
671 tester->CreateL(1000); |
|
672 User::LeaveIfError(tester->Open(aPort)); |
|
673 CleanupStack::Pop(); |
|
674 return tester; |
|
675 } |
|
676 |
|
677 void CTestRandTerm::Reset() |
|
678 { |
|
679 Test.Printf(_L("Resetting Port\r\n")); |
|
680 iReader->Cancel(); |
|
681 iWriter->Cancel(); |
|
682 iTimer->Cancel(); |
|
683 LineFailOff(); |
|
684 iComm.ResetBuffers(); |
|
685 iTimer->After(1000000); |
|
686 iState = EWaitReset; |
|
687 } |
|
688 |
|
689 void CTestRandTerm::RunL() |
|
690 { |
|
691 iCount = 0; |
|
692 iState = EIdle; |
|
693 iSeed = 1; |
|
694 Test.Printf(_L("Waiting for Port\r\n")); |
|
695 ZeroTerminate(); |
|
696 iWriter->Ready(); |
|
697 iTimer->After(1000000); |
|
698 iState = EWaitReady; |
|
699 } |
|
700 |
|
701 void CTestRandTerm::ReadComplete(TInt aStatus) |
|
702 { |
|
703 if (iTrace) |
|
704 Test.Printf(_L("CTestRandTerm::ReadComplete(%d) len = %d/%d\r\n"), aStatus, iWriter->iDes.Length(), iWriter->iDes.MaxLength()); |
|
705 |
|
706 if (aStatus!=KErrNone) |
|
707 { |
|
708 Fail(ETestFailRead, aStatus); |
|
709 return; |
|
710 } |
|
711 |
|
712 switch (iState) |
|
713 { |
|
714 case EWaitIO: |
|
715 iRetries = 0; |
|
716 iTimer->Cancel(); |
|
717 if (CheckRead()) |
|
718 { |
|
719 iPackets++; |
|
720 if (iReader->iCount==iWriter->iCount) |
|
721 { |
|
722 iCount += iWriter->iCount; |
|
723 Test.Printf(_L("%c %6d %d\r"), KSpinner[iSpin++ & 3], iPackets, iCount); |
|
724 Write(); |
|
725 Read(); |
|
726 } |
|
727 else |
|
728 { |
|
729 iOffset = iReader->iCount; |
|
730 Test.Printf(_L("%c\r"), KSpinner[iSpin++ & 3]); |
|
731 Read(); |
|
732 } |
|
733 } |
|
734 else |
|
735 { |
|
736 Fail(ETestBadData, KErrNone); |
|
737 } |
|
738 break; |
|
739 default: |
|
740 break; |
|
741 } |
|
742 } |
|
743 |
|
744 void CTestRandTerm::WriteComplete(TInt aStatus) |
|
745 { |
|
746 if (iTrace) |
|
747 { |
|
748 Test.Printf(_L("CTestRandTerm::WriteComplete(%d) len = %d/%d\r\n"), aStatus, iWriter->iDes.Length(), iWriter->iDes.MaxLength()); |
|
749 } |
|
750 |
|
751 if (aStatus!=KErrNone) |
|
752 { |
|
753 Fail(ETestFailWrite, aStatus); |
|
754 return; |
|
755 } |
|
756 |
|
757 switch (iState) |
|
758 { |
|
759 case EWaitReady: |
|
760 iRetries = 0; |
|
761 iTimer->Cancel(); |
|
762 iState = EWaitIO; |
|
763 Test.Printf(_L("Port Ready\r\n")); |
|
764 LineFailOn(); |
|
765 Write(); |
|
766 Read(); |
|
767 break; |
|
768 case EWaitIO: |
|
769 iRetries = 0; |
|
770 if (iReader->iCount==iWriter->iCount) |
|
771 { |
|
772 Write(); |
|
773 Read(); |
|
774 } |
|
775 break; |
|
776 default: |
|
777 break; |
|
778 } |
|
779 } |
|
780 |
|
781 void CTestRandTerm::TimeComplete(TInt aStatus) |
|
782 { |
|
783 if (iTrace) |
|
784 Test.Printf(_L("CTestRandTerm::TimeComplete(%d)\r\n"), aStatus); |
|
785 |
|
786 if (aStatus!=KErrNone) |
|
787 { |
|
788 __DEBUGGER(); |
|
789 return; |
|
790 } |
|
791 |
|
792 switch (iState) |
|
793 { |
|
794 case EWaitReset: |
|
795 Test.Printf(_L("Waiting for Port\r\n")); |
|
796 iWriter->Ready(); |
|
797 iTimer->After(1000000); |
|
798 iState = EWaitReady; |
|
799 break; |
|
800 case EWaitReady: |
|
801 if (++iRetries>10) |
|
802 { |
|
803 Test.Printf(_L("Too many retries\r\n")); |
|
804 Halt(); |
|
805 } |
|
806 else |
|
807 { |
|
808 Test.Printf(_L("%c\r"), KSpinner[iSpin++ & 3]); |
|
809 iWriter->Ready(); |
|
810 iTimer->After(1000000); |
|
811 } |
|
812 break; |
|
813 case EWaitIO: |
|
814 Fail(ETestFailBoth, KErrTimedOut); |
|
815 break; |
|
816 default: |
|
817 Reset(); |
|
818 break; |
|
819 } |
|
820 } |
|
821 |
|
822 |
|
823 void CTestRandTerm::KeyComplete(TKeyCode aKey) |
|
824 { |
|
825 if (iTrace) |
|
826 Test.Printf(_L("CTestRandTerm::KeyComplete(%d)\r\n"), aKey); |
|
827 |
|
828 switch ((TInt)aKey) |
|
829 { |
|
830 case EKeyEscape: |
|
831 Halt(); |
|
832 break; |
|
833 case 'd': |
|
834 case 'D': |
|
835 Debug(); |
|
836 break; |
|
837 case 'q': |
|
838 case 'Q': |
|
839 iTrace = 0; |
|
840 break; |
|
841 case 'v': |
|
842 case 'V': |
|
843 iTrace = 1; |
|
844 break; |
|
845 default: |
|
846 break; |
|
847 } |
|
848 } |
|
849 |
|
850 |
|
851 void CTestRandTerm::Fail(TTestFailType aType, TInt aError) |
|
852 { |
|
853 switch (aType) |
|
854 { |
|
855 case ETestFailBoth: |
|
856 Test.Printf(_L("Timeout at offset %d\r\n"), iOffset); |
|
857 break; |
|
858 case ETestFailRead: |
|
859 Test.Printf(_L("Read fail (%d) at offset %d\r\n"), aError, iOffset); |
|
860 break; |
|
861 case ETestFailWrite: |
|
862 Test.Printf(_L("Write fail (%d) at offset %d\r\n"), aError, iOffset); |
|
863 break; |
|
864 case ETestBadData: |
|
865 Test.Printf(_L("Data verify failure at offset %d\r\n"), iOffset); |
|
866 break; |
|
867 } |
|
868 Debug(); |
|
869 Reset(); |
|
870 } |
|
871 |
|
872 |
|
873 void CTestRandTerm::Write() |
|
874 { |
|
875 iOffset = 0; |
|
876 iWriter->ResetCount(); |
|
877 iReader->ResetCount(); |
|
878 |
|
879 TInt i; |
|
880 TInt j = 0; |
|
881 StripeDes(iWriter->iDes, 0, iBufferSize, '@', 'Z'); |
|
882 while (j<iBufferSize) |
|
883 { |
|
884 i = Math::Rand(iSeed) % (iBufferSize/4); |
|
885 if (j+i<iBufferSize) |
|
886 iWriter->iDes[j+i] = '\0'; |
|
887 j += i; |
|
888 } |
|
889 |
|
890 iWriter->Start(); |
|
891 } |
|
892 |
|
893 |
|
894 void CTestRandTerm::Read() |
|
895 { |
|
896 iReader->Start(); |
|
897 iTimer->After(5000000); |
|
898 } |
|
899 |
|
900 |
|
901 TBool CTestRandTerm::CheckRead() |
|
902 { |
|
903 TPtrC8 ref; |
|
904 ref.Set(iWriter->iDes.Ptr()+iOffset, iReader->iDes.Length()); |
|
905 return ref.Compare(iReader->iDes)==0; |
|
906 } |
|
907 |
|
908 void CTestRandTerm::Halt() |
|
909 { |
|
910 iReader->Cancel(); |
|
911 iWriter->Cancel(); |
|
912 iTimer->Cancel(); |
|
913 CActiveScheduler::Stop(); |
|
914 } |
|
915 |
|
916 //////////////////////////////////////////////////////////////////////////////// |
|
917 |
|
918 |
|
919 class CTestSignals : public CDevCommTestBase |
|
920 { |
|
921 public: |
|
922 enum TTestState { EAllOff, ERtsOn, EDtrOn, EAllOn, EMonitor }; |
|
923 public: |
|
924 static CTestSignals* NewL(TInt aPort); |
|
925 CTestSignals(); |
|
926 ~CTestSignals(); |
|
927 virtual void KeyComplete(TKeyCode aKey); |
|
928 virtual void ReadComplete(TInt aStatus); |
|
929 void Halt(); |
|
930 void DoSignals(TTestState aState); |
|
931 protected: |
|
932 virtual void RunL(); |
|
933 public: |
|
934 TTestState iState; |
|
935 }; |
|
936 |
|
937 CTestSignals::CTestSignals() |
|
938 { |
|
939 } |
|
940 |
|
941 CTestSignals::~CTestSignals() |
|
942 { |
|
943 } |
|
944 |
|
945 CTestSignals* CTestSignals::NewL(TInt aPort) |
|
946 { |
|
947 CTestSignals* tester = new (ELeave) CTestSignals; |
|
948 CleanupStack::PushL(tester); |
|
949 tester->CreateL(0); |
|
950 User::LeaveIfError(tester->Open(aPort)); |
|
951 CleanupStack::Pop(); |
|
952 return tester; |
|
953 } |
|
954 |
|
955 void CTestSignals::RunL() |
|
956 { |
|
957 TCommConfig cBuf; |
|
958 TCommConfigV01 &c=cBuf(); |
|
959 iComm.Config(cBuf); |
|
960 c.iHandshake = KConfigFreeRTS | KConfigFreeDTR; |
|
961 iComm.SetConfig(cBuf); |
|
962 iReader->Ready(); |
|
963 } |
|
964 |
|
965 |
|
966 void CTestSignals::Halt() |
|
967 { |
|
968 Test.Printf(_L(" \r")); |
|
969 CActiveScheduler::Stop(); |
|
970 } |
|
971 |
|
972 void CTestSignals::ReadComplete(TInt /*aStatus*/) |
|
973 { |
|
974 DoSignals(EAllOff); |
|
975 } |
|
976 |
|
977 void CTestSignals::KeyComplete(TKeyCode aKey) |
|
978 { |
|
979 switch (aKey) |
|
980 { |
|
981 case EKeyEscape: |
|
982 Halt(); |
|
983 break; |
|
984 default: |
|
985 switch (iState) |
|
986 { |
|
987 case EAllOff: |
|
988 DoSignals(ERtsOn); |
|
989 break; |
|
990 case ERtsOn: |
|
991 DoSignals(EDtrOn); |
|
992 break; |
|
993 case EDtrOn: |
|
994 DoSignals(EAllOn); |
|
995 break; |
|
996 case EAllOn: |
|
997 DoSignals(EAllOff); |
|
998 break; |
|
999 default: |
|
1000 break; |
|
1001 } |
|
1002 } |
|
1003 } |
|
1004 |
|
1005 void CTestSignals::DoSignals(TTestState aState) |
|
1006 { |
|
1007 TUint set=0, clr=0; |
|
1008 |
|
1009 switch (aState) |
|
1010 { |
|
1011 case EAllOff: |
|
1012 set = 0; |
|
1013 clr = KSignalRTS | KSignalDTR; |
|
1014 break; |
|
1015 case ERtsOn: |
|
1016 set = KSignalRTS; |
|
1017 clr = KSignalDTR; |
|
1018 break; |
|
1019 case EDtrOn: |
|
1020 set = KSignalDTR; |
|
1021 clr = KSignalRTS; |
|
1022 break; |
|
1023 case EAllOn: |
|
1024 set = KSignalRTS | KSignalDTR; |
|
1025 clr = 0; |
|
1026 break; |
|
1027 default: |
|
1028 set = 0; |
|
1029 clr = 0; |
|
1030 } |
|
1031 iComm.SetSignals(set, clr); |
|
1032 TUint sig = iComm.Signals(); |
|
1033 ShowLoopSignals(set, sig); |
|
1034 iState = aState; |
|
1035 Test.Printf(_L("Press key for next state\r")); |
|
1036 } |
|
1037 |
|
1038 //////////////////////////////////////////////////////////////////////////////// |
|
1039 |
|
1040 class CTestPerf : public CDevCommTestBase |
|
1041 { |
|
1042 public: |
|
1043 enum TTestRandTermState { EIdle, EWaitReady, EWaitReset, EWaitIO }; |
|
1044 enum TTestFailType { ETestFailBoth, ETestFailRead, ETestFailWrite, ETestBadData }; |
|
1045 public: |
|
1046 static CTestPerf* NewL(TInt aPort); |
|
1047 CTestPerf(); |
|
1048 ~CTestPerf(); |
|
1049 virtual void ReadComplete(TInt aStatus); |
|
1050 virtual void WriteComplete(TInt aStatus); |
|
1051 virtual void TimeComplete(TInt aStatus); |
|
1052 virtual void KeyComplete(TKeyCode aKey); |
|
1053 void Reset(); |
|
1054 void Write(); |
|
1055 void Read(); |
|
1056 TBool CheckRead(); |
|
1057 void Halt(); |
|
1058 void Fail(TTestFailType aType, TInt aError); |
|
1059 protected: |
|
1060 virtual void RunL(); |
|
1061 public: |
|
1062 TTestRandTermState iState; |
|
1063 TInt64 iSeed; |
|
1064 TInt iCount; |
|
1065 TInt iOffset; |
|
1066 TInt iRetries; |
|
1067 TInt iPackets; |
|
1068 TInt iSpin; |
|
1069 TBool iTrace; |
|
1070 TTime iStartTime; |
|
1071 TInt iRate; |
|
1072 TInt iSpeed; |
|
1073 }; |
|
1074 |
|
1075 CTestPerf::CTestPerf() |
|
1076 { |
|
1077 } |
|
1078 |
|
1079 CTestPerf::~CTestPerf() |
|
1080 { |
|
1081 } |
|
1082 |
|
1083 CTestPerf* CTestPerf::NewL(TInt aPort) |
|
1084 { |
|
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'); |
|
1091 return tester; |
|
1092 } |
|
1093 |
|
1094 void CTestPerf::Reset() |
|
1095 { |
|
1096 Test.Printf(_L("Resetting Port\r\n")); |
|
1097 iReader->Cancel(); |
|
1098 iWriter->Cancel(); |
|
1099 iTimer->Cancel(); |
|
1100 LineFailOff(); |
|
1101 iComm.ResetBuffers(); |
|
1102 iTimer->After(1000000); |
|
1103 iState = EWaitReset; |
|
1104 } |
|
1105 |
|
1106 void CTestPerf::RunL() |
|
1107 { |
|
1108 iCount = 0; |
|
1109 iState = EIdle; |
|
1110 iSeed = 1; |
|
1111 Test.Printf(_L("Waiting for Port\r\n")); |
|
1112 ZeroTerminate(); |
|
1113 iWriter->Ready(); |
|
1114 iTimer->After(1000000); |
|
1115 iState = EWaitReady; |
|
1116 } |
|
1117 |
|
1118 void CTestPerf::ReadComplete(TInt aStatus) |
|
1119 { |
|
1120 if (iTrace) |
|
1121 Test.Printf(_L("CTestPerf::ReadComplete(%d) len = %d/%d\r\n"), aStatus, iWriter->iDes.Length(), iWriter->iDes.MaxLength()); |
|
1122 |
|
1123 if (aStatus!=KErrNone) |
|
1124 { |
|
1125 Fail(ETestFailRead, aStatus); |
|
1126 return; |
|
1127 } |
|
1128 |
|
1129 switch (iState) |
|
1130 { |
|
1131 case EWaitIO: |
|
1132 iRetries = 0; |
|
1133 iTimer->Cancel(); |
|
1134 iCount += iReader->iCount; |
|
1135 iPackets++; |
|
1136 { |
|
1137 TTime end; |
|
1138 end.UniversalTime(); |
|
1139 TInt64 difftime = (end.MicroSecondsFrom(iStartTime).Int64()+TInt64(500000))/TInt64(1000000); |
|
1140 if (difftime==0) |
|
1141 difftime = 1; |
|
1142 TInt64 cps = MAKE_TINT64(0,iCount)/difftime; |
|
1143 TInt rate = (I64INT(cps)*10000)/11520; |
|
1144 |
|
1145 iRate += rate; |
|
1146 iSpeed += I64INT(cps); |
|
1147 |
|
1148 Test.Printf(_L("%c %6d %d (%dbps=%d.%02d%%)\r"), KSpinner[iSpin++ & 3], iPackets, iCount, iSpeed/iPackets, (iRate/iPackets)/100, (iRate/iPackets)%100); |
|
1149 } |
|
1150 Read(); |
|
1151 break; |
|
1152 default: |
|
1153 break; |
|
1154 } |
|
1155 } |
|
1156 |
|
1157 void CTestPerf::WriteComplete(TInt aStatus) |
|
1158 { |
|
1159 if (iTrace) |
|
1160 { |
|
1161 Test.Printf(_L("CTestPerf::WriteComplete(%d) len = %d/%d\r\n"), aStatus, iWriter->iDes.Length(), iWriter->iDes.MaxLength()); |
|
1162 } |
|
1163 |
|
1164 if (aStatus!=KErrNone) |
|
1165 { |
|
1166 Fail(ETestFailWrite, aStatus); |
|
1167 return; |
|
1168 } |
|
1169 |
|
1170 switch (iState) |
|
1171 { |
|
1172 case EWaitReady: |
|
1173 iRetries = 0; |
|
1174 iTimer->Cancel(); |
|
1175 iState = EWaitIO; |
|
1176 Test.Printf(_L("Port Ready\r\n")); |
|
1177 LineFailOn(); |
|
1178 iStartTime.UniversalTime();; |
|
1179 Write(); |
|
1180 Read(); |
|
1181 break; |
|
1182 case EWaitIO: |
|
1183 iRetries = 0; |
|
1184 Write(); |
|
1185 break; |
|
1186 default: |
|
1187 break; |
|
1188 } |
|
1189 } |
|
1190 |
|
1191 void CTestPerf::TimeComplete(TInt aStatus) |
|
1192 { |
|
1193 if (iTrace) |
|
1194 Test.Printf(_L("CTestPerf::TimeComplete(%d)\r\n"), aStatus); |
|
1195 |
|
1196 if (aStatus!=KErrNone) |
|
1197 { |
|
1198 __DEBUGGER(); |
|
1199 return; |
|
1200 } |
|
1201 |
|
1202 switch (iState) |
|
1203 { |
|
1204 case EWaitReset: |
|
1205 Test.Printf(_L("Waiting for Port\r\n")); |
|
1206 iWriter->Ready(); |
|
1207 iTimer->After(1000000); |
|
1208 iState = EWaitReady; |
|
1209 break; |
|
1210 case EWaitReady: |
|
1211 if (++iRetries>10) |
|
1212 { |
|
1213 Test.Printf(_L("Too many retries\r\n")); |
|
1214 Halt(); |
|
1215 } |
|
1216 else |
|
1217 { |
|
1218 Test.Printf(_L("%c\r"), KSpinner[iSpin++ & 3]); |
|
1219 iWriter->Ready(); |
|
1220 iTimer->After(1000000); |
|
1221 } |
|
1222 break; |
|
1223 case EWaitIO: |
|
1224 Fail(ETestFailBoth, KErrTimedOut); |
|
1225 break; |
|
1226 default: |
|
1227 Reset(); |
|
1228 break; |
|
1229 } |
|
1230 } |
|
1231 |
|
1232 |
|
1233 void CTestPerf::KeyComplete(TKeyCode aKey) |
|
1234 { |
|
1235 if (iTrace) |
|
1236 Test.Printf(_L("CTestPerf::KeyComplete(%d)\r\n"), aKey); |
|
1237 |
|
1238 switch ((TInt)aKey) |
|
1239 { |
|
1240 case EKeyEscape: |
|
1241 Halt(); |
|
1242 break; |
|
1243 case 'd': |
|
1244 case 'D': |
|
1245 Test.Printf(_L("\r\n")); |
|
1246 Debug(); |
|
1247 break; |
|
1248 case 'q': |
|
1249 case 'Q': |
|
1250 iTrace = 0; |
|
1251 break; |
|
1252 case 'v': |
|
1253 case 'V': |
|
1254 iTrace = 1; |
|
1255 break; |
|
1256 case 's': |
|
1257 case 'S': |
|
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()); |
|
1263 break; |
|
1264 default: |
|
1265 break; |
|
1266 } |
|
1267 } |
|
1268 |
|
1269 |
|
1270 void CTestPerf::Fail(TTestFailType aType, TInt aError) |
|
1271 { |
|
1272 switch (aType) |
|
1273 { |
|
1274 case ETestFailBoth: |
|
1275 Test.Printf(_L("\r\nTimeout at offset %d\r\n"), iOffset); |
|
1276 break; |
|
1277 case ETestFailRead: |
|
1278 Test.Printf(_L("\r\nRead fail (%d) at offset %d\r\n"), aError, iOffset); |
|
1279 break; |
|
1280 case ETestFailWrite: |
|
1281 Test.Printf(_L("\r\nWrite fail (%d) at offset %d\r\n"), aError, iOffset); |
|
1282 break; |
|
1283 case ETestBadData: |
|
1284 Test.Printf(_L("\r\nData verify failure at offset %d\r\n"), iOffset); |
|
1285 break; |
|
1286 } |
|
1287 Debug(); |
|
1288 Reset(); |
|
1289 } |
|
1290 |
|
1291 |
|
1292 void CTestPerf::Write() |
|
1293 { |
|
1294 iOffset = 0; |
|
1295 iWriter->ResetCount(); |
|
1296 iWriter->Start(); |
|
1297 } |
|
1298 |
|
1299 void CTestPerf::Read() |
|
1300 { |
|
1301 iReader->ResetCount(); |
|
1302 iReader->Start(); |
|
1303 iTimer->After(5000000); |
|
1304 } |
|
1305 |
|
1306 TBool CTestPerf::CheckRead() |
|
1307 { |
|
1308 TPtrC8 ref; |
|
1309 ref.Set(iWriter->iDes.Ptr()+iOffset, iReader->iDes.Length()); |
|
1310 return ref.Compare(iReader->iDes)==0; |
|
1311 } |
|
1312 |
|
1313 void CTestPerf::Halt() |
|
1314 { |
|
1315 iReader->Cancel(); |
|
1316 iWriter->Cancel(); |
|
1317 iTimer->Cancel(); |
|
1318 CActiveScheduler::Stop(); |
|
1319 } |
|
1320 |
|
1321 //////////////////////////////////////////////////////////////////////////////// |
|
1322 |
|
1323 class CTestXonXoff : public CDevCommTestBase |
|
1324 { |
|
1325 public: |
|
1326 enum TTestRandTermState { EIdle, EWaitReady, EWaitReset, EWaitIO }; |
|
1327 enum TTestFailType { ETestFailBoth, ETestFailRead, ETestFailWrite, ETestBadData }; |
|
1328 public: |
|
1329 static CTestXonXoff* NewL(TInt aPort); |
|
1330 CTestXonXoff(); |
|
1331 ~CTestXonXoff(); |
|
1332 virtual void ReadComplete(TInt aStatus); |
|
1333 virtual void WriteComplete(TInt aStatus); |
|
1334 virtual void TimeComplete(TInt aStatus); |
|
1335 virtual void KeyComplete(TKeyCode aKey); |
|
1336 void Reset(); |
|
1337 void Write(); |
|
1338 void Read(); |
|
1339 TBool CheckRead(); |
|
1340 void Halt(); |
|
1341 void Fail(TTestFailType aType, TInt aError); |
|
1342 protected: |
|
1343 virtual void RunL(); |
|
1344 public: |
|
1345 TTestRandTermState iState; |
|
1346 TInt64 iSeed; |
|
1347 TInt iCount; |
|
1348 TInt iOffset; |
|
1349 TInt iRetries; |
|
1350 TInt iPackets; |
|
1351 TInt iSpin; |
|
1352 TBool iTrace; |
|
1353 TTime iStartTime; |
|
1354 TInt iRate; |
|
1355 TInt iSpeed; |
|
1356 }; |
|
1357 |
|
1358 CTestXonXoff::CTestXonXoff() |
|
1359 { |
|
1360 } |
|
1361 |
|
1362 CTestXonXoff::~CTestXonXoff() |
|
1363 { |
|
1364 } |
|
1365 |
|
1366 CTestXonXoff* CTestXonXoff::NewL(TInt aPort) |
|
1367 { |
|
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'); |
|
1375 return tester; |
|
1376 } |
|
1377 |
|
1378 void CTestXonXoff::Reset() |
|
1379 { |
|
1380 Test.Printf(_L("Resetting Port\r\n")); |
|
1381 iReader->Cancel(); |
|
1382 iWriter->Cancel(); |
|
1383 iTimer->Cancel(); |
|
1384 LineFailOff(); |
|
1385 iComm.ResetBuffers(); |
|
1386 iTimer->After(1000000); |
|
1387 iState = EWaitReset; |
|
1388 } |
|
1389 |
|
1390 void CTestXonXoff::RunL() |
|
1391 { |
|
1392 iCount = 0; |
|
1393 iState = EIdle; |
|
1394 iSeed = 1; |
|
1395 Test.Printf(_L("Waiting for Port\r\n")); |
|
1396 ZeroTerminate(); |
|
1397 |
|
1398 iWriter->Ready(); |
|
1399 iTimer->After(1000000); |
|
1400 |
|
1401 // iState = EWaitReady; |
|
1402 // WriteComplete(0); |
|
1403 } |
|
1404 |
|
1405 void CTestXonXoff::ReadComplete(TInt aStatus) |
|
1406 { |
|
1407 if (iTrace) |
|
1408 Test.Printf(_L("CTestXonXoff::ReadComplete(%d) len = %d/%d (%d)\r\n"), aStatus, iReader->iDes.Length(), iReader->iDes.MaxLength(), iReader->iTotal); |
|
1409 |
|
1410 if (aStatus!=KErrNone) |
|
1411 { |
|
1412 Fail(ETestFailRead, aStatus); |
|
1413 return; |
|
1414 } |
|
1415 |
|
1416 switch (iState) |
|
1417 { |
|
1418 case EWaitIO: |
|
1419 iRetries = 0; |
|
1420 iTimer->Cancel(); |
|
1421 if (!CheckDes(iReader->iDes, 0, iReader->iDes.Length(), '@', 'Z', iCount & 0x3fff)) |
|
1422 { |
|
1423 Fail(ETestBadData, aStatus); |
|
1424 return; |
|
1425 } |
|
1426 iCount += iReader->iCount; |
|
1427 iPackets++; |
|
1428 { |
|
1429 TTime end; |
|
1430 end.UniversalTime(); |
|
1431 TInt64 difftime = (end.MicroSecondsFrom(iStartTime).Int64()+TInt64(500000))/TInt64(1000000); |
|
1432 if (difftime==0) |
|
1433 difftime = 1; |
|
1434 TInt64 cps = MAKE_TINT64(0,iCount)/difftime; |
|
1435 TInt rate = (I64INT(cps)*10000)/11520; |
|
1436 iRate += rate; |
|
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); |
|
1439 } |
|
1440 Read(); |
|
1441 break; |
|
1442 default: |
|
1443 break; |
|
1444 } |
|
1445 } |
|
1446 |
|
1447 void CTestXonXoff::WriteComplete(TInt aStatus) |
|
1448 { |
|
1449 if (iTrace) |
|
1450 { |
|
1451 Test.Printf(_L("CTestXonXoff::WriteComplete(%d) len = %d/%d (%d)\r\n"), aStatus, iWriter->iDes.Length(), iWriter->iDes.MaxLength(), iWriter->iTotal); |
|
1452 } |
|
1453 |
|
1454 if (aStatus!=KErrNone) |
|
1455 { |
|
1456 Fail(ETestFailWrite, aStatus); |
|
1457 return; |
|
1458 } |
|
1459 |
|
1460 switch (iState) |
|
1461 { |
|
1462 case EWaitReady: |
|
1463 iRetries = 0; |
|
1464 iTimer->Cancel(); |
|
1465 iState = EWaitIO; |
|
1466 Test.Printf(_L("Port Ready\r\n")); |
|
1467 LineFailOn(); |
|
1468 iStartTime.UniversalTime();; |
|
1469 Write(); |
|
1470 Read(); |
|
1471 break; |
|
1472 case EWaitIO: |
|
1473 iRetries = 0; |
|
1474 Write(); |
|
1475 break; |
|
1476 default: |
|
1477 break; |
|
1478 } |
|
1479 } |
|
1480 |
|
1481 void CTestXonXoff::TimeComplete(TInt aStatus) |
|
1482 { |
|
1483 if (iTrace) |
|
1484 Test.Printf(_L("CTestXonXoff::TimeComplete(%d)\r\n"), aStatus); |
|
1485 |
|
1486 if (aStatus!=KErrNone) |
|
1487 { |
|
1488 __DEBUGGER(); |
|
1489 return; |
|
1490 } |
|
1491 |
|
1492 switch (iState) |
|
1493 { |
|
1494 case EWaitReset: |
|
1495 Test.Printf(_L("Waiting for Port\r\n")); |
|
1496 iWriter->Ready(); |
|
1497 iTimer->After(1000000); |
|
1498 iState = EWaitReady; |
|
1499 break; |
|
1500 case EWaitReady: |
|
1501 if (++iRetries>10) |
|
1502 { |
|
1503 Test.Printf(_L("Too many retries\r\n")); |
|
1504 Halt(); |
|
1505 } |
|
1506 else |
|
1507 { |
|
1508 Test.Printf(_L("%c\r"), KSpinner[iSpin++ & 3]); |
|
1509 iWriter->Ready(); |
|
1510 iTimer->After(1000000); |
|
1511 } |
|
1512 break; |
|
1513 case EWaitIO: |
|
1514 Fail(ETestFailBoth, KErrTimedOut); |
|
1515 break; |
|
1516 default: |
|
1517 Reset(); |
|
1518 break; |
|
1519 } |
|
1520 } |
|
1521 |
|
1522 |
|
1523 void CTestXonXoff::KeyComplete(TKeyCode aKey) |
|
1524 { |
|
1525 if (iTrace) |
|
1526 Test.Printf(_L("CTestXonXoff::KeyComplete(%d)\r\n"), aKey); |
|
1527 |
|
1528 switch ((TInt)aKey) |
|
1529 { |
|
1530 case EKeyEscape: |
|
1531 Halt(); |
|
1532 break; |
|
1533 case 'd': |
|
1534 case 'D': |
|
1535 Test.Printf(_L("\r\n")); |
|
1536 Debug(); |
|
1537 break; |
|
1538 case 'q': |
|
1539 case 'Q': |
|
1540 iTrace = 0; |
|
1541 break; |
|
1542 case 'v': |
|
1543 case 'V': |
|
1544 iTrace = 1; |
|
1545 break; |
|
1546 case 's': |
|
1547 case 'S': |
|
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()); |
|
1553 break; |
|
1554 default: |
|
1555 break; |
|
1556 } |
|
1557 } |
|
1558 |
|
1559 |
|
1560 void CTestXonXoff::Fail(TTestFailType aType, TInt aError) |
|
1561 { |
|
1562 switch (aType) |
|
1563 { |
|
1564 case ETestFailBoth: |
|
1565 Test.Printf(_L("\r\nTimeout at offset %d\r\n"), iOffset); |
|
1566 break; |
|
1567 case ETestFailRead: |
|
1568 Test.Printf(_L("\r\nRead fail (%d) at offset %d\r\n"), aError, iOffset); |
|
1569 break; |
|
1570 case ETestFailWrite: |
|
1571 Test.Printf(_L("\r\nWrite fail (%d) at offset %d\r\n"), aError, iOffset); |
|
1572 break; |
|
1573 case ETestBadData: |
|
1574 Test.Printf(_L("\r\nData verify failure at offset %d\r\n"), iOffset); |
|
1575 break; |
|
1576 } |
|
1577 Debug(); |
|
1578 Reset(); |
|
1579 } |
|
1580 |
|
1581 |
|
1582 void CTestXonXoff::Write() |
|
1583 { |
|
1584 iOffset = 0; |
|
1585 iWriter->ResetCount(); |
|
1586 StripeDes(iWriter->iDes, 0, iWriter->iDes.Length(), '@', 'Z'); |
|
1587 iWriter->Start(); |
|
1588 } |
|
1589 |
|
1590 void CTestXonXoff::Read() |
|
1591 { |
|
1592 User::After(1000000); |
|
1593 iReader->ResetCount(); |
|
1594 iReader->Start(); |
|
1595 iTimer->After(5000000); |
|
1596 } |
|
1597 |
|
1598 TBool CTestXonXoff::CheckRead() |
|
1599 { |
|
1600 TPtrC8 ref; |
|
1601 ref.Set(iWriter->iDes.Ptr()+iOffset, iReader->iDes.Length()); |
|
1602 return ref.Compare(iReader->iDes)==0; |
|
1603 } |
|
1604 |
|
1605 void CTestXonXoff::Halt() |
|
1606 { |
|
1607 iReader->Cancel(); |
|
1608 iWriter->Cancel(); |
|
1609 iTimer->Cancel(); |
|
1610 CActiveScheduler::Stop(); |
|
1611 } |
|
1612 |
|
1613 |
|
1614 //////////////////////////////////////////////////////////////////////////////// |
|
1615 |
|
1616 TInt E32Main() |
|
1617 { |
|
1618 TInt err; |
|
1619 |
|
1620 Test.Start(_L("Comm Driver Tests")); |
|
1621 CommStart(); |
|
1622 Test.Printf(_L("Insert plug in then press a key\r\n")); |
|
1623 Test.Getch(); |
|
1624 |
|
1625 TEST(CTrapCleanup::New()!=NULL); |
|
1626 CActiveScheduler* Scheduler = new CActiveScheduler; |
|
1627 TEST(Scheduler!=NULL); |
|
1628 CActiveScheduler::Install(Scheduler); |
|
1629 /* |
|
1630 CTestSignals* testsignals = NULL; |
|
1631 TRAP(err, testsignals = CTestSignals::NewL(0)); |
|
1632 TEST(err==KErrNone); |
|
1633 testsignals->Start(); |
|
1634 Scheduler->Start(); |
|
1635 delete testsignals; |
|
1636 |
|
1637 CTestRandTerm* testrandterm = NULL; |
|
1638 TRAP(err, testrandterm = CTestRandTerm::NewL(0)); |
|
1639 TEST(err==KErrNone); |
|
1640 testrandterm->Start(); |
|
1641 Scheduler->Start(); |
|
1642 delete testrandterm; |
|
1643 |
|
1644 CTestPerf* testperf = NULL; |
|
1645 TRAP(err, testperf = CTestPerf::NewL(0)); |
|
1646 TEST(err==KErrNone); |
|
1647 testperf->Start(); |
|
1648 Scheduler->Start(); |
|
1649 delete testperf; |
|
1650 */ |
|
1651 |
|
1652 CTestXonXoff* testx = NULL; |
|
1653 TRAP(err, testx = CTestXonXoff::NewL(0)); |
|
1654 TEST(err==KErrNone); |
|
1655 testx->Start(); |
|
1656 Scheduler->Start(); |
|
1657 delete testx; |
|
1658 |
|
1659 /* |
|
1660 CTestXonXoff* testx1 = NULL; |
|
1661 TRAP(err, testx1 = CTestXonXoff::NewL(0)); |
|
1662 TEST(err==KErrNone); |
|
1663 testx1->Start(); |
|
1664 |
|
1665 CTestXonXoff* testx2 = NULL; |
|
1666 TRAP(err, testx2 = CTestXonXoff::NewL(1)); |
|
1667 TEST(err==KErrNone); |
|
1668 testx2->Start(); |
|
1669 |
|
1670 Scheduler->Start(); |
|
1671 |
|
1672 delete testx1; |
|
1673 delete testx2; |
|
1674 */ |
|
1675 Test.End(); |
|
1676 return KErrNone; |
|
1677 } |