1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/device/t_dce.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,777 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\device\t_dce.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +// Cogent uses two port loopback, Linda doesn't
1.22 +#define _TWO_PORT_LOOPBACK_
1.23 +
1.24 +#include <e32base.h>
1.25 +#include <e32base_private.h>
1.26 +#include <e32test.h>
1.27 +#include <e32cons.h>
1.28 +#include <e32svr.h>
1.29 +#include <e32hal.h>
1.30 +#include <d32comm.h>
1.31 +#include <e32uid.h>
1.32 +
1.33 +const TInt KUnit0=0;
1.34 +const TInt KUnit1=1;
1.35 +const TInt KUnit2=2;
1.36 +
1.37 +#ifdef _TWO_PORT_LOOPBACK_
1.38 +#define NOTIFY_TIMEOUT 2000000 // 2 seconds
1.39 +#else
1.40 +#define NOTIFY_TIMEOUT 10000000 // 10 seconds
1.41 +#endif
1.42 +
1.43 +const TInt KTestPatternSize=250;
1.44 +
1.45 +#if defined (__WINS__)
1.46 +// Running this test in WINS is fairly pointless since WINS uses the DTE driver.
1.47 +// The WINS version was just to get the basic test program working - i.e. to
1.48 +// speed up the debug process.
1.49 +#define PDD_NAME _L("ECDRV.PDD")
1.50 +#define LDD_NAME _L("ECOMM.LDD")
1.51 +const TInt KTestUnitDte=KUnit0;
1.52 +const TInt KTestUnitDce=KUnit1;
1.53 +const TInt KChangeSigIn=KSignalCTS; // DTE driver used on WINS so read DSR rather than RTS
1.54 +const TInt KOtherSigIn=KSignalDCD; // DTE driver used on WINS so read DCD rather than DTR
1.55 +const TInt KChangeSigOut=KSignalRTS;
1.56 +#else
1.57 +#define DTEPDD_NAME _L("EUART3")
1.58 +//#define DCEPDD_NAME _L("EUART1DCE") // Linda
1.59 +#define DCEPDD_NAME _L("EUART1") // Cogent
1.60 +#define DTELDD_NAME _L("ECOMM")
1.61 +#define DCELDD_NAME _L("ECOMMDCE")
1.62 +const TInt KTestUnitDte=KUnit2;
1.63 +const TInt KTestUnitDce=KUnit0;
1.64 +const TInt KChangeSigIn=KSignalRTS; // DCE input - Cogent
1.65 +const TInt KOtherSigIn=KSignalDTR; // DCE input - Cogent
1.66 +const TInt KChangeSigOut=KSignalRTS; // DTE output - Cogent
1.67 +//const TInt KChangeSigIn=KSignalDTR; // DCE input - Linda
1.68 +//const TInt KOtherSigIn=KSignalRTS; // DCE input - Linda
1.69 +//const TInt KChangeSigOut=KSignalDTR; // DTE output - Linda
1.70 +#endif
1.71 +
1.72 +// Our own comms object with synchronous writes
1.73 +class RComm : public RBusDevComm
1.74 + {
1.75 +public:
1.76 + TInt WriteS(const TDesC8& aDes);
1.77 + TInt WriteS(const TDesC8& aDes,TInt aLength);
1.78 + };
1.79 +
1.80 +LOCAL_D RTest test(_L("T_DCE"));
1.81 +RComm* TheDteSerialPort;
1.82 +#if defined (__WINS__)
1.83 +RBusDevComm* TheDceSerialPort;
1.84 +#else
1.85 +RBusDevCommDCE* TheDceSerialPort;
1.86 +#endif
1.87 +
1.88 +TCommConfig TheConfigDceBuf;
1.89 +TCommConfigV01& TheConfigDce=TheConfigDceBuf();
1.90 +TCommConfig TheConfigDteBuf;
1.91 +TCommConfigV01& TheConfigDte=TheConfigDteBuf();
1.92 +TCommCaps2 TheCapsDceBuf;
1.93 +TCommCapsV02& TheCapsDce=TheCapsDceBuf();
1.94 +
1.95 +
1.96 +TInt RComm::WriteS(const TDesC8& aDes)
1.97 +
1.98 +// Syncronous write
1.99 +
1.100 + {
1.101 + return(WriteS(aDes,aDes.Length()));
1.102 + }
1.103 +
1.104 +TInt RComm::WriteS(const TDesC8& aDes,TInt aLength)
1.105 +
1.106 +// Syncronous write
1.107 +
1.108 + {
1.109 +
1.110 + TRequestStatus s;
1.111 + Write(s,aDes,aLength);
1.112 + User::WaitForRequest(s);
1.113 + return(s.Int());
1.114 + }
1.115 +
1.116 +LOCAL_C void StripeMem(TDes8& aBuf,TUint aStartChar,TUint anEndChar)
1.117 +//
1.118 +// Mark a buffer with repeating byte pattern
1.119 +//
1.120 + {
1.121 +
1.122 + if (aStartChar==anEndChar)
1.123 + {
1.124 + aBuf.Fill(aStartChar);
1.125 + return;
1.126 + }
1.127 +
1.128 + TUint character=aStartChar;
1.129 + for (TInt i=0;i<aBuf.Length();i++)
1.130 + {
1.131 + aBuf[i]=(TText8)character;
1.132 + if(++character>anEndChar)
1.133 + character=aStartChar;
1.134 + }
1.135 + }
1.136 +
1.137 +#define COLUMN_HEADER _L(" RxBuf | Expected \r\n")
1.138 +LOCAL_C void DumpDescriptors(TDes8 &aLeft,TDes8 &aRight)
1.139 +//
1.140 +//
1.141 +//
1.142 + {
1.143 +
1.144 + TBuf<80> b;
1.145 + test.Printf(_L("Compare failed:\r\n"));
1.146 + TInt minLen=Min(aLeft.Length(),aRight.Length());
1.147 + test.Printf(COLUMN_HEADER);
1.148 + TInt i=0;
1.149 + TInt j=0;
1.150 + while (i<=minLen)
1.151 + {
1.152 + b.Format(_L("%02x: "),i);
1.153 + for (j=0;j<8;j++)
1.154 + {
1.155 + if ((i+j)<minLen)
1.156 + {
1.157 + TInt v=aLeft[i+j];
1.158 + b.AppendFormat(_L("%02x "),v);
1.159 + }
1.160 + else
1.161 + b.Append(_L(" "));
1.162 + }
1.163 + b.Append(_L(" | "));
1.164 + for (j=0;j<8;j++)
1.165 + {
1.166 + if ((i+j)<minLen)
1.167 + {
1.168 + TInt v=aRight[i+j];
1.169 + b.AppendFormat(_L("%02x "),v);
1.170 + }
1.171 + else
1.172 + b.Append(_L(" "));
1.173 + }
1.174 + b.Append(_L("\r\n"));
1.175 + test.Printf(b);
1.176 + i+=8;
1.177 + if ((i%64)==0)
1.178 + test.Getch();
1.179 + }
1.180 + }
1.181 +
1.182 +LOCAL_C TInt CheckedWrite(TInt aBufSize)
1.183 +//
1.184 +// Write/Read loopback test - requires either a loopback connector or a
1.185 +// connected device looping back the data (running T_DCEUTL).
1.186 +//
1.187 + {
1.188 + TUint8* inBuf=new TUint8[aBufSize];
1.189 + test(inBuf!=NULL);
1.190 + TUint8* outBuf=new TUint8[aBufSize];
1.191 + test(outBuf!=NULL);
1.192 + TPtr8 outDes(outBuf,aBufSize,aBufSize);
1.193 + TPtr8 inDes(inBuf,aBufSize,aBufSize);
1.194 +
1.195 + RTimer tim;
1.196 + tim.CreateLocal();
1.197 + TRequestStatus readStatus;
1.198 + TRequestStatus timeStatus;
1.199 +
1.200 + StripeMem(outDes,'A','Z');
1.201 + inDes.FillZ();
1.202 +
1.203 + TheDceSerialPort->Read(readStatus,inDes,aBufSize+1);
1.204 + test(readStatus==KErrGeneral);
1.205 +
1.206 + TheDceSerialPort->Read(readStatus,inDes);
1.207 + test(readStatus==KRequestPending);
1.208 +
1.209 + TInt ret;
1.210 +#if defined (_TWO_PORT_LOOPBACK_)
1.211 + ret=TheDteSerialPort->WriteS(outDes,aBufSize);
1.212 +#else
1.213 + TRequestStatus ws;
1.214 + TheDceSerialPort->Write(ws,outDes,aBufSize);
1.215 + User::WaitForRequest(ws);
1.216 + ret=ws.Int();
1.217 +#endif
1.218 + test(ret==KErrNone);
1.219 + const TUint KTimeOut=6000000;
1.220 + tim.After(timeStatus,KTimeOut);
1.221 + test(timeStatus==KRequestPending);
1.222 + User::WaitForRequest(readStatus,timeStatus);
1.223 + if (timeStatus==KErrNone)
1.224 + {
1.225 + TheDceSerialPort->ReadCancel();
1.226 + User::WaitForRequest(readStatus);
1.227 + test.Printf(_L("Timed Out!\n\r"));
1.228 + test.Getch();
1.229 + test(FALSE);
1.230 + }
1.231 + else
1.232 + {
1.233 + tim.Cancel();
1.234 + User::WaitForRequest(timeStatus);
1.235 + if (readStatus!=KErrNone)
1.236 + {
1.237 + test.Printf(_L("Read Failed! (%d)\n\r"),readStatus.Int());
1.238 + test.Getch();
1.239 + test(FALSE);
1.240 + }
1.241 + test(readStatus==KErrNone);
1.242 + test.Printf(_L("Read %d of %d\n\r"),inDes.Length(),outDes.Length());
1.243 + ret=outDes.Compare(inDes);
1.244 + if (ret!=0)
1.245 + DumpDescriptors(inDes,outDes);
1.246 + test(ret==0);
1.247 + }
1.248 +
1.249 + tim.Close();
1.250 + delete inBuf;
1.251 + delete outBuf;
1.252 +
1.253 + return inDes.Length();
1.254 + }
1.255 +
1.256 +LOCAL_C TInt TestingNotifySignalChange(TUint aChangeSignal)
1.257 +//
1.258 +// Test NotifySignalChange()
1.259 +//
1.260 + {
1.261 +
1.262 + RTimer tim;
1.263 + tim.CreateLocal();
1.264 + TRequestStatus notifStatus;
1.265 + TRequestStatus timeStatus;
1.266 +
1.267 + if (!(TheCapsDce.iNotificationCaps & KNotifySignalsChangeSupported))
1.268 + test.Printf(_L("Signal change notification not supported on this platform"));
1.269 + else
1.270 + {
1.271 + test.Next(_L("Testing NotifySignalChange() with no mask set"));
1.272 +#if defined (_TWO_PORT_LOOPBACK_)
1.273 + TheDteSerialPort->SetSignals(0,KChangeSigOut); // Clear
1.274 +#else
1.275 + test.Printf(_L("Make sure DTR negated(??D) - hit a key to start\n\r"));
1.276 + test.Getch();
1.277 + test.Printf(_L("10 seconds to assert DTR(D)\n\r"));
1.278 +#endif
1.279 +
1.280 + TUint signals=0;
1.281 + TheDceSerialPort->NotifySignalChange(notifStatus,signals);
1.282 + test(notifStatus==KRequestPending);
1.283 + const TUint KTimeOut=NOTIFY_TIMEOUT;
1.284 + tim.After(timeStatus,KTimeOut);
1.285 + test(timeStatus==KRequestPending);
1.286 +#if defined (_TWO_PORT_LOOPBACK_)
1.287 + TheDteSerialPort->SetSignals(KChangeSigOut,0); // Set
1.288 +#endif
1.289 + User::WaitForRequest(notifStatus,timeStatus);
1.290 + if (notifStatus==KErrNone)
1.291 + {
1.292 + tim.Cancel();
1.293 + User::WaitForRequest(timeStatus);
1.294 +#ifndef __WINS__
1.295 + TUint sigmask=((aChangeSignal*KSignalChanged)|aChangeSignal);
1.296 + test((signals&sigmask)==sigmask);
1.297 +#endif
1.298 + }
1.299 + else
1.300 + {
1.301 + TheDceSerialPort->NotifySignalChangeCancel();
1.302 + User::WaitForRequest(notifStatus);
1.303 + test.Printf(_L("Timed Out!\n\r"));
1.304 + test.Getch();
1.305 + test(FALSE);
1.306 + }
1.307 + TUint rdSignals=TheDceSerialPort->Signals();
1.308 + test(rdSignals&aChangeSignal);
1.309 +
1.310 + test.Next(_L("Testing NotifySignalChange() when not expected"));
1.311 + // Test notification doesn't happen with mask set to some other signal
1.312 + signals=0;
1.313 + TheDceSerialPort->NotifySignalChange(notifStatus,signals,KOtherSigIn);
1.314 + test(notifStatus==KRequestPending);
1.315 + tim.After(timeStatus,KTimeOut);
1.316 + test(timeStatus==KRequestPending);
1.317 +#if defined (_TWO_PORT_LOOPBACK_)
1.318 + TheDteSerialPort->SetSignals(0,KChangeSigOut); // Clear
1.319 +#else
1.320 + test.Printf(_L("10 seconds to negate DTR(D)\n\r"));
1.321 +#endif
1.322 + User::WaitForRequest(notifStatus,timeStatus);
1.323 + if (notifStatus==KErrNone)
1.324 + {
1.325 + tim.Cancel();
1.326 + User::WaitForRequest(timeStatus);
1.327 + test(FALSE);
1.328 + }
1.329 + else
1.330 + {
1.331 + test(timeStatus==KErrNone); // Success
1.332 + TheDceSerialPort->NotifySignalChangeCancel(); // Tests cancel
1.333 + User::WaitForRequest(notifStatus);
1.334 + }
1.335 +#ifndef __WINS__
1.336 + rdSignals=TheDceSerialPort->Signals();
1.337 + test(!(rdSignals&aChangeSignal));
1.338 +#endif
1.339 +
1.340 + test.Next(_L("Testing NotifySignalChange() with mask set"));
1.341 + // Test notification happens with mask set to this signal
1.342 + signals=0;
1.343 + TheDceSerialPort->NotifySignalChange(notifStatus,signals,aChangeSignal);
1.344 + test(notifStatus==KRequestPending);
1.345 + tim.After(timeStatus,KTimeOut);
1.346 + test(timeStatus==KRequestPending);
1.347 +#if defined (_TWO_PORT_LOOPBACK_)
1.348 + TheDteSerialPort->SetSignals(KChangeSigOut,0); // Set
1.349 +#else
1.350 + test.Printf(_L("10 seconds to assert DTR(D)\n\r"));
1.351 +#endif
1.352 + User::WaitForRequest(notifStatus,timeStatus);
1.353 + if (notifStatus==KErrNone)
1.354 + {
1.355 + tim.Cancel();
1.356 + User::WaitForRequest(timeStatus);
1.357 + test(signals==((aChangeSignal*KSignalChanged)|aChangeSignal));
1.358 + }
1.359 + else
1.360 + {
1.361 + TheDceSerialPort->NotifySignalChangeCancel();
1.362 + User::WaitForRequest(notifStatus);
1.363 + test.Printf(_L("Timed Out!\n\r"));
1.364 + test.Getch();
1.365 + test(FALSE);
1.366 + }
1.367 + rdSignals=TheDceSerialPort->Signals();
1.368 + test(rdSignals&aChangeSignal);
1.369 + }
1.370 +
1.371 + return(KErrNone);
1.372 + }
1.373 +
1.374 +LOCAL_C TInt TestingNotifyReceiveDataAvailable()
1.375 +//
1.376 +// Test NotifyReceiveDataAvailable()
1.377 +//
1.378 + {
1.379 +
1.380 + RTimer tim;
1.381 + tim.CreateLocal();
1.382 + TRequestStatus notifStatus;
1.383 + TRequestStatus timeStatus;
1.384 +
1.385 + if (!(TheCapsDce.iNotificationCaps & KNotifyDataAvailableSupported))
1.386 + test.Printf(_L("Data available notification not supported on this platform"));
1.387 + else
1.388 + {
1.389 + test.Next(_L("Testing NotifyReceiveDataAvailable()"));
1.390 +#if !defined (_TWO_PORT_LOOPBACK_)
1.391 + test.Printf(_L("Hit a key to start\n\r"));
1.392 + test.Getch();
1.393 +#endif
1.394 + TPtrC8 buf1(_S8("AT&f\r"));
1.395 + TBuf8<0x10> buf2(0x10);
1.396 +
1.397 + TheDceSerialPort->ResetBuffers();
1.398 + TheDceSerialPort->NotifyReceiveDataAvailable(notifStatus);
1.399 + test(notifStatus==KRequestPending);
1.400 + const TUint KTimeOut=NOTIFY_TIMEOUT;
1.401 + tim.After(timeStatus,KTimeOut);
1.402 + test(timeStatus==KRequestPending);
1.403 +#if defined (_TWO_PORT_LOOPBACK_)
1.404 + test(TheDteSerialPort->WriteS(buf1)==KErrNone);
1.405 +#else
1.406 + test.Printf(_L("10 seconds to send hayes command(H)\n\r"));
1.407 +#endif
1.408 + User::WaitForRequest(notifStatus,timeStatus);
1.409 + if (notifStatus==KErrNone)
1.410 + {
1.411 + tim.Cancel();
1.412 + User::WaitForRequest(timeStatus);
1.413 + }
1.414 + else
1.415 + {
1.416 + TheDceSerialPort->NotifyReceiveDataAvailableCancel();
1.417 + test.Printf(_L("Timed Out!\n\r"));
1.418 + test.Getch();
1.419 + test(FALSE);
1.420 + }
1.421 + User::After(500000);
1.422 + TInt len=TheDceSerialPort->QueryReceiveBuffer();
1.423 +// test(len==buf1.Length());
1.424 + buf2.FillZ();
1.425 + TheDceSerialPort->Read(notifStatus,buf2,len);
1.426 + User::WaitForRequest(notifStatus);
1.427 + TInt ret=buf2.Compare(buf1);
1.428 + if (ret!=0)
1.429 + {
1.430 + test.Printf(_L("Compare error\r\n"));
1.431 + test.Getch();
1.432 + }
1.433 + test(ret==0);
1.434 + }
1.435 + return(KErrNone);
1.436 + }
1.437 +
1.438 +#if !defined (__WINS__)
1.439 +LOCAL_C TInt TestingFlowControlChange()
1.440 +//
1.441 +// Test NotifyFlowControlChange()
1.442 +//
1.443 + {
1.444 +
1.445 + RTimer tim;
1.446 + tim.CreateLocal();
1.447 + TRequestStatus notifStatus;
1.448 + TRequestStatus timeStatus;
1.449 +
1.450 + if (!(TheCapsDce.iNotificationCaps & KNotifyFlowControlChangeSupported))
1.451 + test.Printf(_L("Flow Control change notification not supported on this platform"));
1.452 + else
1.453 + {
1.454 +#if !defined (_TWO_PORT_LOOPBACK_)
1.455 + test.Printf(_L("Hit a key to start\n\r"));
1.456 + test.Getch();
1.457 +#endif
1.458 +
1.459 + test.Next(_L("Testing GetFlowControlStatus()"));
1.460 + TheConfigDce.iHandshake=KConfigObeyXoff;
1.461 + test(TheDceSerialPort->SetConfig(TheConfigDceBuf)==KErrNone);
1.462 + TFlowControl fc;
1.463 + TheDceSerialPort->GetFlowControlStatus(fc);
1.464 + test(fc==EFlowControlOff);
1.465 +
1.466 + test.Next(_L("Testing NotifyFlowControlChange() with s/w flow control"));
1.467 + TheDceSerialPort->NotifyFlowControlChange(notifStatus);
1.468 + test(notifStatus==KRequestPending);
1.469 + const TUint KTimeOut=NOTIFY_TIMEOUT;
1.470 + tim.After(timeStatus,KTimeOut);
1.471 + test(timeStatus==KRequestPending);
1.472 +#if defined (_TWO_PORT_LOOPBACK_)
1.473 + test(TheDteSerialPort->WriteS(_L8("\x13"))==KErrNone); // XOFF
1.474 +#else
1.475 + test.Printf(_L("10 seconds to send XOFF(O)\n\r"));
1.476 +#endif
1.477 + User::WaitForRequest(notifStatus,timeStatus);
1.478 + if (notifStatus==KErrNone)
1.479 + {
1.480 + tim.Cancel();
1.481 + User::WaitForRequest(timeStatus);
1.482 + }
1.483 + else
1.484 + {
1.485 + TheDceSerialPort->NotifyFlowControlChangeCancel();
1.486 + test.Printf(_L("Timed Out!\n\r"));
1.487 + test.Getch();
1.488 + test(FALSE);
1.489 + }
1.490 +
1.491 + test.Next(_L("Testing GetFlowControlStatus() again"));
1.492 + TheDceSerialPort->GetFlowControlStatus(fc);
1.493 + test(fc==EFlowControlOn);
1.494 +
1.495 +#if defined (_TWO_PORT_LOOPBACK_)
1.496 + test(TheDteSerialPort->WriteS(_L8("\x11"))==KErrNone); // XON
1.497 +#else
1.498 + test.Printf(_L("Send XON(X)\n\r"));
1.499 +#endif
1.500 + User::After(1000000); // 1Sec
1.501 + TheDceSerialPort->GetFlowControlStatus(fc);
1.502 + test(fc==EFlowControlOff);
1.503 + TheConfigDce.iHandshake=0;
1.504 + test(TheDceSerialPort->SetConfig(TheConfigDceBuf)==KErrNone);
1.505 +
1.506 +#if defined (_TWO_PORT_LOOPBACK_)
1.507 + test.Next(_L("Testing NotifyFlowControlChange() with h/w flow control"));
1.508 + TheConfigDce.iHandshake=KConfigObeyRTS;
1.509 + test(TheDceSerialPort->SetConfig(TheConfigDceBuf)==KErrNone);
1.510 + TheDceSerialPort->GetFlowControlStatus(fc);
1.511 + test(fc==EFlowControlOff);
1.512 +
1.513 + TheDceSerialPort->NotifyFlowControlChange(notifStatus);
1.514 + test(notifStatus==KRequestPending);
1.515 + tim.After(timeStatus,KTimeOut);
1.516 + test(timeStatus==KRequestPending);
1.517 + TheDteSerialPort->SetSignals(0,KChangeSigOut); // Clear
1.518 + User::WaitForRequest(notifStatus,timeStatus);
1.519 + if (notifStatus==KErrNone)
1.520 + {
1.521 + tim.Cancel();
1.522 + User::WaitForRequest(timeStatus);
1.523 + }
1.524 + else
1.525 + {
1.526 + TheDceSerialPort->NotifyFlowControlChangeCancel();
1.527 + test.Printf(_L("Timed Out!\n\r"));
1.528 + test.Getch();
1.529 + test(FALSE);
1.530 + }
1.531 +
1.532 + TheDceSerialPort->GetFlowControlStatus(fc);
1.533 + test(fc==EFlowControlOn);
1.534 +
1.535 + TheDteSerialPort->SetSignals(KChangeSigOut,0); // Set
1.536 + User::After(1000000); // 1Sec
1.537 + TheDceSerialPort->GetFlowControlStatus(fc);
1.538 + test(fc==EFlowControlOff);
1.539 +
1.540 + test.Next(_L("Testing NotifyFlowControlChange() when not expected"));
1.541 + // Test notification doesn't happen when s/w flow control happens
1.542 + TheDceSerialPort->NotifyFlowControlChange(notifStatus);
1.543 + test(notifStatus==KRequestPending);
1.544 + tim.After(timeStatus,KTimeOut);
1.545 + test(timeStatus==KRequestPending);
1.546 + test(TheDteSerialPort->WriteS(_L8("\x13"))==KErrNone); // XOFF
1.547 + User::WaitForRequest(notifStatus,timeStatus);
1.548 + if (notifStatus==KErrNone)
1.549 + {
1.550 + tim.Cancel();
1.551 + User::WaitForRequest(timeStatus);
1.552 + test(FALSE);
1.553 + }
1.554 + else
1.555 + {
1.556 + test(timeStatus==KErrNone); // Success
1.557 + TheDceSerialPort->NotifyFlowControlChangeCancel(); // Tests cancel
1.558 + User::WaitForRequest(notifStatus);
1.559 + }
1.560 + test(TheDteSerialPort->WriteS(_L8("\x11"))==KErrNone); // XON
1.561 + TheDceSerialPort->GetFlowControlStatus(fc);
1.562 + test(fc==EFlowControlOff);
1.563 +
1.564 + TheConfigDce.iHandshake=0;
1.565 + test(TheDceSerialPort->SetConfig(TheConfigDceBuf)==KErrNone);
1.566 +#endif
1.567 + }
1.568 + return(KErrNone);
1.569 + }
1.570 +
1.571 +LOCAL_C TInt TestingNotifyConfigChange()
1.572 +//
1.573 +// Test NotifyConfigChange()
1.574 +//
1.575 + {
1.576 +
1.577 + RTimer tim;
1.578 + tim.CreateLocal();
1.579 + TRequestStatus notifStatus;
1.580 + TRequestStatus timeStatus;
1.581 +
1.582 + if (!(TheCapsDce.iNotificationCaps & KNotifyRateChangeSupported))
1.583 + test.Printf(_L("Rate change notification not supported on this platform"));
1.584 + else
1.585 + {
1.586 + test.Next(_L("Testing NotifyConfigChange()"));
1.587 +#if defined (_TWO_PORT_LOOPBACK_)
1.588 + TheConfigDte.iRate=EBps9600;
1.589 + test(TheDteSerialPort->SetConfig(TheConfigDteBuf)==KErrNone);
1.590 +#else
1.591 + test.Printf(_L("Change baudrate to 9600(BB)\n\r"));
1.592 + test.Printf(_L("Hit a key to start\n\r"));
1.593 + test.Getch();
1.594 +#endif
1.595 + TCommNotificationPckg cmBuf;
1.596 + TCommNotificationV01& cm=cmBuf();
1.597 +
1.598 + // Test requesting before autobauding is enabled
1.599 + TheDceSerialPort->NotifyConfigChange(notifStatus,cmBuf);
1.600 + User::WaitForRequest(notifStatus);
1.601 + test(notifStatus==KErrGeneral);
1.602 +
1.603 + // Enable autobauding
1.604 + TheConfigDce.iRate=EBpsAutobaud;
1.605 + test(TheDceSerialPort->SetConfig(TheConfigDceBuf)==KErrNone);
1.606 +
1.607 + cm.iChangedMembers=0;
1.608 + cm.iRate=EBps50;
1.609 + TheDceSerialPort->NotifyConfigChange(notifStatus,cmBuf);
1.610 + test(notifStatus==KRequestPending);
1.611 + const TUint KTimeOut=NOTIFY_TIMEOUT;
1.612 + tim.After(timeStatus,KTimeOut);
1.613 + test(timeStatus==KRequestPending);
1.614 +#if defined (_TWO_PORT_LOOPBACK_)
1.615 + test(TheDteSerialPort->WriteS(_L8("AT&f\r"))==KErrNone);
1.616 +#else
1.617 + test.Printf(_L("10 seconds to send hayes command(H)\n\r"));
1.618 +#endif
1.619 + User::WaitForRequest(notifStatus,timeStatus);
1.620 + if (notifStatus==KErrNone)
1.621 + {
1.622 + tim.Cancel();
1.623 + User::WaitForRequest(timeStatus);
1.624 + test(cm.iChangedMembers==KRateChanged);
1.625 + test(cm.iRate==EBps9600);
1.626 + }
1.627 + else
1.628 + {
1.629 + TheDceSerialPort->NotifyConfigChangeCancel();
1.630 + test.Printf(_L("Timed Out!\n\r"));
1.631 + test.Getch();
1.632 + test(FALSE);
1.633 + }
1.634 + }
1.635 + return(KErrNone);
1.636 + }
1.637 +#endif
1.638 +
1.639 +GLDEF_C TInt E32Main()
1.640 +//
1.641 +// Test DCE serial driver
1.642 +//
1.643 + {
1.644 +
1.645 + test.Title();
1.646 + test.Start(_L("Turn off logging"));
1.647 + test.SetLogged(EFalse);//turn off serial port debugging!
1.648 +
1.649 + TInt r;
1.650 + test.Next(_L("Load drivers"));
1.651 +#if defined (__WINS__)
1.652 + r=User::LoadPhysicalDevice(PDD_NAME);
1.653 + test.Printf(_L("Load EUART Return %d\n\r"),r);
1.654 + r=User::LoadLogicalDevice(LDD_NAME);
1.655 + test.Printf(_L("Load ECOMM Return %d\n\r"),r);
1.656 + TheDceSerialPort=new RBusDevComm;
1.657 +#else
1.658 + r=User::LoadPhysicalDevice(DTEPDD_NAME);
1.659 + test.Printf(_L("Load DTE EUART Return %d\n\r"),r);
1.660 + r=User::LoadPhysicalDevice(DCEPDD_NAME);
1.661 + test.Printf(_L("Load DCE EUART Return %d\n\r"),r);
1.662 + r=User::LoadLogicalDevice(DTELDD_NAME);
1.663 + test.Printf(_L("Load DTE ECOMM Return %d\n\r"),r);
1.664 + r=User::LoadLogicalDevice(DCELDD_NAME);
1.665 + test.Printf(_L("Load DCE ECOMM Return %d\n\r"),r);
1.666 + TheDceSerialPort=new RBusDevCommDCE;
1.667 +#endif
1.668 + test(TheDceSerialPort!=NULL);
1.669 + TheDteSerialPort=new RComm;
1.670 + test(TheDteSerialPort!=NULL);
1.671 +//
1.672 + test.Next(_L("Open:"));
1.673 + r=TheDceSerialPort->Open(KTestUnitDce);
1.674 + test.Printf(_L("Open(DCE)=%d\n\r"),r);
1.675 + test(r==KErrNone);
1.676 + r=TheDteSerialPort->Open(KTestUnitDte);
1.677 + test.Printf(_L("Open(DTE)=%d\n\r"),r);
1.678 + test(r==KErrNone);
1.679 +
1.680 + // Setup serial ports
1.681 + test.Next(_L("Setup serial port"));
1.682 + TheDceSerialPort->Config(TheConfigDceBuf);
1.683 + TheConfigDce.iRate=EBps9600;
1.684 + TheConfigDce.iDataBits=EData8;
1.685 + TheConfigDce.iStopBits=EStop1;
1.686 + TheConfigDce.iParity=EParityNone;
1.687 + TheConfigDce.iHandshake=0;
1.688 + r=TheDceSerialPort->SetConfig(TheConfigDceBuf);
1.689 + test(r==KErrNone);
1.690 +
1.691 + TheDteSerialPort->Config(TheConfigDteBuf);
1.692 + TheConfigDte.iRate=EBps9600;
1.693 + TheConfigDte.iDataBits=EData8;
1.694 + TheConfigDte.iStopBits=EStop1;
1.695 + TheConfigDte.iParity=EParityNone;
1.696 + TheConfigDte.iHandshake=0;
1.697 + r=TheDteSerialPort->SetConfig(TheConfigDteBuf);
1.698 + test(r==KErrNone);
1.699 +
1.700 + test.Next(_L("Get DCE caps"));
1.701 + TheDceSerialPort->Caps(TheCapsDceBuf);
1.702 + test(r==KErrNone);
1.703 +
1.704 +#ifndef __WINS__
1.705 + test.Next(_L("I/p signals"));
1.706 +#if defined (_TWO_PORT_LOOPBACK_)
1.707 + TheDteSerialPort->SetSignals(0,KChangeSigOut); // Clear
1.708 +#else
1.709 + test.Printf(_L("Negate DTR(D) - hit a key\n\r"));
1.710 + test.Getch();
1.711 +#endif
1.712 + TUint sig=TheDceSerialPort->Signals();
1.713 + test.Printf(_L("Check (%x) is negated: %x\n\r"),KChangeSigIn,sig);
1.714 + test(!(sig&KChangeSigIn));
1.715 +#if defined (_TWO_PORT_LOOPBACK_)
1.716 + TheDteSerialPort->SetSignals(KChangeSigOut,0); // Set
1.717 +#else
1.718 + test.Printf(_L("Assert DTR(D) - hit a key\n\r"));
1.719 + test.Getch();
1.720 +#endif
1.721 + sig=TheDceSerialPort->Signals();
1.722 + test.Printf(_L("Check (%x) is asserted: %x\n\r"),KChangeSigIn,sig);
1.723 + test(sig&KChangeSigIn);
1.724 +
1.725 +#if defined (_TWO_PORT_LOOPBACK_)
1.726 + test.Next(_L("O/p signals"));
1.727 + TheDceSerialPort->SetSignals(0,KSignalCTS); // Clear
1.728 + sig=TheDteSerialPort->Signals();
1.729 + test.Printf(_L("Check (%x) is negated: %x\n\r"),KSignalCTS,sig);
1.730 + test(!(sig&KSignalCTS));
1.731 + TheDceSerialPort->SetSignals(KSignalCTS,0); // Set
1.732 + sig=TheDteSerialPort->Signals();
1.733 + test.Printf(_L("Check (%x) is asserted: %x\n\r"),KSignalCTS,sig);
1.734 + test(sig&KSignalCTS);
1.735 +#endif
1.736 +#endif
1.737 + test.Next(_L("Loopback test at 9600"));
1.738 +#if !defined (_TWO_PORT_LOOPBACK_)
1.739 + test.Printf(_L("Start loopback at 9600(L) - hit a key when ready\n\r"));
1.740 + test.Getch();
1.741 +#endif
1.742 + test(CheckedWrite(KTestPatternSize)==KTestPatternSize);
1.743 +
1.744 + test.Next(_L("Loopback test at 115200"));
1.745 + TheConfigDce.iRate=EBps115200;
1.746 + r=TheDceSerialPort->SetConfig(TheConfigDceBuf);
1.747 + test(r==KErrNone);
1.748 +#if defined (_TWO_PORT_LOOPBACK_)
1.749 + TheConfigDte.iRate=EBps115200;
1.750 + r=TheDteSerialPort->SetConfig(TheConfigDteBuf);
1.751 + test(r==KErrNone);
1.752 +#else
1.753 + test.Printf(_L("Start loopback at 115200(??BFL) - hit a key when ready\n\r"));
1.754 + test.Getch();
1.755 +#endif
1.756 + test(CheckedWrite(KTestPatternSize)==KTestPatternSize);
1.757 +
1.758 + test.Next(_L("Test signal change notification"));
1.759 + TestingNotifySignalChange(KChangeSigIn);
1.760 +
1.761 + test.Next(_L("Test receive data available notification"));
1.762 + TestingNotifyReceiveDataAvailable();
1.763 +
1.764 +#if !defined (__WINS__)
1.765 + test.Next(_L("Test flow control change"));
1.766 + TestingFlowControlChange();
1.767 +
1.768 + test.Next(_L("Test config change notification"));
1.769 + TestingNotifyConfigChange();
1.770 +#endif
1.771 +
1.772 + TheDceSerialPort->Close();
1.773 + TheDteSerialPort->Close();
1.774 + test.Printf(_L("Hit a key"));
1.775 + test.Getch();
1.776 + test.End();
1.777 + return(KErrNone);
1.778 + }
1.779 +
1.780 +