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