os/kernelhwsrv/kerneltest/e32test/device/t_dce.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1998-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_dce.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
// Cogent uses two port loopback, Linda doesn't
sl@0
    19
#define _TWO_PORT_LOOPBACK_ 
sl@0
    20
sl@0
    21
#include <e32base.h>
sl@0
    22
#include <e32base_private.h>
sl@0
    23
#include <e32test.h>
sl@0
    24
#include <e32cons.h>
sl@0
    25
#include <e32svr.h>
sl@0
    26
#include <e32hal.h>
sl@0
    27
#include <d32comm.h>
sl@0
    28
#include <e32uid.h>
sl@0
    29
sl@0
    30
const TInt KUnit0=0;
sl@0
    31
const TInt KUnit1=1;
sl@0
    32
const TInt KUnit2=2;
sl@0
    33
sl@0
    34
#ifdef _TWO_PORT_LOOPBACK_
sl@0
    35
#define NOTIFY_TIMEOUT 2000000 // 2 seconds
sl@0
    36
#else
sl@0
    37
#define NOTIFY_TIMEOUT 10000000 // 10 seconds
sl@0
    38
#endif
sl@0
    39
sl@0
    40
const TInt KTestPatternSize=250;
sl@0
    41
sl@0
    42
#if defined (__WINS__)
sl@0
    43
// Running this test in WINS is fairly pointless since WINS uses the DTE driver.
sl@0
    44
// The WINS version was just to get the basic test program working - i.e. to 
sl@0
    45
// speed up the debug process.
sl@0
    46
#define PDD_NAME _L("ECDRV.PDD")
sl@0
    47
#define LDD_NAME _L("ECOMM.LDD")
sl@0
    48
const TInt KTestUnitDte=KUnit0;
sl@0
    49
const TInt KTestUnitDce=KUnit1;
sl@0
    50
const TInt KChangeSigIn=KSignalCTS; // DTE driver used on WINS so read DSR rather than RTS
sl@0
    51
const TInt KOtherSigIn=KSignalDCD; // DTE driver used on WINS so read DCD rather than DTR
sl@0
    52
const TInt KChangeSigOut=KSignalRTS;
sl@0
    53
#else
sl@0
    54
#define DTEPDD_NAME _L("EUART3")
sl@0
    55
//#define DCEPDD_NAME _L("EUART1DCE") // Linda
sl@0
    56
#define DCEPDD_NAME _L("EUART1") // Cogent
sl@0
    57
#define DTELDD_NAME _L("ECOMM")
sl@0
    58
#define DCELDD_NAME _L("ECOMMDCE")
sl@0
    59
const TInt KTestUnitDte=KUnit2;
sl@0
    60
const TInt KTestUnitDce=KUnit0;
sl@0
    61
const TInt KChangeSigIn=KSignalRTS; // DCE input - Cogent
sl@0
    62
const TInt KOtherSigIn=KSignalDTR; // DCE input - Cogent
sl@0
    63
const TInt KChangeSigOut=KSignalRTS; // DTE output - Cogent
sl@0
    64
//const TInt KChangeSigIn=KSignalDTR; // DCE input - Linda
sl@0
    65
//const TInt KOtherSigIn=KSignalRTS; // DCE input - Linda
sl@0
    66
//const TInt KChangeSigOut=KSignalDTR; // DTE output - Linda
sl@0
    67
#endif
sl@0
    68
sl@0
    69
//	Our own comms object with synchronous writes
sl@0
    70
class RComm : public RBusDevComm
sl@0
    71
	{
sl@0
    72
public:
sl@0
    73
	TInt WriteS(const TDesC8& aDes);
sl@0
    74
	TInt WriteS(const TDesC8& aDes,TInt aLength);
sl@0
    75
	};
sl@0
    76
sl@0
    77
LOCAL_D RTest test(_L("T_DCE"));
sl@0
    78
RComm* TheDteSerialPort;
sl@0
    79
#if defined (__WINS__)
sl@0
    80
RBusDevComm* TheDceSerialPort;
sl@0
    81
#else
sl@0
    82
RBusDevCommDCE* TheDceSerialPort;
sl@0
    83
#endif
sl@0
    84
sl@0
    85
TCommConfig TheConfigDceBuf;
sl@0
    86
TCommConfigV01& TheConfigDce=TheConfigDceBuf();
sl@0
    87
TCommConfig TheConfigDteBuf;
sl@0
    88
TCommConfigV01& TheConfigDte=TheConfigDteBuf();
sl@0
    89
TCommCaps2 TheCapsDceBuf;
sl@0
    90
TCommCapsV02& TheCapsDce=TheCapsDceBuf();
sl@0
    91
sl@0
    92
sl@0
    93
TInt RComm::WriteS(const TDesC8& aDes)
sl@0
    94
sl@0
    95
//	Syncronous write
sl@0
    96
sl@0
    97
	{
sl@0
    98
	return(WriteS(aDes,aDes.Length()));
sl@0
    99
	}
sl@0
   100
	
sl@0
   101
TInt RComm::WriteS(const TDesC8& aDes,TInt aLength)
sl@0
   102
sl@0
   103
//	Syncronous write
sl@0
   104
sl@0
   105
	{
sl@0
   106
sl@0
   107
	TRequestStatus s;
sl@0
   108
	Write(s,aDes,aLength);
sl@0
   109
	User::WaitForRequest(s);
sl@0
   110
	return(s.Int());
sl@0
   111
	}
sl@0
   112
sl@0
   113
LOCAL_C void StripeMem(TDes8& aBuf,TUint aStartChar,TUint anEndChar)
sl@0
   114
//
sl@0
   115
// Mark a buffer with repeating byte pattern
sl@0
   116
//
sl@0
   117
	{
sl@0
   118
sl@0
   119
	if (aStartChar==anEndChar)
sl@0
   120
		{
sl@0
   121
		aBuf.Fill(aStartChar);
sl@0
   122
		return;
sl@0
   123
		}
sl@0
   124
sl@0
   125
	TUint character=aStartChar;
sl@0
   126
	for (TInt i=0;i<aBuf.Length();i++)
sl@0
   127
		{
sl@0
   128
		aBuf[i]=(TText8)character;
sl@0
   129
		if(++character>anEndChar)
sl@0
   130
			character=aStartChar;
sl@0
   131
		}
sl@0
   132
	}
sl@0
   133
sl@0
   134
#define COLUMN_HEADER _L("            RxBuf            |          Expected       \r\n")
sl@0
   135
LOCAL_C void DumpDescriptors(TDes8 &aLeft,TDes8 &aRight)
sl@0
   136
//
sl@0
   137
//
sl@0
   138
//
sl@0
   139
	{
sl@0
   140
sl@0
   141
	TBuf<80> b;
sl@0
   142
	test.Printf(_L("Compare failed:\r\n"));
sl@0
   143
	TInt minLen=Min(aLeft.Length(),aRight.Length());
sl@0
   144
	test.Printf(COLUMN_HEADER);
sl@0
   145
	TInt i=0;
sl@0
   146
	TInt j=0;
sl@0
   147
	while (i<=minLen)
sl@0
   148
		{
sl@0
   149
		b.Format(_L("%02x: "),i);
sl@0
   150
		for (j=0;j<8;j++)
sl@0
   151
			{
sl@0
   152
			if ((i+j)<minLen)
sl@0
   153
				{
sl@0
   154
				TInt v=aLeft[i+j];
sl@0
   155
				b.AppendFormat(_L("%02x "),v);
sl@0
   156
				}
sl@0
   157
			else
sl@0
   158
				b.Append(_L("   "));
sl@0
   159
			}
sl@0
   160
		b.Append(_L(" | "));
sl@0
   161
		for (j=0;j<8;j++)
sl@0
   162
			{
sl@0
   163
			if ((i+j)<minLen)
sl@0
   164
				{
sl@0
   165
				TInt v=aRight[i+j];
sl@0
   166
				b.AppendFormat(_L("%02x "),v);
sl@0
   167
				}
sl@0
   168
			else
sl@0
   169
				b.Append(_L("   "));
sl@0
   170
			}
sl@0
   171
		b.Append(_L("\r\n"));
sl@0
   172
		test.Printf(b);
sl@0
   173
		i+=8;
sl@0
   174
		if ((i%64)==0)
sl@0
   175
			test.Getch();
sl@0
   176
		}
sl@0
   177
	}
sl@0
   178
sl@0
   179
LOCAL_C TInt CheckedWrite(TInt aBufSize)
sl@0
   180
// 
sl@0
   181
// Write/Read loopback test - requires either a loopback connector or a
sl@0
   182
// connected device looping back the data (running T_DCEUTL).
sl@0
   183
//
sl@0
   184
	{
sl@0
   185
	TUint8* inBuf=new TUint8[aBufSize];
sl@0
   186
	test(inBuf!=NULL); 
sl@0
   187
	TUint8* outBuf=new TUint8[aBufSize];
sl@0
   188
	test(outBuf!=NULL); 
sl@0
   189
	TPtr8 outDes(outBuf,aBufSize,aBufSize);
sl@0
   190
	TPtr8 inDes(inBuf,aBufSize,aBufSize);
sl@0
   191
	
sl@0
   192
	RTimer tim;
sl@0
   193
	tim.CreateLocal();
sl@0
   194
	TRequestStatus readStatus;
sl@0
   195
	TRequestStatus timeStatus;
sl@0
   196
sl@0
   197
	StripeMem(outDes,'A','Z');
sl@0
   198
	inDes.FillZ();
sl@0
   199
sl@0
   200
	TheDceSerialPort->Read(readStatus,inDes,aBufSize+1);
sl@0
   201
	test(readStatus==KErrGeneral);
sl@0
   202
sl@0
   203
	TheDceSerialPort->Read(readStatus,inDes);
sl@0
   204
	test(readStatus==KRequestPending);
sl@0
   205
sl@0
   206
    TInt ret;
sl@0
   207
#if defined (_TWO_PORT_LOOPBACK_)
sl@0
   208
	ret=TheDteSerialPort->WriteS(outDes,aBufSize);
sl@0
   209
#else
sl@0
   210
	TRequestStatus ws;
sl@0
   211
	TheDceSerialPort->Write(ws,outDes,aBufSize);
sl@0
   212
	User::WaitForRequest(ws);
sl@0
   213
	ret=ws.Int();
sl@0
   214
#endif
sl@0
   215
	test(ret==KErrNone);
sl@0
   216
	const TUint KTimeOut=6000000;
sl@0
   217
	tim.After(timeStatus,KTimeOut);
sl@0
   218
	test(timeStatus==KRequestPending);
sl@0
   219
	User::WaitForRequest(readStatus,timeStatus);
sl@0
   220
	if (timeStatus==KErrNone)
sl@0
   221
		{
sl@0
   222
		TheDceSerialPort->ReadCancel();
sl@0
   223
		User::WaitForRequest(readStatus);
sl@0
   224
		test.Printf(_L("Timed Out!\n\r"));
sl@0
   225
		test.Getch();
sl@0
   226
		test(FALSE);
sl@0
   227
		}
sl@0
   228
	else
sl@0
   229
		{
sl@0
   230
		tim.Cancel();
sl@0
   231
		User::WaitForRequest(timeStatus);
sl@0
   232
		if (readStatus!=KErrNone)
sl@0
   233
			{
sl@0
   234
			test.Printf(_L("Read Failed! (%d)\n\r"),readStatus.Int());
sl@0
   235
			test.Getch();
sl@0
   236
			test(FALSE);
sl@0
   237
			}
sl@0
   238
		test(readStatus==KErrNone);
sl@0
   239
		test.Printf(_L("Read %d of %d\n\r"),inDes.Length(),outDes.Length());
sl@0
   240
		ret=outDes.Compare(inDes);
sl@0
   241
		if (ret!=0)
sl@0
   242
			DumpDescriptors(inDes,outDes);
sl@0
   243
  		test(ret==0);
sl@0
   244
		}
sl@0
   245
sl@0
   246
	tim.Close();
sl@0
   247
	delete inBuf;
sl@0
   248
	delete outBuf;
sl@0
   249
sl@0
   250
	return inDes.Length();
sl@0
   251
	}
sl@0
   252
sl@0
   253
LOCAL_C TInt TestingNotifySignalChange(TUint aChangeSignal)
sl@0
   254
//
sl@0
   255
// Test NotifySignalChange()
sl@0
   256
//
sl@0
   257
	{
sl@0
   258
sl@0
   259
	RTimer tim;
sl@0
   260
	tim.CreateLocal();
sl@0
   261
	TRequestStatus notifStatus;
sl@0
   262
	TRequestStatus timeStatus;
sl@0
   263
sl@0
   264
	if (!(TheCapsDce.iNotificationCaps & KNotifySignalsChangeSupported))
sl@0
   265
        test.Printf(_L("Signal change notification not supported on this platform"));
sl@0
   266
    else
sl@0
   267
        {
sl@0
   268
		test.Next(_L("Testing NotifySignalChange() with no mask set"));
sl@0
   269
#if defined (_TWO_PORT_LOOPBACK_)
sl@0
   270
	    TheDteSerialPort->SetSignals(0,KChangeSigOut); // Clear
sl@0
   271
#else
sl@0
   272
		test.Printf(_L("Make sure DTR negated(??D) - hit a key to start\n\r"));
sl@0
   273
		test.Getch();
sl@0
   274
		test.Printf(_L("10 seconds to assert DTR(D)\n\r"));
sl@0
   275
#endif
sl@0
   276
	
sl@0
   277
	    TUint signals=0;
sl@0
   278
	    TheDceSerialPort->NotifySignalChange(notifStatus,signals);
sl@0
   279
	    test(notifStatus==KRequestPending);
sl@0
   280
	    const TUint KTimeOut=NOTIFY_TIMEOUT;
sl@0
   281
	    tim.After(timeStatus,KTimeOut);
sl@0
   282
	    test(timeStatus==KRequestPending);
sl@0
   283
#if defined (_TWO_PORT_LOOPBACK_)
sl@0
   284
	    TheDteSerialPort->SetSignals(KChangeSigOut,0); // Set
sl@0
   285
#endif
sl@0
   286
 	    User::WaitForRequest(notifStatus,timeStatus);
sl@0
   287
	    if (notifStatus==KErrNone)
sl@0
   288
		    {
sl@0
   289
		    tim.Cancel();
sl@0
   290
			User::WaitForRequest(timeStatus);
sl@0
   291
#ifndef __WINS__
sl@0
   292
			TUint sigmask=((aChangeSignal*KSignalChanged)|aChangeSignal);
sl@0
   293
		    test((signals&sigmask)==sigmask);
sl@0
   294
#endif
sl@0
   295
		    }
sl@0
   296
	    else
sl@0
   297
		    {
sl@0
   298
		    TheDceSerialPort->NotifySignalChangeCancel();
sl@0
   299
			User::WaitForRequest(notifStatus);
sl@0
   300
		    test.Printf(_L("Timed Out!\n\r"));
sl@0
   301
			test.Getch();
sl@0
   302
		    test(FALSE);
sl@0
   303
		    }
sl@0
   304
	    TUint rdSignals=TheDceSerialPort->Signals();
sl@0
   305
		test(rdSignals&aChangeSignal);
sl@0
   306
sl@0
   307
		test.Next(_L("Testing NotifySignalChange() when not expected"));
sl@0
   308
        // Test notification doesn't happen with mask set to some other signal
sl@0
   309
	    signals=0;
sl@0
   310
	    TheDceSerialPort->NotifySignalChange(notifStatus,signals,KOtherSigIn);
sl@0
   311
	    test(notifStatus==KRequestPending);
sl@0
   312
	    tim.After(timeStatus,KTimeOut);
sl@0
   313
	    test(timeStatus==KRequestPending);
sl@0
   314
#if defined (_TWO_PORT_LOOPBACK_)
sl@0
   315
	    TheDteSerialPort->SetSignals(0,KChangeSigOut); // Clear
sl@0
   316
#else
sl@0
   317
		test.Printf(_L("10 seconds to negate DTR(D)\n\r"));
sl@0
   318
#endif
sl@0
   319
	    User::WaitForRequest(notifStatus,timeStatus);
sl@0
   320
	    if (notifStatus==KErrNone)
sl@0
   321
		    {
sl@0
   322
		    tim.Cancel();
sl@0
   323
			User::WaitForRequest(timeStatus);
sl@0
   324
		    test(FALSE);
sl@0
   325
		    }
sl@0
   326
	    else
sl@0
   327
			{
sl@0
   328
		    test(timeStatus==KErrNone); // Success
sl@0
   329
		    TheDceSerialPort->NotifySignalChangeCancel(); // Tests cancel 
sl@0
   330
			User::WaitForRequest(notifStatus);
sl@0
   331
			}
sl@0
   332
#ifndef __WINS__
sl@0
   333
	    rdSignals=TheDceSerialPort->Signals();
sl@0
   334
		test(!(rdSignals&aChangeSignal));
sl@0
   335
#endif
sl@0
   336
sl@0
   337
		test.Next(_L("Testing NotifySignalChange() with mask set"));
sl@0
   338
        // Test notification happens with mask set to this signal
sl@0
   339
	    signals=0;
sl@0
   340
	    TheDceSerialPort->NotifySignalChange(notifStatus,signals,aChangeSignal);
sl@0
   341
	    test(notifStatus==KRequestPending);
sl@0
   342
	    tim.After(timeStatus,KTimeOut);
sl@0
   343
	    test(timeStatus==KRequestPending);
sl@0
   344
#if defined (_TWO_PORT_LOOPBACK_)
sl@0
   345
	    TheDteSerialPort->SetSignals(KChangeSigOut,0); // Set
sl@0
   346
#else
sl@0
   347
		test.Printf(_L("10 seconds to assert DTR(D)\n\r"));
sl@0
   348
#endif
sl@0
   349
	    User::WaitForRequest(notifStatus,timeStatus);
sl@0
   350
	    if (notifStatus==KErrNone)
sl@0
   351
		    {
sl@0
   352
		    tim.Cancel();
sl@0
   353
			User::WaitForRequest(timeStatus);
sl@0
   354
		    test(signals==((aChangeSignal*KSignalChanged)|aChangeSignal));
sl@0
   355
		    }
sl@0
   356
	    else
sl@0
   357
		    {
sl@0
   358
		    TheDceSerialPort->NotifySignalChangeCancel();
sl@0
   359
			User::WaitForRequest(notifStatus);
sl@0
   360
		    test.Printf(_L("Timed Out!\n\r"));
sl@0
   361
			test.Getch();
sl@0
   362
		    test(FALSE);
sl@0
   363
		    }
sl@0
   364
	    rdSignals=TheDceSerialPort->Signals();
sl@0
   365
		test(rdSignals&aChangeSignal);
sl@0
   366
        }
sl@0
   367
sl@0
   368
	return(KErrNone);
sl@0
   369
	}
sl@0
   370
sl@0
   371
LOCAL_C TInt TestingNotifyReceiveDataAvailable()
sl@0
   372
//
sl@0
   373
// Test NotifyReceiveDataAvailable()
sl@0
   374
//
sl@0
   375
	{
sl@0
   376
sl@0
   377
	RTimer tim;
sl@0
   378
	tim.CreateLocal();
sl@0
   379
	TRequestStatus notifStatus;
sl@0
   380
	TRequestStatus timeStatus;
sl@0
   381
sl@0
   382
	if (!(TheCapsDce.iNotificationCaps & KNotifyDataAvailableSupported))
sl@0
   383
        test.Printf(_L("Data available notification not supported on this platform"));
sl@0
   384
    else
sl@0
   385
        {
sl@0
   386
		test.Next(_L("Testing NotifyReceiveDataAvailable()"));
sl@0
   387
#if !defined (_TWO_PORT_LOOPBACK_)
sl@0
   388
		test.Printf(_L("Hit a key to start\n\r"));
sl@0
   389
		test.Getch();
sl@0
   390
#endif
sl@0
   391
		TPtrC8 buf1(_S8("AT&f\r"));
sl@0
   392
	    TBuf8<0x10> buf2(0x10);
sl@0
   393
sl@0
   394
        TheDceSerialPort->ResetBuffers();
sl@0
   395
	    TheDceSerialPort->NotifyReceiveDataAvailable(notifStatus);
sl@0
   396
	    test(notifStatus==KRequestPending);
sl@0
   397
	    const TUint KTimeOut=NOTIFY_TIMEOUT;
sl@0
   398
	    tim.After(timeStatus,KTimeOut);
sl@0
   399
	    test(timeStatus==KRequestPending);
sl@0
   400
#if defined (_TWO_PORT_LOOPBACK_)
sl@0
   401
        test(TheDteSerialPort->WriteS(buf1)==KErrNone);
sl@0
   402
#else
sl@0
   403
		test.Printf(_L("10 seconds to send hayes command(H)\n\r"));
sl@0
   404
#endif
sl@0
   405
	    User::WaitForRequest(notifStatus,timeStatus);
sl@0
   406
	    if (notifStatus==KErrNone)
sl@0
   407
		    {
sl@0
   408
		    tim.Cancel();
sl@0
   409
			User::WaitForRequest(timeStatus);
sl@0
   410
		    }
sl@0
   411
	    else
sl@0
   412
		    {
sl@0
   413
	        TheDceSerialPort->NotifyReceiveDataAvailableCancel();
sl@0
   414
		    test.Printf(_L("Timed Out!\n\r"));
sl@0
   415
			test.Getch();
sl@0
   416
		    test(FALSE);
sl@0
   417
		    }
sl@0
   418
		User::After(500000);
sl@0
   419
		TInt len=TheDceSerialPort->QueryReceiveBuffer();
sl@0
   420
//        test(len==buf1.Length());
sl@0
   421
	    buf2.FillZ();
sl@0
   422
	    TheDceSerialPort->Read(notifStatus,buf2,len);
sl@0
   423
		User::WaitForRequest(notifStatus);
sl@0
   424
		TInt ret=buf2.Compare(buf1);
sl@0
   425
  	    if (ret!=0)
sl@0
   426
			{
sl@0
   427
			test.Printf(_L("Compare error\r\n"));
sl@0
   428
			test.Getch();
sl@0
   429
			}
sl@0
   430
		test(ret==0);
sl@0
   431
        }
sl@0
   432
	return(KErrNone);
sl@0
   433
	}
sl@0
   434
sl@0
   435
#if !defined (__WINS__)
sl@0
   436
LOCAL_C TInt TestingFlowControlChange()
sl@0
   437
//
sl@0
   438
// Test NotifyFlowControlChange()
sl@0
   439
//
sl@0
   440
	{
sl@0
   441
sl@0
   442
	RTimer tim;
sl@0
   443
	tim.CreateLocal();
sl@0
   444
	TRequestStatus notifStatus;
sl@0
   445
	TRequestStatus timeStatus;
sl@0
   446
sl@0
   447
	if (!(TheCapsDce.iNotificationCaps & KNotifyFlowControlChangeSupported))
sl@0
   448
        test.Printf(_L("Flow Control change notification not supported on this platform"));
sl@0
   449
    else
sl@0
   450
        {
sl@0
   451
#if !defined (_TWO_PORT_LOOPBACK_)
sl@0
   452
		test.Printf(_L("Hit a key to start\n\r"));
sl@0
   453
		test.Getch();
sl@0
   454
#endif
sl@0
   455
sl@0
   456
		test.Next(_L("Testing GetFlowControlStatus()"));
sl@0
   457
		TheConfigDce.iHandshake=KConfigObeyXoff;
sl@0
   458
		test(TheDceSerialPort->SetConfig(TheConfigDceBuf)==KErrNone);
sl@0
   459
		TFlowControl fc;
sl@0
   460
		TheDceSerialPort->GetFlowControlStatus(fc);
sl@0
   461
		test(fc==EFlowControlOff);
sl@0
   462
sl@0
   463
		test.Next(_L("Testing NotifyFlowControlChange() with s/w flow control"));
sl@0
   464
	    TheDceSerialPort->NotifyFlowControlChange(notifStatus);
sl@0
   465
	    test(notifStatus==KRequestPending);
sl@0
   466
	    const TUint KTimeOut=NOTIFY_TIMEOUT;
sl@0
   467
	    tim.After(timeStatus,KTimeOut);
sl@0
   468
	    test(timeStatus==KRequestPending);
sl@0
   469
#if defined (_TWO_PORT_LOOPBACK_)
sl@0
   470
        test(TheDteSerialPort->WriteS(_L8("\x13"))==KErrNone); // XOFF
sl@0
   471
#else
sl@0
   472
		test.Printf(_L("10 seconds to send XOFF(O)\n\r"));
sl@0
   473
#endif
sl@0
   474
	    User::WaitForRequest(notifStatus,timeStatus);
sl@0
   475
	    if (notifStatus==KErrNone)
sl@0
   476
		    {
sl@0
   477
		    tim.Cancel();
sl@0
   478
			User::WaitForRequest(timeStatus);
sl@0
   479
		    }
sl@0
   480
	    else
sl@0
   481
		    {
sl@0
   482
	        TheDceSerialPort->NotifyFlowControlChangeCancel();
sl@0
   483
		    test.Printf(_L("Timed Out!\n\r"));
sl@0
   484
			test.Getch();
sl@0
   485
		    test(FALSE);
sl@0
   486
		    }
sl@0
   487
sl@0
   488
		test.Next(_L("Testing GetFlowControlStatus() again"));
sl@0
   489
		TheDceSerialPort->GetFlowControlStatus(fc);
sl@0
   490
		test(fc==EFlowControlOn);
sl@0
   491
sl@0
   492
#if defined (_TWO_PORT_LOOPBACK_)
sl@0
   493
        test(TheDteSerialPort->WriteS(_L8("\x11"))==KErrNone); // XON
sl@0
   494
#else
sl@0
   495
		test.Printf(_L("Send XON(X)\n\r"));
sl@0
   496
#endif
sl@0
   497
		User::After(1000000);		  // 1Sec
sl@0
   498
		TheDceSerialPort->GetFlowControlStatus(fc);
sl@0
   499
		test(fc==EFlowControlOff);
sl@0
   500
		TheConfigDce.iHandshake=0;
sl@0
   501
		test(TheDceSerialPort->SetConfig(TheConfigDceBuf)==KErrNone);
sl@0
   502
sl@0
   503
#if defined (_TWO_PORT_LOOPBACK_)
sl@0
   504
		test.Next(_L("Testing NotifyFlowControlChange() with h/w flow control"));
sl@0
   505
		TheConfigDce.iHandshake=KConfigObeyRTS;
sl@0
   506
		test(TheDceSerialPort->SetConfig(TheConfigDceBuf)==KErrNone);
sl@0
   507
		TheDceSerialPort->GetFlowControlStatus(fc);
sl@0
   508
		test(fc==EFlowControlOff);
sl@0
   509
sl@0
   510
	    TheDceSerialPort->NotifyFlowControlChange(notifStatus);
sl@0
   511
	    test(notifStatus==KRequestPending);
sl@0
   512
	    tim.After(timeStatus,KTimeOut);
sl@0
   513
	    test(timeStatus==KRequestPending);
sl@0
   514
		TheDteSerialPort->SetSignals(0,KChangeSigOut); // Clear
sl@0
   515
	    User::WaitForRequest(notifStatus,timeStatus);
sl@0
   516
	    if (notifStatus==KErrNone)
sl@0
   517
		    {
sl@0
   518
		    tim.Cancel();
sl@0
   519
			User::WaitForRequest(timeStatus);
sl@0
   520
		    }
sl@0
   521
	    else
sl@0
   522
		    {
sl@0
   523
	        TheDceSerialPort->NotifyFlowControlChangeCancel();
sl@0
   524
		    test.Printf(_L("Timed Out!\n\r"));
sl@0
   525
			test.Getch();
sl@0
   526
		    test(FALSE);
sl@0
   527
		    }
sl@0
   528
sl@0
   529
		TheDceSerialPort->GetFlowControlStatus(fc);
sl@0
   530
		test(fc==EFlowControlOn);
sl@0
   531
sl@0
   532
		TheDteSerialPort->SetSignals(KChangeSigOut,0); // Set
sl@0
   533
		User::After(1000000);		  // 1Sec
sl@0
   534
		TheDceSerialPort->GetFlowControlStatus(fc);
sl@0
   535
		test(fc==EFlowControlOff);
sl@0
   536
sl@0
   537
		test.Next(_L("Testing NotifyFlowControlChange() when not expected"));
sl@0
   538
        // Test notification doesn't happen when s/w flow control happens
sl@0
   539
	    TheDceSerialPort->NotifyFlowControlChange(notifStatus);
sl@0
   540
	    test(notifStatus==KRequestPending);
sl@0
   541
	    tim.After(timeStatus,KTimeOut);
sl@0
   542
	    test(timeStatus==KRequestPending);
sl@0
   543
        test(TheDteSerialPort->WriteS(_L8("\x13"))==KErrNone); // XOFF
sl@0
   544
	    User::WaitForRequest(notifStatus,timeStatus);
sl@0
   545
	    if (notifStatus==KErrNone)
sl@0
   546
		    {
sl@0
   547
		    tim.Cancel();
sl@0
   548
			User::WaitForRequest(timeStatus);
sl@0
   549
		    test(FALSE);
sl@0
   550
		    }
sl@0
   551
	    else
sl@0
   552
		    {
sl@0
   553
		    test(timeStatus==KErrNone); // Success
sl@0
   554
	        TheDceSerialPort->NotifyFlowControlChangeCancel(); // Tests cancel
sl@0
   555
			User::WaitForRequest(notifStatus);
sl@0
   556
		    }
sl@0
   557
        test(TheDteSerialPort->WriteS(_L8("\x11"))==KErrNone); // XON
sl@0
   558
		TheDceSerialPort->GetFlowControlStatus(fc);
sl@0
   559
		test(fc==EFlowControlOff);
sl@0
   560
sl@0
   561
		TheConfigDce.iHandshake=0;
sl@0
   562
		test(TheDceSerialPort->SetConfig(TheConfigDceBuf)==KErrNone);
sl@0
   563
#endif
sl@0
   564
        }
sl@0
   565
	return(KErrNone);
sl@0
   566
	}
sl@0
   567
sl@0
   568
LOCAL_C TInt TestingNotifyConfigChange()
sl@0
   569
//
sl@0
   570
// Test NotifyConfigChange()
sl@0
   571
//
sl@0
   572
	{
sl@0
   573
sl@0
   574
	RTimer tim;
sl@0
   575
	tim.CreateLocal();
sl@0
   576
	TRequestStatus notifStatus;
sl@0
   577
	TRequestStatus timeStatus;
sl@0
   578
sl@0
   579
	if (!(TheCapsDce.iNotificationCaps & KNotifyRateChangeSupported))
sl@0
   580
        test.Printf(_L("Rate change notification not supported on this platform"));
sl@0
   581
    else
sl@0
   582
        {
sl@0
   583
		test.Next(_L("Testing NotifyConfigChange()"));
sl@0
   584
#if defined (_TWO_PORT_LOOPBACK_)
sl@0
   585
	    TheConfigDte.iRate=EBps9600;
sl@0
   586
	    test(TheDteSerialPort->SetConfig(TheConfigDteBuf)==KErrNone);
sl@0
   587
#else
sl@0
   588
		test.Printf(_L("Change baudrate to 9600(BB)\n\r"));
sl@0
   589
		test.Printf(_L("Hit a key to start\n\r"));
sl@0
   590
		test.Getch();
sl@0
   591
#endif
sl@0
   592
		TCommNotificationPckg cmBuf;
sl@0
   593
		TCommNotificationV01& cm=cmBuf();
sl@0
   594
sl@0
   595
		// Test requesting before autobauding is enabled
sl@0
   596
	    TheDceSerialPort->NotifyConfigChange(notifStatus,cmBuf);
sl@0
   597
	    User::WaitForRequest(notifStatus);
sl@0
   598
	    test(notifStatus==KErrGeneral);
sl@0
   599
sl@0
   600
		// Enable autobauding
sl@0
   601
		TheConfigDce.iRate=EBpsAutobaud;  
sl@0
   602
		test(TheDceSerialPort->SetConfig(TheConfigDceBuf)==KErrNone);
sl@0
   603
sl@0
   604
		cm.iChangedMembers=0;
sl@0
   605
		cm.iRate=EBps50;
sl@0
   606
	    TheDceSerialPort->NotifyConfigChange(notifStatus,cmBuf);
sl@0
   607
	    test(notifStatus==KRequestPending);
sl@0
   608
	    const TUint KTimeOut=NOTIFY_TIMEOUT;
sl@0
   609
	    tim.After(timeStatus,KTimeOut);
sl@0
   610
	    test(timeStatus==KRequestPending);
sl@0
   611
#if defined (_TWO_PORT_LOOPBACK_)
sl@0
   612
        test(TheDteSerialPort->WriteS(_L8("AT&f\r"))==KErrNone);
sl@0
   613
#else
sl@0
   614
		test.Printf(_L("10 seconds to send hayes command(H)\n\r"));
sl@0
   615
#endif
sl@0
   616
	    User::WaitForRequest(notifStatus,timeStatus);
sl@0
   617
	    if (notifStatus==KErrNone)
sl@0
   618
		    {
sl@0
   619
		    tim.Cancel();
sl@0
   620
			User::WaitForRequest(timeStatus);
sl@0
   621
			test(cm.iChangedMembers==KRateChanged);
sl@0
   622
			test(cm.iRate==EBps9600);
sl@0
   623
		    }
sl@0
   624
	    else
sl@0
   625
		    {
sl@0
   626
	        TheDceSerialPort->NotifyConfigChangeCancel();
sl@0
   627
		    test.Printf(_L("Timed Out!\n\r"));
sl@0
   628
			test.Getch();
sl@0
   629
		    test(FALSE);
sl@0
   630
		    }
sl@0
   631
        }
sl@0
   632
	return(KErrNone);
sl@0
   633
	}
sl@0
   634
#endif
sl@0
   635
sl@0
   636
GLDEF_C TInt E32Main()
sl@0
   637
//
sl@0
   638
// Test DCE serial driver
sl@0
   639
//
sl@0
   640
    {
sl@0
   641
sl@0
   642
	test.Title();
sl@0
   643
	test.Start(_L("Turn off logging"));
sl@0
   644
	test.SetLogged(EFalse);//turn off serial port debugging!
sl@0
   645
sl@0
   646
	TInt r;
sl@0
   647
	test.Next(_L("Load drivers"));
sl@0
   648
#if defined (__WINS__)
sl@0
   649
	r=User::LoadPhysicalDevice(PDD_NAME);
sl@0
   650
	test.Printf(_L("Load EUART Return %d\n\r"),r);
sl@0
   651
	r=User::LoadLogicalDevice(LDD_NAME);
sl@0
   652
	test.Printf(_L("Load ECOMM Return %d\n\r"),r);
sl@0
   653
	TheDceSerialPort=new RBusDevComm;
sl@0
   654
#else
sl@0
   655
	r=User::LoadPhysicalDevice(DTEPDD_NAME);
sl@0
   656
	test.Printf(_L("Load DTE EUART Return %d\n\r"),r);
sl@0
   657
	r=User::LoadPhysicalDevice(DCEPDD_NAME);
sl@0
   658
	test.Printf(_L("Load DCE EUART Return %d\n\r"),r);
sl@0
   659
	r=User::LoadLogicalDevice(DTELDD_NAME);
sl@0
   660
	test.Printf(_L("Load DTE ECOMM Return %d\n\r"),r);
sl@0
   661
	r=User::LoadLogicalDevice(DCELDD_NAME);
sl@0
   662
	test.Printf(_L("Load DCE ECOMM Return %d\n\r"),r);
sl@0
   663
	TheDceSerialPort=new RBusDevCommDCE;
sl@0
   664
#endif
sl@0
   665
	test(TheDceSerialPort!=NULL);
sl@0
   666
	TheDteSerialPort=new RComm;
sl@0
   667
	test(TheDteSerialPort!=NULL);
sl@0
   668
//
sl@0
   669
	test.Next(_L("Open:"));
sl@0
   670
	r=TheDceSerialPort->Open(KTestUnitDce);
sl@0
   671
	test.Printf(_L("Open(DCE)=%d\n\r"),r);
sl@0
   672
	test(r==KErrNone);
sl@0
   673
	r=TheDteSerialPort->Open(KTestUnitDte);
sl@0
   674
	test.Printf(_L("Open(DTE)=%d\n\r"),r);
sl@0
   675
	test(r==KErrNone);
sl@0
   676
sl@0
   677
	// Setup serial ports
sl@0
   678
	test.Next(_L("Setup serial port"));
sl@0
   679
	TheDceSerialPort->Config(TheConfigDceBuf);
sl@0
   680
	TheConfigDce.iRate=EBps9600;
sl@0
   681
	TheConfigDce.iDataBits=EData8;
sl@0
   682
	TheConfigDce.iStopBits=EStop1;
sl@0
   683
	TheConfigDce.iParity=EParityNone;
sl@0
   684
	TheConfigDce.iHandshake=0;
sl@0
   685
	r=TheDceSerialPort->SetConfig(TheConfigDceBuf);
sl@0
   686
	test(r==KErrNone);
sl@0
   687
sl@0
   688
	TheDteSerialPort->Config(TheConfigDteBuf);
sl@0
   689
	TheConfigDte.iRate=EBps9600;
sl@0
   690
	TheConfigDte.iDataBits=EData8;
sl@0
   691
	TheConfigDte.iStopBits=EStop1;
sl@0
   692
	TheConfigDte.iParity=EParityNone;
sl@0
   693
	TheConfigDte.iHandshake=0;
sl@0
   694
	r=TheDteSerialPort->SetConfig(TheConfigDteBuf);
sl@0
   695
	test(r==KErrNone);
sl@0
   696
sl@0
   697
	test.Next(_L("Get DCE caps"));
sl@0
   698
	TheDceSerialPort->Caps(TheCapsDceBuf);
sl@0
   699
	test(r==KErrNone);
sl@0
   700
sl@0
   701
#ifndef __WINS__
sl@0
   702
	test.Next(_L("I/p signals"));
sl@0
   703
#if defined (_TWO_PORT_LOOPBACK_)
sl@0
   704
	TheDteSerialPort->SetSignals(0,KChangeSigOut); // Clear
sl@0
   705
#else
sl@0
   706
	test.Printf(_L("Negate DTR(D) - hit a key\n\r"));
sl@0
   707
	test.Getch();
sl@0
   708
#endif
sl@0
   709
	TUint sig=TheDceSerialPort->Signals();
sl@0
   710
	test.Printf(_L("Check (%x) is negated: %x\n\r"),KChangeSigIn,sig);
sl@0
   711
	test(!(sig&KChangeSigIn));
sl@0
   712
#if defined (_TWO_PORT_LOOPBACK_)
sl@0
   713
	TheDteSerialPort->SetSignals(KChangeSigOut,0); // Set
sl@0
   714
#else
sl@0
   715
	test.Printf(_L("Assert DTR(D) - hit a key\n\r"));
sl@0
   716
	test.Getch();
sl@0
   717
#endif
sl@0
   718
	sig=TheDceSerialPort->Signals();
sl@0
   719
	test.Printf(_L("Check (%x) is asserted: %x\n\r"),KChangeSigIn,sig);
sl@0
   720
	test(sig&KChangeSigIn);
sl@0
   721
sl@0
   722
#if defined (_TWO_PORT_LOOPBACK_)
sl@0
   723
	test.Next(_L("O/p signals"));
sl@0
   724
	TheDceSerialPort->SetSignals(0,KSignalCTS); // Clear
sl@0
   725
	sig=TheDteSerialPort->Signals();
sl@0
   726
	test.Printf(_L("Check (%x) is negated: %x\n\r"),KSignalCTS,sig);
sl@0
   727
	test(!(sig&KSignalCTS));
sl@0
   728
	TheDceSerialPort->SetSignals(KSignalCTS,0); // Set
sl@0
   729
	sig=TheDteSerialPort->Signals();
sl@0
   730
	test.Printf(_L("Check (%x) is asserted: %x\n\r"),KSignalCTS,sig);
sl@0
   731
	test(sig&KSignalCTS);
sl@0
   732
#endif
sl@0
   733
#endif
sl@0
   734
	test.Next(_L("Loopback test at 9600"));
sl@0
   735
#if !defined (_TWO_PORT_LOOPBACK_)
sl@0
   736
	test.Printf(_L("Start loopback at 9600(L) - hit a key when ready\n\r"));
sl@0
   737
	test.Getch();
sl@0
   738
#endif
sl@0
   739
	test(CheckedWrite(KTestPatternSize)==KTestPatternSize);
sl@0
   740
sl@0
   741
	test.Next(_L("Loopback test at 115200"));
sl@0
   742
	TheConfigDce.iRate=EBps115200;
sl@0
   743
	r=TheDceSerialPort->SetConfig(TheConfigDceBuf);
sl@0
   744
	test(r==KErrNone);
sl@0
   745
#if defined (_TWO_PORT_LOOPBACK_)
sl@0
   746
	TheConfigDte.iRate=EBps115200;
sl@0
   747
	r=TheDteSerialPort->SetConfig(TheConfigDteBuf);
sl@0
   748
	test(r==KErrNone);
sl@0
   749
#else
sl@0
   750
	test.Printf(_L("Start loopback at 115200(??BFL) - hit a key when ready\n\r"));
sl@0
   751
	test.Getch();
sl@0
   752
#endif
sl@0
   753
	test(CheckedWrite(KTestPatternSize)==KTestPatternSize);
sl@0
   754
sl@0
   755
	test.Next(_L("Test signal change notification"));
sl@0
   756
	TestingNotifySignalChange(KChangeSigIn);
sl@0
   757
sl@0
   758
	test.Next(_L("Test receive data available notification"));
sl@0
   759
	TestingNotifyReceiveDataAvailable();
sl@0
   760
sl@0
   761
#if !defined (__WINS__)
sl@0
   762
	test.Next(_L("Test flow control change"));
sl@0
   763
	TestingFlowControlChange();
sl@0
   764
sl@0
   765
	test.Next(_L("Test config change notification"));
sl@0
   766
	TestingNotifyConfigChange();
sl@0
   767
#endif
sl@0
   768
sl@0
   769
	TheDceSerialPort->Close();
sl@0
   770
	TheDteSerialPort->Close();
sl@0
   771
	test.Printf(_L("Hit a key"));
sl@0
   772
	test.Getch();
sl@0
   773
	test.End();
sl@0
   774
	return(KErrNone);
sl@0
   775
	}
sl@0
   776
sl@0
   777