os/kernelhwsrv/kerneltest/e32test/misc/t_lbk.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\misc\t_lbk.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32test.h>
sl@0
    19
#include <d32comm.h>
sl@0
    20
sl@0
    21
RTest test(_L("LoopBack"));
sl@0
    22
sl@0
    23
#define TEST(c)	((void)((c)||(test.Printf(_L("Failed at line %d\n"),__LINE__),test.Getch(),test(0),0)))
sl@0
    24
sl@0
    25
const TInt KBufferSize=4096;
sl@0
    26
sl@0
    27
_LIT(KLddName,"ECOMM");
sl@0
    28
_LIT(KPddName,"EUART");
sl@0
    29
sl@0
    30
TUint8 Buffer[2*KBufferSize];
sl@0
    31
sl@0
    32
void LoadCommDrivers()
sl@0
    33
	{
sl@0
    34
	test.Printf(_L("Load LDD\n"));
sl@0
    35
	TInt r=User::LoadLogicalDevice(KLddName);
sl@0
    36
	TEST(r==KErrNone || r==KErrAlreadyExists);
sl@0
    37
sl@0
    38
	TInt i;
sl@0
    39
	TInt n=0;
sl@0
    40
	for (i=-1; i<10; ++i)
sl@0
    41
		{
sl@0
    42
		TBuf<16> pddName=KPddName();
sl@0
    43
		if (i>=0)
sl@0
    44
			pddName.Append('0'+i);
sl@0
    45
		TInt r=User::LoadPhysicalDevice(pddName);
sl@0
    46
		if (r==KErrNone || r==KErrAlreadyExists)
sl@0
    47
			{
sl@0
    48
			++n;
sl@0
    49
			test.Printf(_L("%S found\n"),&pddName);
sl@0
    50
			}
sl@0
    51
		}
sl@0
    52
	TEST(n!=0);
sl@0
    53
	}
sl@0
    54
sl@0
    55
GLDEF_C TInt E32Main()
sl@0
    56
	{
sl@0
    57
	RThread().SetPriority(EPriorityAbsoluteForeground);
sl@0
    58
	test.SetLogged(EFalse);
sl@0
    59
	test.Title();
sl@0
    60
sl@0
    61
	TBuf<256> cmd;
sl@0
    62
	User::CommandLine(cmd);
sl@0
    63
	TInt port=0;
sl@0
    64
	if (cmd.Length()!=0)
sl@0
    65
		{
sl@0
    66
		TUint8 c=(TUint8)cmd[0];
sl@0
    67
		if (c>='0' && c<='9')
sl@0
    68
			{
sl@0
    69
			port=c-'0';
sl@0
    70
			}
sl@0
    71
		}
sl@0
    72
sl@0
    73
	TInt r=KErrNone;
sl@0
    74
	LoadCommDrivers();
sl@0
    75
sl@0
    76
	RBusDevComm comm;
sl@0
    77
	r=comm.Open(port);
sl@0
    78
	test(r==KErrNone);
sl@0
    79
	TCommConfig cfg;
sl@0
    80
	TCommConfigV01& c=cfg();
sl@0
    81
	comm.Config(cfg);
sl@0
    82
	c.iRate=EBps115200;
sl@0
    83
	c.iDataBits=EData8;
sl@0
    84
	c.iStopBits=EStop1;
sl@0
    85
	c.iParity=EParityNone;
sl@0
    86
	c.iHandshake=0;
sl@0
    87
	c.iFifo=EFifoEnable;
sl@0
    88
	c.iTerminatorCount=0;
sl@0
    89
	r=comm.SetConfig(cfg);
sl@0
    90
	test(r==KErrNone);
sl@0
    91
sl@0
    92
	TRequestStatus rxs, txs;
sl@0
    93
	TRequestStatus* pS=&txs;
sl@0
    94
	User::RequestComplete(pS,0);
sl@0
    95
sl@0
    96
	TInt pos=0;
sl@0
    97
	FOREVER
sl@0
    98
		{
sl@0
    99
		TPtr8 dptr(Buffer+pos,0,KBufferSize);
sl@0
   100
		comm.ReadOneOrMore(rxs,dptr);
sl@0
   101
		User::WaitForRequest(rxs);
sl@0
   102
		if (rxs!=KErrNone)
sl@0
   103
			test.Printf(_L("RX error %d\n"),rxs.Int());
sl@0
   104
		User::WaitForRequest(txs);
sl@0
   105
		if (txs!=KErrNone)
sl@0
   106
			test.Printf(_L("TX error %d\n"),txs.Int());
sl@0
   107
		comm.Write(txs,dptr);
sl@0
   108
		if (pos)
sl@0
   109
			pos=0;
sl@0
   110
		else
sl@0
   111
			pos=KBufferSize;
sl@0
   112
		}
sl@0
   113
	}