os/kernelhwsrv/kerneltest/e32test/personality/example/t_expers.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/personality/example/t_expers.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,199 @@
     1.4 +// Copyright (c) 1997-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\personality\example\t_expers.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32base.h>
    1.22 +#include <e32base_private.h>
    1.23 +#include <e32test.h>
    1.24 +#include "ifcldd.h"
    1.25 +#include "../../misc/prbs.h"
    1.26 +
    1.27 +RTest test(_L("EXAMPLE PERSONALITY"));
    1.28 +
    1.29 +_LIT(KIfcLddName,"expers.ldd");
    1.30 +
    1.31 +class CRxData : public CActive
    1.32 +	{
    1.33 +public:
    1.34 +	CRxData();
    1.35 +	static void New(RRtosIfc aIfc);
    1.36 +	void Start();
    1.37 +	void RunL();
    1.38 +	void DoCancel();
    1.39 +public:
    1.40 +	RRtosIfc iIfc;
    1.41 +	TUint8 iBuf[512];
    1.42 +	};
    1.43 +
    1.44 +void CRxData::New(RRtosIfc aIfc)
    1.45 +	{
    1.46 +	CRxData* p = new CRxData;
    1.47 +	test(p!=NULL);
    1.48 +	p->iIfc = aIfc;
    1.49 +	CActiveScheduler::Add(p);
    1.50 +	p->Start();
    1.51 +	}
    1.52 +
    1.53 +CRxData::CRxData()
    1.54 +	:	CActive(0)
    1.55 +	{
    1.56 +	}
    1.57 +
    1.58 +void CRxData::DoCancel()
    1.59 +	{
    1.60 +	iIfc.Cancel(RRtosIfc::ECancelReceive);
    1.61 +	}
    1.62 +
    1.63 +void CRxData::Start()
    1.64 +	{
    1.65 +	iIfc.Receive(iStatus, *(SRxData*)iBuf);
    1.66 +	SetActive();
    1.67 +	}
    1.68 +
    1.69 +void CRxData::RunL()
    1.70 +	{
    1.71 +	SRxData& rxd = *(SRxData*)iBuf;
    1.72 +	TInt l = rxd.iLength;
    1.73 +	TUint cs = 0;
    1.74 +	TInt i;
    1.75 +	for (i=0; i<l; ++i)
    1.76 +		cs += rxd.iData[i];
    1.77 +	test( (cs & 0xff) == rxd.iChecksum);
    1.78 +	test.Printf(_L("RXD: l=%02x cs=%02x\n"), l, rxd.iChecksum);
    1.79 +	Start();
    1.80 +	}
    1.81 +
    1.82 +class CReport : public CActive
    1.83 +	{
    1.84 +public:
    1.85 +	CReport();
    1.86 +	static void New(RRtosIfc aIfc);
    1.87 +	void Start();
    1.88 +	void RunL();
    1.89 +	void DoCancel();
    1.90 +	void SendData();
    1.91 +public:
    1.92 +	RRtosIfc iIfc;
    1.93 +	TUint iSeed[2];
    1.94 +	SReport iRpt;
    1.95 +	};
    1.96 +
    1.97 +void CReport::New(RRtosIfc aIfc)
    1.98 +	{
    1.99 +	CReport* p = new CReport;
   1.100 +	test(p!=NULL);
   1.101 +	p->iIfc = aIfc;
   1.102 +	CActiveScheduler::Add(p);
   1.103 +	p->Start();
   1.104 +	}
   1.105 +
   1.106 +CReport::CReport()
   1.107 +	:	CActive(0)
   1.108 +	{
   1.109 +	iSeed[0] = 0xb504f333;
   1.110 +	}
   1.111 +
   1.112 +void CReport::DoCancel()
   1.113 +	{
   1.114 +	iIfc.Cancel(RRtosIfc::ECancelReport);
   1.115 +	}
   1.116 +
   1.117 +void CReport::Start()
   1.118 +	{
   1.119 +	iIfc.Report(iStatus, iRpt);
   1.120 +	SetActive();
   1.121 +	}
   1.122 +
   1.123 +void CReport::RunL()
   1.124 +	{
   1.125 +	switch (iRpt.iType)
   1.126 +		{
   1.127 +		case SReport::ESem:
   1.128 +			test.Printf(_L("SEM: C:%10d OK:%10d BAD:%10d\n"), iRpt.iCount, iRpt.iOkCount, iRpt.iBadCount);
   1.129 +			if (iRpt.iOkCount>1000000)
   1.130 +				CActiveScheduler::Stop();
   1.131 +			break;
   1.132 +		case SReport::ERcv:
   1.133 +			test.Printf(_L("RCV: C:%10d OK:%10d BAD:%10d\n"), iRpt.iCount, iRpt.iOkCount, iRpt.iBadCount);
   1.134 +			break;
   1.135 +		case SReport::ETm:
   1.136 +			test.Printf(_L("TM: C:%10d\n"), iRpt.iCount);
   1.137 +#ifndef __EPOC32__
   1.138 +			if (iRpt.iCount > 100000)
   1.139 +				CActiveScheduler::Stop();
   1.140 +#endif
   1.141 +			TUint x = Random(iSeed) & 3;
   1.142 +			if (x==3)
   1.143 +				SendData();
   1.144 +			if (x)
   1.145 +				SendData();
   1.146 +			else
   1.147 +				iIfc.FlushData();
   1.148 +			break;
   1.149 +		}
   1.150 +	Start();
   1.151 +	}
   1.152 +
   1.153 +void CReport::SendData()
   1.154 +	{
   1.155 +	TInt l = (Random(iSeed)&127)+128;
   1.156 +	TUint buf[64];
   1.157 +	TInt i;
   1.158 +	for (i=0; i<64; ++i)
   1.159 +		buf[i] = Random(iSeed);
   1.160 +	TPtrC8 ptr((const TUint8*)buf, l);
   1.161 +	TInt r = iIfc.SendData(ptr);
   1.162 +	test(r==KErrNone);
   1.163 +	}
   1.164 +
   1.165 +
   1.166 +GLDEF_C TInt E32Main()
   1.167 +	{
   1.168 +	test.Title();
   1.169 +	test.Start(_L("Load interface LDD"));
   1.170 +
   1.171 +	TInt r = User::LoadLogicalDevice(KIfcLddName);
   1.172 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.173 +
   1.174 +	test.Next(_L("Open channel"));
   1.175 +	RRtosIfc ifc;
   1.176 +	RThread().SetPriority(EPriorityAbsoluteHigh);
   1.177 +	r = ifc.Open();
   1.178 +	test(r==KErrNone);
   1.179 +
   1.180 +	test.Next(_L("Start personality tests"));
   1.181 +	ifc.Init();
   1.182 +
   1.183 +	TRequestStatus s;
   1.184 +	ifc.WaitInitialTests(s);
   1.185 +	User::WaitForRequest(s);
   1.186 +	test(s==KErrNone);
   1.187 +
   1.188 +	CActiveScheduler* as = new CActiveScheduler;
   1.189 +	test(as!=NULL);
   1.190 +	CActiveScheduler::Install(as);
   1.191 +	CRxData::New(ifc);
   1.192 +	CReport::New(ifc);
   1.193 +
   1.194 +	CActiveScheduler::Start();
   1.195 +
   1.196 +	ifc.Finish();
   1.197 +	ifc.Close();
   1.198 +
   1.199 +	test.End();
   1.200 +	return 0;
   1.201 +	}
   1.202 +