kerneltest/e32test/misc/t_lbk.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test\misc\t_lbk.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 #include <d32comm.h>
       
    20 
       
    21 RTest test(_L("LoopBack"));
       
    22 
       
    23 #define TEST(c)	((void)((c)||(test.Printf(_L("Failed at line %d\n"),__LINE__),test.Getch(),test(0),0)))
       
    24 
       
    25 const TInt KBufferSize=4096;
       
    26 
       
    27 _LIT(KLddName,"ECOMM");
       
    28 _LIT(KPddName,"EUART");
       
    29 
       
    30 TUint8 Buffer[2*KBufferSize];
       
    31 
       
    32 void LoadCommDrivers()
       
    33 	{
       
    34 	test.Printf(_L("Load LDD\n"));
       
    35 	TInt r=User::LoadLogicalDevice(KLddName);
       
    36 	TEST(r==KErrNone || r==KErrAlreadyExists);
       
    37 
       
    38 	TInt i;
       
    39 	TInt n=0;
       
    40 	for (i=-1; i<10; ++i)
       
    41 		{
       
    42 		TBuf<16> pddName=KPddName();
       
    43 		if (i>=0)
       
    44 			pddName.Append('0'+i);
       
    45 		TInt r=User::LoadPhysicalDevice(pddName);
       
    46 		if (r==KErrNone || r==KErrAlreadyExists)
       
    47 			{
       
    48 			++n;
       
    49 			test.Printf(_L("%S found\n"),&pddName);
       
    50 			}
       
    51 		}
       
    52 	TEST(n!=0);
       
    53 	}
       
    54 
       
    55 GLDEF_C TInt E32Main()
       
    56 	{
       
    57 	RThread().SetPriority(EPriorityAbsoluteForeground);
       
    58 	test.SetLogged(EFalse);
       
    59 	test.Title();
       
    60 
       
    61 	TBuf<256> cmd;
       
    62 	User::CommandLine(cmd);
       
    63 	TInt port=0;
       
    64 	if (cmd.Length()!=0)
       
    65 		{
       
    66 		TUint8 c=(TUint8)cmd[0];
       
    67 		if (c>='0' && c<='9')
       
    68 			{
       
    69 			port=c-'0';
       
    70 			}
       
    71 		}
       
    72 
       
    73 	TInt r=KErrNone;
       
    74 	LoadCommDrivers();
       
    75 
       
    76 	RBusDevComm comm;
       
    77 	r=comm.Open(port);
       
    78 	test(r==KErrNone);
       
    79 	TCommConfig cfg;
       
    80 	TCommConfigV01& c=cfg();
       
    81 	comm.Config(cfg);
       
    82 	c.iRate=EBps115200;
       
    83 	c.iDataBits=EData8;
       
    84 	c.iStopBits=EStop1;
       
    85 	c.iParity=EParityNone;
       
    86 	c.iHandshake=0;
       
    87 	c.iFifo=EFifoEnable;
       
    88 	c.iTerminatorCount=0;
       
    89 	r=comm.SetConfig(cfg);
       
    90 	test(r==KErrNone);
       
    91 
       
    92 	TRequestStatus rxs, txs;
       
    93 	TRequestStatus* pS=&txs;
       
    94 	User::RequestComplete(pS,0);
       
    95 
       
    96 	TInt pos=0;
       
    97 	FOREVER
       
    98 		{
       
    99 		TPtr8 dptr(Buffer+pos,0,KBufferSize);
       
   100 		comm.ReadOneOrMore(rxs,dptr);
       
   101 		User::WaitForRequest(rxs);
       
   102 		if (rxs!=KErrNone)
       
   103 			test.Printf(_L("RX error %d\n"),rxs.Int());
       
   104 		User::WaitForRequest(txs);
       
   105 		if (txs!=KErrNone)
       
   106 			test.Printf(_L("TX error %d\n"),txs.Int());
       
   107 		comm.Write(txs,dptr);
       
   108 		if (pos)
       
   109 			pos=0;
       
   110 		else
       
   111 			pos=KBufferSize;
       
   112 		}
       
   113 	}